diff options
| author | azidar | 2015-08-20 14:19:02 -0700 |
|---|---|---|
| committer | azidar | 2015-08-20 14:19:26 -0700 |
| commit | 5bf451acbe03ecfd6407d7376cbb782ac0dd0f11 (patch) | |
| tree | dddff083fe2e733bec114b34aadae5070714bcc7 | |
| parent | 9175d99c622ca9b8c85ff733dbf9f0aa3ec8e266 (diff) | |
Added rsh to BigInt library. Const Prop now works on rsh's on constants. #19.
| -rw-r--r-- | src/main/stanza/bigint2.stanza | 11 | ||||
| -rw-r--r-- | src/main/stanza/ir-parser.stanza | 4 | ||||
| -rw-r--r-- | src/main/stanza/ir-utils.stanza | 5 | ||||
| -rw-r--r-- | src/main/stanza/passes.stanza | 17 |
4 files changed, 23 insertions, 14 deletions
diff --git a/src/main/stanza/bigint2.stanza b/src/main/stanza/bigint2.stanza index d7376649..4657878a 100644 --- a/src/main/stanza/bigint2.stanza +++ b/src/main/stanza/bigint2.stanza @@ -75,7 +75,7 @@ public defn BigInt (d:Array<Int>, num-bits:Int) : public defmethod get (b:BigInt, index:Int) -> Int : check-index(index) - if index > num-bits(b) : error("Bit index is too high") + if index >= num-bits(b) : error("Bit index is too high") val word-index = index / 32 val bit-index = index % 32 (d(b)[word-index] >> bit-index) & 1 @@ -147,12 +147,9 @@ public defn bit (b:BigInt, index:Int) -> BigInt : b*[0] = b[index] b* -; For now, rsh does not change the number of bits -public defn rsh-unsigned (b:BigInt, amount:Int) -> BigInt : - val b* = BigIntZero(num-bits(b)) - for i in 0 to num-bits(b*) do : - b*[i] = b[i + amount] - b* +public defn rsh (b:BigInt, amount:Int) -> BigInt : + check-index(amount) + bits(b,num-bits(b), amount) diff --git a/src/main/stanza/ir-parser.stanza b/src/main/stanza/ir-parser.stanza index 71236795..13b23906 100644 --- a/src/main/stanza/ir-parser.stanza +++ b/src/main/stanza/ir-parser.stanza @@ -284,8 +284,8 @@ defsyntax firrtl : (t:UIntType) : if (v as Int) < 0 : FPE(form, "UIntValue cannot be negative.") - UIntValue(BigIntLit(v as Int,32), width(t)) - (t:SIntType) : SIntValue(BigIntLit(v as Int,32), width(t)) + UIntValue(BigIntLit(v as Int), width(t)) + (t:SIntType) : SIntValue(BigIntLit(v as Int), width(t)) expterm = (?op:#sym(?es:#exp ... ?ints:#int ... ?rest ...)) : if not empty?(rest) : diff --git a/src/main/stanza/ir-utils.stanza b/src/main/stanza/ir-utils.stanza index 25006659..8f260e8c 100644 --- a/src/main/stanza/ir-utils.stanza +++ b/src/main/stanza/ir-utils.stanza @@ -128,7 +128,10 @@ public defn to-int (x:Long) -> Int : else : to-int(to-string(x)) public defn req-num-bits (i: Int) -> Int : - max(1, ceil-log2(i + 1)) + val i* = + if i < 0 : ((-1 * i) - 1) + else : i + ceil-log2(i* + 1) + 1 ;============== PRINTERS =================================== diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza index 0470d521..a6239baa 100644 --- a/src/main/stanza/passes.stanza +++ b/src/main/stanza/passes.stanza @@ -1170,7 +1170,7 @@ defn expand-connect-indexed-stmt (s: Stmt,sh:HashTable<Symbol,Int>) -> Stmt : to-list $ for (i in 0 to false, l in locs(s)) stream : Conditionally( info(s), - equality(ref,UIntValue(BigIntLit(i,32),UnknownWidth())), + equality(ref,UIntValue(BigIntLit(i),UnknownWidth())), Connect(info(s),l,exp(s)), EmptyStmt() ) @@ -1184,7 +1184,7 @@ defn expand-connect-indexed-stmt (s: Stmt,sh:HashTable<Symbol,Int>) -> Stmt : to-list $ for (i in 1 to false, e in tail(exps(s))) stream : Conditionally( info(s), - equality(ref,UIntValue(BigIntLit(i,32),UnknownWidth())), + equality(ref,UIntValue(BigIntLit(i),UnknownWidth())), Connect(info(s),loc(s),e), EmptyStmt() ) @@ -1230,8 +1230,8 @@ public defmethod short-name (b:ExpandWhens) -> String : "expand-whens" ; ======== Expression Computation Library =========== -val zero = UIntValue(BigIntLit(0,32),IntWidth(1)) -val one = UIntValue(BigIntLit(1,32),IntWidth(1)) +val zero = UIntValue(BigIntLit(0),IntWidth(1)) +val one = UIntValue(BigIntLit(1),IntWidth(1)) defmethod equal? (e1:Expression,e2:Expression) -> True|False : match(e1,e2) : @@ -2425,6 +2425,15 @@ defn const-prop-e (e:Expression) -> Expression : match(map(const-prop-e,e)) : (e:DoPrim) : switch {op(e) == _} : + SHIFT-RIGHT-OP : + match(args(e)[0]) : + (x:UIntValue) : + val b = rsh(value(x),consts(e)[0]) + UIntValue(b,width(type(e) as UIntType)) + (x:SIntValue) : + val b = rsh(value(x),consts(e)[0]) + SIntValue(b,width(type(e) as SIntType)) + (x) : e BITS-SELECT-OP : match(args(e)[0]) : (x:UIntValue) : |
