2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
2021-07-26 08:21:09 -04:00
|
|
|
//# Function: Binary adder #
|
2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
|
|
|
//# Author: Andreas Olofsson #
|
2021-07-26 08:21:09 -04:00
|
|
|
//# License: MIT (see LICENSE file in OH! repository) #
|
2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
2015-12-17 13:50:59 -05:00
|
|
|
|
2021-07-26 08:21:09 -04:00
|
|
|
module oh_add
|
2021-07-26 22:34:03 -04:00
|
|
|
#(parameter N = 32, // block width
|
2021-07-26 08:21:09 -04:00
|
|
|
parameter SYN = "TRUE", // synthesizable
|
|
|
|
parameter TYPE = "DEFAULT" // implementation type
|
|
|
|
)
|
|
|
|
(//inputs
|
2021-07-26 22:34:03 -04:00
|
|
|
input [N-1:0] a, // first operand
|
|
|
|
input [N-1:0] b, // second operand
|
|
|
|
input [N-1:0] k, // carrry kill signal (active high)
|
|
|
|
input cin,// carry in
|
2021-07-26 08:21:09 -04:00
|
|
|
//outputs
|
2021-07-26 22:34:03 -04:00
|
|
|
output [N-1:0] sum,// sum
|
|
|
|
output [N-1:0] carry,// complete carry out vector
|
|
|
|
output cout// carry out from msb
|
2016-04-11 12:01:59 -04:00
|
|
|
);
|
2015-12-17 13:50:59 -05:00
|
|
|
|
2021-07-26 08:21:09 -04:00
|
|
|
generate
|
2021-07-26 22:34:03 -04:00
|
|
|
if(SYN == "TRUE") begin
|
|
|
|
assign {cout,sum[N-1:0]} = a[N-1:0] + b[N-1:0] + cin;
|
2021-08-02 17:37:36 -04:00
|
|
|
//TODO: FIX
|
|
|
|
assign carry = 'b0;
|
2021-07-26 08:21:09 -04:00
|
|
|
end
|
|
|
|
else begin
|
2021-07-26 08:43:05 -04:00
|
|
|
asic_add #(.TYPE(TYPE),
|
2021-07-26 22:34:03 -04:00
|
|
|
.N(N))
|
2021-07-26 08:21:09 -04:00
|
|
|
asic_add (// Outputs
|
2021-07-26 22:34:03 -04:00
|
|
|
.sum (sum[N-1:0]),
|
|
|
|
.carry (carry[N-1:0]),
|
2021-07-26 08:21:09 -04:00
|
|
|
.cout (cout),
|
|
|
|
// Inputs
|
2021-07-26 22:34:03 -04:00
|
|
|
.a (a[N-1:0]),
|
|
|
|
.b (b[N-1:0]),
|
|
|
|
.k (k[N-1:0]),
|
2021-07-26 08:21:09 -04:00
|
|
|
.cin (cin));
|
|
|
|
|
|
|
|
end
|
|
|
|
endgenerate
|
|
|
|
endmodule
|