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/byte8.ma".
29 nrecord word24 : Type ≝
37 notation "〈x;y;z〉" non associative with precedence 80
38 for @{ 'mk_word24 $x $y $z }.
39 interpretation "mk_word24" 'mk_word24 x y z = (mk_word24 x y z).
41 (* iteratore sulle word *)
42 ndefinition forall_w24 ≝
47 P (mk_word24 bx bh bl )))).
51 λw1,w2.(eq_b8 (w24x w1) (w24x w2)) ⊗
52 (eq_b8 (w24h w1) (w24h w2)) ⊗
53 (eq_b8 (w24l w1) (w24l w2)).
58 (lt_b8 (w24x w1) (w24x w2)) ⊕
59 ((eq_b8 (w24x w1) (w24x w2)) ⊗ ((lt_b8 (w24h w1) (w24h w2)) ⊕
60 ((eq_b8 (w24h w1) (w24h w2)) ⊗ (lt_b8 (w24l w1) (w24l w2))))).
65 (lt_b8 (w24x w1) (w24x w2)) ⊕
66 ((eq_b8 (w24x w1) (w24x w2)) ⊗ ((lt_b8 (w24h w1) (w24h w2)) ⊕
67 ((eq_b8 (w24h w1) (w24h w2)) ⊗ (le_b8 (w24l w1) (w24l w2))))).
72 (gt_b8 (w24x w1) (w24x w2)) ⊕
73 ((eq_b8 (w24x w1) (w24x w2)) ⊗ ((gt_b8 (w24h w1) (w24h w2)) ⊕
74 ((eq_b8 (w24h w1) (w24h w2)) ⊗ (gt_b8 (w24l w1) (w24l w2))))).
79 (gt_b8 (w24x w1) (w24x w2)) ⊕
80 ((eq_b8 (w24x w1) (w24x w2)) ⊗ ((gt_b8 (w24h w1) (w24h w2)) ⊕
81 ((eq_b8 (w24h w1) (w24h w2)) ⊗ (ge_b8 (w24l w1) (w24l w2))))).
86 mk_word24 (and_b8 (w24x w1) (w24x w2))
87 (and_b8 (w24h w1) (w24h w2))
88 (and_b8 (w24l w1) (w24l w2)).
93 mk_word24 (or_b8 (w24x w1) (w24x w2))
94 (or_b8 (w24h w1) (w24h w2))
95 (or_b8 (w24l w1) (w24l w2)).
100 mk_word24 (xor_b8 (w24x w1) (w24x w2))
101 (xor_b8 (w24h w1) (w24h w2))
102 (xor_b8 (w24l w1) (w24l w2)).
104 (* operatore Most Significant Bit *)
105 ndefinition getMSB_w24 ≝ λw:word24.getMSB_b8 (w24x w).
106 ndefinition setMSB_w24 ≝ λw:word24.mk_word24 (setMSB_b8 (w24x w)) (w24h w) (w24l w).
107 ndefinition clrMSB_w24 ≝ λw:word24.mk_word24 (clrMSB_b8 (w24x w)) (w24h w) (w24l w).
109 (* operatore Least Significant Bit *)
110 ndefinition getLSB_w24 ≝ λw:word24.getLSB_b8 (w24l w).
111 ndefinition setLSB_w24 ≝ λw:word24.mk_word24 (w24x w) (w24h w) (setLSB_b8 (w24l w)).
112 ndefinition clrLSB_w24 ≝ λw:word24.mk_word24 (w24x w) (w24h w) (clrLSB_b8 (w24l w)).
114 (* operatore rotazione destra con carry *)
115 ndefinition rcr_w24 ≝
116 λc:bool.λw:word24.match rcr_b8 c (w24x w) with
117 [ pair c' wx' ⇒ match rcr_b8 c' (w24h w) with
118 [ pair c'' wh' ⇒ match rcr_b8 c'' (w24l w) with
119 [ pair c''' wl' ⇒ pair … c''' (mk_word24 wx' wh' wl') ]]].
121 (* operatore shift destro *)
122 ndefinition shr_w24 ≝ rcr_w24 false.
124 (* operatore rotazione destra *)
125 ndefinition ror_w24 ≝
126 λw.match shr_w24 w with
127 [ pair c w' ⇒ match c with
128 [ true ⇒ setMSB_w24 w' | false ⇒ w' ]].
130 (* operatore rotazione sinistra con carry *)
131 ndefinition rcl_w24 ≝
132 λc:bool.λw:word24.match rcl_b8 c (w24l w) with
133 [ pair c' wl' ⇒ match rcl_b8 c' (w24h w) with
134 [ pair c'' wh' ⇒ match rcl_b8 c'' (w24x w) with
135 [ pair c''' wx' ⇒ pair … c''' (mk_word24 wx' wh' wl') ]]].
137 (* operatore shift sinistro *)
138 ndefinition shl_w24 ≝ rcl_w24 false.
140 (* operatore rotazione sinistra *)
141 ndefinition rol_w24 ≝
142 λw.match shl_w24 w with
143 [ pair c w' ⇒ match c with
144 [ true ⇒ setLSB_w24 w' | false ⇒ w' ]].
146 (* operatore not/complemento a 1 *)
147 ndefinition not_w24 ≝
148 λw:word24.mk_word24 (not_b8 (w24x w)) (not_b8 (w24h w)) (not_b8 (w24l w)).
150 (* operatore somma con data+carry → data+carry *)
151 ndefinition plus_w24_dc_dc ≝
152 λc:bool.λw1,w2:word24.
153 match plus_b8_dc_dc c (w24l w1) (w24l w2) with
154 [ pair c' l ⇒ match plus_b8_dc_dc c' (w24h w1) (w24h w2) with
155 [ pair c'' h ⇒ match plus_b8_dc_dc c'' (w24x w1) (w24x w2) with
156 [ pair c''' x ⇒ pair … c''' 〈x;h;l〉 ]]].
158 (* operatore somma con data+carry → data *)
159 ndefinition plus_w24_dc_d ≝ λc,w1,w2.snd … (plus_w24_dc_dc c w1 w2).
161 (* operatore somma con data+carry → c *)
162 ndefinition plus_w24_dc_c ≝ λc,w1,w2.fst … (plus_w24_dc_dc c w1 w2).
164 (* operatore somma con data → data+carry *)
165 ndefinition plus_w24_d_dc ≝ plus_w24_dc_dc false.
167 (* operatore somma con data → data *)
168 ndefinition plus_w24_d_d ≝ λw1,w2.snd … (plus_w24_d_dc w1 w2).
170 (* operatore somma con data → c *)
171 ndefinition plus_w24_d_c ≝ λw1,w2.fst … (plus_w24_d_dc w1 w2).
173 (* operatore predecessore *)
174 ndefinition pred_w24 ≝
175 λw:word24.match eq_b8 (w24l w) 〈x0,x0〉 with
176 [ true ⇒ match eq_b8 (w24h w) 〈x0,x0〉 with
177 [ true ⇒ mk_word24 (pred_b8 (w24x w)) (pred_b8 (w24h w)) (pred_b8 (w24l w))
178 | false ⇒ mk_word24 (w24x w) (pred_b8 (w24h w)) (pred_b8 (w24l w)) ]
179 | false ⇒ mk_word24 (w24x w) (w24h w) (pred_b8 (w24l w)) ].
181 (* operatore successore *)
182 ndefinition succ_w24 ≝
183 λw:word24.match eq_b8 (w24l w) 〈xF,xF〉 with
184 [ true ⇒ match eq_b8 (w24h w) 〈xF,xF〉 with
185 [ true ⇒ mk_word24 (succ_b8 (w24x w)) (succ_b8 (w24h w)) (succ_b8 (w24l w))
186 | false ⇒ mk_word24 (w24x w) (succ_b8 (w24h w)) (succ_b8 (w24l w)) ]
187 | false ⇒ mk_word24 (w24x w) (w24h w) (succ_b8 (w24l w)) ].
189 (* operatore neg/complemento a 2 *)
190 ndefinition compl_w24 ≝
191 λw:word24.match getMSB_w24 w with
192 [ true ⇒ succ_w24 (not_w24 w)
193 | false ⇒ not_w24 (pred_w24 w) ].
196 ndefinition abs_w24 ≝
197 λw:word24.match getMSB_w24 w with
198 [ true ⇒ compl_w24 w | false ⇒ w ].
200 (* operatore x in [inf,sup] o in sup],[inf *)
201 ndefinition inrange_w24 ≝
203 match le_w24 inf sup with
204 [ true ⇒ and_bool | false ⇒ or_bool ]
205 (le_w24 inf x) (le_w24 x sup).