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>
35 #include "pipe/p_compiler.h"
36 #include "util/u_memory.h"
37 #include "rtasm_ppc_spe.h"
42 * SPE instruction types
44 * There are 6 primary instruction encodings used on the Cell's SPEs. Each of
45 * the following unions encodes one type.
48 * If, at some point, we start generating SPE code from a little-endian host
49 * these unions will not work.
53 * Encode one output register with two input registers
67 * Encode one output register with three input registers
82 * Encode one output register with one input reg. and a 7-bit signed immed
96 * Encode one output register with one input reg. and an 8-bit signed immed
110 * Encode one output register with one input reg. and a 10-bit signed immed
112 union spe_inst_RI10
{
124 * Encode one output register with a 16-bit signed immediate
126 union spe_inst_RI16
{
137 * Encode one output register with a 18-bit signed immediate
139 union spe_inst_RI18
{
151 indent(const struct spe_function
*p
)
154 for (i
= 0; i
< p
->indent
; i
++) {
161 rem_prefix(const char *longname
)
177 /* cycle through four buffers to handle multiple calls per printf */
178 static char buf
[4][10];
181 sprintf(buf
[b
], "$%d", reg
);
188 static void emit_RR(struct spe_function
*p
, unsigned op
, unsigned rT
,
189 unsigned rA
, unsigned rB
, const char *name
)
191 union spe_inst_RR inst
;
196 p
->store
[p
->num_inst
++] = inst
.bits
;
197 assert(p
->num_inst
<= p
->max_inst
);
200 printf("%s\t%s, %s, %s\n",
201 rem_prefix(name
), reg_name(rT
), reg_name(rA
), reg_name(rB
));
206 static void emit_RRR(struct spe_function
*p
, unsigned op
, unsigned rT
,
207 unsigned rA
, unsigned rB
, unsigned rC
, const char *name
)
209 union spe_inst_RRR inst
;
215 p
->store
[p
->num_inst
++] = inst
.bits
;
216 assert(p
->num_inst
<= p
->max_inst
);
219 printf("%s\t%s, %s, %s, %s\n", rem_prefix(name
), reg_name(rT
),
220 reg_name(rA
), reg_name(rB
), reg_name(rC
));
225 static void emit_RI7(struct spe_function
*p
, unsigned op
, unsigned rT
,
226 unsigned rA
, int imm
, const char *name
)
228 union spe_inst_RI7 inst
;
233 p
->store
[p
->num_inst
++] = inst
.bits
;
234 assert(p
->num_inst
<= p
->max_inst
);
237 printf("%s\t%s, %s, 0x%x\n",
238 rem_prefix(name
), reg_name(rT
), reg_name(rA
), imm
);
244 static void emit_RI8(struct spe_function
*p
, unsigned op
, unsigned rT
,
245 unsigned rA
, int imm
, const char *name
)
247 union spe_inst_RI8 inst
;
252 p
->store
[p
->num_inst
++] = inst
.bits
;
253 assert(p
->num_inst
<= p
->max_inst
);
256 printf("%s\t%s, %s, 0x%x\n",
257 rem_prefix(name
), reg_name(rT
), reg_name(rA
), imm
);
263 static void emit_RI10(struct spe_function
*p
, unsigned op
, unsigned rT
,
264 unsigned rA
, int imm
, const char *name
)
266 union spe_inst_RI10 inst
;
271 p
->store
[p
->num_inst
++] = inst
.bits
;
272 assert(p
->num_inst
<= p
->max_inst
);
275 printf("%s\t%s, %s, 0x%x\n",
276 rem_prefix(name
), reg_name(rT
), reg_name(rA
), imm
);
281 /** As above, but do range checking on signed immediate value */
282 static void emit_RI10s(struct spe_function
*p
, unsigned op
, unsigned rT
,
283 unsigned rA
, int imm
, const char *name
)
287 emit_RI10(p
, op
, rT
, rA
, imm
, name
);
291 static void emit_RI16(struct spe_function
*p
, unsigned op
, unsigned rT
,
292 int imm
, const char *name
)
294 union spe_inst_RI16 inst
;
298 p
->store
[p
->num_inst
++] = inst
.bits
;
299 assert(p
->num_inst
<= p
->max_inst
);
302 printf("%s\t%s, 0x%x\n", rem_prefix(name
), reg_name(rT
), imm
);
307 static void emit_RI18(struct spe_function
*p
, unsigned op
, unsigned rT
,
308 int imm
, const char *name
)
310 union spe_inst_RI18 inst
;
314 p
->store
[p
->num_inst
++] = inst
.bits
;
315 assert(p
->num_inst
<= p
->max_inst
);
318 printf("%s\t%s, 0x%x\n", rem_prefix(name
), reg_name(rT
), imm
);
325 #define EMIT_(_name, _op) \
326 void _name (struct spe_function *p, unsigned rT) \
328 emit_RR(p, _op, rT, 0, 0, __FUNCTION__); \
331 #define EMIT_R(_name, _op) \
332 void _name (struct spe_function *p, unsigned rT, unsigned rA) \
334 emit_RR(p, _op, rT, rA, 0, __FUNCTION__); \
337 #define EMIT_RR(_name, _op) \
338 void _name (struct spe_function *p, unsigned rT, unsigned rA, unsigned rB) \
340 emit_RR(p, _op, rT, rA, rB, __FUNCTION__); \
343 #define EMIT_RRR(_name, _op) \
344 void _name (struct spe_function *p, unsigned rT, unsigned rA, unsigned rB, unsigned rC) \
346 emit_RRR(p, _op, rT, rA, rB, rC, __FUNCTION__); \
349 #define EMIT_RI7(_name, _op) \
350 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
352 emit_RI7(p, _op, rT, rA, imm, __FUNCTION__); \
355 #define EMIT_RI8(_name, _op, bias) \
356 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
358 emit_RI8(p, _op, rT, rA, bias - imm, __FUNCTION__); \
361 #define EMIT_RI10(_name, _op) \
362 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
364 emit_RI10(p, _op, rT, rA, imm, __FUNCTION__); \
367 #define EMIT_RI10s(_name, _op) \
368 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
370 emit_RI10s(p, _op, rT, rA, imm, __FUNCTION__); \
373 #define EMIT_RI16(_name, _op) \
374 void _name (struct spe_function *p, unsigned rT, int imm) \
376 emit_RI16(p, _op, rT, imm, __FUNCTION__); \
379 #define EMIT_RI18(_name, _op) \
380 void _name (struct spe_function *p, unsigned rT, int imm) \
382 emit_RI18(p, _op, rT, imm, __FUNCTION__); \
385 #define EMIT_I16(_name, _op) \
386 void _name (struct spe_function *p, int imm) \
388 emit_RI16(p, _op, 0, imm, __FUNCTION__); \
391 #include "rtasm_ppc_spe.h"
396 * Initialize an spe_function.
397 * \param code_size size of instruction buffer to allocate, in bytes.
399 void spe_init_func(struct spe_function
*p
, unsigned code_size
)
403 p
->store
= align_malloc(code_size
, 16);
405 p
->max_inst
= code_size
/ SPE_INST_SIZE
;
408 memset(p
->regs
, 0, SPE_NUM_REGS
* sizeof(p
->regs
[0]));
410 /* Conservatively treat R0 - R2 and R80 - R127 as non-volatile.
412 p
->regs
[0] = p
->regs
[1] = p
->regs
[2] = 1;
413 for (i
= 80; i
<= 127; i
++) {
422 void spe_release_func(struct spe_function
*p
)
424 assert(p
->num_inst
<= p
->max_inst
);
425 if (p
->store
!= NULL
) {
426 align_free(p
->store
);
432 /** Return current code size in bytes. */
433 unsigned spe_code_size(const struct spe_function
*p
)
435 return p
->num_inst
* SPE_INST_SIZE
;
440 * Allocate a SPE register.
441 * \return register index or -1 if none left.
443 int spe_allocate_available_register(struct spe_function
*p
)
446 for (i
= 0; i
< SPE_NUM_REGS
; i
++) {
447 if (p
->regs
[i
] == 0) {
458 * Mark the given SPE register as "allocated".
460 int spe_allocate_register(struct spe_function
*p
, int reg
)
462 assert(reg
< SPE_NUM_REGS
);
463 assert(p
->regs
[reg
] == 0);
470 * Mark the given SPE register as "unallocated". Note that this should
471 * only be used on registers allocated in the current register set; an
472 * assertion will fail if an attempt is made to deallocate a register
473 * allocated in an earlier register set.
475 void spe_release_register(struct spe_function
*p
, int reg
)
477 assert(reg
< SPE_NUM_REGS
);
478 assert(p
->regs
[reg
] == 1);
484 * Start a new set of registers. This can be called if
485 * it will be difficult later to determine exactly what
486 * registers were actually allocated during a code generation
487 * sequence, and you really just want to deallocate all of them.
489 void spe_allocate_register_set(struct spe_function
*p
)
493 /* Keep track of the set count. If it ever wraps around to 0,
497 assert(p
->set_count
> 0);
499 /* Increment the allocation count of all registers currently
500 * allocated. Then any registers that are allocated in this set
501 * will be the only ones with a count of 1; they'll all be released
502 * when the register set is released.
504 for (i
= 0; i
< SPE_NUM_REGS
; i
++) {
510 void spe_release_register_set(struct spe_function
*p
)
514 /* If the set count drops below zero, we're in trouble. */
515 assert(p
->set_count
> 0);
518 /* Drop the allocation level of all registers. Any allocated
519 * during this register set will drop to 0 and then become
522 for (i
= 0; i
< SPE_NUM_REGS
; i
++) {
530 spe_get_registers_used(const struct spe_function
*p
, ubyte used
[])
533 /* only count registers in the range available to callers */
534 for (i
= 2; i
< 80; i
++) {
544 spe_print_code(struct spe_function
*p
, boolean enable
)
551 spe_indent(struct spe_function
*p
, int spaces
)
558 spe_comment(struct spe_function
*p
, int rel_indent
, const char *s
)
561 p
->indent
+= rel_indent
;
563 p
->indent
-= rel_indent
;
571 * NOTE: offset is in bytes and the least significant 4 bits must be zero!
573 void spe_lqd(struct spe_function
*p
, unsigned rT
, unsigned rA
, int offset
)
575 const boolean pSave
= p
->print
;
577 /* offset must be a multiple of 16 */
578 assert(offset
% 16 == 0);
579 /* offset must fit in 10-bit signed int field, after shifting */
580 assert((offset
>> 4) <= 511);
581 assert((offset
>> 4) >= -512);
584 emit_RI10(p
, 0x034, rT
, rA
, offset
>> 4, "spe_lqd");
589 printf("lqd\t%s, %d(%s)\n", reg_name(rT
), offset
, reg_name(rA
));
596 * NOTE: offset is in bytes and the least significant 4 bits must be zero!
598 void spe_stqd(struct spe_function
*p
, unsigned rT
, unsigned rA
, int offset
)
600 const boolean pSave
= p
->print
;
602 /* offset must be a multiple of 16 */
603 assert(offset
% 16 == 0);
604 /* offset must fit in 10-bit signed int field, after shifting */
605 assert((offset
>> 4) <= 511);
606 assert((offset
>> 4) >= -512);
609 emit_RI10(p
, 0x024, rT
, rA
, offset
>> 4, "spe_stqd");
614 printf("stqd\t%s, %d(%s)\n", reg_name(rT
), offset
, reg_name(rA
));
620 * For branch instructions:
621 * \param d if 1, disable interupts if branch is taken
622 * \param e if 1, enable interupts if branch is taken
623 * If d and e are both zero, don't change interupt status (right?)
626 /** Branch Indirect to address in rA */
627 void spe_bi(struct spe_function
*p
, unsigned rA
, int d
, int e
)
629 emit_RI7(p
, 0x1a8, 0, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
632 /** Interupt Return */
633 void spe_iret(struct spe_function
*p
, unsigned rA
, int d
, int e
)
635 emit_RI7(p
, 0x1aa, 0, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
638 /** Branch indirect and set link on external data */
639 void spe_bisled(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
,
642 emit_RI7(p
, 0x1ab, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
645 /** Branch indirect and set link. Save PC in rT, jump to rA. */
646 void spe_bisl(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
,
649 emit_RI7(p
, 0x1a9, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
652 /** Branch indirect if zero word. If rT.word[0]==0, jump to rA. */
653 void spe_biz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
655 emit_RI7(p
, 0x128, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
658 /** Branch indirect if non-zero word. If rT.word[0]!=0, jump to rA. */
659 void spe_binz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
661 emit_RI7(p
, 0x129, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
664 /** Branch indirect if zero halfword. If rT.halfword[1]==0, jump to rA. */
665 void spe_bihz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
667 emit_RI7(p
, 0x12a, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
670 /** Branch indirect if non-zero halfword. If rT.halfword[1]!=0, jump to rA. */
671 void spe_bihnz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
673 emit_RI7(p
, 0x12b, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
677 /* Hint-for-branch instructions
686 /* Control instructions
690 EMIT_RR (spe_stopd
, 0x140);
691 EMIT_ (spe_lnop
, 0x001);
692 EMIT_ (spe_nop
, 0x201);
694 EMIT_ (spe_dsync
, 0x003);
695 EMIT_R (spe_mfspr
, 0x00c);
696 EMIT_R (spe_mtspr
, 0x10c);
701 ** Helper / "macro" instructions.
702 ** Use somewhat verbose names as a reminder that these aren't native
708 spe_load_float(struct spe_function
*p
, unsigned rT
, float x
)
713 else if (x
== 0.5f
) {
714 spe_ilhu(p
, rT
, 0x3f00);
716 else if (x
== 1.0f
) {
717 spe_ilhu(p
, rT
, 0x3f80);
719 else if (x
== -1.0f
) {
720 spe_ilhu(p
, rT
, 0xbf80);
728 spe_ilhu(p
, rT
, bits
.u
>> 16);
729 spe_iohl(p
, rT
, bits
.u
& 0xffff);
735 spe_load_int(struct spe_function
*p
, unsigned rT
, int i
)
737 if (-32768 <= i
&& i
<= 32767) {
741 spe_ilhu(p
, rT
, i
>> 16);
743 spe_iohl(p
, rT
, i
& 0xffff);
747 void spe_load_uint(struct spe_function
*p
, unsigned rT
, unsigned int ui
)
749 /* If the whole value is in the lower 18 bits, use ila, which
750 * doesn't sign-extend. Otherwise, if the two halfwords of
751 * the constant are identical, use ilh. Otherwise, if every byte of
752 * the desired value is 0x00 or 0xff, we can use Form Select Mask for
753 * Bytes Immediate (fsmbi) to load the value in a single instruction.
754 * Otherwise, in the general case, we have to use ilhu followed by iohl.
756 if ((ui
& 0x0003ffff) == ui
) {
759 else if ((ui
>> 16) == (ui
& 0xffff)) {
760 spe_ilh(p
, rT
, ui
& 0xffff);
763 ((ui
& 0x000000ff) == 0 || (ui
& 0x000000ff) == 0x000000ff) &&
764 ((ui
& 0x0000ff00) == 0 || (ui
& 0x0000ff00) == 0x0000ff00) &&
765 ((ui
& 0x00ff0000) == 0 || (ui
& 0x00ff0000) == 0x00ff0000) &&
766 ((ui
& 0xff000000) == 0 || (ui
& 0xff000000) == 0xff000000)
768 unsigned int mask
= 0;
769 /* fsmbi duplicates each bit in the given mask eight times,
770 * using a 16-bit value to initialize a 16-byte quadword.
771 * Each 4-bit nybble of the mask corresponds to a full word
772 * of the result; look at the value and figure out the mask
773 * (replicated for each word in the quadword), and then
774 * form the "select mask" to get the value.
776 if ((ui
& 0x000000ff) == 0x000000ff) mask
|= 0x1111;
777 if ((ui
& 0x0000ff00) == 0x0000ff00) mask
|= 0x2222;
778 if ((ui
& 0x00ff0000) == 0x00ff0000) mask
|= 0x4444;
779 if ((ui
& 0xff000000) == 0xff000000) mask
|= 0x8888;
780 spe_fsmbi(p
, rT
, mask
);
783 /* The general case: this usually uses two instructions, but
784 * may use only one if the low-order 16 bits of each word are 0.
786 spe_ilhu(p
, rT
, ui
>> 16);
788 spe_iohl(p
, rT
, ui
& 0xffff);
793 * This function is constructed identically to spe_xor_uint() below.
794 * Changes to one should be made in the other.
797 spe_and_uint(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned int ui
)
799 /* If we can, emit a single instruction, either And Byte Immediate
800 * (which uses the same constant across each byte), And Halfword Immediate
801 * (which sign-extends a 10-bit immediate to 16 bits and uses that
802 * across each halfword), or And Word Immediate (which sign-extends
803 * a 10-bit immediate to 32 bits).
805 * Otherwise, we'll need to use a temporary register.
809 /* If the upper 23 bits are all 0s or all 1s, sign extension
810 * will work and we can use And Word Immediate
812 tmp
= ui
& 0xfffffe00;
813 if (tmp
== 0xfffffe00 || tmp
== 0) {
814 spe_andi(p
, rT
, rA
, ui
& 0x000003ff);
818 /* If the ui field is symmetric along halfword boundaries and
819 * the upper 7 bits of each halfword are all 0s or 1s, we
820 * can use And Halfword Immediate
822 tmp
= ui
& 0xfe00fe00;
823 if ((tmp
== 0xfe00fe00 || tmp
== 0) && ((ui
>> 16) == (ui
& 0x0000ffff))) {
824 spe_andhi(p
, rT
, rA
, ui
& 0x000003ff);
828 /* If the ui field is symmetric in each byte, then we can use
829 * the And Byte Immediate instruction.
831 tmp
= ui
& 0x000000ff;
832 if ((ui
>> 24) == tmp
&& ((ui
>> 16) & 0xff) == tmp
&& ((ui
>> 8) & 0xff) == tmp
) {
833 spe_andbi(p
, rT
, rA
, tmp
);
837 /* Otherwise, we'll have to use a temporary register. */
838 unsigned int tmp_reg
= spe_allocate_available_register(p
);
839 spe_load_uint(p
, tmp_reg
, ui
);
840 spe_and(p
, rT
, rA
, tmp_reg
);
841 spe_release_register(p
, tmp_reg
);
846 * This function is constructed identically to spe_and_uint() above.
847 * Changes to one should be made in the other.
850 spe_xor_uint(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned int ui
)
852 /* If we can, emit a single instruction, either Exclusive Or Byte
853 * Immediate (which uses the same constant across each byte), Exclusive
854 * Or Halfword Immediate (which sign-extends a 10-bit immediate to
855 * 16 bits and uses that across each halfword), or Exclusive Or Word
856 * Immediate (which sign-extends a 10-bit immediate to 32 bits).
858 * Otherwise, we'll need to use a temporary register.
862 /* If the upper 23 bits are all 0s or all 1s, sign extension
863 * will work and we can use Exclusive Or Word Immediate
865 tmp
= ui
& 0xfffffe00;
866 if (tmp
== 0xfffffe00 || tmp
== 0) {
867 spe_xori(p
, rT
, rA
, ui
& 0x000003ff);
871 /* If the ui field is symmetric along halfword boundaries and
872 * the upper 7 bits of each halfword are all 0s or 1s, we
873 * can use Exclusive Or Halfword Immediate
875 tmp
= ui
& 0xfe00fe00;
876 if ((tmp
== 0xfe00fe00 || tmp
== 0) && ((ui
>> 16) == (ui
& 0x0000ffff))) {
877 spe_xorhi(p
, rT
, rA
, ui
& 0x000003ff);
881 /* If the ui field is symmetric in each byte, then we can use
882 * the Exclusive Or Byte Immediate instruction.
884 tmp
= ui
& 0x000000ff;
885 if ((ui
>> 24) == tmp
&& ((ui
>> 16) & 0xff) == tmp
&& ((ui
>> 8) & 0xff) == tmp
) {
886 spe_xorbi(p
, rT
, rA
, tmp
);
890 /* Otherwise, we'll have to use a temporary register. */
891 unsigned int tmp_reg
= spe_allocate_available_register(p
);
892 spe_load_uint(p
, tmp_reg
, ui
);
893 spe_xor(p
, rT
, rA
, tmp_reg
);
894 spe_release_register(p
, tmp_reg
);
898 spe_compare_equal_uint(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned int ui
)
900 /* If the comparison value is 9 bits or less, it fits inside a
901 * Compare Equal Word Immediate instruction.
903 if ((ui
& 0x000001ff) == ui
) {
904 spe_ceqi(p
, rT
, rA
, ui
);
906 /* Otherwise, we're going to have to load a word first. */
908 unsigned int tmp_reg
= spe_allocate_available_register(p
);
909 spe_load_uint(p
, tmp_reg
, ui
);
910 spe_ceq(p
, rT
, rA
, tmp_reg
);
911 spe_release_register(p
, tmp_reg
);
916 spe_compare_greater_uint(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned int ui
)
918 /* If the comparison value is 10 bits or less, it fits inside a
919 * Compare Logical Greater Than Word Immediate instruction.
921 if ((ui
& 0x000003ff) == ui
) {
922 spe_clgti(p
, rT
, rA
, ui
);
924 /* Otherwise, we're going to have to load a word first. */
926 unsigned int tmp_reg
= spe_allocate_available_register(p
);
927 spe_load_uint(p
, tmp_reg
, ui
);
928 spe_clgt(p
, rT
, rA
, tmp_reg
);
929 spe_release_register(p
, tmp_reg
);
934 spe_splat(struct spe_function
*p
, unsigned rT
, unsigned rA
)
936 /* Duplicate bytes 0, 1, 2, and 3 across the whole register */
937 spe_ila(p
, rT
, 0x00010203);
938 spe_shufb(p
, rT
, rA
, rA
, rT
);
943 spe_complement(struct spe_function
*p
, unsigned rT
, unsigned rA
)
945 spe_nor(p
, rT
, rA
, rA
);
950 spe_move(struct spe_function
*p
, unsigned rT
, unsigned rA
)
952 /* Use different instructions depending on the instruction address
953 * to take advantage of the dual pipelines.
956 spe_shlqbyi(p
, rT
, rA
, 0); /* odd pipe */
958 spe_ori(p
, rT
, rA
, 0); /* even pipe */
963 spe_zero(struct spe_function
*p
, unsigned rT
)
965 spe_xor(p
, rT
, rT
, rT
);
970 spe_splat_word(struct spe_function
*p
, unsigned rT
, unsigned rA
, int word
)
977 spe_ila(p
, tmp1
, 66051);
978 spe_shufb(p
, rT
, rA
, rA
, tmp1
);
981 /* XXX review this, we may not need the rotqbyi instruction */
983 int tmp2
= spe_allocate_available_register(p
);
985 spe_ila(p
, tmp1
, 66051);
986 spe_rotqbyi(p
, tmp2
, rA
, 4 * word
);
987 spe_shufb(p
, rT
, tmp2
, tmp2
, tmp1
);
989 spe_release_register(p
, tmp2
);
994 * For each 32-bit float element of rA and rB, choose the smaller of the
995 * two, compositing them into the rT register.
997 * The Float Compare Greater Than (fcgt) instruction will put 1s into
998 * compare_reg where rA > rB, and 0s where rA <= rB.
1000 * Then the Select Bits (selb) instruction will take bits from rA where
1001 * compare_reg is 0, and from rB where compare_reg is 1; i.e., from rA
1002 * where rA <= rB and from rB where rB > rA, which is exactly the
1005 * The compare_reg could in many cases be the same as rT, unless
1006 * rT == rA || rt == rB. But since this is common in constructions
1007 * like "x = min(x, a)", we always allocate a new register to be safe.
1010 spe_float_min(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned rB
)
1012 unsigned int compare_reg
= spe_allocate_available_register(p
);
1013 spe_fcgt(p
, compare_reg
, rA
, rB
);
1014 spe_selb(p
, rT
, rA
, rB
, compare_reg
);
1015 spe_release_register(p
, compare_reg
);
1019 * For each 32-bit float element of rA and rB, choose the greater of the
1020 * two, compositing them into the rT register.
1022 * The logic is similar to that of spe_float_min() above; the only
1023 * difference is that the registers on spe_selb() have been reversed,
1024 * so that the larger of the two is selected instead of the smaller.
1027 spe_float_max(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned rB
)
1029 unsigned int compare_reg
= spe_allocate_available_register(p
);
1030 spe_fcgt(p
, compare_reg
, rA
, rB
);
1031 spe_selb(p
, rT
, rB
, rA
, compare_reg
);
1032 spe_release_register(p
, compare_reg
);
1035 #endif /* GALLIUM_CELL */