NB. 32 bit adder (circuit model) NB. Constructed from 2 - sixteenBitAdder'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. SixteenBitAdder sixteenBitAdder =: monad define 'a15 a14 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 cin' =. y. t0 =. fourBitAdder a3, a2, a1, a0, b3, b2, b1, b0, cin t1 =. fourBitAdder a7, a6, a5, a4, b7, b6, b5, b4, wireOutput 0 ; t0 t2 =. fourBitAdder a11, a10, a9, a8, b11, b10, b9, b8, wireOutput 0 ; t1 t3 =. fourBitAdder a15, a14, a13, a12, b15, b14, b13, b12, wireOutput 0 ; t2 (wireOutput 0 1 2 3 4 ; t3) , (wireOutput 1 2 3 4 ; t2) , (wireOutput 1 2 3 4 ; t1) , wireOutput 1 2 3 4 ; t0 ) NB. thirtytwoBitAdder thirtytwoBitAdder =: monad define 'a b cin' =: dtb y. t0 =: sixteenBitAdder (16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 { a) , (16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 { b) , 31 { cin t1 =: sixteenBitAdder (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { a) , (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { b) , wireOutput 0 ; t0 btd (wireOutput 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; t1) , wireOutput 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; t0 ) NB. thirtytwoBitALU thirtytwoBitALU =: monad define 'a b cin' =: y. a =: dtb a b =: bitXor rank 1 cin , rank 0 dtb b t0 =. sixteenBitAdder (16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 { a) , (16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 { b) , cin t1 =. sixteenBitAdder (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { a) , (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { b) , wireOutput 0 ; t0 btd (wireOutput 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; t1) , wireOutput 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; 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 ,. 2147483648 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