@@ -2,55 +2,30 @@ open import Pervasives_extra
22open import Machine_word
33open import Sail2_values
44open import Sail2_operators
5- (* TODO: Move monadic operations (to sail2_monadic_combinators?)
6- open import Sail2_prompt_monad
7- open import Sail2_prompt*)
85
96(* Specialisation of operators to machine words *)
107
118let inline uint v = unsignedIntegerFromWord v
129let uint_maybe v = Just (uint v)
13- (*let uint_fail v = return (uint v)
14- let uint_nondet v = return (uint v)*)
1510
1611let inline sint v = signedIntegerFromWord v
1712let sint_maybe v = Just (sint v)
18- (*let sint_fail v = return (sint v)
19- let sint_nondet v = return (sint v)*)
20-
21- val vec_of_bits_maybe : forall 'a. Size 'a => list bitU -> maybe (mword 'a)
22- (*val vec_of_bits_fail : forall 'rv 'a 'e. Size 'a => list bitU -> monad 'rv (mword 'a) 'e
23- val vec_of_bits_nondet : forall 'rv 'a 'e. Size 'a, Register_Value 'rv => list bitU -> monad 'rv (mword 'a) 'e*)
24- val vec_of_bits_failwith : forall 'a. Size 'a => list bitU -> mword 'a
25- val vec_of_bits : forall 'a. Size 'a => list bitU -> mword 'a
26- let vec_of_bits_maybe bits = of_bits bits
27- (*let vec_of_bits_fail bits = of_bits_fail bits
28- let vec_of_bits_nondet bits = of_bits_nondet bits*)
29- let vec_of_bits_failwith bits = of_bits_failwith bits
30- let vec_of_bits bits = of_bits_failwith bits
31-
32- val access_vec_inc : forall 'a. Size 'a => mword 'a -> integer -> bitU
33- let access_vec_inc = access_bv_inc
34-
35- val access_vec_dec : forall 'a. Size 'a => mword 'a -> integer -> bitU
36- let access_vec_dec = access_bv_dec
37-
38- let update_vec_dec_maybe w i b = update_mword_dec w i b
39- (*let update_vec_dec_fail w i b =
40- bool_of_bitU_fail b >>= (fun b ->
41- return (update_mword_bool_dec w i b))
42- let update_vec_dec_nondet w i b =
43- bool_of_bitU_nondet b >>= (fun b ->
44- return (update_mword_bool_dec w i b))*)
13+
14+ val vec_of_bits_maybe : forall 'a. Size 'a => list (mword ty1) -> maybe (mword 'a)
15+ val vec_of_bits_failwith : forall 'a. Size 'a => list (mword ty1) -> mword 'a
16+ val vec_of_bits : forall 'a. Size 'a => list (mword ty1) -> mword 'a
17+ let vec_of_bits_maybe bits = of_bits (List.map (fun b -> bitU_of_bool (getBit b 0)) bits)
18+ let vec_of_bits_failwith bits = of_bits_failwith (List.map (fun b -> bitU_of_bool (getBit b 0)) bits)
19+ let vec_of_bits bits = of_bits_failwith (List.map (fun b -> bitU_of_bool (getBit b 0)) bits)
20+
21+ val update_vec_dec_maybe : forall 'a. Size 'a => mword 'a -> integer -> mword ty1 -> maybe (mword 'a)
22+ val update_vec_dec : forall 'a. Size 'a => mword 'a -> integer -> mword ty1 -> mword 'a
23+ let update_vec_dec_maybe w i b = Just (update_mword_bool_dec w i (getBit b 0))
4524let update_vec_dec w i b = maybe_failwith (update_vec_dec_maybe w i b)
4625
47- let update_vec_inc_maybe w i b = update_mword_inc w i b
48- (*let update_vec_inc_fail w i b =
49- bool_of_bitU_fail b >>= (fun b ->
50- return (update_mword_bool_inc w i b))
51- let update_vec_inc_nondet w i b =
52- bool_of_bitU_nondet b >>= (fun b ->
53- return (update_mword_bool_inc w i b))*)
26+ val update_vec_inc_maybe : forall 'a. Size 'a => mword 'a -> integer -> mword ty1 -> maybe (mword 'a)
27+ val update_vec_inc : forall 'a. Size 'a => mword 'a -> integer -> mword ty1 -> mword 'a
28+ let update_vec_inc_maybe w i b = Just (update_mword_bool_inc w i (getBit b 0))
5429let update_vec_inc w i b = maybe_failwith (update_vec_inc_maybe w i b)
5530
5631val subrange_vec_dec : forall 'a 'b. Size 'a, Size 'b => mword 'a -> integer -> integer -> mword 'b
@@ -59,6 +34,12 @@ let subrange_vec_dec w i j = Machine_word.word_extract (nat_of_int j) (nat_of_in
5934val subrange_vec_inc : forall 'a 'b. Size 'a, Size 'b => mword 'a -> integer -> integer -> mword 'b
6035let subrange_vec_inc w i j = subrange_vec_dec w (length w - 1 - i) (length w - 1 - j)
6136
37+ val access_vec_inc : forall 'a. Size 'a => mword 'a -> integer -> mword ty1
38+ let access_vec_inc w i = subrange_vec_inc w i i
39+
40+ val access_vec_dec : forall 'a. Size 'a => mword 'a -> integer -> mword ty1
41+ let access_vec_dec w i = subrange_vec_dec w i i
42+
6243val update_subrange_vec_dec : forall 'a 'b. Size 'a, Size 'b => mword 'a -> integer -> integer -> mword 'b -> mword 'a
6344let update_subrange_vec_dec w i j w' = Machine_word.word_update w (nat_of_int j) (nat_of_int i) w'
6445
@@ -96,22 +77,16 @@ let concat_vec = Machine_word.word_concat
9677val cons_vec_bool : forall 'a 'b 'c. Size 'a, Size 'b => bool -> mword 'a -> mword 'b
9778let cons_vec_bool b w = wordFromBitlist (b :: bitlistFromWord w)
9879let cons_vec_maybe b w = Maybe.map (fun b -> cons_vec_bool b w) (bool_of_bitU b)
99- (*let cons_vec_fail b w = bool_of_bitU_fail b >>= (fun b -> return (cons_vec_bool b w))
100- let cons_vec_nondet b w = bool_of_bitU_nondet b >>= (fun b -> return (cons_vec_bool b w))*)
10180let cons_vec b w = maybe_failwith (cons_vec_maybe b w)
10281
10382val vec_of_bool : forall 'a. Size 'a => integer -> bool -> mword 'a
10483let vec_of_bool _ b = wordFromBitlist [b]
10584let vec_of_bit_maybe len b = Maybe.map (vec_of_bool len) (bool_of_bitU b)
106- (*let vec_of_bit_fail len b = bool_of_bitU_fail b >>= (fun b -> return (vec_of_bool len b))
107- let vec_of_bit_nondet len b = bool_of_bitU_nondet b >>= (fun b -> return (vec_of_bool len b))*)
10885let vec_of_bit len b = maybe_failwith (vec_of_bit_maybe len b)
10986
11087val cast_bool_vec : bool -> mword ty1
11188let cast_bool_vec b = vec_of_bool 1 b
11289let cast_unit_vec_maybe b = vec_of_bit_maybe 1 b
113- (*let cast_unit_vec_fail b = bool_of_bitU_fail b >>= (fun b -> return (cast_bool_vec b))
114- let cast_unit_vec_nondet b = bool_of_bitU_nondet b >>= (fun b -> return (cast_bool_vec b))*)
11590let cast_unit_vec b = maybe_failwith (cast_unit_vec_maybe b)
11691
11792val msb : forall 'a. Size 'a => mword 'a -> bitU
@@ -123,7 +98,6 @@ let int_of_vec sign w =
12398 then signedIntegerFromWord w
12499 else unsignedIntegerFromWord w
125100let int_of_vec_maybe sign w = Just (int_of_vec sign w)
126- (*let int_of_vec_fail sign w = return (int_of_vec sign w)*)
127101
128102val string_of_bits : forall 'a. Size 'a => mword 'a -> string
129103let string_of_bits = string_of_bv
@@ -177,55 +151,20 @@ val subs_vec_bool : forall 'a. Size 'a => mword 'a -> bool -> mword 'a
177151
178152let add_vec_bool l r = arith_op_bv_bool integerAdd false l r
179153let add_vec_bit_maybe l r = Maybe.map (add_vec_bool l) (bool_of_bitU r)
180- (*let add_vec_bit_fail l r = bool_of_bitU_fail r >>= (fun r -> return (add_vec_bool l r))
181- let add_vec_bit_nondet l r = bool_of_bitU_nondet r >>= (fun r -> return (add_vec_bool l r))*)
182154let add_vec_bit l r = maybe_failwith (add_vec_bit_maybe l r)
183155
184156let adds_vec_bool l r = arith_op_bv_bool integerAdd true l r
185157let adds_vec_bit_maybe l r = Maybe.map (adds_vec_bool l) (bool_of_bitU r)
186- (*let adds_vec_bit_fail l r = bool_of_bitU_fail r >>= (fun r -> return (adds_vec_bool l r))
187- let adds_vec_bit_nondet l r = bool_of_bitU_nondet r >>= (fun r -> return (adds_vec_bool l r))*)
188158let adds_vec_bit l r = maybe_failwith (adds_vec_bit_maybe l r)
189159
190160let sub_vec_bool l r = arith_op_bv_bool integerMinus false l r
191161let sub_vec_bit_maybe l r = Maybe.map (sub_vec_bool l) (bool_of_bitU r)
192- (*let sub_vec_bit_fail l r = bool_of_bitU_fail r >>= (fun r -> return (sub_vec_bool l r))
193- let sub_vec_bit_nondet l r = bool_of_bitU_nondet r >>= (fun r -> return (sub_vec_bool l r))*)
194162let sub_vec_bit l r = maybe_failwith (sub_vec_bit_maybe l r)
195163
196164let subs_vec_bool l r = arith_op_bv_bool integerMinus true l r
197165let subs_vec_bit_maybe l r = Maybe.map (subs_vec_bool l) (bool_of_bitU r)
198- (*let subs_vec_bit_fail l r = bool_of_bitU_fail r >>= (fun r -> return (subs_vec_bool l r))
199- let subs_vec_bit_nondet l r = bool_of_bitU_nondet r >>= (fun r -> return (subs_vec_bool l r))*)
200166let subs_vec_bit l r = maybe_failwith (subs_vec_bit_maybe l r)
201167
202- (* TODO
203- val maybe_mword_of_bits_overflow : forall 'a. Size 'a => (list bitU * bitU * bitU) -> maybe (mword 'a * bitU * bitU)
204- let maybe_mword_of_bits_overflow (bits, overflow, carry) =
205- Maybe.map (fun w -> (w, overflow, carry)) (of_bits bits)
206-
207- val add_overflow_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a * bitU * bitU)
208- val adds_overflow_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a * bitU * bitU)
209- val sub_overflow_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a * bitU * bitU)
210- val subs_overflow_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a * bitU * bitU)
211- val mult_overflow_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a * bitU * bitU)
212- val mults_overflow_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a * bitU * bitU)
213- let add_overflow_vec l r = maybe_mword_of_bits_overflow (add_overflow_bv l r)
214- let adds_overflow_vec l r = maybe_mword_of_bits_overflow (adds_overflow_bv l r)
215- let sub_overflow_vec l r = maybe_mword_of_bits_overflow (sub_overflow_bv l r)
216- let subs_overflow_vec l r = maybe_mword_of_bits_overflow (subs_overflow_bv l r)
217- let mult_overflow_vec l r = maybe_mword_of_bits_overflow (mult_overflow_bv l r)
218- let mults_overflow_vec l r = maybe_mword_of_bits_overflow (mults_overflow_bv l r)
219-
220- val add_overflow_vec_bit : forall 'a. Size 'a => mword 'a -> bitU -> (mword 'a * bitU * bitU)
221- val add_overflow_vec_bit_signed : forall 'a. Size 'a => mword 'a -> bitU -> (mword 'a * bitU * bitU)
222- val sub_overflow_vec_bit : forall 'a. Size 'a => mword 'a -> bitU -> (mword 'a * bitU * bitU)
223- val sub_overflow_vec_bit_signed : forall 'a. Size 'a => mword 'a -> bitU -> (mword 'a * bitU * bitU)
224- let add_overflow_vec_bit = add_overflow_bv_bit
225- let add_overflow_vec_bit_signed = add_overflow_bv_bit_signed
226- let sub_overflow_vec_bit = sub_overflow_bv_bit
227- let sub_overflow_vec_bit_signed = sub_overflow_bv_bit_signed*)
228-
229168val shiftl : forall 'a. Size 'a => mword 'a -> integer -> mword 'a
230169val shiftr : forall 'a. Size 'a => mword 'a -> integer -> mword 'a
231170val arith_shiftr : forall 'a. Size 'a => mword 'a -> integer -> mword 'a
@@ -239,77 +178,35 @@ let rotr = rotr_mword
239178
240179val mod_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> mword 'a
241180val mod_vec_maybe : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a)
242- (*val mod_vec_fail : forall 'rv 'a 'e. Size 'a => mword 'a -> mword 'a -> monad 'rv (mword 'a) 'e
243- val mod_vec_nondet : forall 'rv 'a 'e. Size 'a, Register_Value 'rv => mword 'a -> mword 'a -> monad 'rv (mword 'a) 'e*)
244181let mod_vec l r = mod_mword l r
245182let mod_vec_maybe l r = mod_bv l r
246- (*let mod_vec_fail l r = maybe_fail "mod_vec" (mod_bv l r)
247- let mod_vec_nondet l r =
248- match (mod_bv l r) with
249- | Just w -> return w
250- | Nothing -> mword_nondet ()
251- end*)
252183
253184val quot_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> mword 'a
254185val quot_vec_maybe : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a)
255- (*val quot_vec_fail : forall 'rv 'a 'e. Size 'a => mword 'a -> mword 'a -> monad 'rv (mword 'a) 'e
256- val quot_vec_nondet : forall 'rv 'a 'e. Size 'a, Register_Value 'rv => mword 'a -> mword 'a -> monad 'rv (mword 'a) 'e*)
257186let quot_vec l r = quot_mword l r
258187let quot_vec_maybe l r = quot_bv l r
259- (*let quot_vec_fail l r = maybe_fail "quot_vec" (quot_bv l r)
260- let quot_vec_nondet l r =
261- match (quot_bv l r) with
262- | Just w -> return w
263- | Nothing -> mword_nondet ()
264- end*)
265188
266189val quots_vec : forall 'a. Size 'a => mword 'a -> mword 'a -> mword 'a
267190val quots_vec_maybe : forall 'a. Size 'a => mword 'a -> mword 'a -> maybe (mword 'a)
268- (*val quots_vec_fail : forall 'rv 'a 'e. Size 'a => mword 'a -> mword 'a -> monad 'rv (mword 'a) 'e
269- val quots_vec_nondet : forall 'rv 'a 'e. Size 'a, Register_Value 'rv => mword 'a -> mword 'a -> monad 'rv (mword 'a) 'e*)
270191let quots_vec l r = quots_mword l r
271192let quots_vec_maybe l r = quots_bv l r
272- (*let quots_vec_fail l r = maybe_fail "quots_vec" (quots_bv l r)
273- let quots_vec_nondet l r =
274- match (quots_bv l r) with
275- | Just w -> return w
276- | Nothing -> mword_nondet ()
277- end*)
278193
279194val mod_vec_int : forall 'a. Size 'a => mword 'a -> integer -> mword 'a
280195val mod_vec_int_maybe : forall 'a. Size 'a => mword 'a -> integer -> maybe (mword 'a)
281- (*val mod_vec_int_fail : forall 'rv 'a 'e. Size 'a => mword 'a -> integer -> monad 'rv (mword 'a) 'e
282- val mod_vec_int_nondet : forall 'rv 'a 'e. Size 'a, Register_Value 'rv => mword 'a -> integer -> monad 'rv (mword 'a) 'e*)
283196let mod_vec_int l r = mod_mword_int l r
284197let mod_vec_int_maybe l r = mod_bv_int l r
285- (*let mod_vec_int_fail l r = maybe_fail "mod_vec_int" (mod_bv_int l r)
286- let mod_vec_int_nondet l r =
287- match (mod_bv_int l r) with
288- | Just w -> return w
289- | Nothing -> mword_nondet ()
290- end*)
291198
292199val quot_vec_int : forall 'a. Size 'a => mword 'a -> integer -> mword 'a
293200val quot_vec_int_maybe : forall 'a. Size 'a => mword 'a -> integer -> maybe (mword 'a)
294- (*val quot_vec_int_fail : forall 'rv 'a 'e. Size 'a => mword 'a -> integer -> monad 'rv (mword 'a) 'e
295- val quot_vec_int_nondet : forall 'rv 'a 'e. Size 'a, Register_Value 'rv => mword 'a -> integer -> monad 'rv (mword 'a) 'e*)
296201let quot_vec_int l r = quot_mword_int l r
297202let quot_vec_int_maybe l r = quot_bv_int l r
298- (*let quot_vec_int_fail l r = maybe_fail "quot_vec_int" (quot_bv_int l r)
299- let quot_vec_int_nondet l r =
300- match (quot_bv_int l r) with
301- | Just w -> return w
302- | Nothing -> mword_nondet ()
303- end*)
304203
305204val replicate_bits : forall 'a 'b. Size 'a, Size 'b => mword 'a -> integer -> mword 'b
306205let replicate_bits v count = wordFromBitlist (repeat (bitlistFromWord v) count)
307206
308207val duplicate_bool : forall 'a. Size 'a => bool -> integer -> mword 'a
309208let duplicate_bool b n = wordFromBitlist (repeat [b] n)
310209let duplicate_maybe b n = Maybe.map (fun b -> duplicate_bool b n) (bool_of_bitU b)
311- (*let duplicate_fail b n = bool_of_bitU_fail b >>= (fun b -> return (duplicate_bool b n))
312- let duplicate_nondet b n = bool_of_bitU_nondet b >>= (fun b -> return (duplicate_bool b n))*)
313210let duplicate b n = maybe_failwith (duplicate_maybe b n)
314211
315212val reverse_endianness : forall 'a. Size 'a => mword 'a -> mword 'a
0 commit comments