公式WebページにあるGCDの例でChisel3を学ぼうとしています。この例では -% という名前の演算子を使用していますが、これはどういう意味ですか? Wikiの運営者ページでは説明されていません。そして、Cheatsheetには、通常の減算記号「-」として「減算」と記載されています。
それでは、単純な減算「-」とパーセント減算「-%」の違いは何ですか?
[編集]
わかりました、これらの関数の定義は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)
& 演算子を使用すると、減算または加算の結果は、最大のオペランドに 1 ビットを加えたサイズになります。しかし、% 演算子を使用すると、演算の結果は最大のオペランドのサイズになります ... 通常の + または - と同様です。では、 - と -% と + と +% の違いは何ですか?