Binary method for calculating hardware/Software mults/divs.

Started by
21 comments, last by Dmytry 19 years, 1 month ago
Zipster?

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Advertisement
Mr zipster, i think that you said that you would post it.....

Anybody else?

....


Anybody?

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Look into that nice thread

Everything through basic binary operators.
Dmitry [lol]. Thats a little... off-center.

Is anything better then the multi-add-with-shift design for multiplication? (currently, this would be huge, in the 100clock range.)

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Ok, my best is using the binary method.

basically if i can get the last bit nicely, then i'm set.

B0 = a & e
B1 = (a & f) | (b & e)

Ect.

But how would i quickly work out the parity of a group of bits? (ie. if the number of bits is odd or even?)

From,
Nice coder

Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Quote:Original post by Nice Coder
Dmitry [lol]. Thats a little... off-center.

Is anything better then the multi-add-with-shift design for multiplication? (currently, this would be huge, in the 100clock range.)

From,
Nice coder

don't think there's better ways of doing multiplication. You can have small multiplication table for 4bit multiplications, and use them instead. Basically same thing as multiplying decimal numbers manually.

As about division, from that thread,

//subtraction is needed for division. Of course i can do cool subtraction via cool addition,but it's...inelegantint coolsub(int a,int b){	int c,result, tmp;	c=((~a)&b)<<1;	result=a^b;	while(c!=0){		tmp=result^c;		c=((~result)&c)<<1;		result=tmp;	};	return result;};const high_bit=( ~((unsigned int)(0)) ^ (~((unsigned int)(0))>>1) );int cooldivide(int a,int b){	if(b==0)return 0;//division by zero. What i should return....	if(b==1)return a;	int s=0;	//note that general >,<,<=,>= do subtraction :)      	if(a&high_bit){a=coolsub(0,a);s=1;}	if(b&high_bit){b=coolsub(0,b);s^=1;}	int c,d,m=1,r=0;	c=b;	d=c<<1;	while(d>c){		c=d;		d<<=1;		m<<=1;	}	int e=a;	int k=0;	do{		k=coolsub(e,c);		if((k&high_bit)==0){e=k;r+=m;};		m>>=1;		c>>=1;		}while((m!=0)&&(e!=0));	if(s){return coolsub(0,r);}else{return r;}}


you can replace coolsub with "-" if you like.
Ok, say i have 4 bits, a,b,c and d.

Truth table0000 = 00001 = 10010 = 10011 = 00100 = 10101 = 00110 = 00111 = 11000 = 11001 = 01010 = 01011 = 11100 = 01101 = 11110 = 11111 = 0


Maybe someone else can work this out.... Its stumping me.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Dmitry - Considering that i'm doing all this on hardware, (for one of the banks).

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Ok. Parity = a ^ b ^ c ^ d
Picking a line
0111 = 1

0 ^ 1 = 1
1 ^ 1 = 0

Result = 1 ^ 0 = 1

Now, its cumative, sao i can use a tree based approach. Log2 n time (even though most of it is done beforehand.)

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Now the algorithm reads:

B0 = ae
B1 = af ^ be
B2 = ag ^ af ^ ce
B3 = ah ^ bg ^ cf ^ de
B4 = bh ^ cg ^ df
B5 = ch ^ dg
B6 = dh

Now, this is 4 bit arithmatic
so we go up to B3 which is
B0 = ae
B1 = af ^ be
B2 = ag ^ af ^ ce
B3 = ah ^ bg ^ cf ^ de
Now, we have overflow which is
Overflow = (bh ^ cg ^ df) | (ch ^ dg) | (dh)

Thats 4 bit mult + overflow. Also very fast.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.

This topic is closed to new replies.

Advertisement