flat assembler
Message board for the users of flat assembler.
Index
> Main > Long signed multiplication 
Author 

Tomasz Grysztar
You may find some notes about it here.


17 Mar 2010, 06:11 

edemko
LocoDelAssembly
I'm trying to do 64x64 to get 128bit answer, but the code and description I've seen so far takes the absolute value of the operands and then performs negation of the 128 result when the sign of the operands were different. Code: Use sign xorring: 0 xor 0 = 0 ; '+' * '+' = '+' 1 xor 1 = 0 ; '' * '' = '+' 0 xor 1 = 1 ; '+' * '' = '' 1 xor 0 = 1 ; '' * '+' = '' My question: "xoring" or "xorring"? 

17 Mar 2010, 08:16 

revolution
Without sign detection (i.e. ignore the sign bits) you can get the lower half of the result without any extra code. It is only the high half that creates the difference.
64x64 > 64 means you don't have to care about the sign bits. 128x128 > 128 means you don't have to care about the sign bits. 64x64 > 128 means you do have to consider the sign bits. There really is no other way. 

17 Mar 2010, 08:27 

edemko
revolution
Without sign detection (i.e. ignore the sign bits) you can get the lower half of the result without any extra code. It is only the high half that creates the difference. 1, what will you say? revolution 64x64 > 64 128x128 > 128 64x64 > 128 64 bit signed * 64 bit signed = as maximum (2^64)1 * (2^64)1 = (2^128)(2^641) ~ 2^128 i.e. > 128 revolution once told this and now is negating himself It may happen i did not understand that "64x64 > 64" etc. 

17 Mar 2010, 08:46 

edemko
128 means log(2;64 signed * 64 signed)


17 Mar 2010, 08:48 

revolution
serfasm wrote: 1, what will you say? 1 * 1 = 1 (2^641) * (2^641) = (0xff...fe00..01) or 0x00...01 when just taking the lower 64 bits. 

17 Mar 2010, 08:55 

edemko
i wrote
64 bit signed * 64 bit signed = as maximum (2^64)1 * (2^64)1 = (2^128)(2^641) ~ 2^128 i.e. > 128 wrong minuend 1 used, 2 must be 

17 Mar 2010, 10:04 

edemko
LocoDelAssembly, do you prefer general purpose registers only?


17 Mar 2010, 10:23 

LocoDelAssembly
Got it, thanks guys.


17 Mar 2010, 15:55 

edemko
LocoDelAssembly, i was a bit wrong with the ranges.
Maximum one we may get is (maximum negative)^2 i.e. there will be positive: 2^63 * 2^63 = 2^126 = = 0100..0b = $4..0. As you can see, multiplying 64*64, 128bit got. At my oppinion 64 * 64 is the easiest. If you fill difficult with those loongish numbers imagine xxxxb is a dword then xxxx'xxxxb will be a qword. Hence 1000'0000b is max.neg and 0111'1111b is max.pos. Tomasz calls this extrapolation(and he is right). Well, max.pos*max.pos < max.neg.*max.neg = (2^631)^2 < extrapolation. Remembering that (a+b)^2 = (a+b)(a+b) = aa+ab+ba+bb = a^2+2ab+b^2 we get (2^63)^2 + 2*2^63*(1) + (1)^2 = 2^126  2^1*2^63 + 1 = 2^126  2^64 + 1 = 2^1261  2^641 + 3. Currently i'm not at my own pc and text formating may be inconvinient, sorry. 

18 Mar 2010, 06:39 

< Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992020, Tomasz Grysztar.
Powered by rwasa.