aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/rtasm/rtasm_ppc.h
blob: f194d3be1343c01d596da7ab1e31f395d6ba3367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/**************************************************************************
 *
 * Copyright (C) 2008 Tungsten Graphics, Inc.   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/

/**
 * PPC code generation.
 * \author Brian Paul
 */


#ifndef RTASM_PPC_H
#define RTASM_PPC_H


#include "pipe/p_compiler.h"


#define PPC_INST_SIZE 4  /**< 4 bytes / instruction */

#define PPC_NUM_REGS 32
#define PPC_NUM_FP_REGS 32
#define PPC_NUM_VEC_REGS 32

/** Stack pointer register */
#define PPC_REG_SP 1

/** Branch conditions */
#define BRANCH_COND_ALWAYS       0x14  /* binary 1z1zz (z=ignored) */

/** Branch hints */
#define BRANCH_HINT_SUB_RETURN   0x0   /* binary 00 */


struct ppc_function
{
   uint32_t *store;  /**< instruction buffer */
   uint num_inst;
   uint max_inst;
   uint32_t reg_used;   /** used/free general-purpose registers bitmask */
   uint32_t fp_used;   /** used/free floating point registers bitmask */
   uint32_t vec_used;   /** used/free vector registers bitmask */
};



extern void ppc_init_func(struct ppc_function *p, unsigned max_inst);
extern void ppc_release_func(struct ppc_function *p);
extern void (*ppc_get_func( struct ppc_function *p ))( void );
extern void ppc_dump_func(const struct ppc_function *p);

extern int ppc_reserve_register(struct ppc_function *p, int reg);
extern int ppc_allocate_register(struct ppc_function *p);
extern void ppc_release_register(struct ppc_function *p, int reg);
extern int ppc_allocate_fp_register(struct ppc_function *p);
extern void ppc_release_fp_register(struct ppc_function *p, int reg);
extern int ppc_allocate_vec_register(struct ppc_function *p);
extern void ppc_release_vec_register(struct ppc_function *p, int reg);



/**
 ** float vector arithmetic
 **/

/** vector float add */
extern void
ppc_vaddfp(struct ppc_function *p,uint vD, uint vA, uint vB);

/** vector float substract */
extern void
ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector float min */
extern void
ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector float max */
extern void
ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector float mult add */
extern void
ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);

/** vector float compare greater than */
extern void
ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector float compare greater than or equal to */
extern void
ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector float compare equal */
extern void
ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector float 2^x */
extern void
ppc_vexptefp(struct ppc_function *p, uint vD, uint vB);

/** vector float log2(x) */
extern void
ppc_vlogefp(struct ppc_function *p, uint vD, uint vB);

/** vector float reciprocol */
extern void
ppc_vrefp(struct ppc_function *p, uint vD, uint vB);

/** vector float reciprocol sqrt estimate */
extern void
ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB);

/** vector float round to negative infinity */
extern void
ppc_vrfim(struct ppc_function *p, uint vD, uint vB);

/** vector float round to positive infinity */
extern void
ppc_vrfip(struct ppc_function *p, uint vD, uint vB);

/** vector float round to nearest int */
extern void
ppc_vrfin(struct ppc_function *p, uint vD, uint vB);

/** vector float round to int toward zero */
extern void
ppc_vrfiz(struct ppc_function *p, uint vD, uint vB);


/** vector store: store vR at mem[vA+vB] */
extern void
ppc_stvx(struct ppc_function *p, uint vR, uint vA, uint vB);

/** vector load: vR = mem[vA+vB] */
extern void
ppc_lvx(struct ppc_function *p, uint vR, uint vA, uint vB);

/** load vector element word: vR = mem_word[vA+vB] */
extern void
ppc_lvewx(struct ppc_function *p, uint vR, uint vA, uint vB);

/** vector load float: vr = splats(imm) */
extern void
ppc_vload_float(struct ppc_function *p, uint vr, float imm);



/**
 ** vector bitwise operations
 **/


/** vector and */
extern void
ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector and complement */
extern void
ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector or */
extern void
ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector nor */
extern void
ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB);

/** vector xor */
extern void
ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB);

/** Pseudo-instruction: vector move */
extern void
ppc_vecmove(struct ppc_function *p, uint vD, uint vA);

/** Set vector register to {0,0,0,0} */
extern void
ppc_vzero(struct ppc_function *p, uint vr);



/**
 ** Vector shuffle / select / splat / etc
 **/

/** vector permute */
extern void
ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);

/** vector select */
extern void
ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC);

/** vector splat byte */
extern void
ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm);

/** vector splat half word */
extern void
ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm);

/** vector splat word */
extern void
ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm);

/** vector splat signed immediate word */
extern void
ppc_vspltisw(struct ppc_function *p, uint vD, int imm);

/** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */
extern void
ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB);



/**
 ** scalar arithmetic
 **/

extern void
ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb);

extern void
ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm);

extern void
ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb);

extern void
ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm);

extern void
ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb);

extern void
ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm);

extern void
ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb);

extern void
ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm);

extern void
ppc_mr(struct ppc_function *p, uint rt, uint ra);

extern void
ppc_li(struct ppc_function *p, uint rt, int imm);

extern void
ppc_lis(struct ppc_function *p, uint rt, int imm);

extern void
ppc_load_int(struct ppc_function *p, uint rt, int imm);



/**
 ** scalar load/store
 **/

extern void
ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d);

extern void
ppc_stw(struct ppc_function *p, uint rs, uint ra, int d);

extern void
ppc_lwz(struct ppc_function *p, uint rs, uint ra, int d);



/**
 ** Float (non-vector) arithmetic
 **/

extern void
ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb);

extern void
ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb);

extern void
ppc_fctiwz(struct ppc_function *p, uint rt, uint ra);

extern void
ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset);

extern void
ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb);



/**
 ** branch instructions
 **/

extern void
ppc_blr(struct ppc_function *p);

void
ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg);

extern void
ppc_return(struct ppc_function *p);


#endif /* RTASM_PPC_H */