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 / ng / a64 / tests / macho / lib / libmath.om

53 lines · 1199 bytes Raw Blame History
1target macos
2note libmath: the float registers. sqrt(2.0) through d0 and pow(2.0, 10.0) through d0 and d1; the results come
3note back at byte 64 of the register file. Status 1 when both have the exact bits, else 2 or 3.
4text s_sqrt "sqrt"
5text s_pow "pow"
6
7fn p64 b edit uchar 128 o ulong v ulong to void
8for i ulong 8
9put b add o i uchar and shr v mul i 8 255
10end
11end
12
13fn g64 b view uchar 128 o ulong to ulong
14v = ulong 0
15for i ulong 8
16v = or v shl ulong get b add o i mul i 8
17end
18ret v
19end
20
21note the address of the library function named by the n bytes of nm (nm is zero after them)
22fn sym rg edit uchar 128 nm edit uchar 64 to ulong
23p64 rg 0 18446744073709551614
24p64 rg 8 ulong libptr nm 0 64
25ret ulong libcall ulong libfn 1 rg 0 128
26end
27
28fn main to int
29rg = new uchar 128 0
30nm = new uchar 64 0
31for i ulong len s_sqrt
32put nm i get s_sqrt i
33end
34put nm len s_sqrt 0
35f = sym rg nm
36p64 rg 64 4611686018427387904
37r = libcall f rg 0 128
38if ne g64 rg 64 4609047870845172685
39ret 2
40end
41for i ulong len s_pow
42put nm i get s_pow i
43end
44put nm len s_pow 0
45g = sym rg nm
46p64 rg 64 4611686018427387904
47p64 rg 72 4621819117588971520
48r = libcall g rg 0 128
49if ne g64 rg 64 4652218415073722368
50ret 3
51end
52ret 1
53end