Unary operators¶
All unary RTL cells have one input port A
and one output port Y
. They
also have the following parameters:
A_SIGNED
Set to a non-zero value if the input
A
is signed and therefore should be sign-extended when needed.A_WIDTH
The width of the input port
A
.Y_WIDTH
The width of the output port
Y
.
Verilog |
Cell Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For the unary cells that output a logical value ($reduce_and
, $reduce_or
,
$reduce_xor
, $reduce_xnor
, $reduce_bool
, $logic_not
), when the
Y_WIDTH
parameter is greater than 1, the output is zero-extended, and only
the least significant bit varies.
Note that $reduce_or
and $reduce_bool
generally represent the same logic
function. But the read_verilog
frontend will generate them in different
situations. A $reduce_or
cell is generated when the prefix |
operator is
being used. A $reduce_bool
cell is generated when a bit vector is used as a
condition in an if
-statement or ?:
-expression.
- yosys> help $buf¶
A simple coarse-grain buffer cell type for the experimental buffered-normalized mode. Note this cell does’t get removed by ‘opt_clean’ and is not recommended for general use.
- Properties:
- Simulation model (verilog)¶
98module \$buf (A, Y); 99 100 parameter WIDTH = 0; 101 102 input [WIDTH-1:0] A; 103 output [WIDTH-1:0] Y; 104 105 assign Y = A; 106 107endmodule
- yosys> help $logic_not¶
A logical inverter. This corresponds to the Verilog unary prefix ‘!’ operator.
- Properties:
- Simulation model (verilog)¶
1399module \$logic_not (A, Y); 1400 1401 parameter A_SIGNED = 0; 1402 parameter A_WIDTH = 0; 1403 parameter Y_WIDTH = 0; 1404 1405 input [A_WIDTH-1:0] A; 1406 output [Y_WIDTH-1:0] Y; 1407 1408 generate 1409 if (A_SIGNED) begin:BLOCK1 1410 assign Y = !$signed(A); 1411 end else begin:BLOCK2 1412 assign Y = !A; 1413 end 1414 endgenerate 1415 1416endmodule
- yosys> help $neg¶
An arithmetic inverter. This corresponds to the Verilog unary prefix ‘-’ operator.
- Properties:
- Simulation model (verilog)¶
118module \$neg (A, Y); 119 120 parameter A_SIGNED = 0; 121 parameter A_WIDTH = 0; 122 parameter Y_WIDTH = 0; 123 124 input [A_WIDTH-1:0] A; 125 output [Y_WIDTH-1:0] Y; 126 127 generate 128 if (A_SIGNED) begin:BLOCK1 129 assign Y = -$signed(A); 130 end else begin:BLOCK2 131 assign Y = -A; 132 end 133 endgenerate 134 135endmodule
- yosys> help $not¶
Bit-wise inverter
This corresponds to the Verilog unary prefix ‘~’ operator.
- Properties:
- Simulation model (verilog)¶
40module \$not (A, Y); 41 42 parameter A_SIGNED = 0; 43 parameter A_WIDTH = 0; 44 parameter Y_WIDTH = 0; 45 46 input [A_WIDTH-1:0] A; 47 output [Y_WIDTH-1:0] Y; 48 49 generate 50 if (A_SIGNED) begin:BLOCK1 51 assign Y = ~$signed(A); 52 end else begin:BLOCK2 53 assign Y = ~A; 54 end 55 endgenerate 56 57endmodule
- yosys> help $pos¶
A buffer. This corresponds to the Verilog unary prefix ‘+’ operator.
- Properties:
- Simulation model (verilog)¶
68module \$pos (A, Y); 69 70 parameter A_SIGNED = 0; 71 parameter A_WIDTH = 0; 72 parameter Y_WIDTH = 0; 73 74 input [A_WIDTH-1:0] A; 75 output [Y_WIDTH-1:0] Y; 76 77 generate 78 if (A_SIGNED) begin:BLOCK1 79 assign Y = $signed(A); 80 end else begin:BLOCK2 81 assign Y = A; 82 end 83 endgenerate 84 85endmodule
- yosys> help $reduce_and¶
An AND reduction. This corresponds to the Verilog unary prefix ‘&’ operator.
- Properties:
- Simulation model (verilog)¶
270module \$reduce_and (A, Y); 271 272 parameter A_SIGNED = 0; 273 parameter A_WIDTH = 0; 274 parameter Y_WIDTH = 0; 275 276 input [A_WIDTH-1:0] A; 277 output [Y_WIDTH-1:0] Y; 278 279 generate 280 if (A_SIGNED) begin:BLOCK1 281 assign Y = &$signed(A); 282 end else begin:BLOCK2 283 assign Y = &A; 284 end 285 endgenerate 286 287endmodule
- yosys> help $reduce_bool¶
An OR reduction. This cell type is used instead of $reduce_or when a signal is implicitly converted to a boolean signal, e.g. for operands of ‘&&’ and ‘||’.
- Properties:
- Simulation model (verilog)¶
383module \$reduce_bool (A, Y); 384 385 parameter A_SIGNED = 0; 386 parameter A_WIDTH = 0; 387 parameter Y_WIDTH = 0; 388 389 input [A_WIDTH-1:0] A; 390 output [Y_WIDTH-1:0] Y; 391 392 generate 393 if (A_SIGNED) begin:BLOCK1 394 assign Y = !(!$signed(A)); 395 end else begin:BLOCK2 396 assign Y = !(!A); 397 end 398 endgenerate 399 400endmodule
- yosys> help $reduce_or¶
An OR reduction. This corresponds to the Verilog unary prefix ‘|’ operator.
- Properties:
- Simulation model (verilog)¶
298module \$reduce_or (A, Y); 299 300 parameter A_SIGNED = 0; 301 parameter A_WIDTH = 0; 302 parameter Y_WIDTH = 0; 303 304 input [A_WIDTH-1:0] A; 305 output [Y_WIDTH-1:0] Y; 306 307 generate 308 if (A_SIGNED) begin:BLOCK1 309 assign Y = |$signed(A); 310 end else begin:BLOCK2 311 assign Y = |A; 312 end 313 endgenerate 314 315endmodule
- yosys> help $reduce_xnor¶
A XNOR reduction. This corresponds to the Verilog unary prefix ‘~^’ operator.
- Properties:
- Simulation model (verilog)¶
354module \$reduce_xnor (A, Y); 355 356 parameter A_SIGNED = 0; 357 parameter A_WIDTH = 0; 358 parameter Y_WIDTH = 0; 359 360 input [A_WIDTH-1:0] A; 361 output [Y_WIDTH-1:0] Y; 362 363 generate 364 if (A_SIGNED) begin:BLOCK1 365 assign Y = ~^$signed(A); 366 end else begin:BLOCK2 367 assign Y = ~^A; 368 end 369 endgenerate 370 371endmodule
- yosys> help $reduce_xor¶
A XOR reduction. This corresponds to the Verilog unary prefix ‘^’ operator.
- Properties:
- Simulation model (verilog)¶
326module \$reduce_xor (A, Y); 327 328 parameter A_SIGNED = 0; 329 parameter A_WIDTH = 0; 330 parameter Y_WIDTH = 0; 331 332 input [A_WIDTH-1:0] A; 333 output [Y_WIDTH-1:0] Y; 334 335 generate 336 if (A_SIGNED) begin:BLOCK1 337 assign Y = ^$signed(A); 338 end else begin:BLOCK2 339 assign Y = ^A; 340 end 341 endgenerate 342 343endmodule