-
Notifications
You must be signed in to change notification settings - Fork 5
/
U32.fm
118 lines (94 loc) · 2.26 KB
/
U32.fm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
T U32
| U32.new(a: Word(32));
U32.0: U32
U32.new(Word.zero(32))
U32.add(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.add<>(a_val, b_val))
U32.and(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.and<>(a_val, b_val))
U32.concat(a: U32, b: U32): U64
get a_val = a
get b_val = b
U64.new(Word.concat<><>(a_val, b_val))
U32.div(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.div<>(a_val, b_val))
// a == b
U32.eql(a: U32, b: U32): Bool
get a_val = a
get b_val = b
Word.eql<>(a_val, b_val)
// a >= b
U32.gte(a: U32, b: U32): Bool
get a_val = a
get b_val = b
Word.gte<>(a_val, b_val)
// a > b
U32.gtn(a: U32, b: U32): Bool
get a_val = a
get b_val = b
Word.gtn<>(a_val, b_val)
U32.hash2(a: U32, b: U32): U32
get w64 = U64.mix(U32.concat(a,b))
U32.new(Word.drop<>(32, w64))
U32.inc(a: U32): U32
get a_val = a
U32.new(Word.inc<>(a_val))
// a <= b
U32.lte(a: U32, b: U32): Bool
get a_val = a
get b_val = b
Word.lte<>(a_val, b_val)
// a < b
U32.ltn(a: U32, b: U32): Bool
get a_val = a
get b_val = b
Word.ltn<>(a_val, b_val)
U32.mod(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.mod<>(a_val, b_val))
U32.mul(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.mul<>(a_val, b_val))
U32.or(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.or<>(a_val, b_val))
U32.parse_hex(str: String): U32
U32.new(Word.from_bits(32, Bits.parse_hex(str)))
U32.pow(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.pow<>(a_val, b_val))
U32.shl(n: Nat, a: U32): U32
get a_val = a
U32.new(Word.shift_left<>(n, a_val))
U32.shr(n: Nat, a: U32): U32
get a_val = a
U32.new(Word.shift_right<>(n, a_val))
U32.sub(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.sub<>(a_val, b_val))
U32.to_bits(a: U32): Bits
get a_val = a
Word.to_bits<>(a_val)
U32.to_nat(a: U32): Nat
get a_val = a
Word.to_nat<>(a_val)
U32.xor(a: U32, b: U32): U32
get a_val = a
get b_val = b
U32.new(Word.xor<>(a_val, b_val))
U32.for<S: Type>(state: S, from: U32, til: U32, func: U32 -> S -> S): S
if U32.eql(from, til) then
state
else
U32.for<S>(func(from, state), U32.inc(from), til, func)