kern/135718: [PATCH] enhance qsort(3) to properly handle 32-bit
aligned data on 64-bit systems
Jay Howard
jhoward at alumni.utexas.net
Fri Jun 19 04:10:04 UTC 2009
The following reply was made to PR kern/135718; it has been noted by GNATS.
From: Jay Howard <jhoward at alumni.utexas.net>
To: bug-followup at 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 at 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 at 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'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'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'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) > 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>begin 600 qsort.c.patch<br>M+2TM('%S;W)T+F,),C`P.=
2TP-BTQ.2`P,CHR-CHQ-RXP,#`P,#`P,#`@*S`P<br>M,#`**RLK('%S;W)T+F,N<&am=
p;%T8VAE9`DR,#`Y+3`V+3$Y(#`S.C`W.C`Y+C`P<br>M,#`P,#`P,"`K,#`P,`I`0&quo=
t;`M-3DL."`K-3DL.2!`0`H@("`@("`@("!]('=3DH<br>
M:6QE("@M+6D@/B`P*3L)"0D)7`H@?0H@"BTC9&5F:6YE(%-705!)3DE=
4*&$L<br>M(&5S*2!S=3DV%P=3D'EP92`]("@H8VAA<B`J*6$@+2`H8=
VAA<B`J*3`I("4@<VEZ<br>M96]F*&QO;F<I('Q\(%P*+0EE<R=
`E('-I>F5O9BAL;VYG*2`_(#(@.B!E<R`]<br>
M/2!S:7IE;V8H;&]N9RD_(#`@.B`Q.PHK(V1E9FEN92!35T%024Y)5"AA+"!E=
<br>M<RD@<W=3DA<'1Y<&4@/2`H*&-H87(@*BEA("T@*&a=
mp;-H87(@*BDP*2`E('-I>F5O<br>M9BAI;G0I('Q\(%P**PEE<R`E('-=
I>F5O9BAI;G0I(#\@,B`Z("@H8VAA<B`J<br>
M*6$@+2`H8VAA<B`J*3`I("4@<VEZ96]F*&QO;F<I(#\@,2`Z(%P**PEE=
<R`A<br>M/2!S:7IE;V8H;&]N9RD["B`*('-T871I8R!I;FQI;F4@=3DF]I=
9`H@<W=3DA<&9U<br>M;F,H82P at 8BP@;BP@<W=3DA<'1Y<&4=
I"D!`("TV."PW("LV.2PW($!`"B`):6YT<br>
M(&XL('-W87!T>7!<a href=3D"http://E.PH">E.PH</a>@>PH@"6E=
F*'-W87!T>7!E(#P](#$I"BT)"7-W87!C<br>M;V1E*&QO;F<L(=
&$L(&(L(&XI"BL)"7-W87!C;V1E*&EN=3D"P at 82P@8BP=
@;BD*<br>
E(`EE;'-E"B`)"7-W87!C;V1E*&-H87(L(&$L(&(L(&XI=
"B!]"BP@<br>`<br>end<br><br>
--0016e6db61c045af8e046cab2fd7--
More information about the freebsd-bugs
mailing list