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 / gpu / driver / tests / q38_sass_encode.om

81 lines · 1545 bytes Raw Blame History
1note tests/q38_sass_encode.om: Stage 2 pure-Omega regalloc + sm_121 SASS encoder.
2note Composes after: gpu/nvidia/om/components/bw_alloc.om, gpu/nvidia/om/encoder/bw_enc_sm121.om.
3note Reads 7 binary IR records from stdin (from q38_sass_emit.om), runs bc_regalloc + bw_enc_sm121,
4note and writes framed [u32_le byte_len][sm_121 SASS bytes] to stdout.
5
6fn rd_all b edit uchar 8192 n ulong to void
7off = ulong 0
8while lt off n bound 1024
9r = read 0 b off sub n off
10if le r 0
11trap 1
12end
13off = add off ulong r
14end
15end
16
17fn get_u64 b view uchar 8192 off ulong to ulong
18v = ulong 0
19for k ulong 8
20v = or v shl ulong get b add off k mul k 8
21end
22ret v
23end
24
25fn wr_code b view uchar 16384 n ulong to void
26off = ulong 0
27while lt off n bound 1024
28r = write 1 b off sub n off
29if le r 0
30trap 5
31end
32off = add off ulong r
33end
34end
35
36fn enc_one to void
37x = new ulong 8192 0
38am = new ulong 2048 0
39phys = new ulong 288 0
40st = new ulong 4 0
41buf = new uchar 8192 0
42code = new uchar 16384 0
43hdr = new uchar 4 0
44rd_all buf 2312
45n = get_u64 buf 0
46if or eq n 0 gt n 1024
47trap 2
48end
49for i ulong 288
50put am i get_u64 buf mul add i 1 8
51end
52for i ulong n
53rd_all buf 64
54for f ulong 8
55put x add mul i 8 f get_u64 buf mul f 8
56end
57end
58if ne bc_regalloc x n am phys st 128 0
59trap 3
60end
61nb = bw_enc_sm121 x phys n 1 code
62if eq nb 0
63trap 4
64end
65put hdr 0 uchar and nb 255
66put hdr 1 uchar and shr nb 8 255
67put hdr 2 uchar and shr nb 16 255
68put hdr 3 uchar and shr nb 24 255
69w = write 1 hdr 0 4
70if ne w 4
71trap 5
72end
73wr_code code nb
74end
75
76fn main to int
77for k ulong 7
78enc_one
79end
80ret 0
81end