Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Jun 2009 04:10:04 GMT
From:      Jay Howard <jhoward@alumni.utexas.net>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/135718: [PATCH] enhance qsort(3) to properly handle 32-bit aligned data on 64-bit systems
Message-ID:  <200906190410.n5J4A4D6028495@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/135718; it has been noted by GNATS.

From: Jay Howard <jhoward@alumni.utexas.net>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/135718: [PATCH] enhance qsort(3) to properly handle 32-bit 
	aligned data on 64-bit systems
Date: Thu, 18 Jun 2009 22:33:15 -0500

 --0016e6db61c045af8e046cab2fd7
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 It occurs to me that a simpler solution would to just do int-by-int swaps in
 all cases when the base addr and element size are int-aligned, char-by-char
 swaps when they're not, and an inline long-swap when the base addr is
 long-aligned and element size is exactly sizeof(long).
 
 It's notable that BSD bcopy() only does int-by-int copying and makes no
 effort to do long-by-long copying when the data would permit
 
 Here's a second patch that makes the above change.
 
 On systems where sizeof(int) = sizeof(long) this version becomes identical
 to the current version.  When sizeof(long) > sizeof(int) bulk swapping
 happens int-by-int instead of long-by-long.  Inline swaps are still used
 when the base is long-aligned and element size = sizeof(long).
 
 uuencoded:
 
 begin 600 qsort.c.patch
 M+2TM('%S;W)T+F,),C`P.2TP-BTQ.2`P,CHR-CHQ-RXP,#`P,#`P,#`@*S`P
 M,#`**RLK('%S;W)T+F,N<&%T8VAE9`DR,#`Y+3`V+3$Y(#`S.C`W.C`Y+C`P
 M,#`P,#`P,"`K,#`P,`I`0"`M-3DL."`K-3DL.2!`0`H@("`@("`@("!]('=H
 M:6QE("@M+6D@/B`P*3L)"0D)7`H@?0H@"BTC9&5F:6YE(%-705!)3DE4*&$L
 M(&5S*2!S=V%P='EP92`]("@H8VAA<B`J*6$@+2`H8VAA<B`J*3`I("4@<VEZ
 M96]F*&QO;F<I('Q\(%P*+0EE<R`E('-I>F5O9BAL;VYG*2`_(#(@.B!E<R`]
 M/2!S:7IE;V8H;&]N9RD_(#`@.B`Q.PHK(V1E9FEN92!35T%024Y)5"AA+"!E
 M<RD@<W=A<'1Y<&4@/2`H*&-H87(@*BEA("T@*&-H87(@*BDP*2`E('-I>F5O
 M9BAI;G0I('Q\(%P**PEE<R`E('-I>F5O9BAI;G0I(#\@,B`Z("@H8VAA<B`J
 M*6$@+2`H8VAA<B`J*3`I("4@<VEZ96]F*&QO;F<I(#\@,2`Z(%P**PEE<R`A
 M/2!S:7IE;V8H;&]N9RD["B`*('-T871I8R!I;FQI;F4@=F]I9`H@<W=A<&9U
 M;F,H82P@8BP@;BP@<W=A<'1Y<&4I"D!`("TV."PW("LV.2PW($!`"B`):6YT
 M(&XL('-W87!T>7!E.PH@>PH@"6EF*'-W87!T>7!E(#P](#$I"BT)"7-W87!C
 M;V1E*&QO;F<L(&$L(&(L(&XI"BL)"7-W87!C;V1E*&EN="P@82P@8BP@;BD*
 E(`EE;'-E"B`)"7-W87!C;V1E*&-H87(L(&$L(&(L(&XI"B!]"BP@
 `
 end
 
 --0016e6db61c045af8e046cab2fd7
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 It occurs to me that a simpler solution would to just do int-by-int swaps i=
 n all cases when the base addr and element size are int-aligned, char-by-ch=
 ar swaps when they&#39;re not, and an inline long-swap when the base addr i=
 s long-aligned and element size is exactly sizeof(long).<br>
 <br>It&#39;s notable that BSD bcopy() only does int-by-int copying and make=
 s no effort to do long-by-long copying when the data would permit<br><br>He=
 re&#39;s a second patch that makes the above change.<br><br>On systems wher=
 e sizeof(int) =3D sizeof(long) this version becomes identical to the curren=
 t version.=A0 When sizeof(long) &gt; sizeof(int) bulk swapping happens int-=
 by-int instead of long-by-long.=A0 Inline swaps are still used when the bas=
 e is long-aligned and element size =3D sizeof(long).<br>
 <br>uuencoded:<br><br>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(&quot;LV.2PW($!`&quot;B`):6YT<br>
 M(&amp;XL(&#39;-W87!T&gt;7!<a href=3D"http://E.PH">E.PH</a>@&gt;PH@&quot;6E=
 F*&#39;-W87!T&gt;7!E(#P](#$I&quot;BT)&quot;7-W87!C<br>M;V1E*&amp;QO;F&lt;L(=
 &amp;$L(&amp;(L(&amp;XI&quot;BL)&quot;7-W87!C;V1E*&amp;EN=3D&quot;P@82P@8BP=
 @;BD*<br>
 E(`EE;&#39;-E&quot;B`)&quot;7-W87!C;V1E*&amp;-H87(L(&amp;$L(&amp;(L(&amp;XI=
 &quot;B!]&quot;BP@<br>`<br>end<br><br>
 
 --0016e6db61c045af8e046cab2fd7--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906190410.n5J4A4D6028495>