From owner-freebsd-bugs@FreeBSD.ORG Fri Jun 19 04:10:04 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 955041065674 for ; Fri, 19 Jun 2009 04:10:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 81E138FC12 for ; Fri, 19 Jun 2009 04:10:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n5J4A4HS028496 for ; Fri, 19 Jun 2009 04:10:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n5J4A4D6028495; Fri, 19 Jun 2009 04:10:04 GMT (envelope-from gnats) Date: Fri, 19 Jun 2009 04:10:04 GMT Message-Id: <200906190410.n5J4A4D6028495@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jay Howard Cc: Subject: Re: kern/135718: [PATCH] enhance qsort(3) to properly handle 32-bit aligned data on 64-bit systems X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jay Howard List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jun 2009 04:10:04 -0000 The following reply was made to PR kern/135718; it has been noted by GNATS. From: Jay Howard 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`]("@H8VAAF5O9BAL;VYG*2`_(#(@.B!EF5O M9BAI;G0I('Q\(%P**PEEF5O9BAI;G0I(#\@,B`Z("@H8VAA7!E.PH@>PH@"6EF*'-W87!T>7!E(#P](#$I"BT)"7-W87!C M;V1E*&QO;F
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

He= re's a second patch that makes the above change.

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).

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<&am= p;%T8VAE9`DR,#`Y+3`V+3$Y(#`S.C`W.C`Y+C`P
M,#`P,#`P,"`K,#`P,`I`0&quo= t;`M-3DL."`K-3DL.2!`0`H@("`@("`@("!]('=3DH
M:6QE("@M+6D@/B`P*3L)"0D)7`H@?0H@"BTC9&5F:6YE(%-705!)3DE= 4*&$L
M(&5S*2!S=3DV%P=3D'EP92`]("@H8VAA<B`J*6$@+2`H8= VAA<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=3DA<'1Y<&4@/2`H*&-H87(@*BEA("T@*&a= mp;-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@=3DF]I= 9`H@<W=3DA<&9U
M;F,H82P@8BP@;BP@<W=3DA<'1Y<&4= I"D!`("TV."PW("LV.2PW($!`"B`):6YT
M(&XL('-W87!T>7!E.PH@>PH@"6E= F*'-W87!T>7!E(#P](#$I"BT)"7-W87!C
M;V1E*&QO;F<L(= &$L(&(L(&XI"BL)"7-W87!C;V1E*&EN=3D"P@82P@8BP= @;BD*
E(`EE;'-E"B`)"7-W87!C;V1E*&-H87(L(&$L(&(L(&XI= "B!]"BP@
`
end

--0016e6db61c045af8e046cab2fd7--