1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (c) 2017 Lima Project
3bf215546Sopenharmony_ci * Copyright (c) 2013 Ben Brewer (ben.brewer@codethink.co.uk)
4bf215546Sopenharmony_ci * Copyright (c) 2013 Connor Abbott (connor@abbott.cx)
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
14bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
15bf215546Sopenharmony_ci * of the Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
24bf215546Sopenharmony_ci *
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#ifndef LIMA_IR_GP_CODEGEN_H
28bf215546Sopenharmony_ci#define LIMA_IR_GP_CODEGEN_H
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_citypedef enum {
31bf215546Sopenharmony_ci   gpir_codegen_src_attrib_x     =  0,
32bf215546Sopenharmony_ci   gpir_codegen_src_attrib_y     =  1,
33bf215546Sopenharmony_ci   gpir_codegen_src_attrib_z     =  2,
34bf215546Sopenharmony_ci   gpir_codegen_src_attrib_w     =  3,
35bf215546Sopenharmony_ci   gpir_codegen_src_register_x   =  4,
36bf215546Sopenharmony_ci   gpir_codegen_src_register_y   =  5,
37bf215546Sopenharmony_ci   gpir_codegen_src_register_z   =  6,
38bf215546Sopenharmony_ci   gpir_codegen_src_register_w   =  7,
39bf215546Sopenharmony_ci   gpir_codegen_src_unknown_0    =  8,
40bf215546Sopenharmony_ci   gpir_codegen_src_unknown_1    =  9,
41bf215546Sopenharmony_ci   gpir_codegen_src_unknown_2    = 10,
42bf215546Sopenharmony_ci   gpir_codegen_src_unknown_3    = 11,
43bf215546Sopenharmony_ci   gpir_codegen_src_load_x       = 12,
44bf215546Sopenharmony_ci   gpir_codegen_src_load_y       = 13,
45bf215546Sopenharmony_ci   gpir_codegen_src_load_z       = 14,
46bf215546Sopenharmony_ci   gpir_codegen_src_load_w       = 15,
47bf215546Sopenharmony_ci   gpir_codegen_src_p1_acc_0     = 16,
48bf215546Sopenharmony_ci   gpir_codegen_src_p1_acc_1     = 17,
49bf215546Sopenharmony_ci   gpir_codegen_src_p1_mul_0     = 18,
50bf215546Sopenharmony_ci   gpir_codegen_src_p1_mul_1     = 19,
51bf215546Sopenharmony_ci   gpir_codegen_src_p1_pass      = 20,
52bf215546Sopenharmony_ci   gpir_codegen_src_unused       = 21,
53bf215546Sopenharmony_ci   gpir_codegen_src_ident        = 22,
54bf215546Sopenharmony_ci   gpir_codegen_src_p1_complex   = 22,
55bf215546Sopenharmony_ci   gpir_codegen_src_p2_pass      = 23,
56bf215546Sopenharmony_ci   gpir_codegen_src_p2_acc_0     = 24,
57bf215546Sopenharmony_ci   gpir_codegen_src_p2_acc_1     = 25,
58bf215546Sopenharmony_ci   gpir_codegen_src_p2_mul_0     = 26,
59bf215546Sopenharmony_ci   gpir_codegen_src_p2_mul_1     = 27,
60bf215546Sopenharmony_ci   gpir_codegen_src_p1_attrib_x  = 28,
61bf215546Sopenharmony_ci   gpir_codegen_src_p1_attrib_y  = 29,
62bf215546Sopenharmony_ci   gpir_codegen_src_p1_attrib_z  = 30,
63bf215546Sopenharmony_ci   gpir_codegen_src_p1_attrib_w  = 31,
64bf215546Sopenharmony_ci} gpir_codegen_src;
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_citypedef enum {
67bf215546Sopenharmony_ci   gpir_codegen_load_off_ld_addr_0 = 1,
68bf215546Sopenharmony_ci   gpir_codegen_load_off_ld_addr_1 = 2,
69bf215546Sopenharmony_ci   gpir_codegen_load_off_ld_addr_2 = 3,
70bf215546Sopenharmony_ci   gpir_codegen_load_off_none      = 7,
71bf215546Sopenharmony_ci} gpir_codegen_load_off;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_citypedef enum {
74bf215546Sopenharmony_ci   gpir_codegen_store_src_acc_0   = 0,
75bf215546Sopenharmony_ci   gpir_codegen_store_src_acc_1   = 1,
76bf215546Sopenharmony_ci   gpir_codegen_store_src_mul_0   = 2,
77bf215546Sopenharmony_ci   gpir_codegen_store_src_mul_1   = 3,
78bf215546Sopenharmony_ci   gpir_codegen_store_src_pass    = 4,
79bf215546Sopenharmony_ci   gpir_codegen_store_src_unknown = 5,
80bf215546Sopenharmony_ci   gpir_codegen_store_src_complex = 6,
81bf215546Sopenharmony_ci   gpir_codegen_store_src_none    = 7,
82bf215546Sopenharmony_ci} gpir_codegen_store_src;
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_citypedef enum {
85bf215546Sopenharmony_ci   gpir_codegen_acc_op_add   = 0,
86bf215546Sopenharmony_ci   gpir_codegen_acc_op_floor = 1,
87bf215546Sopenharmony_ci   gpir_codegen_acc_op_sign  = 2,
88bf215546Sopenharmony_ci   gpir_codegen_acc_op_ge    = 4,
89bf215546Sopenharmony_ci   gpir_codegen_acc_op_lt    = 5,
90bf215546Sopenharmony_ci   gpir_codegen_acc_op_min   = 6,
91bf215546Sopenharmony_ci   gpir_codegen_acc_op_max   = 7,
92bf215546Sopenharmony_ci} gpir_codegen_acc_op;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_citypedef enum {
95bf215546Sopenharmony_ci   gpir_codegen_complex_op_nop	 = 0,
96bf215546Sopenharmony_ci   gpir_codegen_complex_op_exp2	 = 2,
97bf215546Sopenharmony_ci   gpir_codegen_complex_op_log2	 = 3,
98bf215546Sopenharmony_ci   gpir_codegen_complex_op_rsqrt = 4,
99bf215546Sopenharmony_ci   gpir_codegen_complex_op_rcp	 = 5,
100bf215546Sopenharmony_ci   gpir_codegen_complex_op_pass	 = 9,
101bf215546Sopenharmony_ci   gpir_codegen_complex_op_temp_store_addr  = 12,
102bf215546Sopenharmony_ci   gpir_codegen_complex_op_temp_load_addr_0 = 13,
103bf215546Sopenharmony_ci   gpir_codegen_complex_op_temp_load_addr_1 = 14,
104bf215546Sopenharmony_ci   gpir_codegen_complex_op_temp_load_addr_2 = 15,
105bf215546Sopenharmony_ci} gpir_codegen_complex_op;
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_citypedef enum {
108bf215546Sopenharmony_ci   gpir_codegen_mul_op_mul	= 0,
109bf215546Sopenharmony_ci   gpir_codegen_mul_op_complex1 = 1,
110bf215546Sopenharmony_ci   gpir_codegen_mul_op_complex2 = 3,
111bf215546Sopenharmony_ci   gpir_codegen_mul_op_select	= 4,
112bf215546Sopenharmony_ci} gpir_codegen_mul_op;
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_citypedef enum {
115bf215546Sopenharmony_ci   gpir_codegen_pass_op_pass	 = 2,
116bf215546Sopenharmony_ci   gpir_codegen_pass_op_preexp2	 = 4,
117bf215546Sopenharmony_ci   gpir_codegen_pass_op_postlog2 = 5,
118bf215546Sopenharmony_ci   gpir_codegen_pass_op_clamp	 = 6,
119bf215546Sopenharmony_ci} gpir_codegen_pass_op;
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_citypedef struct __attribute__((__packed__)) {
123bf215546Sopenharmony_ci   gpir_codegen_src        mul0_src0           : 5;
124bf215546Sopenharmony_ci   gpir_codegen_src        mul0_src1           : 5;
125bf215546Sopenharmony_ci   gpir_codegen_src        mul1_src0           : 5;
126bf215546Sopenharmony_ci   gpir_codegen_src        mul1_src1           : 5;
127bf215546Sopenharmony_ci   bool                    mul0_neg            : 1;
128bf215546Sopenharmony_ci   bool                    mul1_neg            : 1;
129bf215546Sopenharmony_ci   gpir_codegen_src        acc0_src0           : 5;
130bf215546Sopenharmony_ci   gpir_codegen_src        acc0_src1           : 5;
131bf215546Sopenharmony_ci   gpir_codegen_src        acc1_src0           : 5;
132bf215546Sopenharmony_ci   gpir_codegen_src        acc1_src1           : 5;
133bf215546Sopenharmony_ci   bool                    acc0_src0_neg       : 1;
134bf215546Sopenharmony_ci   bool                    acc0_src1_neg       : 1;
135bf215546Sopenharmony_ci   bool                    acc1_src0_neg       : 1;
136bf215546Sopenharmony_ci   bool                    acc1_src1_neg       : 1;
137bf215546Sopenharmony_ci   unsigned                load_addr           : 9;
138bf215546Sopenharmony_ci   gpir_codegen_load_off   load_offset         : 3;
139bf215546Sopenharmony_ci   unsigned                register0_addr      : 4;
140bf215546Sopenharmony_ci   bool                    register0_attribute : 1;
141bf215546Sopenharmony_ci   unsigned                register1_addr      : 4;
142bf215546Sopenharmony_ci   bool                    store0_temporary    : 1;
143bf215546Sopenharmony_ci   bool                    store1_temporary    : 1;
144bf215546Sopenharmony_ci   bool                    branch              : 1;
145bf215546Sopenharmony_ci   bool                    branch_target_lo    : 1;
146bf215546Sopenharmony_ci   gpir_codegen_store_src  store0_src_x        : 3;
147bf215546Sopenharmony_ci   gpir_codegen_store_src  store0_src_y        : 3;
148bf215546Sopenharmony_ci   gpir_codegen_store_src  store1_src_z        : 3;
149bf215546Sopenharmony_ci   gpir_codegen_store_src  store1_src_w        : 3;
150bf215546Sopenharmony_ci   gpir_codegen_acc_op     acc_op              : 3;
151bf215546Sopenharmony_ci   gpir_codegen_complex_op complex_op          : 4;
152bf215546Sopenharmony_ci   unsigned                store0_addr         : 4;
153bf215546Sopenharmony_ci   bool                    store0_varying      : 1;
154bf215546Sopenharmony_ci   unsigned                store1_addr         : 4;
155bf215546Sopenharmony_ci   bool                    store1_varying      : 1;
156bf215546Sopenharmony_ci   gpir_codegen_mul_op     mul_op              : 3;
157bf215546Sopenharmony_ci   gpir_codegen_pass_op    pass_op             : 3;
158bf215546Sopenharmony_ci   gpir_codegen_src        complex_src         : 5;
159bf215546Sopenharmony_ci   gpir_codegen_src        pass_src            : 5;
160bf215546Sopenharmony_ci   unsigned                unknown_1           : 4; /* 12: tmp_st, 13: branch */
161bf215546Sopenharmony_ci   unsigned                branch_target       : 8;
162bf215546Sopenharmony_ci} gpir_codegen_instr;
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_civoid gpir_disassemble_program(gpir_codegen_instr *code, unsigned num_instr, FILE *fp);
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_ci#endif
167