1 /**************************************************************************
3 * Copyright (C) 2008 Tungsten Graphics, Inc. All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 **************************************************************************/
25 * PPC code generation.
30 #include "util/u_memory.h"
31 #include "pipe/p_debug.h"
32 #include "rtasm_ppc.h"
36 ppc_init_func(struct ppc_function
*p
, unsigned max_inst
)
38 p
->store
= align_malloc(max_inst
* PPC_INST_SIZE
, 16);
40 p
->max_inst
= max_inst
;
46 ppc_release_func(struct ppc_function
*p
)
48 assert(p
->num_inst
<= p
->max_inst
);
49 if (p
->store
!= NULL
) {
57 * Alloate a vector register.
58 * \return register index or -1 if none left.
61 ppc_allocate_vec_register(struct ppc_function
*p
, int reg
)
64 for (i
= 0; i
< PPC_NUM_VEC_REGS
; i
++) {
65 const uint64_t mask
= 1 << i
;
66 if ((p
->vec_used
& mask
) != 0) {
77 * Mark the given vector register as "unallocated".
80 ppc_release_vec_register(struct ppc_function
*p
, int reg
)
82 assert(reg
< PPC_NUM_VEC_REGS
);
83 assert((p
->vec_used
& (1 << reg
)) == 0);
85 p
->vec_used
|= (1 << reg
);
127 emit_vx(struct ppc_function
*p
, uint op2
, uint vD
, uint vA
, uint vB
)
135 p
->store
[p
->num_inst
++] = inst
.bits
;
136 assert(p
->num_inst
<= p
->max_inst
);
140 emit_vxr(struct ppc_function
*p
, uint op2
, uint vD
, uint vA
, uint vB
)
149 p
->store
[p
->num_inst
++] = inst
.bits
;
150 assert(p
->num_inst
<= p
->max_inst
);
154 emit_va(struct ppc_function
*p
, uint op2
, uint vD
, uint vA
, uint vB
, uint vC
)
163 p
->store
[p
->num_inst
++] = inst
.bits
;
164 assert(p
->num_inst
<= p
->max_inst
);
170 ** float vector arithmetic
173 /** vector float add */
175 ppc_vaddfp(struct ppc_function
*p
,uint vD
, uint vA
, uint vB
)
177 emit_vx(p
, 10, vD
, vA
, vB
);
180 /** vector float substract */
182 ppc_vsubfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
184 emit_vx(p
, 74, vD
, vA
, vB
);
187 /** vector float min */
189 ppc_vminfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
191 emit_vx(p
, 1098, vD
, vA
, vB
);
194 /** vector float max */
196 ppc_vmaxfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
198 emit_vx(p
, 1034, vD
, vA
, vB
);
201 /** vector float mult add */
203 ppc_vmaddfp(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
)
205 emit_va(p
, 46, vD
, vA
, vB
, vC
);
208 /** vector float compare greater than */
210 ppc_vcmpgtfpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
212 emit_vxr(p
, 710, vD
, vA
, vB
);
215 /** vector float compare greater than or equal to */
217 ppc_vcmpgefpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
219 emit_vxr(p
, 454, vD
, vA
, vB
);
222 /** vector float compare equal */
224 ppc_vcmpeqfpx(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
226 emit_vxr(p
, 198, vD
, vA
, vB
);
229 /** vector float 2^x */
231 ppc_vexptefp(struct ppc_function
*p
, uint vD
, uint vB
)
233 emit_vx(p
, 394, vD
, 0, vB
);
236 /** vector float log2(x) */
238 ppc_vlogefp(struct ppc_function
*p
, uint vD
, uint vB
)
240 emit_vx(p
, 458, vD
, 0, vB
);
243 /** vector float reciprocol */
245 ppc_vrefp(struct ppc_function
*p
, uint vD
, uint vB
)
247 emit_vx(p
, 266, vD
, 0, vB
);
250 /** vector float reciprocol sqrt estimate */
252 ppc_vrsqrtefp(struct ppc_function
*p
, uint vD
, uint vB
)
254 emit_vx(p
, 330, vD
, 0, vB
);
257 /** vector float round to negative infinity */
259 ppc_vrfim(struct ppc_function
*p
, uint vD
, uint vB
)
261 emit_vx(p
, 714, vD
, 0, vB
);
264 /** vector float round to positive infinity */
266 ppc_vrfip(struct ppc_function
*p
, uint vD
, uint vB
)
268 emit_vx(p
, 650, vD
, 0, vB
);
271 /** vector float round to nearest int */
273 ppc_vrfin(struct ppc_function
*p
, uint vD
, uint vB
)
275 emit_vx(p
, 522, vD
, 0, vB
);
278 /** vector float round to int toward zero */
280 ppc_vrfiz(struct ppc_function
*p
, uint vD
, uint vB
)
282 emit_vx(p
, 586, vD
, 0, vB
);
288 ** bitwise operations
294 ppc_vand(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
296 emit_vx(p
, 1028, vD
, vA
, vB
);
299 /** vector and complement */
301 ppc_vandc(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
303 emit_vx(p
, 1092, vD
, vA
, vB
);
308 ppc_vor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
310 emit_vx(p
, 1156, vD
, vA
, vB
);
315 ppc_vnor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
317 emit_vx(p
, 1284, vD
, vA
, vB
);
322 ppc_vxor(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
)
324 emit_vx(p
, 1220, vD
, vA
, vB
);
329 ** Vector shuffle / select / splat / etc
332 /** vector permute */
334 ppc_vperm(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
)
336 emit_va(p
, 43, vD
, vA
, vB
, vC
);
341 ppc_vsel(struct ppc_function
*p
, uint vD
, uint vA
, uint vB
, uint vC
)
343 emit_va(p
, 42, vD
, vA
, vB
, vC
);
346 /** vector splat byte */
348 ppc_vspltb(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
)
350 emit_vx(p
, 42, vD
, imm
, vB
);
353 /** vector splat half word */
355 ppc_vsplthw(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
)
357 emit_vx(p
, 588, vD
, imm
, vB
);
360 /** vector splat word */
362 ppc_vspltw(struct ppc_function
*p
, uint vD
, uint vB
, uint imm
)
364 emit_vx(p
, 652, vD
, imm
, vB
);