1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-30 02:32:53 +08:00

Adding asic_add block to abs circuit

This commit is contained in:
aolofsson 2021-07-26 11:32:43 -04:00
parent e82fdb65a1
commit edaa41dac7

View File

@ -2,20 +2,34 @@
//# Function: Calculates absolute value of input #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_abs #(parameter DW = 2) // data width
module oh_abs
#(parameter N = 32, // block width
parameter SYN = "TRUE", // synthesizable
parameter TYPE = "DEFAULT" // implementation type
)
(
input [DW-1:0] in, //input operand
output [DW-1:0] out, //out = abs(in) (signed two's complement)
output overflow //high for max negative #
input [N-1:0] in, // input operand
output [N-1:0] out, // out = abs(in) (signed two's complement)
output overflow // high for max negative #
);
assign out[DW-1:0] = in[DW-1] ? ~in[DW-1:0] + 1'b1 :
in[DW-1:0];
assign overflow = in[DW-1] & ~(|in[DW-2:0]);
endmodule // oh_abs
generate
if(SYN == "TRUE") begin
assign out[N-1:0] = in[N-1] ? ~in[N-1:0] + 1'b1 : in[N-1:0];
assign overflow = in[N-1] & ~(|in[N-2:0]);
end
else begin
asic_abs #(.TYPE(TYPE),
.N(N))
asic_abs(// Outputs
.out (out[N-1:0]),
.overflow (overflow),
// Inputs
.in (in[N-1:0]));
end
endgenerate
endmodule