]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/ng_assembly/num/word32.ma
e9b99efc39bf1a73b4f5df9ffd04e9ad42754084
[helm.git] / matita / 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 ndefinition clrMSB_w32 ≝ setOPH_cn ? clrMSB_w16.
68
69 (* operatore Least Significant Bit *)
70 ndefinition getLSB_w32 ≝ getOPL_cn ? getLSB_w16.
71 ndefinition setLSB_w32 ≝ setOPL_cn ? setLSB_w16.
72 ndefinition clrLSB_w32 ≝ setOPL_cn ? clrLSB_w16.
73
74 (* operatore estensione unsigned *)
75 ndefinition extu_w32 ≝ λw2.〈〈〈x0,x0〉:〈x0,x0〉〉.w2〉.
76 ndefinition extu2_w32 ≝ λb2.〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:b2〉〉.
77 ndefinition extu3_w32 ≝ λe2.〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:〈x0,e2〉〉〉.
78
79 (* operatore estensione signed *)
80 ndefinition exts_w32 ≝
81 λw2.〈(match getMSB_w16 w2 with
82       [ true ⇒ 〈〈xF,xF〉:〈xF,xF〉〉 | false ⇒ 〈〈x0,x0〉:〈x0,x0〉〉 ]).w2〉.
83 ndefinition exts2_w32 ≝
84 λb2.(match getMSB_b8 b2 with
85       [ true ⇒ 〈〈〈xF,xF〉:〈xF,xF〉〉.〈〈xF,xF〉:b2〉〉 | false ⇒ 〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:b2〉〉 ]).
86 ndefinition exts3_w32 ≝
87 λe2.(match getMSB_ex e2 with
88       [ true ⇒ 〈〈〈xF,xF〉:〈xF,xF〉〉.〈〈xF,xF〉:〈xF,e2〉〉〉 | false ⇒ 〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:〈x0,e2〉〉〉 ]).
89
90 (* operatore rotazione destra con carry *)
91 ndefinition rcr_w32 ≝ opcr_cn ? rcr_w16.
92
93 (* operatore shift destro *)
94 ndefinition shr_w32 ≝ opcr_cn ? rcr_w16 false.
95
96 (* operatore rotazione destra *)
97 ndefinition ror_w32 ≝
98 λw.match shr_w32 w with
99  [ pair c w' ⇒ match c with
100   [ true ⇒ setMSB_w32 w' | false ⇒ w' ]].
101
102 (* operatore rotazione sinistra con carry *)
103 ndefinition rcl_w32 ≝ opcl_cn ? rcl_w16.
104
105 (* operatore shift sinistro *)
106 ndefinition shl_w32 ≝ opcl_cn ? rcl_w16 false.
107
108 (* operatore rotazione sinistra *)
109 ndefinition rol_w32 ≝
110 λw.match shl_w32 w with
111  [ pair c w' ⇒ match c with
112   [ true ⇒ setLSB_w32 w' | false ⇒ w' ]].
113
114 (* operatore not/complemento a 1 *)
115 ndefinition not_w32 ≝ fop_cn ? not_w16.
116
117 (* operatore somma con data+carry → data+carry *)
118 ndefinition plus_w32_dc_dc ≝ opcl2_cn ? plus_w16_dc_dc.
119
120 (* operatore somma con data+carry → data *)
121 ndefinition plus_w32_dc_d ≝ λc,w1,w2.snd … (plus_w32_dc_dc c w1 w2).
122
123 (* operatore somma con data+carry → c *)
124 ndefinition plus_w32_dc_c ≝ λc,w1,w2.fst … (plus_w32_dc_dc c w1 w2).
125
126 (* operatore somma con data → data+carry *)
127 ndefinition plus_w32_d_dc ≝ opcl2_cn ? plus_w16_dc_dc false.
128
129 (* operatore somma con data → data *)
130 ndefinition plus_w32_d_d ≝ λw1,w2.snd … (plus_w32_d_dc w1 w2).
131
132 (* operatore somma con data → c *)
133 ndefinition plus_w32_d_c ≝ λw1,w2.fst … (plus_w32_d_dc w1 w2).
134
135 (* operatore predecessore *)
136 ndefinition pred_w32 ≝ predsucc_cn ? (eq_w16 〈〈x0,x0〉:〈x0,x0〉〉) pred_w16.
137
138 (* operatore successore *)
139 ndefinition succ_w32 ≝ predsucc_cn ? (eq_w16 〈〈xF,xF〉:〈xF,xF〉〉) succ_w16.
140
141 (* operatore neg/complemento a 2 *)
142 ndefinition compl_w32 ≝
143 λw:word32.match getMSB_w32 w with
144  [ true ⇒ succ_w32 (not_w32 w)
145  | false ⇒ not_w32 (pred_w32 w) ].
146
147 (* operatore abs *)
148 ndefinition abs_w32 ≝
149 λw:word32.match getMSB_w32 w with
150  [ true ⇒ compl_w32 w | false ⇒ w ].
151
152 (* operatore x in [inf,sup] o in sup],[inf *)
153 ndefinition inrange_w32 ≝
154 λx,inf,sup:word32.
155  match le_w32 inf sup with
156   [ true ⇒ and_bool | false ⇒ or_bool ]
157  (le_w32 inf x) (le_w32 x sup).
158
159 (* operatore moltiplicazione senza segno *)
160 (* 〈a1,a2〉 * 〈b1,b2〉 = (a1*b1) x0 x0 + x0 (a1*b2) x0 + x0 (a2*b1) x0 + x0 x0 (a2*b2) *)
161 ndefinition mulu_w16_aux ≝
162 λw.nat_it ? rol_w32 w nat8.
163
164 ndefinition mulu_w16 ≝
165 λw1,w2:word16.
166  plus_w32_d_d 〈(mulu_b8 (cnH ? w1) (cnH ? w2)).〈〈x0,x0〉:〈x0,x0〉〉〉
167  (plus_w32_d_d (mulu_w16_aux (extu_w32 (mulu_b8 (cnH ? w1) (cnL ? w2))))
168   (plus_w32_d_d (mulu_w16_aux (extu_w32 (mulu_b8 (cnL ? w1) (cnH ? w2))))
169                 (extu_w32 (mulu_b8 (cnL ? w1) (cnL ? w2))))).
170
171 (* operatore moltiplicazione con segno *)
172 (* x * y = sgn(x) * sgn(y) * |x| * |y| *)
173 ndefinition muls_w16 ≝
174 λw1,w2:word16.
175 (* ++/-- → +, +-/-+ → - *)
176  match (getMSB_w16 w1) ⊙ (getMSB_w16 w2) with
177   (* +- -+ → - *)
178   [ true ⇒ compl_w32
179   (* ++/-- → + *)
180   | false ⇒ λx.x ] (mulu_w16 (abs_w16 w1) (abs_w16 w2)).
181
182 nlemma pippo : ∃b.b=(muls_w16 〈〈xC,x3〉:〈x0,x4〉〉 〈〈x7,xE〉:〈xF,x9〉〉). nnormalize;
183