什么'&'和'%' Chisel3中的运算符 - &, - %,+&,+%?

时间:2016-11-08 09:43:52

标签: scala hdl chisel

我尝试使用official web page中给出的GCD示例来学习Chisel3。这个例子使用名为 - %的运算符,这是什么意思? 它没有在Wiki operator page上解释。并且Cheatsheet说"减法"作为正常的减法符号' - '。

那么简单的减法与' - '之间有什么区别?和减少百分比' - %' ?

[编辑]

好的,我在chisel3 code下找到了这些函数的定义:

 // 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)

与&运算符减法或加法的结果将是bigest操作数加上一位的大小。 但是对于%运算符,运算结果将是bigest操作数的大小...与normal +或 - 一样。那么 - 和 - %之间和+一个+%之间有什么区别?

1 个答案:

答案 0 :(得分:2)

我很抱歉不在Wiki操作页面上包含这些信息,我将很快添加它。

你已经通过编辑击中了头部:+&-&正在扩展运算符,因为结果的宽度等于最宽操作数加上1的大小。{{ 1}}和+%是非扩展运算符,因为结果的宽度等于最宽的操作数。

-%只是+的别名,而+%别名为-

相关问题