Sunday, March 18, 2012

First step to optimize ALU

I found a good schematic for look ahead carry adder 4 bit and added it to my 4bit adder. But before I did that I was thinking why would adding more gates make it go any faster then I thought the adding part the less gates it acutely goes through the faster and since the carry is just essentially copying the input and working on it in parallel of the actually addition I can see how it could be a lot faster. With no further ado here is the code I got from the schematic.

[code]

CHIP Add4 {
    IN a[4], b[4],c;
    OUT out[4],carry;

    PARTS:
This is my first 4bit adder
/* HalfAdder(a=a[0],b=b[0], sum=out[0], carry=c1);
FullAdder(a=c1,b=a[1],c=b[1],sum=out[1],carry=outa3);
FullAdder(a=outa3,b=a[2],c=b[2],sum=out[2],carry=outa4);
FullAdder(a=outa4,b=a[3],c=b[3],sum=out[3],carry=outa5);*/

//A0 B0
And(a=a[0],b=b[0],out=out1);
Or(a=a[0],b=b[0],out=out2);

And(a=out2,b=c,out=out3);//needs an input
Or(a=out1,b=out3,out=out4);

Not(in=out2,out=out5);

Or(a=out5,b=out1,out=out6);

Xor(a=out6,b=c,out=out7);//needs an input
Not(in=out7,out=out[0]);

//A1 B1
And(a=a[1],b=b[1],out=out11);
Or(a=a[1],b=b[1],out=out21);

And(a=out21,b=out4,out=out31);//needs an input
Or(a=out31,b=out11,out=out41);

Not(in=out21,out=out51);

Or(a=out51,b=out11,out=out61);

Xor(a=out61,b=out4,out=out71);//needs an input
Not(in=out71,out=out[1]);

//A2 B2
And(a=a[2],b=b[2],out=out12);
Or(a=a[2],b=b[2],out=out22);

And(a=out22,b=out41,out=out32);//needs an input
Or(a=out32,b=out12,out=out42);

Not(in=out22,out=out52);

Or(a=out52,b=out12,out=out62);

Xor(a=out62,b=out41,out=out72);//needs an input
Not(in=out72,out=out[2]);

//A3 B3
And(a=a[3],b=b[3],out=out13);
Or(a=a[3],b=b[3],out=out23);

//And(a=out2,b=,out=out3);//needs an input
//Or(a=out3,b=b[0],out=out4);

Not(in=out23,out=out53);

Or(a=out53,b=out13,out=out63);

Xor(a=out63,b=out42,out=out73);//needs an input
Not(in=out73,out=out[3]);

//C1
//4 way and
And(a=out1,b=out21,out=cout1);
And(a=cout1,b=out22,out=cout2);
And(a=cout2,b=out23,out=cout3);//out
//3 way and
And(a=out11,b=out22,out=cout4);
And(a=cout4,b=out23,out=cout5);//out
//
And(a=out12,b=out23,out=cout6);//out
//4 way and
And(a=out2,b=out21,out=cout7);
And(a=cout7,b=out22,out=cout8);
And(a=cout8,b=out23,out=cout9);//out


//4 way or
Or(a=cout3,b=cout5,out=cout10);
Or(a=cout10,b=cout6,out=cout11);
Or(a=cout11,b=cout13,out=cout12);//out

And(a=cout9,b=c,out=cout13);

Or(a=cout12,b=cout13,out=carry);

}
[/code]
If any one knows how I can break this up into basic adder and faster carry sections let me know. I haven't annualized the code that close to see what would need to be done.
The more help I get the faster I can get all of this done and have a open source system that any one could build.

No comments:

Post a Comment

Search Engine Submission - AddMe