diff options
| author | azidar | 2015-11-06 18:55:39 -0800 |
|---|---|---|
| committer | azidar | 2016-01-16 14:28:16 -0800 |
| commit | 9113d54b61b681215a3cc9fcf44e64167fad0568 (patch) | |
| tree | 3cf0e1d3e48397a71c398fad38bef8af0c827e09 /src/main/stanza/bigint2.stanza | |
| parent | ffa090c10d6210395e3f304e56008e2183a85698 (diff) | |
WIP. Compiles, need to test
Diffstat (limited to 'src/main/stanza/bigint2.stanza')
| -rw-r--r-- | src/main/stanza/bigint2.stanza | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/main/stanza/bigint2.stanza b/src/main/stanza/bigint2.stanza index bc2e9f36..91cd4558 100644 --- a/src/main/stanza/bigint2.stanza +++ b/src/main/stanza/bigint2.stanza @@ -1,7 +1,6 @@ defpackage bigint2 : import core import verse - import firrtl/ir-utils ;============ Big Int Library ============= @@ -9,6 +8,30 @@ defpackage bigint2 : ; index 0. ;------------ Helper Functions ------------ +public defn pow (x:Int,y:Int) -> Int : + var x* = 1 + var y* = y + while y* != 0 : + x* = times(x*,x) + y* = minus(y*,1) + x* + +public defn pow (x:Long,y:Long) -> Long : + var x* = to-long(1) + var y* = y + while y* != to-long(0) : + x* = times(x*,x) + y* = minus(y*,to-long(1)) + x* +public defn to-int (x:Long) -> Int : + if x > to-long(2147483647) or x < to-long(-2147483648) : error("Long too big to convert to Int") + else : to-int(to-string(x)) + +public defn req-num-bits (i: Int) -> Int : + val i* = + if i < 0 : ((-1 * i) - 1) + else : i + ceil-log2(i* + 1) + 1 val word-size = 32 val all-digits = "0123456789abcdef" |
