NB. 32 bit adder (circuit model) NB. Constructed from 8 - fourBitAdder's require 'circuits.ijs' dtb =: (32 # 2) & #: signed_value =: monad define digits =. # y. if. 1 = 1 take y. do. ((digits copy 2) base x: y. ) - 2^ x: digits else. (digits copy 2) base x: y. end. ) btd =: signed_value NB. thirtytwoBitAdder thirtytwoBitAdder =: monad define 'a b cin' =. dtb y. t0 =. fourBitAdder (28 29 30 31 { a) , (28 29 30 31 { b) , 31 { cin t1 =. fourBitAdder (24 25 26 27 { a) , (24 25 26 27 { b) , wireOutput 0 ; t0 t2 =. fourBitAdder (20 21 22 23 { a) , (20 21 22 23 { b) , wireOutput 0 ; t1 t3 =. fourBitAdder (16 17 18 19 { a) , (16 17 18 19 { b) , wireOutput 0 ; t2 t4 =. fourBitAdder (12 13 14 15 { a) , (12 13 14 15 { b) , wireOutput 0 ; t3 t5 =. fourBitAdder (8 9 10 11 { a) , (8 9 10 11 { b) , wireOutput 0 ; t4 t6 =. fourBitAdder (4 5 6 7 { a) , (4 5 6 7 { b) , wireOutput 0 ; t5 t7 =. fourBitAdder (0 1 2 3 { a) , (0 1 2 3 { b) , wireOutput 0 ; t6 btd (wireOutput 1 2 3 4 ; t7) , (wireOutput 1 2 3 4 ; t6) , (wireOutput 1 2 3 4 ; t5) , (wireOutput 1 2 3 4 ; t4) , (wireOutput 1 2 3 4 ; t3) , (wireOutput 1 2 3 4 ; t2) , (wireOutput 1 2 3 4 ; t1) , wireOutput 1 2 3 4 ; t0 ) NB. thirtytwoBitALU thirtytwoBitALU =: monad define 'a b cin' =. y. a =. dtb a b =. bitXor rank 1 cin,rank 0 dtb b t0 =. fourBitAdder (28 29 30 31 { a) , (28 29 30 31 { b) , cin t1 =. fourBitAdder (24 25 26 27 { a) , (24 25 26 27 { b) , wireOutput 0 ; t0 t2 =. fourBitAdder (20 21 22 23 { a) , (20 21 22 23 { b) , wireOutput 0 ; t1 t3 =. fourBitAdder (16 17 18 19 { a) , (16 17 18 19 { b) , wireOutput 0 ; t2 t4 =. fourBitAdder (12 13 14 15 { a) , (12 13 14 15 { b) , wireOutput 0 ; t3 t5 =. fourBitAdder (8 9 10 11 { a) , (8 9 10 11 { b) , wireOutput 0 ; t4 t6 =. fourBitAdder (4 5 6 7 { a) , (4 5 6 7 { b) , wireOutput 0 ; t5 t7 =. fourBitAdder (0 1 2 3 { a) , (0 1 2 3 { b) , wireOutput 0 ; t6 btd (wireOutput 1 2 3 4 ; t7) , (wireOutput 1 2 3 4 ; t6) , (wireOutput 1 2 3 4 ; t5) , (wireOutput 1 2 3 4 ; t4) , (wireOutput 1 2 3 4 ; t3) , (wireOutput 1 2 3 4 ; t2) , (wireOutput 1 2 3 4 ; t1) , wireOutput 1 2 3 4 ; t0 ) NB. synonym for thirtytwoBitAdder tba =: thirtytwoBitAdder NB. A test suite of border-line values test =: transpose 0 1 0x ,. _1 1 0x ,. _1 1 1x ,. 4294967295 1 0x ,. _4294967296 1 0x ,. 4294967295 2 0x ,. _4294967296 _1 0x ,. 4294967295 4294967295 0x ,. _4294967296 _4294967296 0x ,. 3 2 1x NB. To test outputs, test ,. tba rows test NB. To test outputs, test ,. thirtytwoBitALU rows test