@@ -4,7 +4,7 @@ import Data.Fin
44
55%default total
66
7−public
7+public export
88nextPow2 : Nat -> Nat
99nextPow2 Z = Z
1010nextPow2 (S x) = if (S x) == (2 `power` l2x)
@@ -13,11 +13,11 @@ nextPow2 (S x) = if (S x) == (2 `power` l2x)
1313 where
1414 l2x = log2NZ (S x) SIsNotZ
1515
16−public
16+public export
1717nextBytes : Nat -> Nat
1818nextBytes bits = (nextPow2 (divCeilNZ bits 8 SIsNotZ))
1919
20−public
20+public export
2121machineTy : Nat -> Type
2222machineTy Z = Bits8
2323machineTy (S Z) = Bits16
@@ -47,7 +47,7 @@ natToBits {n=n} x with (n)
4747getPad : Nat -> machineTy n
4848getPad n = natToBits (minus (bitsUsed (nextBytes n)) n)
4949
50−public
50+public export
5151data Bits : Nat -> Type where
5252 MkBits : machineTy (nextBytes n) -> Bits n
5353
@@ -99,7 +99,7 @@ shiftLeft' {n=n} x c with (nextBytes n)
9999 | S (S Z) = pad32' n prim__shlB32 x c
100100 | S (S (S _)) = pad64' n prim__shlB64 x c
101101
102−public
102+public export
103103shiftLeft : Bits n -> Bits n -> Bits n
104104shiftLeft (MkBits x) (MkBits y) = MkBits (shiftLeft' x y)
105105
@@ -110,7 +110,7 @@ shiftRightLogical' {n=n} x c with (n)
110110 | S (S Z) = prim__lshrB32 x c
111111 | S (S (S _)) = prim__lshrB64 x c
112112
113−public
113+public export
114114shiftRightLogical : Bits n -> Bits n -> Bits n
115115shiftRightLogical {n} (MkBits x) (MkBits y)
116116 = MkBits {n} (shiftRightLogical' {n=nextBytes n} x y)
@@ -122,7 +122,7 @@ shiftRightArithmetic' {n=n} x c with (nextBytes n)
122122 | S (S Z) = pad32' n prim__ashrB32 x c
123123 | S (S (S _)) = pad64' n prim__ashrB64 x c
124124
125−public
125+public export
126126shiftRightArithmetic : Bits n -> Bits n -> Bits n
127127shiftRightArithmetic (MkBits x) (MkBits y) = MkBits (shiftRightArithmetic' x y)
128128
@@ -133,7 +133,7 @@ and' {n=n} x y with (n)
133133 | S (S Z) = prim__andB32 x y
134134 | S (S (S _)) = prim__andB64 x y
135135
136−public
136+public export
137137and : Bits n -> Bits n -> Bits n
138138and {n} (MkBits x) (MkBits y) = MkBits (and' {n=nextBytes n} x y)
139139
@@ -144,7 +144,7 @@ or' {n=n} x y with (n)
144144 | S (S Z) = prim__orB32 x y
145145 | S (S (S _)) = prim__orB64 x y
146146
147−public
147+public export
148148or : Bits n -> Bits n -> Bits n
149149or {n} (MkBits x) (MkBits y) = MkBits (or' {n=nextBytes n} x y)
150150
@@ -155,7 +155,7 @@ xor' {n=n} x y with (n)
155155 | S (S Z) = prim__xorB32 x y
156156 | S (S (S _)) = prim__xorB64 x y
157157
158−public
158+public export
159159xor : Bits n -> Bits n -> Bits n
160160xor {n} (MkBits x) (MkBits y) = MkBits {n} (xor' {n=nextBytes n} x y)
161161
@@ -166,7 +166,7 @@ plus' {n=n} x y with (nextBytes n)
166166 | S (S Z) = pad32 n prim__addB32 x y
167167 | S (S (S _)) = pad64 n prim__addB64 x y
168168
169−public
169+public export
170170plus : Bits n -> Bits n -> Bits n
171171plus (MkBits x) (MkBits y) = MkBits (plus' x y)
172172
@@ -177,7 +177,7 @@ minus' {n=n} x y with (nextBytes n)
177177 | S (S Z) = pad32 n prim__subB32 x y
178178 | S (S (S _)) = pad64 n prim__subB64 x y
179179
180−public
180+public export
181181minus : Bits n -> Bits n -> Bits n
182182minus (MkBits x) (MkBits y) = MkBits (minus' x y)
183183
@@ -188,7 +188,7 @@ times' {n=n} x y with (nextBytes n)
188188 | S (S Z) = pad32 n prim__mulB32 x y
189189 | S (S (S _)) = pad64 n prim__mulB64 x y
190190
191−public
191+public export
192192times : Bits n -> Bits n -> Bits n
193193times (MkBits x) (MkBits y) = MkBits (times' x y)
194194
@@ -200,7 +200,7 @@ sdiv' {n=n} x y with (nextBytes n)
200200 | S (S Z) = prim__sdivB32 x y
201201 | S (S (S _)) = prim__sdivB64 x y
202202
203−public partial
203+public export partial
204204sdiv : Bits n -> Bits n -> Bits n
205205sdiv (MkBits x) (MkBits y) = MkBits (sdiv' x y)
206206
@@ -212,7 +212,7 @@ udiv' {n=n} x y with (nextBytes n)
212212 | S (S Z) = prim__udivB32 x y
213213 | S (S (S _)) = prim__udivB64 x y
214214
215−public partial
215+public export partial
216216udiv : Bits n -> Bits n -> Bits n
217217udiv (MkBits x) (MkBits y) = MkBits (udiv' x y)
218218
@@ -224,7 +224,7 @@ srem' {n=n} x y with (nextBytes n)
224224 | S (S Z) = prim__sremB32 x y
225225 | S (S (S _)) = prim__sremB64 x y
226226
227−public partial
227+public export partial
228228srem : Bits n -> Bits n -> Bits n
229229srem (MkBits x) (MkBits y) = MkBits (srem' x y)
230230
@@ -236,7 +236,7 @@ urem' {n=n} x y with (nextBytes n)
236236 | S (S Z) = prim__uremB32 x y
237237 | S (S (S _)) = prim__uremB64 x y
238238
239−public partial
239+public export partial
240240urem : Bits n -> Bits n -> Bits n
241241urem (MkBits x) (MkBits y) = MkBits (urem' x y)
242242
@@ -302,7 +302,7 @@ complement' {n=n} x with (nextBytes n)
302302 | S (S (S _)) = let pad = getPad {n=3} n in
303303 prim__complB64 (x `prim__shlB64` pad) `prim__lshrB64` pad
304304
305−public
305+public export
306306complement : Bits n -> Bits n
307307complement (MkBits x) = MkBits (complement' x)
308308
@@ -321,7 +321,7 @@ zext' {n=n} {m=m} x with (nextBytes n, nextBytes (n+m))
321321 | (S (S Z), S (S (S _))) = believe_me (prim__zextB32_B64 (believe_me x))
322322 | (S (S (S _)), S (S (S _))) = believe_me x
323323
324−public
324+public export
325325zeroExtend : Bits n -> Bits (n+m)
326326zeroExtend (MkBits x) = MkBits (zext' x)
327327
@@ -337,7 +337,7 @@ intToBits' {n=n} x with (nextBytes n)
337337 | S (S (S _)) = let pad = getPad {n=3} n in
338338 prim__lshrB64 (prim__shlB64 (prim__truncBigInt_B64 x) pad) pad
339339
340−public
340+public export
341341intToBits : Integer -> Bits n
342342intToBits n = MkBits (intToBits' n)
343343
@@ -351,7 +351,7 @@ bitsToInt' {n=n} x with (nextBytes n)
351351 | S (S Z) = prim__zextB32_BigInt x
352352 | S (S (S _)) = prim__zextB64_BigInt x
353353
354−public
354+public export
355355bitsToInt : Bits n -> Integer
356356bitsToInt (MkBits x) = bitsToInt' x
357357
@@ -393,7 +393,7 @@ sext' {n=n} {m=m} x with (nextBytes n, nextBytes (n+m))
393393 | (S (S (S _)), S (S (S _))) = let pad = getPad {n=3} n in
394394 believe_me (prim__ashrB64 (prim__shlB64 (believe_me x) pad) pad)
395395
396−--public
396+--public export
397397--signExtend : Bits n -> Bits (n+m)
398398--signExtend {m=m} (MkBits x) = MkBits (zeroUnused (sext' x))
399399
@@ -412,23 +412,23 @@ trunc' {m=m} {n=n} x with (nextBytes n, nextBytes (m+n))
412412 | (S (S Z), S (S (S _))) = believe_me (prim__truncB64_B32 (believe_me x))
413413 | (S (S (S _)), S (S (S _))) = believe_me x
414414
415−public
415+public export
416416truncate : Bits (m+n) -> Bits n
417417truncate (MkBits x) = MkBits (zeroUnused (trunc' x))
418418
419−public
419+public export
420420bitAt : Fin n -> Bits n
421421bitAt n = intToBits 1 `shiftLeft` intToBits (cast n)
422422
423−public
423+public export
424424getBit : Fin n -> Bits n -> Bool
425425getBit n x = (x `and` (bitAt n)) /= intToBits 0
426426
427−public
427+public export
428428setBit : Fin n -> Bits n -> Bits n
429429setBit n x = x `or` (bitAt n)
430430
431−public
431+public export
432432unsetBit : Fin n -> Bits n -> Bits n
433433unsetBit n x = x `and` complement (bitAt n)
434434