我正在尝试使用官方网页中给出的 GCD 示例来学习 Chisel3 。此示例使用名为 -% 的运算符,这是什么意思?Wiki operator page上没有解释。备忘单将“减法”作为正常的减法符号“-”。
那么简单减法 '-' 和百分比减法 '-%' 有什么区别呢?
[编辑]
好的,我在chisel3 代码下找到了这些函数的定义:
// TODO: refactor to share documentation with Num or add independent scaladoc
def unary_- : UInt = UInt(0) - this
def unary_-% : UInt = UInt(0) -% this
def +& (other: UInt): UInt = binop(UInt((this.width max other.width) + 1), AddOp, other)
def + (other: UInt): UInt = this +% other
def +% (other: UInt): UInt = (this +& other) tail 1
def -& (other: UInt): UInt = binop(UInt((this.width max other.width) + 1), SubOp, other)
def - (other: UInt): UInt = this -% other
def -% (other: UInt): UInt = (this -& other) tail 1
def * (other: UInt): UInt = binop(UInt(this.width + other.width), TimesOp, other)
def * (other: SInt): SInt = other * this
def / (other: UInt): UInt = binop(UInt(this.width), DivideOp, other)
def % (other: UInt): UInt = binop(UInt(this.width), RemOp, other)
def & (other: UInt): UInt = binop(UInt(this.width max other.width), BitAndOp, other)
def | (other: UInt): UInt = binop(UInt(this.width max other.width), BitOrOp, other)
def ^ (other: UInt): UInt = binop(UInt(this.width max other.width), BitXorOp, other)
使用 & 运算符,减法或加法的结果将是最大操作数的大小加上一位。但是使用 % 运算符,操作的结果将是最大操作数的大小......就像普通的 + 或 - 一样。那么 - 和 -% 和 + an +% 之间有什么区别?