1217309Snwhitehornstructure wordsSyntax :> wordsSyntax = 2255852Sdteskestruct 3217309Snwhitehorn 4220749Snwhitehornopen HolKernel Parse boolLib bossLib 5217309Snwhitehornopen bitSyntax fcpSyntax fcpLib wordsTheory 6255852Sdteske 7217309Snwhitehornval ERR = mk_HOL_ERR "wordsSyntax" 8217309Snwhitehorn 9217309Snwhitehornfun syntax_fns n d m = HolKernel.syntax_fns {n = n, dest = d, make = m} "words" 10217309Snwhitehorn 11217309Snwhitehorn(*---------------------------------------------------------------------------*) 12217309Snwhitehorn(* Word types *) 13217309Snwhitehorn(*---------------------------------------------------------------------------*) 14217309Snwhitehorn 15217309Snwhitehornfun mk_word_type ty = fcpSyntax.mk_cart_type (Type.bool, ty) 16217309Snwhitehorn 17217309Snwhitehornval mk_int_word_type = mk_word_type o fcpSyntax.mk_int_numeric_type 18217309Snwhitehorn 19217309Snwhitehornfun dest_word_type ty = 20217309Snwhitehorn let 21217309Snwhitehorn val (a, b) = fcpSyntax.dest_cart_type ty 22217309Snwhitehorn val _ = a = Type.bool orelse 23217309Snwhitehorn raise ERR "dest_word_type" "not an instance of :bool['a]" 24217309Snwhitehorn in 25217309Snwhitehorn b 26217309Snwhitehorn end 27217309Snwhitehorn 28217309Snwhitehornval is_word_type = Lib.can dest_word_type 29217309Snwhitehornval dim_of = dest_word_type o Term.type_of 30217309Snwhitehornval size_of = fcpLib.index_to_num o dim_of 31217309Snwhitehorn 32217309Snwhitehorn(*---------------------------------------------------------------------------*) 33217309Snwhitehorn(* Terms, Constructors, Destructors and Discriminators *) 34217309Snwhitehorn(*---------------------------------------------------------------------------*) 35217309Snwhitehorn 36220749Snwhitehornval fcp_index_tm = fcpSyntax.fcp_index_tm 37217309Snwhitehorn 38224014Snwhitehornfun mk_index (w, n) = 39224014Snwhitehorn Lib.with_exn HolKernel.list_mk_comb 40224014Snwhitehorn (Term.inst [Type.alpha |-> Type.bool, Type.beta |-> dim_of w] fcp_index_tm, 41217309Snwhitehorn [w, n]) 42255852Sdteske (ERR "mk_index" "") 43217309Snwhitehorn 44217309Snwhitehornval dest_index = fcpSyntax.dest_fcp_index 45217309Snwhitehornval is_index = Lib.can dest_index 46217309Snwhitehorn 47217309Snwhitehornval dimindex_tm = fcpSyntax.dimindex_tm 48217309Snwhitehornval mk_dimindex = fcpSyntax.mk_dimindex 49217309Snwhitehornval dest_dimindex = fcpSyntax.dest_dimindex 50217309Snwhitehornval is_dimindex = Lib.can dest_dimindex 51224014Snwhitehorn 52224014Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 53217309Snwhitehorn 54224014Snwhitehornval s = syntax_fns 0 55224014Snwhitehorn (fn tm1 => fn e => fn tm2 => 56224014Snwhitehorn if Term.same_const tm1 tm2 then dim_of tm2 else raise e) 57224014Snwhitehorn (fn tm => fn ty => Term.inst [Type.alpha |-> ty] tm) 58224014Snwhitehorn 59224014Snwhitehornval (word_T_tm, mk_word_T, dest_word_T, is_word_T) = s "word_T" 60224014Snwhitehornval (word_L_tm, mk_word_L, dest_word_L, is_word_L) = s "word_L" 61224014Snwhitehornval (word_H_tm, mk_word_H, dest_word_H, is_word_H) = s "word_H" 62224014Snwhitehornval (word_L2_tm, mk_word_L2, dest_word_L2, is_word_L2) = s "word_L2" 63224014Snwhitehorn 64224014Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 65224014Snwhitehorn 66224014Snwhitehornval s = syntax_fns 1 67224014Snwhitehorn (fn tm1 => fn e => boolSyntax.dest_itself o HolKernel.dest_monop tm1 e) 68224014Snwhitehorn (fn tm => fn ty => 69224014Snwhitehorn Term.mk_comb (Term.inst [Type.alpha |-> ty] tm, boolSyntax.mk_itself ty)) 70224014Snwhitehorn 71224014Snwhitehornval (dimword_tm, mk_dimword, dest_dimword, is_dimword) = s "dimword" 72224014Snwhitehornval (uint_max_tm, mk_uint_max, dest_uint_max, is_uint_max) = s "UINT_MAX" 73224014Snwhitehornval (int_min_tm, mk_int_min, dest_int_min, is_int_min) = s "INT_MIN" 74224014Snwhitehornval (int_max_tm, mk_int_max, dest_int_max, is_int_max) = s "INT_MAX" 75224014Snwhitehorn 76224014Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 77224014Snwhitehorn 78224014Snwhitehornval s = HolKernel.syntax_fns1 "words" 79224014Snwhitehorn 80224014Snwhitehornval (w2n_tm, mk_w2n, dest_w2n, is_w2n) = s "w2n" 81224014Snwhitehornval (word_abs_tm, mk_word_abs, dest_word_abs, is_word_abs) = s "word_abs" 82224014Snwhitehornval (word_len_tm, mk_word_len, dest_word_len, is_word_len) = s "word_len" 83224014Snwhitehornval (word_log2_tm, mk_word_log2, dest_word_log2, is_word_log2) = s "word_log2" 84224014Snwhitehornval (word_msb_tm, mk_word_msb, dest_word_msb, is_word_msb) = s "word_msb" 85224014Snwhitehornval (word_lsb_tm, mk_word_lsb, dest_word_lsb, is_word_lsb) = s "word_lsb" 86224014Snwhitehornval (bit_count_tm, mk_bit_count, dest_bit_count, is_bit_count) = s "bit_count" 87224014Snwhitehornval (reduce_or_tm, mk_reduce_or, dest_reduce_or, is_reduce_or) = s "reduce_or" 88224014Snwhitehorn 89217309Snwhitehornval (reduce_and_tm, mk_reduce_and, dest_reduce_and, is_reduce_and) = 90217309Snwhitehorn s "reduce_and" 91217309Snwhitehorn 92217309Snwhitehornval (reduce_nand_tm, mk_reduce_nand, dest_reduce_nand, is_reduce_nand) = 93217309Snwhitehorn s "reduce_nand" 94217309Snwhitehorn 95217309Snwhitehornval (reduce_nor_tm, mk_reduce_nor, dest_reduce_nor, is_reduce_nor) = 96224014Snwhitehorn s "reduce_nor" 97251843Sbapt 98217309Snwhitehornval (reduce_xnor_tm, mk_reduce_xnor, dest_reduce_xnor, is_reduce_xnor) = 99217309Snwhitehorn s "reduce_xnor" 100217309Snwhitehorn 101217309Snwhitehornval (reduce_xor_tm, mk_reduce_xor, dest_reduce_xor, is_reduce_xor) = 102217309Snwhitehorn s "reduce_xor" 103217309Snwhitehorn 104217309Snwhitehornval (word_1comp_tm, mk_word_1comp, dest_word_1comp, is_word_1comp) = 105217309Snwhitehorn s "word_1comp" 106217309Snwhitehorn 107217309Snwhitehornval (word_2comp_tm, mk_word_2comp, dest_word_2comp, is_word_2comp) = 108217309Snwhitehorn s "word_2comp" 109217309Snwhitehorn 110217309Snwhitehornval (word_reverse_tm, mk_word_reverse, dest_word_reverse, is_word_reverse) = 111217309Snwhitehorn s "word_reverse" 112217309Snwhitehorn 113217309Snwhitehornval (word_to_bin_list_tm, mk_word_to_bin_list, 114217309Snwhitehorn dest_word_to_bin_list, is_word_to_bin_list) = s "word_to_bin_list" 115217309Snwhitehorn 116217309Snwhitehornval (word_to_oct_list_tm, mk_word_to_oct_list, 117217309Snwhitehorn dest_word_to_oct_list, is_word_to_oct_list) = s "word_to_oct_list" 118217309Snwhitehorn 119217309Snwhitehornval (word_to_dec_list_tm, mk_word_to_dec_list, 120217309Snwhitehorn dest_word_to_dec_list, is_word_to_dec_list) = s "word_to_dec_list" 121217309Snwhitehorn 122217309Snwhitehornval (word_to_hex_list_tm, mk_word_to_hex_list, 123217309Snwhitehorn dest_word_to_hex_list, is_word_to_hex_list) = s "word_to_hex_list" 124220749Snwhitehorn 125220749Snwhitehornval (word_to_bin_string_tm, mk_word_to_bin_string, 126251843Sbapt dest_word_to_bin_string, is_word_to_bin_string) = s "word_to_bin_string" 127251843Sbapt 128217309Snwhitehornval (word_to_oct_string_tm, mk_word_to_oct_string, 129220749Snwhitehorn dest_word_to_oct_string, is_word_to_oct_string) = s "word_to_oct_string" 130217309Snwhitehorn 131251843Sbaptval (word_to_dec_string_tm, mk_word_to_dec_string, 132224014Snwhitehorn dest_word_to_dec_string, is_word_to_dec_string) = s "word_to_dec_string" 133220749Snwhitehorn 134217309Snwhitehornval (word_to_hex_string_tm, mk_word_to_hex_string, 135251843Sbapt dest_word_to_hex_string, is_word_to_hex_string) = s "word_to_hex_string" 136251843Sbapt 137251843Sbapt(* - - - - - - - - - - - - - - - - - - - - - - *) 138251843Sbapt 139251843Sbaptval s = syntax_fns 1 140251843Sbapt (fn tm => fn e => pairSyntax.dest_pair o HolKernel.dest_monop tm e) 141217309Snwhitehorn (fn tm => fn (x, w) => 142220749Snwhitehorn Term.mk_comb (Term.inst [Type.alpha |-> dim_of w] tm, 143220749Snwhitehorn pairSyntax.mk_pair (x, w))) 144251843Sbapt 145220749Snwhitehornval (word_rrx_tm, mk_word_rrx, dest_word_rrx, is_word_rrx) = s "word_rrx" 146220749Snwhitehorn 147220749Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 148251843Sbapt 149217309Snwhitehornval s = syntax_fns 1 150220749Snwhitehorn (fn tm => fn e => fn x => 151220749Snwhitehorn let 152217309Snwhitehorn val (a, y) = pairSyntax.dest_pair (HolKernel.dest_monop tm e x) 153220749Snwhitehorn val (b, c) = pairSyntax.dest_pair y 154220749Snwhitehorn in 155217309Snwhitehorn (a, b, c) 156220749Snwhitehorn end) 157220749Snwhitehorn (fn tm => fn (a, b, c) => 158220749Snwhitehorn Term.mk_comb (Term.inst [Type.alpha |-> dim_of a] tm, 159220749Snwhitehorn pairSyntax.list_mk_pair [a, b, c])) 160220749Snwhitehorn 161220749Snwhitehornval (add_with_carry_tm, mk_add_with_carry, 162251843Sbapt dest_add_with_carry, is_add_with_carry) = s "add_with_carry" 163220749Snwhitehorn 164220749Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 165251843Sbapt 166217309Snwhitehornval s = syntax_fns 1 167220749Snwhitehorn (fn tm1 => fn e => fn w => (HolKernel.dest_monop tm1 e w, dim_of w)) 168220749Snwhitehorn (fn tm => fn (w, ty) => Term.mk_comb (Term.inst [Type.alpha |-> ty] tm, w)) 169220749Snwhitehorn 170251843Sbaptval (n2w_tm, mk_n2w, dest_n2w, is_n2w) = s "n2w" 171220749Snwhitehorn 172220749Snwhitehornval (saturate_n2w_tm, mk_saturate_n2w, dest_saturate_n2w, is_saturate_n2w) = 173220749Snwhitehorn s "saturate_n2w" 174220749Snwhitehorn 175220749Snwhitehornval (word_from_bin_list_tm, mk_word_from_bin_list, 176220749Snwhitehorn dest_word_from_bin_list, is_word_from_bin_list) = s "word_from_bin_list" 177217309Snwhitehorn 178217309Snwhitehornval (word_from_oct_list_tm, mk_word_from_oct_list, 179217309Snwhitehorn dest_word_from_oct_list, is_word_from_oct_list) = s "word_from_oct_list" 180220749Snwhitehorn 181220749Snwhitehornval (word_from_dec_list_tm, mk_word_from_dec_list, 182217309Snwhitehorn dest_word_from_dec_list, is_word_from_dec_list) = s "word_from_dec_list" 183220749Snwhitehorn 184220749Snwhitehornval (word_from_hex_list_tm, mk_word_from_hex_list, 185217309Snwhitehorn dest_word_from_hex_list, is_word_from_hex_list) = s "word_from_hex_list" 186251843Sbapt 187217309Snwhitehornval (word_from_bin_string_tm, mk_word_from_bin_string, 188220749Snwhitehorn dest_word_from_bin_string, is_word_from_bin_string) = 189220749Snwhitehorn s "word_from_bin_string" 190220749Snwhitehorn 191217309Snwhitehornval (word_from_oct_string_tm, mk_word_from_oct_string, 192217309Snwhitehorn dest_word_from_oct_string, is_word_from_oct_string) = 193217309Snwhitehorn s "word_from_oct_string" 194217309Snwhitehorn 195217309Snwhitehornval (word_from_dec_string_tm, mk_word_from_dec_string, 196217309Snwhitehorn dest_word_from_dec_string, is_word_from_dec_string) = 197217309Snwhitehorn s "word_from_dec_string" 198217309Snwhitehorn 199217309Snwhitehornval (word_from_hex_string_tm, mk_word_from_hex_string, 200217309Snwhitehorn dest_word_from_hex_string, is_word_from_hex_string) = s 201217309Snwhitehorn "word_from_hex_string" 202217309Snwhitehorn 203217309Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 204217309Snwhitehorn 205217309Snwhitehornval s = syntax_fns 1 206217309Snwhitehorn (fn tm1 => fn e => fn w => (HolKernel.dest_monop tm1 e w, dim_of w)) 207217309Snwhitehorn (fn tm => fn (w, ty) => 208217309Snwhitehorn Term.mk_comb 209217309Snwhitehorn (Term.inst [Type.alpha |-> dim_of w, Type.beta |-> ty] tm, w)) 210217309Snwhitehorn 211217309Snwhitehornval (w2w_tm, mk_w2w, dest_w2w, is_w2w) = s "w2w" 212217309Snwhitehornval (sw2sw_tm, mk_sw2sw, dest_sw2sw, is_sw2sw) = s "sw2sw" 213217309Snwhitehorn 214217309Snwhitehornval (saturate_w2w_tm, mk_saturate_w2w, dest_saturate_w2w, is_saturate_w2w) = 215217309Snwhitehorn s "saturate_w2w" 216217309Snwhitehorn 217217309Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 218217309Snwhitehorn 219217309Snwhitehornval s = syntax_fns 1 220217309Snwhitehorn (fn tm1 => fn e => fn w => (HolKernel.dest_monop tm1 e w, dim_of w)) 221217309Snwhitehorn (fn tm => fn (l, ty) => 222217309Snwhitehorn let 223220749Snwhitehorn val d = dest_word_type (listSyntax.dest_list_type (Term.type_of l)) 224220749Snwhitehorn in 225224014Snwhitehorn Term.mk_comb (Term.inst [Type.alpha |-> d, Type.beta |-> ty] tm, l) 226220749Snwhitehorn end) 227220749Snwhitehorn 228217309Snwhitehornval (concat_word_list_tm, mk_concat_word_list, 229217309Snwhitehorn dest_concat_word_list, is_concat_word_list) = s "concat_word_list" 230220749Snwhitehorn 231220749Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 232220749Snwhitehorn 233220749Snwhitehornval s = HolKernel.syntax_fns2 "words" 234220749Snwhitehorn 235220749Snwhitehornval (w2l_tm, mk_w2l, dest_w2l, is_w2l) = s "w2l" 236220749Snwhitehornval (nzcv_tm, mk_nzcv, dest_nzcv, is_nzcv) = s "nzcv" 237220749Snwhitehornval (word_lt_tm, mk_word_lt, dest_word_lt, is_word_lt) = s "word_lt" 238217309Snwhitehornval (word_le_tm, mk_word_le, dest_word_le, is_word_le) = s "word_le" 239217309Snwhitehornval (word_gt_tm, mk_word_gt, dest_word_gt, is_word_gt) = s "word_gt" 240217309Snwhitehornval (word_ge_tm, mk_word_ge, dest_word_ge, is_word_ge) = s "word_ge" 241217309Snwhitehornval (word_lo_tm, mk_word_lo, dest_word_lo, is_word_lo) = s "word_lo" 242217309Snwhitehornval (word_ls_tm, mk_word_ls, dest_word_ls, is_word_ls) = s "word_ls" 243217309Snwhitehornval (word_hi_tm, mk_word_hi, dest_word_hi, is_word_hi) = s "word_hi" 244217309Snwhitehornval (word_hs_tm, mk_word_hs, dest_word_hs, is_word_hs) = s "word_hs" 245217309Snwhitehornval (word_or_tm, mk_word_or, dest_word_or, is_word_or) = s "word_or" 246220749Snwhitehornval (word_and_tm, mk_word_and, dest_word_and, is_word_and) = s "word_and" 247217309Snwhitehornval (word_xor_tm, mk_word_xor, dest_word_xor, is_word_xor) = s "word_xor" 248220749Snwhitehornval (word_nor_tm, mk_word_nor, dest_word_nor, is_word_nor) = s "word_nor" 249224014Snwhitehornval (word_nand_tm, mk_word_nand, dest_word_nand, is_word_nand) = s "word_nand" 250224014Snwhitehornval (word_xnor_tm, mk_word_xnor, dest_word_xnor, is_word_xnor) = s "word_xnor" 251217309Snwhitehornval (word_add_tm, mk_word_add, dest_word_add, is_word_add) = s "word_add" 252217309Snwhitehornval (word_sub_tm, mk_word_sub, dest_word_sub, is_word_sub) = s "word_sub" 253217309Snwhitehornval (word_mul_tm, mk_word_mul, dest_word_mul, is_word_mul) = s "word_mul" 254217309Snwhitehornval (word_div_tm, mk_word_div, dest_word_div, is_word_div) = s "word_div" 255217309Snwhitehornval (word_mod_tm, mk_word_mod, dest_word_mod, is_word_mod) = s "word_mod" 256217309Snwhitehornval (word_quot_tm, mk_word_quot, dest_word_quot, is_word_quot) = s "word_quot" 257217309Snwhitehornval (word_rem_tm, mk_word_rem, dest_word_rem, is_word_rem) = s "word_rem" 258217309Snwhitehornval (word_smin_tm, mk_word_smin, dest_word_smin, is_word_smin) = s "word_smin" 259217309Snwhitehornval (word_smax_tm, mk_word_smax, dest_word_smax, is_word_smax) = s "word_smax" 260217309Snwhitehornval (word_min_tm, mk_word_min, dest_word_min, is_word_min) = s "word_min" 261217309Snwhitehornval (word_max_tm, mk_word_max, dest_word_max, is_word_max) = s "word_max" 262217309Snwhitehornval (word_lsl_tm, mk_word_lsl, dest_word_lsl, is_word_lsl) = s "word_lsl" 263224014Snwhitehornval (word_lsr_tm, mk_word_lsr, dest_word_lsr, is_word_lsr) = s "word_lsr" 264224014Snwhitehornval (word_asr_tm, mk_word_asr, dest_word_asr, is_word_asr) = s "word_asr" 265217309Snwhitehornval (word_ror_tm, mk_word_ror, dest_word_ror, is_word_ror) = s "word_ror" 266224014Snwhitehornval (word_rol_tm, mk_word_rol, dest_word_rol, is_word_rol) = s "word_rol" 267224014Snwhitehornval (word_bit_tm, mk_word_bit, dest_word_bit, is_word_bit) = s "word_bit" 268224014Snwhitehorn 269217309Snwhitehornval (word_lsl_bv_tm, mk_word_lsl_bv, dest_word_lsl_bv, is_word_lsl_bv) = 270217309Snwhitehorn s "word_lsl_bv" 271217309Snwhitehorn 272224014Snwhitehornval (word_lsr_bv_tm, mk_word_lsr_bv, dest_word_lsr_bv, is_word_lsr_bv) = 273224014Snwhitehorn s "word_lsr_bv" 274224014Snwhitehorn 275224014Snwhitehornval (word_asr_bv_tm, mk_word_asr_bv, dest_word_asr_bv, is_word_asr_bv) = 276255852Sdteske s "word_asr_bv" 277224014Snwhitehorn 278255852Sdteskeval (word_ror_bv_tm, mk_word_ror_bv, dest_word_ror_bv, is_word_ror_bv) = 279224014Snwhitehorn s "word_ror_bv" 280224014Snwhitehorn 281224014Snwhitehornval (word_rol_bv_tm, mk_word_rol_bv, dest_word_rol_bv, is_word_rol_bv) = 282255852Sdteske s "word_rol_bv" 283224014Snwhitehorn 284224014Snwhitehornval (word_compare_tm, mk_word_compare, dest_word_compare, is_word_compare) = 285217309Snwhitehorn s "word_compare" 286255852Sdteske 287217309Snwhitehornval (saturate_add_tm, mk_saturate_add, dest_saturate_add, is_saturate_add) = 288224014Snwhitehorn s "saturate_add" 289255852Sdteske 290255852Sdteskeval (saturate_sub_tm, mk_saturate_sub, dest_saturate_sub, is_saturate_sub) = 291255852Sdteske s "saturate_sub" 292255852Sdteske 293255852Sdteskeval (saturate_mul_tm, mk_saturate_mul, dest_saturate_mul, is_saturate_mul) = 294255852Sdteske s "saturate_mul" 295217309Snwhitehorn 296217309Snwhitehornval (word_modify_tm, mk_word_modify, dest_word_modify, is_word_modify) = 297255852Sdteske s "word_modify" 298255852Sdteske 299217309Snwhitehornval (word_reduce_tm, mk_word_reduce, dest_word_reduce, is_word_reduce) = 300255852Sdteske s "word_reduce" 301217309Snwhitehorn 302217309Snwhitehornval (bit_count_upto_tm, mk_bit_count_upto, 303255852Sdteske dest_bit_count_upto, is_bit_count_upto) = s "bit_count_upto" 304255852Sdteske 305255852Sdteskeval (word_sign_extend_tm, mk_word_sign_extend, 306255852Sdteske dest_word_sign_extend, is_word_sign_extend) = s "word_sign_extend" 307217309Snwhitehorn 308255852Sdteskeval (word_join_tm, mk_word_join, dest_word_join, is_word_join) = s "word_join" 309255852Sdteske 310255852Sdteske(* - - - - - - - - - - - - - - - - - - - - - - *) 311217309Snwhitehorn 312255852Sdteskeval s = syntax_fns 2 313255852Sdteske (fn tm1 => fn e => fn w => 314255852Sdteske let val (n, l) = HolKernel.dest_binop tm1 e w in (n, l, dim_of w) end) 315255852Sdteske (fn tm => fn (n, l, ty) => 316255852Sdteske Term.list_mk_comb (Term.inst [Type.alpha |-> ty] tm, [n, l])) 317255852Sdteske 318217309Snwhitehornval (l2w_tm, mk_l2w, dest_l2w, is_l2w) = s "l2w" 319255852Sdteske 320255852Sdteske(* - - - - - - - - - - - - - - - - - - - - - - *) 321255852Sdteske 322255852Sdteskeval s = syntax_fns 2 HolKernel.dest_binop 323255852Sdteske (fn tm => fn (w1, w2) => 324255852Sdteske let 325255852Sdteske val d1 = dim_of w1 326217309Snwhitehorn val d2 = dim_of w2 327224014Snwhitehorn val d3 = fcpLib.index_type 328224014Snwhitehorn (Arbnum.+ (fcpLib.index_to_num d1, fcpLib.index_to_num d2)) 329224014Snwhitehorn handle HOL_ERR _ => Type.gamma 330224014Snwhitehorn in 331224014Snwhitehorn Term.list_mk_comb 332217309Snwhitehorn (Term.inst [Type.alpha |-> d1, Type.beta |-> d2, 333255852Sdteske Type.gamma |-> d3] tm, [w1, w2]) 334255852Sdteske end) 335255852Sdteske 336255852Sdteskeval (word_concat_tm, mk_word_concat, dest_word_concat, is_word_concat) = 337255852Sdteske s "word_concat" 338255852Sdteske 339255852Sdteske(* - - - - - - - - - - - - - - - - - - - - - - *) 340255852Sdteske 341255852Sdteskeval s = syntax_fns 2 HolKernel.dest_binop 342224014Snwhitehorn (fn tm => fn (n, w) => 343224014Snwhitehorn let 344224014Snwhitehorn val d1 = dim_of w 345224014Snwhitehorn val d2 = fcpLib.index_type 346224014Snwhitehorn (Arbnum.* (fcpLib.index_to_num d1, 347255852Sdteske numSyntax.dest_numeral n)) 348255852Sdteske handle HOL_ERR _ => Type.beta 349255852Sdteske in 350255852Sdteske Term.list_mk_comb 351255852Sdteske (Term.inst [Type.alpha |-> d1, Type.beta |-> d2] tm, [n, w]) 352224014Snwhitehorn end) 353255852Sdteske 354224014Snwhitehornval (word_replicate_tm, mk_word_replicate, 355224014Snwhitehorn dest_word_replicate, is_word_replicate) = s "word_replicate" 356224014Snwhitehorn 357255852Sdteskefun mk_word_replicate_ty (n, w, ty) = 358255852Sdteske Term.list_mk_comb 359255852Sdteske (Term.inst [Type.alpha |-> dim_of w, Type.beta |-> ty] word_replicate_tm, 360255852Sdteske [n, w]) 361255852Sdteske 362255852Sdteske(* - - - - - - - - - - - - - - - - - - - - - - *) 363255852Sdteske 364255852Sdteskeval (bit_set_tm, mk_bit_set, dest_bit_set, is_bit_set) = 365255852Sdteske syntax_fns 3 HolKernel.dest_binop HolKernel.mk_binop "BIT_SET" 366255852Sdteske 367224014Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 368224014Snwhitehorn 369224014Snwhitehornval s = HolKernel.syntax_fns3 "words" 370224014Snwhitehorn 371224014Snwhitehornval (word_bits_tm, mk_word_bits, dest_word_bits, is_word_bits) = s "word_bits" 372224014Snwhitehorn 373224014Snwhitehornval (word_slice_tm, mk_word_slice, dest_word_slice, is_word_slice) = 374224014Snwhitehorn s "word_slice" 375224014Snwhitehorn 376224014Snwhitehornval (w2s_tm, mk_w2s, dest_w2s, is_w2s) = s "w2s" 377217309Snwhitehorn 378224014Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 379217309Snwhitehorn 380224014Snwhitehornval s = syntax_fns 3 381224014Snwhitehorn (fn tm1 => fn e => fn w => 382224014Snwhitehorn let 383224014Snwhitehorn val (n1, n2, s) = HolKernel.dest_triop tm1 e w 384224014Snwhitehorn in 385224014Snwhitehorn (n1, n2, w, dim_of w) 386224014Snwhitehorn end) 387224014Snwhitehorn (fn tm => fn (n1, n2, n3, ty) => 388224014Snwhitehorn Term.list_mk_comb (Term.inst [Type.alpha |-> ty] tm, [n1, n2, n3])) 389224014Snwhitehorn 390224014Snwhitehornval (s2w_tm, mk_s2w, dest_s2w, is_s2w) = s "s2w" 391224014Snwhitehorn 392224014Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 393224014Snwhitehorn 394224014Snwhitehornval s = syntax_fns 3 395224014Snwhitehorn (fn tm1 => fn e => fn w => 396224014Snwhitehorn let 397224014Snwhitehorn val (n1, n2, w1) = HolKernel.dest_triop tm1 e w 398224014Snwhitehorn in 399217309Snwhitehorn (n1, n2, w1, dim_of w) 400224014Snwhitehorn end) 401224014Snwhitehorn (fn tm => fn (n1, n2, w, ty) => 402224014Snwhitehorn Term.list_mk_comb 403251843Sbapt (Term.inst [Type.alpha |-> dim_of w, Type.beta |-> ty] tm, 404217309Snwhitehorn [n1, n2, w])) 405224014Snwhitehorn 406217309Snwhitehornval (word_extract_tm, mk_word_extract, dest_word_extract, is_word_extract) = 407217309Snwhitehorn s "word_extract" 408224014Snwhitehorn 409224014Snwhitehorn(* - - - - - - - - - - - - - - - - - - - - - - *) 410224014Snwhitehorn 411224014Snwhitehornval s = HolKernel.syntax_fns4 "words" 412224014Snwhitehorn 413224014Snwhitehornval (bit_field_insert_tm, mk_bit_field_insert, 414224014Snwhitehorn dest_bit_field_insert, is_bit_field_insert) = s "bit_field_insert" 415224014Snwhitehorn 416224014Snwhitehorn(*---------------------------------------------------------------------------*) 417224014Snwhitehorn 418224014Snwhitehornfun mk_word (v, n) = mk_n2w (numSyntax.mk_numeral v, fcpLib.index_type n) 419224014Snwhitehornfun mk_wordi (v, i) = mk_word (v, Arbnum.fromInt i) 420224014Snwhitehornfun mk_wordii (v, i) = mk_wordi (Arbnum.fromInt v, i) 421224014Snwhitehorn 422224014Snwhitehornval dest_word_literal = numSyntax.dest_numeral o fst o dest_n2w 423224014Snwhitehorn 424217309Snwhitehornval is_word_literal = Lib.can dest_word_literal 425224014Snwhitehorn 426217309Snwhitehornval uint_of_word = numSyntax.int_of_term o fst o dest_n2w 427224014Snwhitehorn 428224014Snwhitehornfun mod_2exp (m, n) = 429224014Snwhitehorn if n = Arbnum.zero orelse m = Arbnum.zero 430217309Snwhitehorn then Arbnum.zero 431217309Snwhitehorn else let 432217309Snwhitehorn val v = Arbnum.times2 (mod_2exp (Arbnum.div2 m, Arbnum.less1 n)) 433224014Snwhitehorn in 434217309Snwhitehorn if Arbnum.mod2 m = Arbnum.zero then v else Arbnum.plus1 v 435224014Snwhitehorn end 436217309Snwhitehorn 437217309Snwhitehornfun dest_mod_word_literal tm = 438217309Snwhitehorn let 439 val (tm1, ty) = dest_n2w tm 440 val sz = fcpLib.index_to_num ty 441 in 442 (mod_2exp (numSyntax.dest_numeral tm1, sz), sz) 443 end handle HOL_ERR _ => raise ERR "dest_mod_word_literal" "" 444 445end 446