2 * (C) Copyright IBM Corporation 2008
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Real-time assembly generation interface for Cell B.E. SPEs.
29 * \author Ian Romanick <idr@us.ibm.com>
32 #include "pipe/p_compiler.h"
33 #include "pipe/p_util.h"
34 #include "rtasm_ppc_spe.h"
38 * SPE instruction types
40 * There are 6 primary instruction encodings used on the Cell's SPEs. Each of
41 * the following unions encodes one type.
44 * If, at some point, we start generating SPE code from a little-endian host
45 * these unions will not work.
49 * Encode one output register with two input registers
63 * Encode one output register with three input registers
78 * Encode one output register with one input reg. and a 7-bit signed immed
92 * Encode one output register with one input reg. and an 8-bit signed immed
106 * Encode one output register with one input reg. and a 10-bit signed immed
108 union spe_inst_RI10
{
120 * Encode one output register with a 16-bit signed immediate
122 union spe_inst_RI16
{
133 * Encode one output register with a 18-bit signed immediate
135 union spe_inst_RI18
{
146 static void emit_RR(struct spe_function
*p
, unsigned op
, unsigned rT
,
147 unsigned rA
, unsigned rB
)
149 union spe_inst_RR inst
;
159 static void emit_RRR(struct spe_function
*p
, unsigned op
, unsigned rT
,
160 unsigned rA
, unsigned rB
, unsigned rC
)
162 union spe_inst_RRR inst
;
173 static void emit_RI7(struct spe_function
*p
, unsigned op
, unsigned rT
,
174 unsigned rA
, int imm
)
176 union spe_inst_RI7 inst
;
187 static void emit_RI8(struct spe_function
*p
, unsigned op
, unsigned rT
,
188 unsigned rA
, int imm
)
190 union spe_inst_RI8 inst
;
201 static void emit_RI10(struct spe_function
*p
, unsigned op
, unsigned rT
,
202 unsigned rA
, int imm
)
204 union spe_inst_RI10 inst
;
214 static void emit_RI16(struct spe_function
*p
, unsigned op
, unsigned rT
,
217 union spe_inst_RI16 inst
;
226 static void emit_RI18(struct spe_function
*p
, unsigned op
, unsigned rT
,
229 union spe_inst_RI18 inst
;
240 #define EMIT_(_name, _op) \
241 void _name (struct spe_function *p, unsigned rT) \
243 emit_RR(p, _op, rT, 0, 0); \
246 #define EMIT_R(_name, _op) \
247 void _name (struct spe_function *p, unsigned rT, unsigned rA) \
249 emit_RR(p, _op, rT, rA, 0); \
252 #define EMIT_RR(_name, _op) \
253 void _name (struct spe_function *p, unsigned rT, unsigned rA, unsigned rB) \
255 emit_RR(p, _op, rT, rA, rB); \
258 #define EMIT_RRR(_name, _op) \
259 void _name (struct spe_function *p, unsigned rT, unsigned rA, unsigned rB, unsigned rC) \
261 emit_RRR(p, _op, rT, rA, rB, rC); \
264 #define EMIT_RI7(_name, _op) \
265 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
267 emit_RI7(p, _op, rT, rA, imm); \
270 #define EMIT_RI8(_name, _op) \
271 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
273 emit_RI8(p, _op, rT, rA, 155 - imm); \
276 #define EMIT_RI10(_name, _op) \
277 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
279 emit_RI10(p, _op, rT, rA, imm); \
282 #define EMIT_RI16(_name, _op) \
283 void _name (struct spe_function *p, unsigned rT, int imm) \
285 emit_RI16(p, _op, rT, imm); \
288 #define EMIT_RI18(_name, _op) \
289 void _name (struct spe_function *p, unsigned rT, int imm) \
291 emit_RI18(p, _op, rT, imm); \
294 #define EMIT_I16(_name, _op) \
295 void _name (struct spe_function *p, int imm) \
297 emit_RI16(p, _op, 0, imm); \
300 #include "rtasm_ppc_spe.h"
305 void spe_init_func(struct spe_function
*p
, unsigned code_size
)
307 p
->store
= align_malloc(code_size
, 16);
312 void spe_release_func(struct spe_function
*p
)
314 align_free(p
->store
);
320 void spe_bi(struct spe_function
*p
, unsigned rA
, int d
, int e
)
322 emit_RI7(p
, 0x1a8, 0, rA
, (d
<< 5) | (e
<< 4));
325 void spe_iret(struct spe_function
*p
, unsigned rA
, int d
, int e
)
327 emit_RI7(p
, 0x1aa, 0, rA
, (d
<< 5) | (e
<< 4));
330 void spe_bisled(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
,
333 emit_RI7(p
, 0x1ab, rT
, rA
, (d
<< 5) | (e
<< 4));
336 void spe_bisl(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
,
339 emit_RI7(p
, 0x1a9, rT
, rA
, (d
<< 5) | (e
<< 4));
342 void spe_biz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
,
345 emit_RI7(p
, 0x128, rT
, rA
, (d
<< 5) | (e
<< 4));
348 void spe_binz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
350 emit_RI7(p
, 0x129, rT
, rA
, (d
<< 5) | (e
<< 4));
353 void spe_bihz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
355 emit_RI7(p
, 0x12a, rT
, rA
, (d
<< 5) | (e
<< 4));
358 void spe_bihnz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
360 emit_RI7(p
, 0x12b, rT
, rA
, (d
<< 5) | (e
<< 4));
364 /* Hint-for-branch instructions
373 /* Control instructions
377 EMIT_RR (spe_stopd
, 0x140);
378 EMIT_ (spe_lnop
, 0x001);
379 EMIT_ (spe_nop
, 0x201);
381 EMIT_ (spe_dsync
, 0x003);
382 EMIT_R (spe_mfspr
, 0x00c);
383 EMIT_R (spe_mtspr
, 0x10c);
386 #endif /* GALLIUM_CELL */