X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fmatita%2Fcontribs%2Fng_assembly%2Fnum%2Fbyte8.ma;h=4d621bb29168702bcf9405615975fa1c715a900c;hb=a90c31c1b53222bd6d57360c5ba5c2d0fe7d5207;hp=d3d6eddef8b3d2366ed66eab95aa7ce6ce6601ce;hpb=4377e950998c9c63937582952a79975947aa9a45;p=helm.git diff --git a/helm/software/matita/contribs/ng_assembly/num/byte8.ma b/helm/software/matita/contribs/ng_assembly/num/byte8.ma index d3d6eddef..4d621bb29 100755 --- a/helm/software/matita/contribs/ng_assembly/num/byte8.ma +++ b/helm/software/matita/contribs/ng_assembly/num/byte8.ma @@ -16,142 +16,182 @@ (* Progetto FreeScale *) (* *) (* Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it *) -(* Sviluppo: 2008-2010 *) +(* Ultima modifica: 05/08/2009 *) (* *) (* ********************************************************************** *) include "num/exadecim.ma". -include "num/comp_num.ma". include "num/bitrigesim.ma". -include "common/nat.ma". (* **** *) (* BYTE *) (* **** *) -ndefinition byte8 ≝ comp_num exadecim. -ndefinition mk_byte8 ≝ λe1,e2.mk_comp_num exadecim e1 e2. +nrecord byte8 : Type ≝ + { + b8h: exadecim; + b8l: exadecim + }. (* \langle \rangle *) notation "〈x,y〉" non associative with precedence 80 - for @{ mk_comp_num exadecim $x $y }. - -(* iteratore sui byte *) -ndefinition forall_b8 ≝ forall_cn ? forall_ex. + for @{ 'mk_byte8 $x $y }. +interpretation "mk_byte8" 'mk_byte8 x y = (mk_byte8 x y). (* operatore = *) -ndefinition eq_b8 ≝ eq2_cn ? eq_ex. +ndefinition eq_b8 ≝ λb1,b2:byte8.(eq_ex (b8h b1) (b8h b2)) ⊗ (eq_ex (b8l b1) (b8l b2)). (* operatore < *) -ndefinition lt_b8 ≝ ltgt_cn ? eq_ex lt_ex. +ndefinition lt_b8 ≝ +λb1,b2:byte8. + (lt_ex (b8h b1) (b8h b2)) ⊕ + ((eq_ex (b8h b1) (b8h b2)) ⊗ (lt_ex (b8l b1) (b8l b2))). (* operatore ≤ *) -ndefinition le_b8 ≝ lege_cn ? eq_ex lt_ex le_ex. +ndefinition le_b8 ≝ +λb1,b2:byte8. + (lt_ex (b8h b1) (b8h b2)) ⊕ + ((eq_ex (b8h b1) (b8h b2)) ⊗ (le_ex (b8l b1) (b8l b2))). (* operatore > *) -ndefinition gt_b8 ≝ ltgt_cn ? eq_ex gt_ex. +ndefinition gt_b8 ≝ +λb1,b2:byte8. + (gt_ex (b8h b1) (b8h b2)) ⊕ + ((eq_ex (b8h b1) (b8h b2)) ⊗ (gt_ex (b8l b1) (b8l b2))). (* operatore ≥ *) -ndefinition ge_b8 ≝ lege_cn ? eq_ex gt_ex ge_ex. +ndefinition ge_b8 ≝ +λb1,b2:byte8. + (gt_ex (b8h b1) (b8h b2)) ⊕ + ((eq_ex (b8h b1) (b8h b2)) ⊗ (ge_ex (b8l b1) (b8l b2))). (* operatore and *) -ndefinition and_b8 ≝ fop2_cn ? and_ex. +ndefinition and_b8 ≝ +λb1,b2:byte8.mk_byte8 (and_ex (b8h b1) (b8h b2)) (and_ex (b8l b1) (b8l b2)). (* operatore or *) -ndefinition or_b8 ≝ fop2_cn ? or_ex. +ndefinition or_b8 ≝ +λb1,b2:byte8.mk_byte8 (or_ex (b8h b1) (b8h b2)) (or_ex (b8l b1) (b8l b2)). (* operatore xor *) -ndefinition xor_b8 ≝ fop2_cn ? xor_ex. - -(* operatore Most Significant Bit *) -ndefinition getMSB_b8 ≝ getOPH_cn ? getMSB_ex. -ndefinition setMSB_b8 ≝ setOPH_cn ? setMSB_ex. -ndefinition clrMSB_b8 ≝ setOPH_cn ? clrMSB_ex. - -(* operatore Least Significant Bit *) -ndefinition getLSB_b8 ≝ getOPL_cn ? getLSB_ex. -ndefinition setLSB_b8 ≝ setOPL_cn ? setLSB_ex. -ndefinition clrLSB_b8 ≝ setOPL_cn ? clrLSB_ex. - -(* operatore estensione unsigned *) -ndefinition extu_b8 ≝ λe2.〈x0,e2〉. - -(* operatore estensione signed *) -ndefinition exts_b8 ≝ -λe2.〈(match getMSB_ex e2 with - [ true ⇒ xF | false ⇒ x0 ]),e2〉. +ndefinition xor_b8 ≝ +λb1,b2:byte8.mk_byte8 (xor_ex (b8h b1) (b8h b2)) (xor_ex (b8l b1) (b8l b2)). (* operatore rotazione destra con carry *) -ndefinition rcr_b8 ≝ opcr_cn ? rcr_ex. +ndefinition rcr_b8 ≝ +λb:byte8.λc:bool.match rcr_ex (b8h b) c with + [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with + [ pair bl' c'' ⇒ pair … (mk_byte8 bh' bl') c'' ]]. (* operatore shift destro *) -ndefinition shr_b8 ≝ opcr_cn ? rcr_ex false. +ndefinition shr_b8 ≝ +λb:byte8.match rcr_ex (b8h b) false with + [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with + [ pair bl' c'' ⇒ pair … (mk_byte8 bh' bl') c'' ]]. (* operatore rotazione destra *) ndefinition ror_b8 ≝ -λb.match shr_b8 b with - [ pair c b' ⇒ match c with - [ true ⇒ setMSB_b8 b' | false ⇒ b' ]]. +λb:byte8.match rcr_ex (b8h b) false with + [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with + [ pair bl' c'' ⇒ match c'' with + [ true ⇒ mk_byte8 (or_ex x8 bh') bl' + | false ⇒ mk_byte8 bh' bl' ]]]. + +(* operatore rotazione destra n-volte *) +nlet rec ror_b8_n (b:byte8) (n:nat) on n ≝ + match n with + [ O ⇒ b + | S n' ⇒ ror_b8_n (ror_b8 b) n' ]. (* operatore rotazione sinistra con carry *) -ndefinition rcl_b8 ≝ opcl_cn ? rcl_ex. +ndefinition rcl_b8 ≝ +λb:byte8.λc:bool.match rcl_ex (b8l b) c with + [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with + [ pair bh' c'' ⇒ pair … (mk_byte8 bh' bl') c'' ]]. (* operatore shift sinistro *) -ndefinition shl_b8 ≝ opcl_cn ? rcl_ex false. +ndefinition shl_b8 ≝ +λb:byte8.match rcl_ex (b8l b) false with + [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with + [ pair bh' c'' ⇒ pair … (mk_byte8 bh' bl') c'' ]]. (* operatore rotazione sinistra *) ndefinition rol_b8 ≝ -λb.match shl_b8 b with - [ pair c b' ⇒ match c with - [ true ⇒ setLSB_b8 b' | false ⇒ b' ]]. +λb:byte8.match rcl_ex (b8l b) false with + [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with + [ pair bh' c'' ⇒ match c'' with + [ true ⇒ mk_byte8 bh' (or_ex x1 bl') + | false ⇒ mk_byte8 bh' bl' ]]]. + +(* operatore rotazione sinistra n-volte *) +nlet rec rol_b8_n (b:byte8) (n:nat) on n ≝ + match n with + [ O ⇒ b + | S n' ⇒ rol_b8_n (rol_b8 b) n' ]. (* operatore not/complemento a 1 *) -ndefinition not_b8 ≝ fop_cn ? not_ex. +ndefinition not_b8 ≝ +λb:byte8.mk_byte8 (not_ex (b8h b)) (not_ex (b8l b)). (* operatore somma con data+carry → data+carry *) -ndefinition plus_b8_dc_dc ≝ opcl2_cn ? plus_ex_dc_dc. +ndefinition plus_b8_dc_dc ≝ +λb1,b2:byte8.λc:bool. + match plus_ex_dc_dc (b8l b1) (b8l b2) c with + [ pair l c ⇒ match plus_ex_dc_dc (b8h b1) (b8h b2) c with + [ pair h c' ⇒ pair … 〈h,l〉 c' ]]. (* operatore somma con data+carry → data *) -ndefinition plus_b8_dc_d ≝ λc,b1,b2.snd … (plus_b8_dc_dc c b1 b2). +ndefinition plus_b8_dc_d ≝ +λb1,b2:byte8.λc:bool. + match plus_ex_dc_dc (b8l b1) (b8l b2) c with + [ pair l c ⇒ 〈plus_ex_dc_d (b8h b1) (b8h b2) c,l〉 ]. (* operatore somma con data+carry → c *) -ndefinition plus_b8_dc_c ≝ λc,b1,b2.fst … (plus_b8_dc_dc c b1 b2). +ndefinition plus_b8_dc_c ≝ +λb1,b2:byte8.λc:bool. + plus_ex_dc_c (b8h b1) (b8h b2) (plus_ex_dc_c (b8l b1) (b8l b2) c). (* operatore somma con data → data+carry *) -ndefinition plus_b8_d_dc ≝ opcl2_cn ? plus_ex_dc_dc false. +ndefinition plus_b8_d_dc ≝ +λb1,b2:byte8. + match plus_ex_d_dc (b8l b1) (b8l b2) with + [ pair l c ⇒ match plus_ex_dc_dc (b8h b1) (b8h b2) c with + [ pair h c' ⇒ pair … 〈h,l〉 c' ]]. (* operatore somma con data → data *) -ndefinition plus_b8_d_d ≝ λb1,b2.snd … (plus_b8_d_dc b1 b2). +ndefinition plus_b8_d_d ≝ +λb1,b2:byte8. + match plus_ex_d_dc (b8l b1) (b8l b2) with + [ pair l c ⇒ 〈plus_ex_dc_d (b8h b1) (b8h b2) c,l〉 ]. (* operatore somma con data → c *) -ndefinition plus_b8_d_c ≝ λb1,b2.fst … (plus_b8_d_dc b1 b2). +ndefinition plus_b8_d_c ≝ +λb1,b2:byte8. + plus_ex_dc_c (b8h b1) (b8h b2) (plus_ex_d_c (b8l b1) (b8l b2)). + +(* operatore Most Significant Bit *) +ndefinition MSB_b8 ≝ λb:byte8.eq_ex x8 (and_ex x8 (b8h b)). (* operatore predecessore *) -ndefinition pred_b8 ≝ predsucc_cn ? (eq_ex x0) pred_ex. +ndefinition pred_b8 ≝ +λb:byte8.match eq_ex (b8l b) x0 with + [ true ⇒ mk_byte8 (pred_ex (b8h b)) (pred_ex (b8l b)) + | false ⇒ mk_byte8 (b8h b) (pred_ex (b8l b)) ]. (* operatore successore *) -ndefinition succ_b8 ≝ predsucc_cn ? (eq_ex xF) succ_ex. +ndefinition succ_b8 ≝ +λb:byte8.match eq_ex (b8l b) xF with + [ true ⇒ mk_byte8 (succ_ex (b8h b)) (succ_ex (b8l b)) + | false ⇒ mk_byte8 (b8h b) (succ_ex (b8l b)) ]. (* operatore neg/complemento a 2 *) ndefinition compl_b8 ≝ -λb:byte8.match getMSB_b8 b with +λb:byte8.match MSB_b8 b with [ true ⇒ succ_b8 (not_b8 b) | false ⇒ not_b8 (pred_b8 b) ]. -(* operatore abs *) -ndefinition abs_b8 ≝ -λb:byte8.match getMSB_b8 b with - [ true ⇒ compl_b8 b | false ⇒ b ]. - -(* operatore x in [inf,sup] o in sup],[inf *) -ndefinition inrange_b8 ≝ -λx,inf,sup:byte8. - match le_b8 inf sup with - [ true ⇒ and_bool | false ⇒ or_bool ] - (le_b8 inf x) (le_b8 x sup). - (* operatore moltiplicazione senza segno: e*e=[0x00,0xE1] *) -ndefinition mulu_ex ≝ +ndefinition mul_ex ≝ λe1,e2:exadecim.match e1 with [ x0 ⇒ match e2 with [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x0〉 | x2 ⇒ 〈x0,x0〉 | x3 ⇒ 〈x0,x0〉 @@ -235,91 +275,6 @@ ndefinition mulu_ex ≝ | xC ⇒ 〈xB,x4〉 | xD ⇒ 〈xC,x3〉 | xE ⇒ 〈xD,x2〉 | xF ⇒ 〈xE,x1〉 ] ]. -(* operatore moltiplicazione con segno *) -ndefinition muls_ex ≝ -λe1,e2:exadecim.match e1 with - [ x0 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x0〉 | x2 ⇒ 〈x0,x0〉 | x3 ⇒ 〈x0,x0〉 - | x4 ⇒ 〈x0,x0〉 | x5 ⇒ 〈x0,x0〉 | x6 ⇒ 〈x0,x0〉 | x7 ⇒ 〈x0,x0〉 - | x8 ⇒ 〈x0,x0〉 | x9 ⇒ 〈x0,x0〉 | xA ⇒ 〈x0,x0〉 | xB ⇒ 〈x0,x0〉 - | xC ⇒ 〈x0,x0〉 | xD ⇒ 〈x0,x0〉 | xE ⇒ 〈x0,x0〉 | xF ⇒ 〈x0,x0〉 ] - | x1 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x1〉 | x2 ⇒ 〈x0,x2〉 | x3 ⇒ 〈x0,x3〉 - | x4 ⇒ 〈x0,x4〉 | x5 ⇒ 〈x0,x5〉 | x6 ⇒ 〈x0,x6〉 | x7 ⇒ 〈x0,x7〉 - | x8 ⇒ 〈xF,x8〉 | x9 ⇒ 〈xF,x9〉 | xA ⇒ 〈xF,xA〉 | xB ⇒ 〈xF,xB〉 - | xC ⇒ 〈xF,xC〉 | xD ⇒ 〈xF,xD〉 | xE ⇒ 〈xF,xE〉 | xF ⇒ 〈xF,xF〉 ] - | x2 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x2〉 | x2 ⇒ 〈x0,x4〉 | x3 ⇒ 〈x0,x6〉 - | x4 ⇒ 〈x0,x8〉 | x5 ⇒ 〈x0,xA〉 | x6 ⇒ 〈x0,xC〉 | x7 ⇒ 〈x0,xE〉 - | x8 ⇒ 〈xF,x0〉 | x9 ⇒ 〈xF,x2〉 | xA ⇒ 〈xF,x4〉 | xB ⇒ 〈xF,x6〉 - | xC ⇒ 〈xF,x8〉 | xD ⇒ 〈xF,xA〉 | xE ⇒ 〈xF,xC〉 | xF ⇒ 〈xF,xE〉 ] - | x3 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x3〉 | x2 ⇒ 〈x0,x6〉 | x3 ⇒ 〈x0,x9〉 - | x4 ⇒ 〈x0,xC〉 | x5 ⇒ 〈x0,xF〉 | x6 ⇒ 〈x1,x2〉 | x7 ⇒ 〈x1,x5〉 - | x8 ⇒ 〈xE,x8〉 | x9 ⇒ 〈xE,xB〉 | xA ⇒ 〈xE,xE〉 | xB ⇒ 〈xF,x1〉 - | xC ⇒ 〈xF,x4〉 | xD ⇒ 〈xF,x7〉 | xE ⇒ 〈xF,xA〉 | xF ⇒ 〈xF,xD〉 ] - | x4 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x4〉 | x2 ⇒ 〈x0,x8〉 | x3 ⇒ 〈x0,xC〉 - | x4 ⇒ 〈x1,x0〉 | x5 ⇒ 〈x1,x4〉 | x6 ⇒ 〈x1,x8〉 | x7 ⇒ 〈x1,xC〉 - | x8 ⇒ 〈xE,x0〉 | x9 ⇒ 〈xE,x4〉 | xA ⇒ 〈xE,x8〉 | xB ⇒ 〈xE,xC〉 - | xC ⇒ 〈xF,x0〉 | xD ⇒ 〈xF,x4〉 | xE ⇒ 〈xF,x8〉 | xF ⇒ 〈xF,xC〉 ] - | x5 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x5〉 | x2 ⇒ 〈x0,xA〉 | x3 ⇒ 〈x0,xF〉 - | x4 ⇒ 〈x1,x4〉 | x5 ⇒ 〈x1,x9〉 | x6 ⇒ 〈x1,xE〉 | x7 ⇒ 〈x2,x3〉 - | x8 ⇒ 〈xD,x8〉 | x9 ⇒ 〈xD,xD〉 | xA ⇒ 〈xE,x2〉 | xB ⇒ 〈xE,x7〉 - | xC ⇒ 〈xE,xC〉 | xD ⇒ 〈xF,x1〉 | xE ⇒ 〈xF,x6〉 | xF ⇒ 〈xF,xB〉 ] - | x6 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x6〉 | x2 ⇒ 〈x0,xC〉 | x3 ⇒ 〈x1,x2〉 - | x4 ⇒ 〈x1,x8〉 | x5 ⇒ 〈x1,xE〉 | x6 ⇒ 〈x2,x4〉 | x7 ⇒ 〈x2,xA〉 - | x8 ⇒ 〈xD,x0〉 | x9 ⇒ 〈xD,x6〉 | xA ⇒ 〈xD,xC〉 | xB ⇒ 〈xE,x2〉 - | xC ⇒ 〈xE,x8〉 | xD ⇒ 〈xE,xE〉 | xE ⇒ 〈xF,x4〉 | xF ⇒ 〈xF,xA〉 ] - | x7 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x7〉 | x2 ⇒ 〈x0,xE〉 | x3 ⇒ 〈x1,x5〉 - | x4 ⇒ 〈x1,xC〉 | x5 ⇒ 〈x2,x3〉 | x6 ⇒ 〈x2,xA〉 | x7 ⇒ 〈x3,x1〉 - | x8 ⇒ 〈xC,x8〉 | x9 ⇒ 〈xC,xF〉 | xA ⇒ 〈xD,x6〉 | xB ⇒ 〈xD,xD〉 - | xC ⇒ 〈xE,x4〉 | xD ⇒ 〈xE,xB〉 | xE ⇒ 〈xF,x2〉 | xF ⇒ 〈xF,x9〉 ] - | x8 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,x8〉 | x2 ⇒ 〈xF,x0〉 | x3 ⇒ 〈xE,x8〉 - | x4 ⇒ 〈xE,x0〉 | x5 ⇒ 〈xD,x8〉 | x6 ⇒ 〈xD,x0〉 | x7 ⇒ 〈xC,x8〉 - | x8 ⇒ 〈x4,x0〉 | x9 ⇒ 〈x3,x8〉 | xA ⇒ 〈x3,x0〉 | xB ⇒ 〈x2,x8〉 - | xC ⇒ 〈x2,x0〉 | xD ⇒ 〈x1,x8〉 | xE ⇒ 〈x1,x0〉 | xF ⇒ 〈x0,x8〉 ] - | x9 ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,x9〉 | x2 ⇒ 〈xF,x2〉 | x3 ⇒ 〈xE,xB〉 - | x4 ⇒ 〈xE,x4〉 | x5 ⇒ 〈xD,xD〉 | x6 ⇒ 〈xD,x6〉 | x7 ⇒ 〈xC,xF〉 - | x8 ⇒ 〈x3,x8〉 | x9 ⇒ 〈x3,x1〉 | xA ⇒ 〈x2,xA〉 | xB ⇒ 〈x2,x3〉 - | xC ⇒ 〈x1,xC〉 | xD ⇒ 〈x1,x5〉 | xE ⇒ 〈x0,xE〉 | xF ⇒ 〈x0,x7〉 ] - | xA ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xA〉 | x2 ⇒ 〈xF,x4〉 | x3 ⇒ 〈xE,xE〉 - | x4 ⇒ 〈xE,x8〉 | x5 ⇒ 〈xE,x2〉 | x6 ⇒ 〈xD,xC〉 | x7 ⇒ 〈xD,x6〉 - | x8 ⇒ 〈x3,x0〉 | x9 ⇒ 〈x2,xA〉 | xA ⇒ 〈x2,x4〉 | xB ⇒ 〈x1,xE〉 - | xC ⇒ 〈x1,x8〉 | xD ⇒ 〈x1,x2〉 | xE ⇒ 〈x0,xC〉 | xF ⇒ 〈x0,x6〉 ] - | xB ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xB〉 | x2 ⇒ 〈xF,x6〉 | x3 ⇒ 〈xF,x1〉 - | x4 ⇒ 〈xE,xC〉 | x5 ⇒ 〈xE,x7〉 | x6 ⇒ 〈xE,x2〉 | x7 ⇒ 〈xD,xD〉 - | x8 ⇒ 〈x2,x8〉 | x9 ⇒ 〈x2,x3〉 | xA ⇒ 〈x1,xE〉 | xB ⇒ 〈x1,x9〉 - | xC ⇒ 〈x1,x4〉 | xD ⇒ 〈x0,xF〉 | xE ⇒ 〈x0,xA〉 | xF ⇒ 〈x0,x5〉 ] - | xC ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xC〉 | x2 ⇒ 〈xF,x8〉 | x3 ⇒ 〈xF,x4〉 - | x4 ⇒ 〈xF,x0〉 | x5 ⇒ 〈xE,xC〉 | x6 ⇒ 〈xE,x8〉 | x7 ⇒ 〈xE,x4〉 - | x8 ⇒ 〈x2,x0〉 | x9 ⇒ 〈x1,xC〉 | xA ⇒ 〈x1,x8〉 | xB ⇒ 〈x1,x4〉 - | xC ⇒ 〈x1,x0〉 | xD ⇒ 〈x0,xC〉 | xE ⇒ 〈x0,x8〉 | xF ⇒ 〈x0,x4〉 ] - | xD ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xD〉 | x2 ⇒ 〈xF,xA〉 | x3 ⇒ 〈xF,x7〉 - | x4 ⇒ 〈xF,x4〉 | x5 ⇒ 〈xF,x1〉 | x6 ⇒ 〈xE,xE〉 | x7 ⇒ 〈xE,xB〉 - | x8 ⇒ 〈x1,x8〉 | x9 ⇒ 〈x1,x5〉 | xA ⇒ 〈x1,x2〉 | xB ⇒ 〈x0,xF〉 - | xC ⇒ 〈x0,xC〉 | xD ⇒ 〈x0,x9〉 | xE ⇒ 〈x0,x6〉 | xF ⇒ 〈x0,x3〉 ] - | xE ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xE〉 | x2 ⇒ 〈xF,xC〉 | x3 ⇒ 〈xF,xA〉 - | x4 ⇒ 〈xF,x8〉 | x5 ⇒ 〈xF,x6〉 | x6 ⇒ 〈xF,x4〉 | x7 ⇒ 〈xF,x2〉 - | x8 ⇒ 〈x1,x0〉 | x9 ⇒ 〈x0,xE〉 | xA ⇒ 〈x0,xC〉 | xB ⇒ 〈x0,xA〉 - | xC ⇒ 〈x0,x8〉 | xD ⇒ 〈x0,x6〉 | xE ⇒ 〈x0,x4〉 | xF ⇒ 〈x0,x2〉 ] - | xF ⇒ match e2 with - [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xF〉 | x2 ⇒ 〈xF,xE〉 | x3 ⇒ 〈xF,xD〉 - | x4 ⇒ 〈xF,xC〉 | x5 ⇒ 〈xF,xB〉 | x6 ⇒ 〈xF,xA〉 | x7 ⇒ 〈xF,x9〉 - | x8 ⇒ 〈x0,x8〉 | x9 ⇒ 〈x0,x7〉 | xA ⇒ 〈x0,x6〉 | xB ⇒ 〈x0,x5〉 - | xC ⇒ 〈x0,x4〉 | xD ⇒ 〈x0,x3〉 | xE ⇒ 〈x0,x2〉 | xF ⇒ 〈x0,x1〉 ] - ]. - (* correzione per somma su BCD *) (* input: halfcarry,carry,X(BCD+BCD) *) (* output: X',carry' *) @@ -331,26 +286,37 @@ ndefinition daa_b8 ≝ (* X' = [(b16l X):0x0-0x9] X + [h=1 ? 0x06 : 0x00] + [c=1 ? 0x60 : 0x00] [(b16l X):0xA-0xF] X + 0x06 + [c=1 ? 0x60 : 0x00] *) [ true ⇒ - let X' ≝ match (lt_ex (cnL ? X) xA) ⊗ (⊖h) with + let X' ≝ match (lt_ex (b8l X) xA) ⊗ (⊖h) with [ true ⇒ X | false ⇒ plus_b8_d_d X 〈x0,x6〉 ] in let X'' ≝ match c with [ true ⇒ plus_b8_d_d X' 〈x6,x0〉 | false ⇒ X' ] in - pair … c X'' + pair … X'' c (* [X:0x9A-0xFF] *) (* c' = 1 *) (* X' = [X:0x9A-0xFF] [(b16l X):0x0-0x9] X + [h=1 ? 0x06 : 0x00] + 0x60 [(b16l X):0xA-0xF] X + 0x6 + 0x60 *) | false ⇒ - let X' ≝ match (lt_ex (cnL ? X) xA) ⊗ (⊖h) with + let X' ≝ match (lt_ex (b8l X) xA) ⊗ (⊖h) with [ true ⇒ X | false ⇒ plus_b8_d_d X 〈x0,x6〉 ] in let X'' ≝ plus_b8_d_d X' 〈x6,x0〉 in - pair … true X'' + pair … X'' true ]. +(* operatore x in [inf,sup] *) +ndefinition inrange_b8 ≝ +λx,inf,sup:byte8.(le_b8 inf x) ⊗ (le_b8 x sup). + +(* iteratore sui byte *) +ndefinition forall_b8 ≝ + λP. + forall_ex (λbh. + forall_ex (λbl. + P (mk_byte8 bh bl))). + (* byte ricorsivi *) ninductive rec_byte8 : byte8 → Type ≝ b8_O : rec_byte8 〈x0,x0〉 @@ -423,8 +389,7 @@ nqed. *) ndefinition b8_to_recb8 : Πb.rec_byte8 b ≝ -λb.match b with - [ mk_comp_num h l ⇒ b8_to_recb8_aux3 h l (b8_to_recb8_aux2 h (ex_to_recex h)) ]. +λb.match b with [ mk_byte8 h l ⇒ b8_to_recb8_aux3 h l (b8_to_recb8_aux2 h (ex_to_recex h)) ]. (* ottali → esadecimali *) ndefinition b8_of_bit ≝