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
);
189 emit_instruction(struct spe_function
*p
, uint32_t inst_bits
)
192 return; /* out of memory, drop the instruction */
194 if (p
->num_inst
== p
->max_inst
) {
195 /* allocate larger buffer */
197 p
->max_inst
*= 2; /* 2x larger */
198 newbuf
= align_malloc(p
->max_inst
* SPE_INST_SIZE
, 16);
200 memcpy(newbuf
, p
->store
, p
->num_inst
* SPE_INST_SIZE
);
202 align_free(p
->store
);
211 p
->store
[p
->num_inst
++] = inst_bits
;
216 static void emit_RR(struct spe_function
*p
, unsigned op
, unsigned rT
,
217 unsigned rA
, unsigned rB
, const char *name
)
219 union spe_inst_RR inst
;
224 emit_instruction(p
, inst
.bits
);
227 printf("%s\t%s, %s, %s\n",
228 rem_prefix(name
), reg_name(rT
), reg_name(rA
), reg_name(rB
));
233 static void emit_RRR(struct spe_function
*p
, unsigned op
, unsigned rT
,
234 unsigned rA
, unsigned rB
, unsigned rC
, const char *name
)
236 union spe_inst_RRR inst
;
242 emit_instruction(p
, inst
.bits
);
245 printf("%s\t%s, %s, %s, %s\n", rem_prefix(name
), reg_name(rT
),
246 reg_name(rA
), reg_name(rB
), reg_name(rC
));
251 static void emit_RI7(struct spe_function
*p
, unsigned op
, unsigned rT
,
252 unsigned rA
, int imm
, const char *name
)
254 union spe_inst_RI7 inst
;
259 emit_instruction(p
, inst
.bits
);
262 printf("%s\t%s, %s, 0x%x\n",
263 rem_prefix(name
), reg_name(rT
), reg_name(rA
), imm
);
269 static void emit_RI8(struct spe_function
*p
, unsigned op
, unsigned rT
,
270 unsigned rA
, int imm
, const char *name
)
272 union spe_inst_RI8 inst
;
277 emit_instruction(p
, inst
.bits
);
280 printf("%s\t%s, %s, 0x%x\n",
281 rem_prefix(name
), reg_name(rT
), reg_name(rA
), imm
);
287 static void emit_RI10(struct spe_function
*p
, unsigned op
, unsigned rT
,
288 unsigned rA
, int imm
, const char *name
)
290 union spe_inst_RI10 inst
;
295 emit_instruction(p
, inst
.bits
);
298 printf("%s\t%s, %s, 0x%x\n",
299 rem_prefix(name
), reg_name(rT
), reg_name(rA
), imm
);
304 /** As above, but do range checking on signed immediate value */
305 static void emit_RI10s(struct spe_function
*p
, unsigned op
, unsigned rT
,
306 unsigned rA
, int imm
, const char *name
)
310 emit_RI10(p
, op
, rT
, rA
, imm
, name
);
314 static void emit_RI16(struct spe_function
*p
, unsigned op
, unsigned rT
,
315 int imm
, const char *name
)
317 union spe_inst_RI16 inst
;
321 emit_instruction(p
, inst
.bits
);
324 printf("%s\t%s, 0x%x\n", rem_prefix(name
), reg_name(rT
), imm
);
329 static void emit_RI18(struct spe_function
*p
, unsigned op
, unsigned rT
,
330 int imm
, const char *name
)
332 union spe_inst_RI18 inst
;
336 emit_instruction(p
, inst
.bits
);
339 printf("%s\t%s, 0x%x\n", rem_prefix(name
), reg_name(rT
), imm
);
346 #define EMIT_(_name, _op) \
347 void _name (struct spe_function *p, unsigned rT) \
349 emit_RR(p, _op, rT, 0, 0, __FUNCTION__); \
352 #define EMIT_R(_name, _op) \
353 void _name (struct spe_function *p, unsigned rT, unsigned rA) \
355 emit_RR(p, _op, rT, rA, 0, __FUNCTION__); \
358 #define EMIT_RR(_name, _op) \
359 void _name (struct spe_function *p, unsigned rT, unsigned rA, unsigned rB) \
361 emit_RR(p, _op, rT, rA, rB, __FUNCTION__); \
364 #define EMIT_RRR(_name, _op) \
365 void _name (struct spe_function *p, unsigned rT, unsigned rA, unsigned rB, unsigned rC) \
367 emit_RRR(p, _op, rT, rA, rB, rC, __FUNCTION__); \
370 #define EMIT_RI7(_name, _op) \
371 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
373 emit_RI7(p, _op, rT, rA, imm, __FUNCTION__); \
376 #define EMIT_RI8(_name, _op, bias) \
377 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
379 emit_RI8(p, _op, rT, rA, bias - imm, __FUNCTION__); \
382 #define EMIT_RI10(_name, _op) \
383 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
385 emit_RI10(p, _op, rT, rA, imm, __FUNCTION__); \
388 #define EMIT_RI10s(_name, _op) \
389 void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
391 emit_RI10s(p, _op, rT, rA, imm, __FUNCTION__); \
394 #define EMIT_RI16(_name, _op) \
395 void _name (struct spe_function *p, unsigned rT, int imm) \
397 emit_RI16(p, _op, rT, imm, __FUNCTION__); \
400 #define EMIT_RI18(_name, _op) \
401 void _name (struct spe_function *p, unsigned rT, int imm) \
403 emit_RI18(p, _op, rT, imm, __FUNCTION__); \
406 #define EMIT_I16(_name, _op) \
407 void _name (struct spe_function *p, int imm) \
409 emit_RI16(p, _op, 0, imm, __FUNCTION__); \
412 #include "rtasm_ppc_spe.h"
417 * Initialize an spe_function.
418 * \param code_size initial size of instruction buffer to allocate, in bytes.
419 * If zero, use a default.
421 void spe_init_func(struct spe_function
*p
, unsigned code_size
)
429 p
->max_inst
= code_size
/ SPE_INST_SIZE
;
430 p
->store
= align_malloc(code_size
, 16);
433 memset(p
->regs
, 0, SPE_NUM_REGS
* sizeof(p
->regs
[0]));
435 /* Conservatively treat R0 - R2 and R80 - R127 as non-volatile.
437 p
->regs
[0] = p
->regs
[1] = p
->regs
[2] = 1;
438 for (i
= 80; i
<= 127; i
++) {
447 void spe_release_func(struct spe_function
*p
)
449 assert(p
->num_inst
<= p
->max_inst
);
450 if (p
->store
!= NULL
) {
451 align_free(p
->store
);
457 /** Return current code size in bytes. */
458 unsigned spe_code_size(const struct spe_function
*p
)
460 return p
->num_inst
* SPE_INST_SIZE
;
465 * Allocate a SPE register.
466 * \return register index or -1 if none left.
468 int spe_allocate_available_register(struct spe_function
*p
)
471 for (i
= 0; i
< SPE_NUM_REGS
; i
++) {
472 if (p
->regs
[i
] == 0) {
483 * Mark the given SPE register as "allocated".
485 int spe_allocate_register(struct spe_function
*p
, int reg
)
487 assert(reg
< SPE_NUM_REGS
);
488 assert(p
->regs
[reg
] == 0);
495 * Mark the given SPE register as "unallocated". Note that this should
496 * only be used on registers allocated in the current register set; an
497 * assertion will fail if an attempt is made to deallocate a register
498 * allocated in an earlier register set.
500 void spe_release_register(struct spe_function
*p
, int reg
)
502 assert(reg
< SPE_NUM_REGS
);
503 assert(p
->regs
[reg
] == 1);
509 * Start a new set of registers. This can be called if
510 * it will be difficult later to determine exactly what
511 * registers were actually allocated during a code generation
512 * sequence, and you really just want to deallocate all of them.
514 void spe_allocate_register_set(struct spe_function
*p
)
518 /* Keep track of the set count. If it ever wraps around to 0,
522 assert(p
->set_count
> 0);
524 /* Increment the allocation count of all registers currently
525 * allocated. Then any registers that are allocated in this set
526 * will be the only ones with a count of 1; they'll all be released
527 * when the register set is released.
529 for (i
= 0; i
< SPE_NUM_REGS
; i
++) {
535 void spe_release_register_set(struct spe_function
*p
)
539 /* If the set count drops below zero, we're in trouble. */
540 assert(p
->set_count
> 0);
543 /* Drop the allocation level of all registers. Any allocated
544 * during this register set will drop to 0 and then become
547 for (i
= 0; i
< SPE_NUM_REGS
; i
++) {
555 spe_get_registers_used(const struct spe_function
*p
, ubyte used
[])
558 /* only count registers in the range available to callers */
559 for (i
= 2; i
< 80; i
++) {
569 spe_print_code(struct spe_function
*p
, boolean enable
)
576 spe_indent(struct spe_function
*p
, int spaces
)
583 spe_comment(struct spe_function
*p
, int rel_indent
, const char *s
)
586 p
->indent
+= rel_indent
;
588 p
->indent
-= rel_indent
;
596 * NOTE: offset is in bytes and the least significant 4 bits must be zero!
598 void spe_lqd(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
, 0x034, rT
, rA
, offset
>> 4, "spe_lqd");
614 printf("lqd\t%s, %d(%s)\n", reg_name(rT
), offset
, reg_name(rA
));
621 * NOTE: offset is in bytes and the least significant 4 bits must be zero!
623 void spe_stqd(struct spe_function
*p
, unsigned rT
, unsigned rA
, int offset
)
625 const boolean pSave
= p
->print
;
627 /* offset must be a multiple of 16 */
628 assert(offset
% 16 == 0);
629 /* offset must fit in 10-bit signed int field, after shifting */
630 assert((offset
>> 4) <= 511);
631 assert((offset
>> 4) >= -512);
634 emit_RI10(p
, 0x024, rT
, rA
, offset
>> 4, "spe_stqd");
639 printf("stqd\t%s, %d(%s)\n", reg_name(rT
), offset
, reg_name(rA
));
645 * For branch instructions:
646 * \param d if 1, disable interupts if branch is taken
647 * \param e if 1, enable interupts if branch is taken
648 * If d and e are both zero, don't change interupt status (right?)
651 /** Branch Indirect to address in rA */
652 void spe_bi(struct spe_function
*p
, unsigned rA
, int d
, int e
)
654 emit_RI7(p
, 0x1a8, 0, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
657 /** Interupt Return */
658 void spe_iret(struct spe_function
*p
, unsigned rA
, int d
, int e
)
660 emit_RI7(p
, 0x1aa, 0, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
663 /** Branch indirect and set link on external data */
664 void spe_bisled(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
,
667 emit_RI7(p
, 0x1ab, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
670 /** Branch indirect and set link. Save PC in rT, jump to rA. */
671 void spe_bisl(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
,
674 emit_RI7(p
, 0x1a9, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
677 /** Branch indirect if zero word. If rT.word[0]==0, jump to rA. */
678 void spe_biz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
680 emit_RI7(p
, 0x128, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
683 /** Branch indirect if non-zero word. If rT.word[0]!=0, jump to rA. */
684 void spe_binz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
686 emit_RI7(p
, 0x129, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
689 /** Branch indirect if zero halfword. If rT.halfword[1]==0, jump to rA. */
690 void spe_bihz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
692 emit_RI7(p
, 0x12a, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
695 /** Branch indirect if non-zero halfword. If rT.halfword[1]!=0, jump to rA. */
696 void spe_bihnz(struct spe_function
*p
, unsigned rT
, unsigned rA
, int d
, int e
)
698 emit_RI7(p
, 0x12b, rT
, rA
, (d
<< 5) | (e
<< 4), __FUNCTION__
);
702 /* Hint-for-branch instructions
711 /* Control instructions
715 EMIT_RR (spe_stopd
, 0x140);
716 EMIT_ (spe_lnop
, 0x001);
717 EMIT_ (spe_nop
, 0x201);
719 EMIT_ (spe_dsync
, 0x003);
720 EMIT_R (spe_mfspr
, 0x00c);
721 EMIT_R (spe_mtspr
, 0x10c);
726 ** Helper / "macro" instructions.
727 ** Use somewhat verbose names as a reminder that these aren't native
733 spe_load_float(struct spe_function
*p
, unsigned rT
, float x
)
738 else if (x
== 0.5f
) {
739 spe_ilhu(p
, rT
, 0x3f00);
741 else if (x
== 1.0f
) {
742 spe_ilhu(p
, rT
, 0x3f80);
744 else if (x
== -1.0f
) {
745 spe_ilhu(p
, rT
, 0xbf80);
753 spe_ilhu(p
, rT
, bits
.u
>> 16);
754 spe_iohl(p
, rT
, bits
.u
& 0xffff);
760 spe_load_int(struct spe_function
*p
, unsigned rT
, int i
)
762 if (-32768 <= i
&& i
<= 32767) {
766 spe_ilhu(p
, rT
, i
>> 16);
768 spe_iohl(p
, rT
, i
& 0xffff);
772 void spe_load_uint(struct spe_function
*p
, unsigned rT
, unsigned int ui
)
774 /* If the whole value is in the lower 18 bits, use ila, which
775 * doesn't sign-extend. Otherwise, if the two halfwords of
776 * the constant are identical, use ilh. Otherwise, if every byte of
777 * the desired value is 0x00 or 0xff, we can use Form Select Mask for
778 * Bytes Immediate (fsmbi) to load the value in a single instruction.
779 * Otherwise, in the general case, we have to use ilhu followed by iohl.
781 if ((ui
& 0x0003ffff) == ui
) {
784 else if ((ui
>> 16) == (ui
& 0xffff)) {
785 spe_ilh(p
, rT
, ui
& 0xffff);
788 ((ui
& 0x000000ff) == 0 || (ui
& 0x000000ff) == 0x000000ff) &&
789 ((ui
& 0x0000ff00) == 0 || (ui
& 0x0000ff00) == 0x0000ff00) &&
790 ((ui
& 0x00ff0000) == 0 || (ui
& 0x00ff0000) == 0x00ff0000) &&
791 ((ui
& 0xff000000) == 0 || (ui
& 0xff000000) == 0xff000000)
793 unsigned int mask
= 0;
794 /* fsmbi duplicates each bit in the given mask eight times,
795 * using a 16-bit value to initialize a 16-byte quadword.
796 * Each 4-bit nybble of the mask corresponds to a full word
797 * of the result; look at the value and figure out the mask
798 * (replicated for each word in the quadword), and then
799 * form the "select mask" to get the value.
801 if ((ui
& 0x000000ff) == 0x000000ff) mask
|= 0x1111;
802 if ((ui
& 0x0000ff00) == 0x0000ff00) mask
|= 0x2222;
803 if ((ui
& 0x00ff0000) == 0x00ff0000) mask
|= 0x4444;
804 if ((ui
& 0xff000000) == 0xff000000) mask
|= 0x8888;
805 spe_fsmbi(p
, rT
, mask
);
808 /* The general case: this usually uses two instructions, but
809 * may use only one if the low-order 16 bits of each word are 0.
811 spe_ilhu(p
, rT
, ui
>> 16);
813 spe_iohl(p
, rT
, ui
& 0xffff);
818 * This function is constructed identically to spe_xor_uint() below.
819 * Changes to one should be made in the other.
822 spe_and_uint(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned int ui
)
824 /* If we can, emit a single instruction, either And Byte Immediate
825 * (which uses the same constant across each byte), And Halfword Immediate
826 * (which sign-extends a 10-bit immediate to 16 bits and uses that
827 * across each halfword), or And Word Immediate (which sign-extends
828 * a 10-bit immediate to 32 bits).
830 * Otherwise, we'll need to use a temporary register.
834 /* If the upper 23 bits are all 0s or all 1s, sign extension
835 * will work and we can use And Word Immediate
837 tmp
= ui
& 0xfffffe00;
838 if (tmp
== 0xfffffe00 || tmp
== 0) {
839 spe_andi(p
, rT
, rA
, ui
& 0x000003ff);
843 /* If the ui field is symmetric along halfword boundaries and
844 * the upper 7 bits of each halfword are all 0s or 1s, we
845 * can use And Halfword Immediate
847 tmp
= ui
& 0xfe00fe00;
848 if ((tmp
== 0xfe00fe00 || tmp
== 0) && ((ui
>> 16) == (ui
& 0x0000ffff))) {
849 spe_andhi(p
, rT
, rA
, ui
& 0x000003ff);
853 /* If the ui field is symmetric in each byte, then we can use
854 * the And Byte Immediate instruction.
856 tmp
= ui
& 0x000000ff;
857 if ((ui
>> 24) == tmp
&& ((ui
>> 16) & 0xff) == tmp
&& ((ui
>> 8) & 0xff) == tmp
) {
858 spe_andbi(p
, rT
, rA
, tmp
);
862 /* Otherwise, we'll have to use a temporary register. */
863 unsigned int tmp_reg
= spe_allocate_available_register(p
);
864 spe_load_uint(p
, tmp_reg
, ui
);
865 spe_and(p
, rT
, rA
, tmp_reg
);
866 spe_release_register(p
, tmp_reg
);
871 * This function is constructed identically to spe_and_uint() above.
872 * Changes to one should be made in the other.
875 spe_xor_uint(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned int ui
)
877 /* If we can, emit a single instruction, either Exclusive Or Byte
878 * Immediate (which uses the same constant across each byte), Exclusive
879 * Or Halfword Immediate (which sign-extends a 10-bit immediate to
880 * 16 bits and uses that across each halfword), or Exclusive Or Word
881 * Immediate (which sign-extends a 10-bit immediate to 32 bits).
883 * Otherwise, we'll need to use a temporary register.
887 /* If the upper 23 bits are all 0s or all 1s, sign extension
888 * will work and we can use Exclusive Or Word Immediate
890 tmp
= ui
& 0xfffffe00;
891 if (tmp
== 0xfffffe00 || tmp
== 0) {
892 spe_xori(p
, rT
, rA
, ui
& 0x000003ff);
896 /* If the ui field is symmetric along halfword boundaries and
897 * the upper 7 bits of each halfword are all 0s or 1s, we
898 * can use Exclusive Or Halfword Immediate
900 tmp
= ui
& 0xfe00fe00;
901 if ((tmp
== 0xfe00fe00 || tmp
== 0) && ((ui
>> 16) == (ui
& 0x0000ffff))) {
902 spe_xorhi(p
, rT
, rA
, ui
& 0x000003ff);
906 /* If the ui field is symmetric in each byte, then we can use
907 * the Exclusive Or Byte Immediate instruction.
909 tmp
= ui
& 0x000000ff;
910 if ((ui
>> 24) == tmp
&& ((ui
>> 16) & 0xff) == tmp
&& ((ui
>> 8) & 0xff) == tmp
) {
911 spe_xorbi(p
, rT
, rA
, tmp
);
915 /* Otherwise, we'll have to use a temporary register. */
916 unsigned int tmp_reg
= spe_allocate_available_register(p
);
917 spe_load_uint(p
, tmp_reg
, ui
);
918 spe_xor(p
, rT
, rA
, tmp_reg
);
919 spe_release_register(p
, tmp_reg
);
923 spe_compare_equal_uint(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned int ui
)
925 /* If the comparison value is 9 bits or less, it fits inside a
926 * Compare Equal Word Immediate instruction.
928 if ((ui
& 0x000001ff) == ui
) {
929 spe_ceqi(p
, rT
, rA
, ui
);
931 /* Otherwise, we're going to have to load a word first. */
933 unsigned int tmp_reg
= spe_allocate_available_register(p
);
934 spe_load_uint(p
, tmp_reg
, ui
);
935 spe_ceq(p
, rT
, rA
, tmp_reg
);
936 spe_release_register(p
, tmp_reg
);
941 spe_compare_greater_uint(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned int ui
)
943 /* If the comparison value is 10 bits or less, it fits inside a
944 * Compare Logical Greater Than Word Immediate instruction.
946 if ((ui
& 0x000003ff) == ui
) {
947 spe_clgti(p
, rT
, rA
, ui
);
949 /* Otherwise, we're going to have to load a word first. */
951 unsigned int tmp_reg
= spe_allocate_available_register(p
);
952 spe_load_uint(p
, tmp_reg
, ui
);
953 spe_clgt(p
, rT
, rA
, tmp_reg
);
954 spe_release_register(p
, tmp_reg
);
959 spe_splat(struct spe_function
*p
, unsigned rT
, unsigned rA
)
961 /* Use a temporary, just in case rT == rA */
962 unsigned int tmp_reg
= spe_allocate_available_register(p
);
963 /* Duplicate bytes 0, 1, 2, and 3 across the whole register */
964 spe_ila(p
, tmp_reg
, 0x00010203);
965 spe_shufb(p
, rT
, rA
, rA
, tmp_reg
);
966 spe_release_register(p
, tmp_reg
);
971 spe_complement(struct spe_function
*p
, unsigned rT
, unsigned rA
)
973 spe_nor(p
, rT
, rA
, rA
);
978 spe_move(struct spe_function
*p
, unsigned rT
, unsigned rA
)
980 /* Use different instructions depending on the instruction address
981 * to take advantage of the dual pipelines.
984 spe_shlqbyi(p
, rT
, rA
, 0); /* odd pipe */
986 spe_ori(p
, rT
, rA
, 0); /* even pipe */
991 spe_zero(struct spe_function
*p
, unsigned rT
)
993 spe_xor(p
, rT
, rT
, rT
);
998 spe_splat_word(struct spe_function
*p
, unsigned rT
, unsigned rA
, int word
)
1005 spe_ila(p
, tmp1
, 66051);
1006 spe_shufb(p
, rT
, rA
, rA
, tmp1
);
1009 /* XXX review this, we may not need the rotqbyi instruction */
1011 int tmp2
= spe_allocate_available_register(p
);
1013 spe_ila(p
, tmp1
, 66051);
1014 spe_rotqbyi(p
, tmp2
, rA
, 4 * word
);
1015 spe_shufb(p
, rT
, tmp2
, tmp2
, tmp1
);
1017 spe_release_register(p
, tmp2
);
1022 * For each 32-bit float element of rA and rB, choose the smaller of the
1023 * two, compositing them into the rT register.
1025 * The Float Compare Greater Than (fcgt) instruction will put 1s into
1026 * compare_reg where rA > rB, and 0s where rA <= rB.
1028 * Then the Select Bits (selb) instruction will take bits from rA where
1029 * compare_reg is 0, and from rB where compare_reg is 1; i.e., from rA
1030 * where rA <= rB and from rB where rB > rA, which is exactly the
1033 * The compare_reg could in many cases be the same as rT, unless
1034 * rT == rA || rt == rB. But since this is common in constructions
1035 * like "x = min(x, a)", we always allocate a new register to be safe.
1038 spe_float_min(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned rB
)
1040 unsigned int compare_reg
= spe_allocate_available_register(p
);
1041 spe_fcgt(p
, compare_reg
, rA
, rB
);
1042 spe_selb(p
, rT
, rA
, rB
, compare_reg
);
1043 spe_release_register(p
, compare_reg
);
1047 * For each 32-bit float element of rA and rB, choose the greater of the
1048 * two, compositing them into the rT register.
1050 * The logic is similar to that of spe_float_min() above; the only
1051 * difference is that the registers on spe_selb() have been reversed,
1052 * so that the larger of the two is selected instead of the smaller.
1055 spe_float_max(struct spe_function
*p
, unsigned rT
, unsigned rA
, unsigned rB
)
1057 unsigned int compare_reg
= spe_allocate_available_register(p
);
1058 spe_fcgt(p
, compare_reg
, rA
, rB
);
1059 spe_selb(p
, rT
, rB
, rA
, compare_reg
);
1060 spe_release_register(p
, compare_reg
);
1063 #endif /* GALLIUM_CELL */