mirror of
https://github.com/chipsalliance/chisel.git
synced 2026-05-31 01:00:52 +08:00
Page:
Builtin Operators
Pages
A Detailed Example
Acknowledgements
Annotations Extending Chisel and Firrtl
BlackBoxes
Builtin Operators
Bundles and Vecs
CS250 Chisel Scala Primer
Chisel Developer Stuff
Chisel Governance
Chisel Introduction
Chisel Memories
Chisel Tutorial
Chisel3 vs Chisel2
ChiselSheet
Combinational Circuits
Cookbook
Datatypes in Chisel
Debugging with the Interpreter REPL 1
Debugging with the Interpreter REPL 2
Debugging with the Interpreter REPL 3
Developers
Experimental Interval Type
Experimental Features
FixedPoint
Frequently Asked Questions
Functional Abstraction
Functional Module Creation
Hardware Expressible in Chisel
Home
Installation Preparation
Interfaces Bulk Connections
Memories
Modules
Multiple Clock Domains
Muxes and Input Selection
Polymorphism and Parameterization
Ports
Printing in Chisel
Randomization flags
Running Stuff
Scala Cheatsheet
Scala Things You Should Know
Scala land vs. Chisel land
Short Users Guide to Chisel
State Elements
Style Guide
Test Coverage
Troubleshooting
Tutorial Problems
Unconnected Wires
Useful SBT Commands
Width Inference
chisel toolchain
how to publish
intellij setup
release notes 17 03 23
release notes 17 04 12
release notes 17 05 03
release notes 17 05 16
release notes 17 05 25
release notes 17 05 30
release notes 17 06 22
release notes 17 07 19
release notes 17 08 16
release notes 17 09 14
release notes 17 09 27
release notes 17 10 06
release notes 17 10 27
release notes 17 11 09
sbt subproject
tips and tricks
Clone
12
Builtin Operators
Taiki Mineno edited this page 2019-07-14 16:23:03 +09:00
Table of Contents
List of operators
Chisel defines a set of hardware operators:
| Operation | Explanation |
|---|---|
| Bitwise operators | Valid on: SInt, UInt, Bool |
val invertedX = ~x |
Bitwise NOT |
val hiBits = x & "h_ffff_0000".U |
Bitwise AND |
val flagsOut = flagsIn | overflow |
Bitwise OR |
val flagsOut = flagsIn ^ toggle |
Bitwise XOR |
| Bitwise reductions. | Valid on: SInt and UInt. Returns Bool. |
val allSet = x.andR |
AND reduction |
val anySet = x.orR |
OR reduction |
val parity = x.xorR |
XOR reduction |
| Equality comparison. | Valid on: SInt, UInt, and Bool. Returns Bool. |
val equ = x === y |
Equality |
val neq = x =/= y |
Inequality |
| Shifts | Valid on: SInt and UInt |
val twoToTheX = 1.S << x |
Logical shift left |
val hiBits = x >> 16.U |
Right shift (logical on UInt and arithmetic on SInt). |
| Bitfield manipulation | Valid on: SInt, UInt, and Bool. |
val xLSB = x(0) |
Extract single bit, LSB has index 0. |
val xTopNibble = x(15, 12) |
Extract bit field from end to start bit position. |
val usDebt = Fill(3, "hA".U) |
Replicate a bit string multiple times. |
val float = Cat(sign, exponent, mantissa) |
Concatenates bit fields, with first argument on left. |
| Logical Operations | Valid on: Bool |
val sleep = !busy |
Logical NOT |
val hit = tagMatch && valid |
Logical AND |
val stall = src1busy || src2busy |
Logical OR |
val out = Mux(sel, inTrue, inFalse) |
Two-input mux where sel is a Bool |
| Arithmetic operations | Valid on Nums: SInt and UInt. |
val sum = a + b or val sum = a +% b |
Addition (without width expansion) |
val sum = a +& b |
Addition (with width expansion) |
val diff = a - b or val diff = a -% b |
Subtraction (without width expansion) |
val diff = a -& b |
Subtraction (with width expansion) |
val prod = a * b |
Multiplication |
val div = a / b |
Division |
val mod = a % b |
Modulus |
| Arithmetic comparisons | Valid on Nums: SInt and UInt. Returns Bool. |
val gt = a > b |
Greater than |
val gte = a >= b |
Greater than or equal |
val lt = a < b |
Less than |
val lte = a <= b |
Less than or equal |
Our choice of operator names was constrained by the Scala language. We have to use triple equals
===for equality and=/=for inequality to allow the native Scala equals operator to remain usable.