mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Math

Reply
 
Thread Tools
Old 2004-12-24, 00:43   #1
dave_dm
 
May 2004

24×5 Posts
Default Montgomery Multiplication

I'm considering writing a 32-bit modular Montgomery reduction routine. This obviously needs to be hand-coded in asm, so experience tells me I should probably ask around first.

On x86 hardware, the naive method of reducing a 64-bit integer modulo a 32-bit integer uses a single DIV instruction which IIRC takes about 17 cycles. When doing a Montgomery reduction, we do two multiplies (3 cycles each), an addition and a contitional subtraction. I assume that it's worth doing some SBB magic to work around the conditional flushing of cache lines every so often.

So, that all done, I can't really see 32-bit Montgomery reduction being faster than a DIV instruction. Has anyone tried this out?

Dave
dave_dm is offline   Reply With Quote
Old 2004-12-24, 05:18   #2
axn
 
axn's Avatar
 
Jun 2003

471210 Posts
Default

I think the DIV takes 37 cycles, not 17 (not sure)
axn is offline   Reply With Quote
Old 2004-12-24, 11:00   #3
dave_dm
 
May 2004

24×5 Posts
Default

I had a look in the AMD White Paper 22007 and it seems to say that a 32-bit division has a latency of 40 cycles (=lots). So your figure of 37 is probably right for some particular species of x86.

The figure of 17 seems to be only of historical interest as it's the latency of a 8-bit division. Eugh!

Dave
dave_dm is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Peter Montgomery's Thesis mickfrancis Computer Science & Computational Number Theory 3 2015-06-25 14:32
Peter Montgomery (IMPORTANT) R.D. Silverman Factoring 8 2014-06-07 18:43
Montgomery method in Prime Numbers: ACP SPWorley Math 5 2009-08-18 17:27
Montgomery powering T.Rex Math 10 2006-04-18 06:57
VIA C7 Montgomery Multiplier? akruppa Hardware 1 2005-08-04 10:25

All times are UTC. The time now is 04:13.

Sat Oct 24 04:13:49 UTC 2020 up 44 days, 1:24, 1 user, load averages: 1.44, 1.58, 1.47

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.