1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
18 (* Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it *)
19 (* Sviluppo: 2008-2010 *)
21 (* ********************************************************************** *)
23 include "num/word16.ma".
29 ndefinition word32 ≝ comp_num word16.
30 ndefinition mk_word32 ≝ λw1,w2.mk_comp_num word16 w1 w2.
31 ndefinition ext_word32 ≝ λw2.mk_comp_num word16 〈〈x0,x0〉:〈x0,x0〉〉 w2.
34 notation "〈x.y〉" non associative with precedence 80
35 for @{ mk_comp_num word16 $x $y }.
37 (* iteratore sulle dword *)
38 ndefinition forall_w32 ≝ forall_cn ? forall_w16.
41 ndefinition eq_w32 ≝ eq2_cn ? eq_w16.
44 ndefinition lt_w32 ≝ ltgt_cn ? eq_w16 lt_w16.
47 ndefinition le_w32 ≝ lege_cn ? eq_w16 lt_w16 le_w16.
50 ndefinition gt_w32 ≝ ltgt_cn ? eq_w16 gt_w16.
53 ndefinition ge_w32 ≝ lege_cn ? eq_w16 gt_w16 ge_w16.
56 ndefinition and_w32 ≝ fop2_cn ? and_w16.
59 ndefinition or_w32 ≝ fop2_cn ? or_w16.
62 ndefinition xor_w32 ≝ fop2_cn ? xor_w16.
64 (* operatore Most Significant Bit *)
65 ndefinition getMSB_w32 ≝ getOPH_cn ? getMSB_w16.
66 ndefinition setMSB_w32 ≝ setOPH_cn ? setMSB_w16.
68 (* operatore Least Significant Bit *)
69 ndefinition getLSB_w32 ≝ getOPL_cn ? getLSB_w16.
70 ndefinition setLSB_w32 ≝ setOPL_cn ? setLSB_w16.
72 (* operatore estensione unsigned *)
73 ndefinition extu_w32 ≝ λw2.〈〈〈x0,x0〉:〈x0,x0〉〉.w2〉.
74 ndefinition extu2_w32 ≝ λb2.〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:b2〉〉.
75 ndefinition extu3_w32 ≝ λe2.〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:〈x0,e2〉〉〉.
77 (* operatore estensione signed *)
78 ndefinition exts_w32 ≝
79 λw2.〈(match getMSB_w16 w2 with
80 [ true ⇒ 〈〈xF,xF〉:〈xF,xF〉〉 | false ⇒ 〈〈x0,x0〉:〈x0,x0〉〉 ]).w2〉.
81 ndefinition exts2_w32 ≝
82 λb2.(match getMSB_b8 b2 with
83 [ true ⇒ 〈〈〈xF,xF〉:〈xF,xF〉〉.〈〈xF,xF〉:b2〉〉 | false ⇒ 〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:b2〉〉 ]).
84 ndefinition exts3_w32 ≝
85 λe2.(match getMSB_ex e2 with
86 [ true ⇒ 〈〈〈xF,xF〉:〈xF,xF〉〉.〈〈xF,xF〉:〈xF,e2〉〉〉 | false ⇒ 〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:〈x0,e2〉〉〉 ]).
88 (* operatore rotazione destra con carry *)
89 ndefinition rcr_w32 ≝ opcr_cn ? rcr_w16.
91 (* operatore shift destro *)
92 ndefinition shr_w32 ≝ opcr_cn ? rcr_w16 false.
94 (* operatore rotazione destra *)
96 λw.match shr_w32 w with
97 [ pair c w' ⇒ match c with
98 [ true ⇒ setMSB_w32 w' | false ⇒ w' ]].
100 (* operatore rotazione sinistra con carry *)
101 ndefinition rcl_w32 ≝ opcl_cn ? rcl_w16.
103 (* operatore shift sinistro *)
104 ndefinition shl_w32 ≝ opcl_cn ? rcl_w16 false.
106 (* operatore rotazione sinistra *)
107 ndefinition rol_w32 ≝
108 λw.match shl_w32 w with
109 [ pair c w' ⇒ match c with
110 [ true ⇒ setLSB_w32 w' | false ⇒ w' ]].
112 (* operatore not/complemento a 1 *)
113 ndefinition not_w32 ≝ fop_cn ? not_w16.
115 (* operatore somma con data+carry → data+carry *)
116 ndefinition plus_w32_dc_dc ≝ opcl2_cn ? plus_w16_dc_dc.
118 (* operatore somma con data+carry → data *)
119 ndefinition plus_w32_dc_d ≝ λc,w1,w2.snd … (plus_w32_dc_dc c w1 w2).
121 (* operatore somma con data+carry → c *)
122 ndefinition plus_w32_dc_c ≝ λc,w1,w2.fst … (plus_w32_dc_dc c w1 w2).
124 (* operatore somma con data → data+carry *)
125 ndefinition plus_w32_d_dc ≝ opcl2_cn ? plus_w16_dc_dc false.
127 (* operatore somma con data → data *)
128 ndefinition plus_w32_d_d ≝ λw1,w2.snd … (plus_w32_d_dc w1 w2).
130 (* operatore somma con data → c *)
131 ndefinition plus_w32_d_c ≝ λw1,w2.fst … (plus_w32_d_dc w1 w2).
133 (* operatore predecessore *)
134 ndefinition pred_w32 ≝ predsucc_cn ? (eq_w16 〈〈x0,x0〉:〈x0,x0〉〉) pred_w16.
136 (* operatore successore *)
137 ndefinition succ_w32 ≝ predsucc_cn ? (eq_w16 〈〈xF,xF〉:〈xF,xF〉〉) succ_w16.
139 (* operatore neg/complemento a 2 *)
140 ndefinition compl_w32 ≝
141 λw:word32.match getMSB_w32 w with
142 [ true ⇒ succ_w32 (not_w32 w)
143 | false ⇒ not_w32 (pred_w32 w) ].
145 (* operatore x in [inf,sup] o in sup],[inf *)
146 ndefinition inrange_w32 ≝
148 match le_w32 inf sup with
149 [ true ⇒ and_bool | false ⇒ or_bool ]
150 (le_w32 inf x) (le_w32 x sup).