1 // Certain arithmetic operations between a signal of width n and a constant can be directly mapped
2 // to a single k-LUT (where n <= k). This is preferable to normal alumacc techmapping process
3 // because for many targets, arithmetic techmapping creates hard logic (such as carry cells) which often
4 // cannot be optimized further.
6 // TODO: Currently, only comparisons with 1-bit output are mapped. Potentially, all arithmetic cells
7 // with n <= k inputs should be techmapped in this way, because this shortens the critical path
8 // from n to 1 by avoiding carry chains.
10 (* techmap_celltype = "$eq $ne $lt $le $gt $ge" *)
11 module _90_lut_cmp_ (A, B, Y);
13 parameter A_SIGNED = 0;
14 parameter B_SIGNED = 0;
15 parameter A_WIDTH = 0;
16 parameter B_WIDTH = 0;
17 parameter Y_WIDTH = 0;
19 input [A_WIDTH-1:0] A;
20 input [B_WIDTH-1:0] B;
21 output [Y_WIDTH-1:0] Y;
23 parameter _TECHMAP_CELLTYPE_ = "";
25 parameter _TECHMAP_CONSTMSK_A_ = 0;
26 parameter _TECHMAP_CONSTVAL_A_ = 0;
27 parameter _TECHMAP_CONSTMSK_B_ = 0;
28 parameter _TECHMAP_CONSTVAL_B_ = 0;
30 function automatic integer gen_lut;
32 input integer operation;
35 input integer operand;
36 integer n, i_var, i_cst, lhs, rhs, o_bit;
39 for (n = 0; n < (1 << width); n++) begin
64 gen_lut = gen_lut | (o_bit << n);
70 if (_TECHMAP_CELLTYPE_ == "$lt")
71 localparam operation = 0;
72 if (_TECHMAP_CELLTYPE_ == "$le")
73 localparam operation = 1;
74 if (_TECHMAP_CELLTYPE_ == "$gt")
75 localparam operation = 2;
76 if (_TECHMAP_CELLTYPE_ == "$ge")
77 localparam operation = 3;
78 if (_TECHMAP_CELLTYPE_ == "$eq")
79 localparam operation = 4;
80 if (_TECHMAP_CELLTYPE_ == "$ne")
81 localparam operation = 5;
83 if (A_WIDTH > `LUT_WIDTH || B_WIDTH > `LUT_WIDTH || Y_WIDTH != 1)
84 wire _TECHMAP_FAIL_ = 1;
85 else if (&_TECHMAP_CONSTMSK_B_)
88 .LUT({ gen_lut(A_WIDTH, operation, 0, A_SIGNED && B_SIGNED, _TECHMAP_CONSTVAL_B_) })
93 else if (&_TECHMAP_CONSTMSK_A_)
96 .LUT({ gen_lut(B_WIDTH, operation, 1, A_SIGNED && B_SIGNED, _TECHMAP_CONSTVAL_A_) })
102 wire _TECHMAP_FAIL_ = 1;