From: James Cloos <cloos@jhcloos.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: linux-kernel@vger.kernel.org,
"Linux-MIPS" <linux-mips@linux-mips.org>,
Florian Fainelli <florian@openwrt.org>,
Andrew Morton <akpm@linux-foundation.org>,
Takashi Iwai <tiwai@suse.de>, Ralf Baechle <ralf@linux-mips.org>
Subject: Re: [PATCH 1/8] add lib/gcd.c
Date: Sat, 13 Jun 2009 15:54:38 -0400 [thread overview]
Message-ID: <m3my8bvrhl.fsf@lugabout.jhcloos.org> (raw)
In-Reply-To: <m3ocssw2sw.fsf@lugabout.jhcloos.org> (James Cloos's message of "Sat, 13 Jun 2009 11:50:15 -0400")
>>>>> "|" == James Cloos <cloos@jhcloos.com> writes:
>>>>> "Alan" == Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
|> Would the binary gcd algorithm not be a better fit for the kernel?
Alan> Could well be the shift based one is better for some processors only.
|> Very likely, I suspect.
|> In any case, I do not have the hardware to do any statistically
|> significant testing;
I take that back. Just in case speed is a relevant issue, I ran a test
on my MX, which is a small xen domU running on a:
,----
| EFamily: 0 EModel: 0 Family: 6 Model: 15 Stepping: 11
| CPU Model: Core 2 Quad
| Processor name string: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
`----
I got, compiling with gcc-4.4 -march=native -O3:
binary
408.39user 0.05system 6:52.75elapsed 98%CPU
quick (the code in the kernel)
600.96user 0.16system 10:19.06elapsed 97%CPU
contfrac (the typical euclid algo)
569.19user 0.12system 9:35.50elapsed 98%CPU
extended euclid (calculates g=ia+jb=gcd(a,b))
684.53user 0.13system 11:32.77elapsed 98%CPU
I also tried on an old Alpha at freeshell; it had gcc-3.3; gcc's -S
output looks like it uses hardware div there, just like it does on
x86 and amd64. The bgcd, though, was 10-16 times faster than either
version of euclid's algo.
On my laptop's P3M, binary gcd was about twice as fast as euclid.
So, although modern processors are *much* better at int div, the
binary gcd algo is still faster.
The timings on the alpha and the laptop were of:
for (a=0xFFF; a > 0; a--)
for (b=a; b > 0; b--)
g=gcd(a,b);
For the core2 times quoted above, I started with a=0xFFFF.
And I forgot to mention: the bgcd code I posted was based on
some old notes of mine which most likely trace to TAoCP.
-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 1024D/ED7DAEA6
prev parent reply other threads:[~2009-06-13 19:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-04 14:15 Florian Fainelli
2009-06-04 14:21 ` Sergei Shtylyov
2009-06-04 14:31 ` Sergei Shtylyov
2009-06-04 14:39 ` Florian Fainelli
2009-06-04 15:57 ` Joe Perches
2009-06-04 19:03 ` Andrew Morton
2009-06-04 22:41 ` Andrew Morton
2009-06-13 12:16 ` James Cloos
2009-06-13 15:28 ` Alan Cox
2009-06-13 15:50 ` James Cloos
2009-06-13 19:54 ` James Cloos [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3my8bvrhl.fsf@lugabout.jhcloos.org \
--to=cloos@jhcloos.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=florian@openwrt.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome