2016-11-08 1075 views
2

我正在试着用official web page给出的GCD示例来学习Chisel3。这个例子使用运算符 - %,这是什么意思? 这不是在Wiki 上解释。并且Cheatsheet将“减法”称为正常减法符号' - '。'&'和'%'在操作符中的含义是什么 - &, - %,+&,+%在Chisel3中?

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

[编辑]

好的,我发现这些功能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操作数的大小......与正常的+或 - 一样。那么 - 和 - %和+ an +%之间有什么区别?

回答

2

我很抱歉没有在Wiki运营商页面中包含这些信息,我很快就会添加它。

你一针见血的头部与编辑:+&-&正在扩大,运营商的结果的宽度等于最宽的操作数的大小加上1 +%-%在非运营商不断扩大结果的宽度等于最宽的操作数。

+只是别名到+%-别名到-%