From 759852914df00609f8797315c6cec76f1c8a3981 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Mon, 12 Aug 2013 14:47:50 +0200 Subject: [PATCH] Added support for "2**n" shifter encoding --- frontends/ast/genrtlil.cc | 4 +++ tests/simple/operators.v | 53 +++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc index 9c027878a..50e959754 100644 --- a/frontends/ast/genrtlil.cc +++ b/frontends/ast/genrtlil.cc @@ -974,8 +974,12 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint) width = width_hint; if (type == AST_MUL) width = std::min(left.width + right.width, width_hint); + if (type == AST_POW) + width = width_hint; } is_signed = children[0]->is_signed && children[1]->is_signed; + if (!flag_noopt && type == AST_POW && left.is_fully_const() && left.as_int() == 2) + return binop2rtlil(this, "$shl", width, RTLIL::SigSpec(1, left.width), right); return binop2rtlil(this, type_name, width, left, right); } diff --git a/tests/simple/operators.v b/tests/simple/operators.v index 6ca6ca7a8..7439101c8 100644 --- a/tests/simple/operators.v +++ b/tests/simple/operators.v @@ -86,30 +86,35 @@ always @(posedge clk) begin 58: y <= s1 % u2; 59: y <= s1 % s2; - 60: y <= +u1; - 61: y <= -u1; - 62: y <= ~u1; - 63: y <= !u1; - - 64: y <= +s1; - 65: y <= -s1; - 66: y <= ~s1; - 67: y <= !s1; - - 68: y <= { &u1, ~&u1, |u1, ~|u1, ^u1, ~^u1, ^~u1 }; - 69: y <= { &s1, ~&s1, |s1, ~|s1, ^s1, ~^s1, ^~s1 }; - 70: y <= { &u1[1:0], ~&u1[1:0], |u1[1:0], ~|u1[1:0], ^u1[1:0], ~^u1[1:0], ^~u1[1:0] }; - 71: y <= { &s1[1:0], ~&s1[1:0], |s1[1:0], ~|s1[1:0], ^s1[1:0], ~^s1[1:0], ^~s1[1:0] }; - - 72: y <= { u1[1:0] && u2[1:0], u1[1:0] && u2[1:0], !u1[1:0] }; - 73: y <= {4{u1[1:0]}}; - 74: y <= {u1, u2} ^ {s1, s2}; - 75: y <= {u1, u2} & {s1, s2}; - - 76: y <= u1[0] ? u1 : u2; - 77: y <= u1[0] ? u1 : s2; - 78: y <= u1[0] ? s1 : u2; - 79: y <= u1[0] ? s1 : s2; + 60: y <= 4'd2 ** u1; + 61: y <= 4'd2 ** s1; + 62: y <= 4'sd2 ** u1; + 63: y <= 4'sd2 ** s1; + + 64: y <= +u1; + 65: y <= -u1; + 66: y <= ~u1; + 67: y <= !u1; + + 68: y <= +s1; + 69: y <= -s1; + 70: y <= ~s1; + 71: y <= !s1; + + 72: y <= { &u1, ~&u1, |u1, ~|u1, ^u1, ~^u1, ^~u1 }; + 73: y <= { &s1, ~&s1, |s1, ~|s1, ^s1, ~^s1, ^~s1 }; + 74: y <= { &u1[1:0], ~&u1[1:0], |u1[1:0], ~|u1[1:0], ^u1[1:0], ~^u1[1:0], ^~u1[1:0] }; + 75: y <= { &s1[1:0], ~&s1[1:0], |s1[1:0], ~|s1[1:0], ^s1[1:0], ~^s1[1:0], ^~s1[1:0] }; + + 76: y <= { u1[1:0] && u2[1:0], u1[1:0] && u2[1:0], !u1[1:0] }; + 77: y <= {4{u1[1:0]}}; + 78: y <= {u1, u2} ^ {s1, s2}; + 79: y <= {u1, u2} & {s1, s2}; + + 80: y <= u1[0] ? u1 : u2; + 81: y <= u1[0] ? u1 : s2; + 82: y <= u1[0] ? s1 : u2; + 83: y <= u1[0] ? s1 : s2; endcase end -- 2.30.2