flat assembler
Message board for the users of flat assembler.
Index
> Main > Working with big numbersGoto page 1, 2 Next |
| Author |
|
|
vid 05 Dec 2007, 14:30
Thanks. Don't you happen to have direct link to this manual, and name of chapter/section where this is? I'd add it as reference to article.
Things in article are basically done same way, except for NEG and that was already pointed out by bitrake on x86asm board. Those bignum divisions are really interesting, I'd have to study them someday. |
|||
|
|
rugxulo 05 Dec 2007, 14:45
Sorry, I posted as close to a direct reference (URL) as I could.
Software Optimization Guide for AMD64 Processors - Integer Optimizations -- Efficient 64-Bit Integer Arithmatic in 32-Bit Mode |
|||
|
|
vid 05 Dec 2007, 14:50
Thanks a lot.
I plan to add bignum multiplication, and with your help even division someday to article. |
|||
|
|
MCD 07 Jan 2008, 05:41
|
|||
|
|
vid 07 Jan 2008, 11:25
MCD:
not sure about math stuff, but my O(n*log(n)) is number of MUL instructions used, probably not what math people intended. My idea is something like this: c = a*b (all number consist of 4 dwords, c0 = first dword of destination, c1 = second, etc... edx is upper 32bits of previous multiplication) Code: c0 = a0 * b0 c1 = a1 * b0 + edx c2 = a2 * b0 + edx c3 = a3 * b0 + edx c1 += a0 * b1 c2 += a1 * b1 + edx c3 += a2 * b1 + edx c2 += a0 * b2 c3 += a1 * b2 + edx c3 += a0 * b3 Isn't this O(n*log(n)) number of MUL instructions? |
|||
|
|
Madis731 07 Jan 2008, 13:19
But if you want this code to scale without loops, you need to scale your code that does the operation.
If you add 128-bit numbers with 32-bit registers you need a loop ECX=4 If you mul 128-bit numbers with 64-bit registers you can do this manually but MUL128 with R32 is tricky. You still need an algorithm, which means shifting is needed on sub-calculations. |
|||
|
|
vid 07 Jan 2008, 14:13
of course that it would be done with loops.
but number of MULs is N + (N-1) + (N-2) + (N-3) + ... + 1 isn't this O(n*log(n))? I never really knew big-O notation |
|||
|
|
LocoDelAssembly 07 Jan 2008, 14:38
The "N + (N-1) + (N-2) + (N-3) + ... + 1" is sometimes refered as the sum of the first N natural numbers (though, you wrote it in reverse order
Doing some maths: Code: 1 + 2 + ... + N-1 + N = ((1 + 2 + 3 + ... + N-2 + N-1 + N) + (N + N-1 + N-2 + ... + 3 + 2 + 1))/2 = (1+N + 2+N-1 + 3+N-2 + ... + N-2+3 + N-1+2 + N+1)/2 = (N+1 + N+1 + N+1 + ... + N+1 + N+1 + N+1)/2 = N(N+1)/2 However, while N(N+1)/2 for N=100 is 5050, log(100) is 2 and log2(100) is 6,64.. Not sure if the notation refers to log2 or log10 but non of those matches your calculation of the number of MULs |
|||
|
|
vid 07 Jan 2008, 14:54
okay, so it is O(N^2)... my bad
I was just quessing anyway... |
|||
|
|
LocoDelAssembly 07 Jan 2008, 14:57
Doesn't exists O(N(N+1)/2)? N^2 is ultra big on big Ns, much much bigger than N(N+1)/2
|
|||
|
|
Tomasz Grysztar 07 Jan 2008, 15:02
N(N+1)/2= 0.5 N^2 + 0.5 N, which is just O(N^2)
For O() notation it doesn't matter whether it is 10*N^2 or 0.0001*N^2, it's stil O(N^2) Why? Because for sizes large enough A*N^2 will always be larger than B*N and smaller than C*N^3, no matter what A, B and C are. |
|||
|
|
bitRAKE 08 Jan 2008, 05:36
I'd like to suggest working in a residual number system (RNS) because it is very parrallel in nature. It is costly to transfer between number systems, but often that only needs to be done at beginning and end of problem. Which means it is not a solution at the single operation level.
http://www.math.utah.edu/~pa/MDS/residual.html ...and it is easy to understand/implement at the code/instruction level. |
|||
|
|
MCD 08 Jan 2008, 05:41
@vid: your algorithm is just a nice and clean rearangement of the usual multiplication algorithm. But in case most of your factors are only a few times bigger than the word size of 32..64bit(maybe say up to 256..4096bits), your algorithm will suretainly outperform the others.
I can't say much more about this subject right now because I'm not into it, but if someone is interested in it, I found this interesting paper about a FFT-based big number multiply: http://citeseer.ist.psu.edu/yap00quickmul.html |
|||
|
|
Madis731 08 Jan 2008, 08:40
I dug into FFT a while ago when I wanted to perform A*B and A^B (powers not xor
|
|||
|
|
ATV 08 Jan 2008, 15:14
I have written multiply algorithms same way as you calculate with pen and paper. First code was written 1985-86 with 8bit 6502 assembly.
Later I have realize, that algorithm is very slow, better use already written librarys. Like GMP or something. They are over 10x faster. _________________ 6213186413*2^605+1 divides Fermat F(600) and 121531*2^30260+1 divides Fermat F(30256) |
|||
|
|
tom tobias 08 Jan 2008, 21:17
Madis731 wrote: ...I couldn't get the hang of FFT so I didn't convert it to using it. Any time varying signal can be expressed as a sum of a series of sinusoids. http://www.relisoft.com/Science/Physics/sound.html http://www.dspguru.com/info/faqs/fftfaq2.htm http://www.gweep.net/~shifty/portfolio/fftmulspreadsheet/index.html http://www.dataq.com/applicat/articles/an11.htm http://ccrma.stanford.edu/~lantz/fourier.html http://www.eeglossary.com/fft.htm |
|||
|
|
MCD 09 Jan 2008, 05:34
The concept around the (fast) Fourier transformation and even the discret cosinus transformation are quiet clear for me, but the thing I don't understand is how to use the FFT for things that are no functions.
Usually you apply the FFT to a function like for example f: t -> E (t being time and E being energy) to get a FFT-function of it: f_FFT: t -> E, this is what tom tobias basically said Quote:
You can generalize this to any kind of function f: x -> y where x and y are any kind of value. (This is a 1-dimensional FFT, and of course FFTs can be any higher dimensions.) now, if you don't have those 2 values, but just 1 value, like it is the case for one big number, how do you make a FFT out of that? for me there is some value missing. (The DCT is a special case of the FFT, where the function is discretized and thus the integrals become sums. Also the evaluation points of the function are even spaced and their number is a power of 2 for 1 period). |
|||
|
|
bitRAKE 09 Jan 2008, 08:25
Imagine the number is a time variant signal - each bit is in fact multiple particles moving through the circuitry! Either way (parallel or serial) we look at it the bits don't arrive at the same time.
|
|||
|
|
Picnic 22 Nov 2008, 21:45
vid wrote: hi, i wrote an article how to do basic operations with bignums (big numbers, more than 32 / 64 bits): Interesting and instructive article vid. |
|||
|
| Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.