diff options
author | Clifford Wolf <clifford@clifford.at> | 2014-08-30 18:59:05 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2014-08-30 18:59:05 +0200 |
commit | 4724d94fbce587b39cd7343dc8de3b859311f55c (patch) | |
tree | 6a1c2a9b82d48f73dbcaa3926003bbcf85b48a0f /techlibs/common/simlib.v | |
parent | 88db09255baa92facbe2736937ef113dc1503e9b (diff) | |
download | yosys-4724d94fbce587b39cd7343dc8de3b859311f55c.tar.gz yosys-4724d94fbce587b39cd7343dc8de3b859311f55c.tar.bz2 yosys-4724d94fbce587b39cd7343dc8de3b859311f55c.zip |
Added $alu cell type
Diffstat (limited to 'techlibs/common/simlib.v')
-rw-r--r-- | techlibs/common/simlib.v | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/techlibs/common/simlib.v b/techlibs/common/simlib.v index 8c0a54e4e..09ffa9a68 100644 --- a/techlibs/common/simlib.v +++ b/techlibs/common/simlib.v @@ -467,6 +467,51 @@ endmodule // -------------------------------------------------------- +module \$alu (A, B, CI, BI, X, Y, CO); + +parameter A_SIGNED = 0; +parameter B_SIGNED = 0; +parameter A_WIDTH = 1; +parameter B_WIDTH = 1; +parameter Y_WIDTH = 1; + +input [A_WIDTH-1:0] A; +input [B_WIDTH-1:0] B; +output [Y_WIDTH-1:0] X, Y; + +input CI, BI; +output [Y_WIDTH-1:0] CO; + +wire [Y_WIDTH-1:0] AA, BB; + +generate + if (A_SIGNED && B_SIGNED) begin:BLOCK1 + assign AA = $signed(A), BB = BI ? ~$signed(B) : $signed(B); + end else begin:BLOCK2 + assign AA = $unsigned(A), BB = BI ? ~$unsigned(B) : $unsigned(B); + end +endgenerate + +assign X = AA ^ BB; +assign Y = AA + BB + CI; + +function get_carry; + input a, b, c; + get_carry = (a&b) | (a&c) | (b&c); +endfunction + +genvar i; +generate + assign CO[0] = get_carry(AA[0], BB[0], CI); + for (i = 1; i < Y_WIDTH; i = i+1) begin:BLOCK3 + assign CO[i] = get_carry(AA[i], BB[i], CO[i-1]); + end +endgenerate + +endmodule + +// -------------------------------------------------------- + module \$lt (A, B, Y); parameter A_SIGNED = 0; |