interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / omc / tests / float / bitcast_int.om

207 lines · 2814 bytes Raw Blame History
1note bitcast between integer types of one width keeps the bits, and the result is a canonical value of the
2note new type: compare, add, signed shr, widening conversion, call argument and array store all see it, and
3note the source name keeps its own value. Each 8/16/32-bit signed/unsigned pair both ways, f32 to and from
4note int, and the 64-bit pair as the control that was already right. omc 2c824805 kept the old extension
5note (uint 4294967295 as int compared unequal to -1 and add 2 trapped 1). Expected values were computed with
6note Wolfram (two's complement of the bit patterns), never by this compiler. Exit 0 when every check passed.
7fn bi32 x uint to int
8ret bitcast int x
9end
10fn bu32 x int to uint
11ret bitcast uint x
12end
13fn bi16 x ushort to short
14ret bitcast short x
15end
16fn bu16 x short to ushort
17ret bitcast ushort x
18end
19fn bi8 x uchar to byte
20ret bitcast byte x
21end
22fn bu8 x byte to uchar
23ret bitcast uchar x
24end
25fn isneg1 x int to int
26if eq x -1
27ret 0
28end
29ret 1
30end
31fn u2i32 to int
32a = new int 1 0
33u = uint 4294967295
34v = bitcast int u
35if ne v -1
36ret 1
37end
38if ge v 0
39ret 2
40end
41if ne add v 2 1
42ret 3
43end
44if ne shr v 1 -1
45ret 4
46end
47if ne long v -1
48ret 5
49end
50if ne u 4294967295
51ret 6
52end
53if ne isneg1 v 0
54ret 7
55end
56put a 0 v
57if ne get a 0 -1
58ret 8
59end
60m = bitcast int uint 2147483648
61if ne add m 1 -2147483647
62ret 9
63end
64if ne bi32 2147483653 -2147483643
65ret 10
66end
67ret 0
68end
69fn i2u32 to int
70s = int -1
71v = bitcast uint s
72if ne v 4294967295
73ret 11
74end
75if ne ulong v 4294967295
76ret 12
77end
78if ne add v 1 0
79ret 13
80end
81if ne shr v 31 1
82ret 14
83end
84if ne s -1
85ret 15
86end
87if ne bu32 -2147483648 2147483648
88ret 16
89end
90ret 0
91end
92fn u2i16 to int
93u = ushort 65535
94v = bitcast short u
95if ne v -1
96ret 21
97end
98if ge v 0
99ret 22
100end
101if ne add v 2 1
102ret 23
103end
104if ne long v -1
105ret 24
106end
107if ne bi16 32768 -32768
108ret 25
109end
110s = short -1
111w = bitcast ushort s
112if ne ulong w 65535
113ret 26
114end
115if ne bu16 -32768 32768
116ret 27
117end
118ret 0
119end
120fn u2i8 to int
121u = uchar 255
122v = bitcast byte u
123if ne v -1
124ret 31
125end
126if ge v 0
127ret 32
128end
129if ne add v 2 1
130ret 33
131end
132if ne long v -1
133ret 34
134end
135if ne bi8 200 -56
136ret 35
137end
138s = byte -1
139w = bitcast uchar s
140if ne ulong w 255
141ret 36
142end
143if ne bu8 -128 128
144ret 37
145end
146ret 0
147end
148fn f32int to int
149f = bitcast f32 int -1
150g = bitcast uint f
151if ne g 4294967295
152ret 41
153end
154if ne ulong g 4294967295
155ret 42
156end
157h = bitcast int f32 -1.0
158if ne h -1082130432
159ret 43
160end
161if ge h 0
162ret 44
163end
164ret 0
165end
166fn w64pair to int
167u = ulong 18446744073709551615
168v = bitcast long u
169if ne v -1
170ret 51
171end
172if ne add v 2 1
173ret 52
174end
175w = bitcast ulong long -1
176if ne w 18446744073709551615
177ret 53
178end
179ret 0
180end
181fn main to int
182r = u2i32
183if ne r 0
184ret r
185end
186r = i2u32
187if ne r 0
188ret r
189end
190r = u2i16
191if ne r 0
192ret r
193end
194r = u2i8
195if ne r 0
196ret r
197end
198r = f32int
199if ne r 0
200ret r
201end
202r = w64pair
203if ne r 0
204ret r
205end
206ret 0
207end