@@ -92,6 +92,10 @@ pad64' n f x y = prim__lshrB64 (f (prim__shlB64 x pad) y) pad
93 pad = getPad {n=3} n
93 pad = getPad {n=3} n
95+-- TODO: This (and all the other functions along these lings) is public export
96+-- because it is used by public export things. Do they really need to be
97+-- public export, or is export good enough?
95shiftLeft' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
99shiftLeft' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
96shiftLeft' {n=n} x c with (nextBytes n)
100shiftLeft' {n=n} x c with (nextBytes n)
97 | Z = pad8' n prim__shlB8 x c
101 | Z = pad8' n prim__shlB8 x c
@@ -103,6 +107,7 @@ public export
103shiftLeft : Bits n -> Bits n -> Bits n
107shiftLeft : Bits n -> Bits n -> Bits n
104shiftLeft (MkBits x) (MkBits y) = MkBits (shiftLeft' x y)
108shiftLeft (MkBits x) (MkBits y) = MkBits (shiftLeft' x y)
106shiftRightLogical' : machineTy n -> machineTy n -> machineTy n
111shiftRightLogical' : machineTy n -> machineTy n -> machineTy n
107shiftRightLogical' {n=n} x c with (n)
112shiftRightLogical' {n=n} x c with (n)
108 | Z = prim__lshrB8 x c
113 | Z = prim__lshrB8 x c
@@ -115,6 +120,7 @@ shiftRightLogical : Bits n -> Bits n -> Bits n
115shiftRightLogical {n} (MkBits x) (MkBits y)
120shiftRightLogical {n} (MkBits x) (MkBits y)
116 = MkBits {n} (shiftRightLogical' {n=nextBytes n} x y)
121 = MkBits {n} (shiftRightLogical' {n=nextBytes n} x y)
118shiftRightArithmetic' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
124shiftRightArithmetic' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
119shiftRightArithmetic' {n=n} x c with (nextBytes n)
125shiftRightArithmetic' {n=n} x c with (nextBytes n)
120 | Z = pad8' n prim__ashrB8 x c
126 | Z = pad8' n prim__ashrB8 x c
@@ -126,6 +132,7 @@ public export
126shiftRightArithmetic : Bits n -> Bits n -> Bits n
132shiftRightArithmetic : Bits n -> Bits n -> Bits n
127shiftRightArithmetic (MkBits x) (MkBits y) = MkBits (shiftRightArithmetic' x y)
133shiftRightArithmetic (MkBits x) (MkBits y) = MkBits (shiftRightArithmetic' x y)
129and' : machineTy n -> machineTy n -> machineTy n
136and' : machineTy n -> machineTy n -> machineTy n
130and' {n=n} x y with (n)
137and' {n=n} x y with (n)
131 | Z = prim__andB8 x y
138 | Z = prim__andB8 x y
@@ -137,6 +144,7 @@ public export
137and : Bits n -> Bits n -> Bits n
144and : Bits n -> Bits n -> Bits n
138and {n} (MkBits x) (MkBits y) = MkBits (and' {n=nextBytes n} x y)
145and {n} (MkBits x) (MkBits y) = MkBits (and' {n=nextBytes n} x y)
140or' : machineTy n -> machineTy n -> machineTy n
148or' : machineTy n -> machineTy n -> machineTy n
141or' {n=n} x y with (n)
149or' {n=n} x y with (n)
142 | Z = prim__orB8 x y
150 | Z = prim__orB8 x y
@@ -148,6 +156,7 @@ public export
148or : Bits n -> Bits n -> Bits n
156or : Bits n -> Bits n -> Bits n
149or {n} (MkBits x) (MkBits y) = MkBits (or' {n=nextBytes n} x y)
157or {n} (MkBits x) (MkBits y) = MkBits (or' {n=nextBytes n} x y)
151xor' : machineTy n -> machineTy n -> machineTy n
160xor' : machineTy n -> machineTy n -> machineTy n
152xor' {n=n} x y with (n)
161xor' {n=n} x y with (n)
153 | Z = prim__xorB8 x y
162 | Z = prim__xorB8 x y
@@ -159,6 +168,7 @@ public export
159xor : Bits n -> Bits n -> Bits n
168xor : Bits n -> Bits n -> Bits n
160xor {n} (MkBits x) (MkBits y) = MkBits {n} (xor' {n=nextBytes n} x y)
169xor {n} (MkBits x) (MkBits y) = MkBits {n} (xor' {n=nextBytes n} x y)
162plus' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
172plus' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
163plus' {n=n} x y with (nextBytes n)
173plus' {n=n} x y with (nextBytes n)
164 | Z = pad8 n prim__addB8 x y
174 | Z = pad8 n prim__addB8 x y
@@ -170,6 +180,7 @@ public export
170plus : Bits n -> Bits n -> Bits n
180plus : Bits n -> Bits n -> Bits n
171plus (MkBits x) (MkBits y) = MkBits (plus' x y)
181plus (MkBits x) (MkBits y) = MkBits (plus' x y)
173minus' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
184minus' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
174minus' {n=n} x y with (nextBytes n)
185minus' {n=n} x y with (nextBytes n)
175 | Z = pad8 n prim__subB8 x y
186 | Z = pad8 n prim__subB8 x y
@@ -181,6 +192,7 @@ public export
181minus : Bits n -> Bits n -> Bits n
192minus : Bits n -> Bits n -> Bits n
182minus (MkBits x) (MkBits y) = MkBits (minus' x y)
193minus (MkBits x) (MkBits y) = MkBits (minus' x y)
184times' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
196times' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
185times' {n=n} x y with (nextBytes n)
197times' {n=n} x y with (nextBytes n)
186 | Z = pad8 n prim__mulB8 x y
198 | Z = pad8 n prim__mulB8 x y
@@ -193,6 +205,7 @@ times : Bits n -> Bits n -> Bits n
193times (MkBits x) (MkBits y) = MkBits (times' x y)
205times (MkBits x) (MkBits y) = MkBits (times' x y)
196sdiv' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
209sdiv' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
197sdiv' {n=n} x y with (nextBytes n)
210sdiv' {n=n} x y with (nextBytes n)
198 | Z = prim__sdivB8 x y
211 | Z = prim__sdivB8 x y
@@ -205,6 +218,7 @@ sdiv : Bits n -> Bits n -> Bits n
205sdiv (MkBits x) (MkBits y) = MkBits (sdiv' x y)
218sdiv (MkBits x) (MkBits y) = MkBits (sdiv' x y)
208udiv' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
222udiv' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
209udiv' {n=n} x y with (nextBytes n)
223udiv' {n=n} x y with (nextBytes n)
210 | Z = prim__udivB8 x y
224 | Z = prim__udivB8 x y
@@ -216,7 +230,7 @@ public export partial
216udiv : Bits n -> Bits n -> Bits n
230udiv : Bits n -> Bits n -> Bits n
217udiv (MkBits x) (MkBits y) = MkBits (udiv' x y)
231udiv (MkBits x) (MkBits y) = MkBits (udiv' x y)
219−partial
233+public export partial
220srem' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
234srem' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
221srem' {n=n} x y with (nextBytes n)
235srem' {n=n} x y with (nextBytes n)
222 | Z = prim__sremB8 x y
236 | Z = prim__sremB8 x y
@@ -228,7 +242,7 @@ public export partial
228srem : Bits n -> Bits n -> Bits n
242srem : Bits n -> Bits n -> Bits n
229srem (MkBits x) (MkBits y) = MkBits (srem' x y)
243srem (MkBits x) (MkBits y) = MkBits (srem' x y)
231−partial
245+public export partial
232urem' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
246urem' : machineTy (nextBytes n) -> machineTy (nextBytes n) -> machineTy (nextBytes n)
233urem' {n=n} x y with (nextBytes n)
247urem' {n=n} x y with (nextBytes n)
234 | Z = prim__uremB8 x y
248 | Z = prim__uremB8 x y
@@ -276,9 +290,11 @@ gt {n=n} x y with (nextBytes n)
276 | S (S Z) = prim__gtB32 x y
290 | S (S Z) = prim__gtB32 x y
277 | S (S (S _)) = prim__gtB64 x y
291 | S (S (S _)) = prim__gtB64 x y
279implementation Eq (Bits n) where
294implementation Eq (Bits n) where
280 (MkBits x) == (MkBits y) = boolOp eq x y
295 (MkBits x) == (MkBits y) = boolOp eq x y
282implementation Ord (Bits n) where
298implementation Ord (Bits n) where
283 (MkBits x) < (MkBits y) = boolOp lt x y
299 (MkBits x) < (MkBits y) = boolOp lt x y
284 (MkBits x) <= (MkBits y) = boolOp lte x y
300 (MkBits x) <= (MkBits y) = boolOp lte x y
@@ -291,6 +307,7 @@ implementation Ord (Bits n) where
294complement' : machineTy (nextBytes n) -> machineTy (nextBytes n)
311complement' : machineTy (nextBytes n) -> machineTy (nextBytes n)
295complement' {n=n} x with (nextBytes n)
312complement' {n=n} x with (nextBytes n)
296 | Z = let pad = getPad {n=0} n in
313 | Z = let pad = getPad {n=0} n in
@@ -307,7 +324,7 @@ complement : Bits n -> Bits n
307complement (MkBits x) = MkBits (complement' x)
324complement (MkBits x) = MkBits (complement' x)
309-- TODO: Prove
326-- TODO: Prove
310−%assert_total -- can't verify coverage of with block
327+public export %assert_total -- can't verify coverage of with block
311zext' : machineTy (nextBytes n) -> machineTy (nextBytes (n+m))
328zext' : machineTy (nextBytes n) -> machineTy (nextBytes (n+m))
312zext' {n=n} {m=m} x with (nextBytes n, nextBytes (n+m))
329zext' {n=n} {m=m} x with (nextBytes n, nextBytes (n+m))
313 | (Z, Z) = believe_me x
330 | (Z, Z) = believe_me x
@@ -325,7 +342,7 @@ public export
325zeroExtend : Bits n -> Bits (n+m)
342zeroExtend : Bits n -> Bits (n+m)
326zeroExtend (MkBits x) = MkBits (zext' x)
343zeroExtend (MkBits x) = MkBits (zext' x)
328−%assert_total
345+public export %assert_total
329intToBits' : Integer -> machineTy (nextBytes n)
346intToBits' : Integer -> machineTy (nextBytes n)
330intToBits' {n=n} x with (nextBytes n)
347intToBits' {n=n} x with (nextBytes n)
331 | Z = let pad = getPad {n=0} n in
348 | Z = let pad = getPad {n=0} n in
@@ -344,6 +361,7 @@ intToBits n = MkBits (intToBits' n)
344implementation Cast Integer (Bits n) where
361implementation Cast Integer (Bits n) where
345 cast = intToBits
362 cast = intToBits
347bitsToInt' : machineTy (nextBytes n) -> Integer
365bitsToInt' : machineTy (nextBytes n) -> Integer
348bitsToInt' {n=n} x with (nextBytes n)
366bitsToInt' {n=n} x with (nextBytes n)
349 | Z = prim__zextB8_BigInt x
367 | Z = prim__zextB8_BigInt x
@@ -356,6 +374,7 @@ bitsToInt : Bits n -> Integer
356bitsToInt (MkBits x) = bitsToInt' x
374bitsToInt (MkBits x) = bitsToInt' x
358-- Zero out the high bits of a truncated bitstring
376-- Zero out the high bits of a truncated bitstring
359zeroUnused : machineTy (nextBytes n) -> machineTy (nextBytes n)
378zeroUnused : machineTy (nextBytes n) -> machineTy (nextBytes n)
360zeroUnused {n} x = x `and'` complement' (intToBits' {n=n} 0)
379zeroUnused {n} x = x `and'` complement' (intToBits' {n=n} 0)
@@ -398,7 +417,7 @@ sext' {n=n} {m=m} x with (nextBytes n, nextBytes (n+m))
398--signExtend {m=m} (MkBits x) = MkBits (zeroUnused (sext' x))
417--signExtend {m=m} (MkBits x) = MkBits (zeroUnused (sext' x))
400-- TODO: Prove
419-- TODO: Prove
401−%assert_total -- can't verify coverage of with block
420+public export %assert_total -- can't verify coverage of with block
402trunc' : machineTy (nextBytes (m+n)) -> machineTy (nextBytes n)
421trunc' : machineTy (nextBytes (m+n)) -> machineTy (nextBytes n)
403trunc' {m=m} {n=n} x with (nextBytes n, nextBytes (m+n))
422trunc' {m=m} {n=n} x with (nextBytes n, nextBytes (m+n))
404 | (Z, Z) = believe_me x
423 | (Z, Z) = believe_me x