]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/num/word32.ma
freescale porting
[helm.git] / helm / software / matita / contribs / ng_assembly / num / word32.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
19 (*   Sviluppo: 2008-2010                                                  *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "num/word16.ma".
24
25 (* ***** *)
26 (* DWORD *)
27 (* ***** *)
28
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.
32
33 (* \langle \rangle *)
34 notation "〈x.y〉" non associative with precedence 80
35  for @{ mk_comp_num word16 $x $y }.
36
37 (* iteratore sulle dword *)
38 ndefinition forall_w32 ≝ forall_cn ? forall_w16.
39
40 (* operatore = *)
41 ndefinition eq_w32 ≝ eq2_cn ? eq_w16.
42
43 (* operatore < *)
44 ndefinition lt_w32 ≝ ltgt_cn ? eq_w16 lt_w16.
45
46 (* operatore ≤ *)
47 ndefinition le_w32 ≝ lege_cn ? eq_w16 lt_w16 le_w16.
48
49 (* operatore > *)
50 ndefinition gt_w32 ≝ ltgt_cn ? eq_w16 gt_w16.
51
52 (* operatore ≥ *)
53 ndefinition ge_w32 ≝ lege_cn ? eq_w16 gt_w16 ge_w16.
54
55 (* operatore and *)
56 ndefinition and_w32 ≝ fop2_cn ? and_w16.
57
58 (* operatore or *)
59 ndefinition or_w32 ≝ fop2_cn ? or_w16.
60
61 (* operatore xor *)
62 ndefinition xor_w32 ≝ fop2_cn ? xor_w16.
63
64 (* operatore Most Significant Bit *)
65 ndefinition getMSB_w32 ≝ getOPH_cn ? getMSB_w16.
66 ndefinition setMSB_w32 ≝ setOPH_cn ? setMSB_w16.
67
68 (* operatore Least Significant Bit *)
69 ndefinition getLSB_w32 ≝ getOPL_cn ? getLSB_w16.
70 ndefinition setLSB_w32 ≝ setOPL_cn ? setLSB_w16.
71
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〉〉〉.
76
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〉〉〉 ]).
87
88 (* operatore rotazione destra con carry *)
89 ndefinition rcr_w32 ≝ opcr_cn ? rcr_w16.
90
91 (* operatore shift destro *)
92 ndefinition shr_w32 ≝ opcr_cn ? rcr_w16 false.
93
94 (* operatore rotazione destra *)
95 ndefinition ror_w32 ≝
96 λw.match shr_w32 w with
97  [ pair c w' ⇒ match c with
98   [ true ⇒ setMSB_w32 w' | false ⇒ w' ]].
99
100 (* operatore rotazione sinistra con carry *)
101 ndefinition rcl_w32 ≝ opcl_cn ? rcl_w16.
102
103 (* operatore shift sinistro *)
104 ndefinition shl_w32 ≝ opcl_cn ? rcl_w16 false.
105
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' ]].
111
112 (* operatore not/complemento a 1 *)
113 ndefinition not_w32 ≝ fop_cn ? not_w16.
114
115 (* operatore somma con data+carry → data+carry *)
116 ndefinition plus_w32_dc_dc ≝ opcl2_cn ? plus_w16_dc_dc.
117
118 (* operatore somma con data+carry → data *)
119 ndefinition plus_w32_dc_d ≝ λc,w1,w2.snd … (plus_w32_dc_dc c w1 w2).
120
121 (* operatore somma con data+carry → c *)
122 ndefinition plus_w32_dc_c ≝ λc,w1,w2.fst … (plus_w32_dc_dc c w1 w2).
123
124 (* operatore somma con data → data+carry *)
125 ndefinition plus_w32_d_dc ≝ opcl2_cn ? plus_w16_dc_dc false.
126
127 (* operatore somma con data → data *)
128 ndefinition plus_w32_d_d ≝ λw1,w2.snd … (plus_w32_d_dc w1 w2).
129
130 (* operatore somma con data → c *)
131 ndefinition plus_w32_d_c ≝ λw1,w2.fst … (plus_w32_d_dc w1 w2).
132
133 (* operatore predecessore *)
134 ndefinition pred_w32 ≝ predsucc_cn ? (eq_w16 〈〈x0,x0〉:〈x0,x0〉〉) pred_w16.
135
136 (* operatore successore *)
137 ndefinition succ_w32 ≝ predsucc_cn ? (eq_w16 〈〈xF,xF〉:〈xF,xF〉〉) succ_w16.
138
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) ].
144
145 (* operatore x in [inf,sup] o in sup],[inf *)
146 ndefinition inrange_w32 ≝
147 λx,inf,sup:word32.
148  match le_w32 inf sup with
149   [ true ⇒ and_bool | false ⇒ or_bool ]
150  (le_w32 inf x) (le_w32 x sup).