2

公式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 ビットを加えたサイズになります。しかし、% 演算子を使用すると、演算の結果は最大のオペランドのサイズになります ... 通常の + または - と同様です。では、 - と -% と + と +% の違いは何ですか?

4

1 に答える 1

2

この情報を Wiki 運営者ページに掲載していないことをお詫びします。まもなく追加します。

編集で頭に釘を打ちました: 結果の幅が最も広いオペランドのサイズに 1を加えたものに等しいという点で展開演算子+&であり、結果の幅が等しいという点で非展開演算子です。最も広いオペランドに。-&+%-%

++%-エイリアスするだけ-%です。

于 2016-11-09T22:10:09.780 に答える