1 # Altivec instruction set, for PSIM, the PowerPC simulator.
3 # Copyright 2003, 2010 Free Software Foundation, Inc.
5 # Contributed by Red Hat Inc; developed under contract from Motorola.
6 # Written by matthew green <mrg@redhat.com>.
8 # This file is part of GDB.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 # Motorola AltiVec instructions.
29 :cache:av::vreg *:vS:VS:(cpu_registers(processor)->altivec.vr + VS)
30 :cache:av::unsigned32:VS_BITMASK:VS:(1 << VS)
32 :cache:av::vreg *:vA:VA:(cpu_registers(processor)->altivec.vr + VA)
33 :cache:av::unsigned32:VA_BITMASK:VA:(1 << VA)
35 :cache:av::vreg *:vB:VB:(cpu_registers(processor)->altivec.vr + VB)
36 :cache:av::unsigned32:VB_BITMASK:VB:(1 << VB)
38 :cache:av::vreg *:vC:VC:(cpu_registers(processor)->altivec.vr + VC)
39 :cache:av::unsigned32:VC_BITMASK:VC:(1 << VC)
43 #define PPC_INSN_INT_VR(OUT_MASK, IN_MASK, OUT_VMASK, IN_VMASK) \
45 if (CURRENT_MODEL_ISSUE > 0) \
46 ppc_insn_int_vr(MY_INDEX, cpu_model(processor), OUT_MASK, IN_MASK, OUT_VMASK, IN_VMASK); \
49 #define PPC_INSN_VR(OUT_VMASK, IN_VMASK) \
51 if (CURRENT_MODEL_ISSUE > 0) \
52 ppc_insn_vr(MY_INDEX, cpu_model(processor), OUT_VMASK, IN_VMASK); \
55 #define PPC_INSN_VR_CR(OUT_VMASK, IN_VMASK, CR_MASK) \
57 if (CURRENT_MODEL_ISSUE > 0) \
58 ppc_insn_vr_cr(MY_INDEX, cpu_model(processor), OUT_VMASK, IN_VMASK, CR_MASK); \
61 #define PPC_INSN_VR_VSCR(OUT_VMASK, IN_VMASK) \
63 if (CURRENT_MODEL_ISSUE > 0) \
64 ppc_insn_vr_vscr(MY_INDEX, cpu_model(processor), OUT_VMASK, IN_VMASK); \
67 #define PPC_INSN_FROM_VSCR(VR_MASK) \
69 if (CURRENT_MODEL_ISSUE > 0) \
70 ppc_insn_from_vscr(MY_INDEX, cpu_model(processor), VR_MASK); \
73 #define PPC_INSN_TO_VSCR(VR_MASK) \
75 if (CURRENT_MODEL_ISSUE > 0) \
76 ppc_insn_to_vscr(MY_INDEX, cpu_model(processor), VR_MASK); \
79 # Trace waiting for AltiVec registers to become available
80 void::model-static::model_trace_altivec_busy_p:model_data *model_ptr, unsigned32 vr_busy
83 vr_busy &= model_ptr->vr_busy;
84 for(i = 0; i < 32; i++) {
85 if (((1 << i) & vr_busy) != 0) {
86 TRACE(trace_model, ("Waiting for register v%d.\n", i));
90 if (model_ptr->vscr_busy)
91 TRACE(trace_model, ("Waiting for VSCR\n"));
93 # Trace making AltiVec registers busy
94 void::model-static::model_trace_altivec_make_busy:model_data *model_ptr, unsigned32 vr_mask, unsigned32 cr_mask
97 for(i = 0; i < 32; i++) {
98 if (((1 << i) & vr_mask) != 0) {
99 TRACE(trace_model, ("Register v%d is now busy.\n", i));
104 for(i = 0; i < 8; i++) {
105 if (((1 << i) & cr_mask) != 0) {
106 TRACE(trace_model, ("Register cr%d is now busy.\n", i));
111 # Schedule an AltiVec instruction that takes integer input registers and produces output registers
112 void::model-function::ppc_insn_int_vr:itable_index index, model_data *model_ptr, const unsigned32 out_mask, const unsigned32 in_mask, const unsigned32 out_vmask, const unsigned32 in_vmask
113 const unsigned32 int_mask = out_mask | in_mask;
114 const unsigned32 vr_mask = out_vmask | in_vmask;
115 model_busy *busy_ptr;
117 if ((model_ptr->int_busy & int_mask) != 0 || (model_ptr->vr_busy & vr_mask)) {
118 model_new_cycle(model_ptr); /* don't count first dependency as a stall */
120 while ((model_ptr->int_busy & int_mask) != 0 || (model_ptr->vr_busy & vr_mask)) {
121 if (WITH_TRACE && ppc_trace[trace_model]) {
122 model_trace_busy_p(model_ptr, int_mask, 0, 0, PPC_NO_SPR);
123 model_trace_altivec_busy_p(model_ptr, vr_mask);
126 model_ptr->nr_stalls_data++;
127 model_new_cycle(model_ptr);
131 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
132 model_ptr->int_busy |= out_mask;
133 busy_ptr->int_busy |= out_mask;
134 model_ptr->vr_busy |= out_vmask;
135 busy_ptr->vr_busy |= out_vmask;
138 busy_ptr->nr_writebacks = (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
141 busy_ptr->nr_writebacks += (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
143 if (WITH_TRACE && ppc_trace[trace_model]) {
144 model_trace_make_busy(model_ptr, out_mask, 0, 0);
145 model_trace_altivec_make_busy(model_ptr, vr_mask, 0);
148 # Schedule an AltiVec instruction that takes vector input registers and produces vector output registers
149 void::model-function::ppc_insn_vr:itable_index index, model_data *model_ptr, const unsigned32 out_vmask, const unsigned32 in_vmask
150 const unsigned32 vr_mask = out_vmask | in_vmask;
151 model_busy *busy_ptr;
153 if (model_ptr->vr_busy & vr_mask) {
154 model_new_cycle(model_ptr); /* don't count first dependency as a stall */
156 while (model_ptr->vr_busy & vr_mask) {
157 if (WITH_TRACE && ppc_trace[trace_model]) {
158 model_trace_altivec_busy_p(model_ptr, vr_mask);
161 model_ptr->nr_stalls_data++;
162 model_new_cycle(model_ptr);
166 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
167 model_ptr->vr_busy |= out_vmask;
168 busy_ptr->vr_busy |= out_vmask;
170 busy_ptr->nr_writebacks = (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
172 if (WITH_TRACE && ppc_trace[trace_model]) {
173 model_trace_altivec_make_busy(model_ptr, vr_mask, 0);
176 # Schedule an AltiVec instruction that takes vector input registers and produces vector output registers, touches CR
177 void::model-function::ppc_insn_vr_cr:itable_index index, model_data *model_ptr, const unsigned32 out_vmask, const unsigned32 in_vmask, const unsigned32 cr_mask
178 const unsigned32 vr_mask = out_vmask | in_vmask;
179 model_busy *busy_ptr;
181 if ((model_ptr->vr_busy & vr_mask) || (model_ptr->cr_fpscr_busy & cr_mask)) {
182 model_new_cycle(model_ptr); /* don't count first dependency as a stall */
184 while ((model_ptr->vr_busy & vr_mask) || (model_ptr->cr_fpscr_busy & cr_mask)) {
185 if (WITH_TRACE && ppc_trace[trace_model]) {
186 model_trace_busy_p(model_ptr, 0, 0, cr_mask, PPC_NO_SPR);
187 model_trace_altivec_busy_p(model_ptr, vr_mask);
190 model_ptr->nr_stalls_data++;
191 model_new_cycle(model_ptr);
195 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
196 model_ptr->cr_fpscr_busy |= cr_mask;
197 busy_ptr->cr_fpscr_busy |= cr_mask;
198 model_ptr->vr_busy |= out_vmask;
199 busy_ptr->vr_busy |= out_vmask;
202 busy_ptr->nr_writebacks = (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
205 busy_ptr->nr_writebacks++;
207 if (WITH_TRACE && ppc_trace[trace_model])
208 model_trace_altivec_make_busy(model_ptr, vr_mask, cr_mask);
210 # Schedule an AltiVec instruction that takes vector input registers and produces vector output registers, touches VSCR
211 void::model-function::ppc_insn_vr_vscr:itable_index index, model_data *model_ptr, const unsigned32 out_vmask, const unsigned32 in_vmask
212 const unsigned32 vr_mask = out_vmask | in_vmask;
213 model_busy *busy_ptr;
215 if ((model_ptr->vr_busy & vr_mask) != 0 || model_ptr->vscr_busy != 0) {
216 model_new_cycle(model_ptr); /* don't count first dependency as a stall */
218 while ((model_ptr->vr_busy & vr_mask) != 0 || model_ptr->vscr_busy != 0) {
219 if (WITH_TRACE && ppc_trace[trace_model])
220 model_trace_altivec_busy_p(model_ptr, vr_mask);
222 model_ptr->nr_stalls_data++;
223 model_new_cycle(model_ptr);
227 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
228 model_ptr->vr_busy |= out_vmask;
229 busy_ptr->vr_busy |= out_vmask;
230 model_ptr->vscr_busy = 1;
231 busy_ptr->vscr_busy = 1;
234 busy_ptr->nr_writebacks = 1 + (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
236 if (WITH_TRACE && ppc_trace[trace_model])
237 model_trace_altivec_make_busy(model_ptr, vr_mask, 0);
239 # Schedule an MFVSCR instruction that VSCR input register and produces an AltiVec output register
240 void::model-function::ppc_insn_from_vscr:itable_index index, model_data *model_ptr, const unsigned32 vr_mask
241 model_busy *busy_ptr;
243 while ((model_ptr->vr_busy & vr_mask) != 0 || model_ptr->vscr_busy != 0) {
244 if (WITH_TRACE && ppc_trace[trace_model])
245 model_trace_altivec_busy_p(model_ptr, vr_mask);
247 model_ptr->nr_stalls_data++;
248 model_new_cycle(model_ptr);
250 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
251 model_ptr->cr_fpscr_busy |= vr_mask;
252 busy_ptr->cr_fpscr_busy |= vr_mask;
255 busy_ptr->nr_writebacks = 1;
257 model_ptr->vr_busy |= vr_mask;
258 if (WITH_TRACE && ppc_trace[trace_model])
259 model_trace_altivec_make_busy(model_ptr, vr_mask, 0);
261 # Schedule an MTVSCR instruction that one AltiVec input register and produces a vscr output register
262 void::model-function::ppc_insn_to_vscr:itable_index index, model_data *model_ptr, const unsigned32 vr_mask
263 model_busy *busy_ptr;
265 while ((model_ptr->vr_busy & vr_mask) != 0 || model_ptr->vscr_busy != 0) {
266 if (WITH_TRACE && ppc_trace[trace_model])
267 model_trace_altivec_busy_p(model_ptr, vr_mask);
269 model_ptr->nr_stalls_data++;
270 model_new_cycle(model_ptr);
272 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
273 busy_ptr ->vscr_busy = 1;
274 model_ptr->vscr_busy = 1;
275 busy_ptr->nr_writebacks = 1;
277 TRACE(trace_model,("Making VSCR busy.\n"));
279 # The follow are AltiVec saturate operations
281 signed8::model-function::altivec_signed_saturate_8:signed16 val, int *sat
286 } else if (val < -128) {
295 signed16::model-function::altivec_signed_saturate_16:signed32 val, int *sat
300 } else if (val < -32768) {
309 signed32::model-function::altivec_signed_saturate_32:signed64 val, int *sat
311 if (val > 2147483647) {
314 } else if (val < -2147483648LL) {
323 unsigned8::model-function::altivec_unsigned_saturate_8:signed16 val, int *sat
328 } else if (val < 0) {
337 unsigned16::model-function::altivec_unsigned_saturate_16:signed32 val, int *sat
342 } else if (val < 0) {
351 unsigned32::model-function::altivec_unsigned_saturate_32:signed64 val, int *sat
353 if (val > 4294967295LL) {
356 } else if (val < 0) {
366 # Load instructions, 6-14 ... 6-22.
369 0.31,6.VS,11.RA,16.RB,21.7,31.0:X:av:lvebx %VD, %RA, %RB:Load Vector Element Byte Indexed
377 (*vS).b[AV_BINDEX(eb)] = MEM(unsigned, EA, 1);
378 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
380 0.31,6.VS,11.RA,16.RB,21.39,31.0:X:av:lvehx %VD, %RA, %RB:Load Vector Element Half Word Indexed
388 (*vS).h[AV_HINDEX(eb/2)] = MEM(unsigned, EA, 2);
389 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
391 0.31,6.VS,11.RA,16.RB,21.71,31.0:X:av:lvewx %VD, %RA, %RB:Load Vector Element Word Indexed
399 (*vS).w[eb/4] = MEM(unsigned, EA, 4);
400 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
403 0.31,6.VS,11.RA,16.RB,21.6,31.0:X:av:lvsl %VD, %RA, %RB:Load Vector for Shift Left
411 for (i = 0; i < 16; i++)
412 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
413 (*vS).b[AV_BINDEX(i)] = j++;
415 (*vS).b[AV_BINDEX(15 - i)] = j++;
416 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
418 0.31,6.VS,11.RA,16.RB,21.38,31.0:X:av:lvsr %VD, %RA, %RB:Load Vector for Shift Right
425 j = 0x10 - (addr & 0xf);
426 for (i = 0; i < 16; i++)
427 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
428 (*vS).b[AV_BINDEX(i)] = j++;
430 (*vS).b[AV_BINDEX(15 - i)] = j++;
431 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
434 0.31,6.VS,11.RA,16.RB,21.103,31.0:X:av:lvx %VD, %RA, %RB:Load Vector Indexed
439 EA = (b + *rB) & ~0xf;
440 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
441 (*vS).w[0] = MEM(unsigned, EA + 0, 4);
442 (*vS).w[1] = MEM(unsigned, EA + 4, 4);
443 (*vS).w[2] = MEM(unsigned, EA + 8, 4);
444 (*vS).w[3] = MEM(unsigned, EA + 12, 4);
446 (*vS).w[0] = MEM(unsigned, EA + 12, 4);
447 (*vS).w[1] = MEM(unsigned, EA + 8, 4);
448 (*vS).w[2] = MEM(unsigned, EA + 4, 4);
449 (*vS).w[3] = MEM(unsigned, EA + 0, 4);
451 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
453 0.31,6.VS,11.RA,16.RB,21.359,31.0:X:av:lvxl %VD, %RA, %RB:Load Vector Indexed LRU
458 EA = (b + *rB) & ~0xf;
459 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
460 (*vS).w[0] = MEM(unsigned, EA + 0, 4);
461 (*vS).w[1] = MEM(unsigned, EA + 4, 4);
462 (*vS).w[2] = MEM(unsigned, EA + 8, 4);
463 (*vS).w[3] = MEM(unsigned, EA + 12, 4);
465 (*vS).w[0] = MEM(unsigned, EA + 12, 4);
466 (*vS).w[1] = MEM(unsigned, EA + 8, 4);
467 (*vS).w[2] = MEM(unsigned, EA + 4, 4);
468 (*vS).w[3] = MEM(unsigned, EA + 0, 4);
470 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
473 # Move to/from VSCR instructions, 6-23 & 6-24.
476 0.4,6.VS,11.0,16.0,21.1540:VX:av:mfvscr %VS:Move from Vector Status and Control Register
481 PPC_INSN_FROM_VSCR(VS_BITMASK);
483 0.4,6.0,11.0,16.VB,21.1604:VX:av:mtvscr %VB:Move to Vector Status and Control Register
485 PPC_INSN_TO_VSCR(VB_BITMASK);
488 # Store instructions, 6-25 ... 6-29.
491 0.31,6.VS,11.RA,16.RB,21.135,31.0:X:av:stvebx %VD, %RA, %RB:Store Vector Element Byte Indexed
499 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
500 STORE(EA, 1, (*vS).b[eb]);
502 STORE(EA, 1, (*vS).b[15-eb]);
503 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
505 0.31,6.VS,11.RA,16.RB,21.167,31.0:X:av:stvehx %VD, %RA, %RB:Store Vector Element Half Word Indexed
513 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
514 STORE(EA, 2, (*vS).h[eb/2]);
516 STORE(EA, 2, (*vS).h[7-eb]);
517 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
519 0.31,6.VS,11.RA,16.RB,21.199,31.0:X:av:stvewx %VD, %RA, %RB:Store Vector Element Word Indexed
527 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
528 STORE(EA, 4, (*vS).w[eb/4]);
530 STORE(EA, 4, (*vS).w[3-(eb/4)]);
531 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
533 0.31,6.VS,11.RA,16.RB,21.231,31.0:X:av:stvx %VD, %RA, %RB:Store Vector Indexed
538 EA = (b + *rB) & ~0xf;
539 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
540 STORE(EA + 0, 4, (*vS).w[0]);
541 STORE(EA + 4, 4, (*vS).w[1]);
542 STORE(EA + 8, 4, (*vS).w[2]);
543 STORE(EA + 12, 4, (*vS).w[3]);
545 STORE(EA + 12, 4, (*vS).w[0]);
546 STORE(EA + 8, 4, (*vS).w[1]);
547 STORE(EA + 4, 4, (*vS).w[2]);
548 STORE(EA + 0, 4, (*vS).w[3]);
550 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
552 0.31,6.VS,11.RA,16.RB,21.487,31.0:X:av:stvxl %VD, %RA, %RB:Store Vector Indexed LRU
557 EA = (b + *rB) & ~0xf;
558 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
559 STORE(EA + 0, 4, (*vS).w[0]);
560 STORE(EA + 4, 4, (*vS).w[1]);
561 STORE(EA + 8, 4, (*vS).w[2]);
562 STORE(EA + 12, 4, (*vS).w[3]);
564 STORE(EA + 12, 4, (*vS).w[0]);
565 STORE(EA + 8, 4, (*vS).w[1]);
566 STORE(EA + 4, 4, (*vS).w[2]);
567 STORE(EA + 0, 4, (*vS).w[3]);
569 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
572 # Vector Add instructions, 6-30 ... 6-40.
575 0.4,6.VS,11.VA,16.VB,21.384:VX:av:vaddcuw %VD, %VA, %VB:Vector Add Carryout Unsigned Word
578 for (i = 0; i < 4; i++) {
579 temp = (unsigned64)(*vA).w[i] + (unsigned64)(*vB).w[i];
580 (*vS).w[i] = temp >> 32;
582 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
584 0.4,6.VS,11.VA,16.VB,21.10:VX:av:vaddfp %VD, %VA, %VB:Vector Add Floating Point
588 for (i = 0; i < 4; i++) {
589 sim_fpu_32to (&a, (*vA).w[i]);
590 sim_fpu_32to (&b, (*vB).w[i]);
591 sim_fpu_add (&d, &a, &b);
592 sim_fpu_to32 (&f, &d);
595 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
597 0.4,6.VS,11.VA,16.VB,21.768:VX:av:vaddsbs %VD, %VA, %VB:Vector Add Signed Byte Saturate
600 for (i = 0; i < 16; i++) {
601 temp = (signed16)(signed8)(*vA).b[i] + (signed16)(signed8)(*vB).b[i];
602 (*vS).b[i] = altivec_signed_saturate_8(temp, &tempsat);
605 ALTIVEC_SET_SAT(sat);
606 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
608 0.4,6.VS,11.VA,16.VB,21.832:VX:av:vaddshs %VD, %VA, %VB:Vector Add Signed Half Word Saturate
611 for (i = 0; i < 8; i++) {
612 a = (signed32)(signed16)(*vA).h[i];
613 b = (signed32)(signed16)(*vB).h[i];
615 (*vS).h[i] = altivec_signed_saturate_16(temp, &tempsat);
618 ALTIVEC_SET_SAT(sat);
619 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
621 0.4,6.VS,11.VA,16.VB,21.896:VX:av:vaddsws %VD, %VA, %VB:Vector Add Signed Word Saturate
624 for (i = 0; i < 4; i++) {
625 temp = (signed64)(signed32)(*vA).w[i] + (signed64)(signed32)(*vB).w[i];
626 (*vS).w[i] = altivec_signed_saturate_32(temp, &tempsat);
629 ALTIVEC_SET_SAT(sat);
630 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
632 0.4,6.VS,11.VA,16.VB,21.0:VX:av:vaddubm %VD, %VA, %VB:Vector Add Unsigned Byte Modulo
634 for (i = 0; i < 16; i++)
635 (*vS).b[i] = ((*vA).b[i] + (*vB).b[i]) & 0xff;
636 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
638 0.4,6.VS,11.VA,16.VB,21.512:VX:av:vaddubs %VD, %VA, %VB:Vector Add Unsigned Byte Saturate
642 for (i = 0; i < 16; i++) {
643 temp = (signed16)(unsigned8)(*vA).b[i] + (signed16)(unsigned8)(*vB).b[i];
644 (*vS).b[i] = altivec_unsigned_saturate_8(temp, &tempsat);
647 ALTIVEC_SET_SAT(sat);
648 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
650 0.4,6.VS,11.VA,16.VB,21.64:VX:av:vadduhm %VD, %VA, %VB:Vector Add Unsigned Half Word Modulo
652 for (i = 0; i < 8; i++)
653 (*vS).h[i] = ((*vA).h[i] + (*vB).h[i]) & 0xffff;
654 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
656 0.4,6.VS,11.VA,16.VB,21.576:VX:av:vadduhs %VD, %VA, %VB:Vector Add Unsigned Half Word Saturate
659 for (i = 0; i < 8; i++) {
660 temp = (signed32)(unsigned16)(*vA).h[i] + (signed32)(unsigned16)(*vB).h[i];
661 (*vS).h[i] = altivec_unsigned_saturate_16(temp, &tempsat);
664 ALTIVEC_SET_SAT(sat);
665 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
667 0.4,6.VS,11.VA,16.VB,21.128:VX:av:vadduwm %VD, %VA, %VB:Vector Add Unsigned Word Modulo
669 for (i = 0; i < 4; i++)
670 (*vS).w[i] = (*vA).w[i] + (*vB).w[i];
671 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
673 0.4,6.VS,11.VA,16.VB,21.640:VX:av:vadduws %VD, %VA, %VB:Vector Add Unsigned Word Saturate
676 for (i = 0; i < 4; i++) {
677 temp = (signed64)(unsigned32)(*vA).w[i] + (signed64)(unsigned32)(*vB).w[i];
678 (*vS).w[i] = altivec_unsigned_saturate_32(temp, &tempsat);
681 ALTIVEC_SET_SAT(sat);
682 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
685 # Vector AND instructions, 6-41, 6-42
688 0.4,6.VS,11.VA,16.VB,21.1028:VX:av:vand %VD, %VA, %VB:Vector Logical AND
690 for (i = 0; i < 4; i++)
691 (*vS).w[i] = (*vA).w[i] & (*vB).w[i];
692 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
694 0.4,6.VS,11.VA,16.VB,21.1092:VX:av:vandc %VD, %VA, %VB:Vector Logical AND with Compliment
696 for (i = 0; i < 4; i++)
697 (*vS).w[i] = (*vA).w[i] & ~((*vB).w[i]);
698 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
702 # Vector Average instructions, 6-43, 6-48
705 0.4,6.VS,11.VA,16.VB,21.1282:VX:av:vavgsb %VD, %VA, %VB:Vector Average Signed Byte
708 for (i = 0; i < 16; i++) {
709 a = (signed16)(signed8)(*vA).b[i];
710 b = (signed16)(signed8)(*vB).b[i];
712 (*vS).b[i] = (temp >> 1) & 0xff;
714 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
716 0.4,6.VS,11.VA,16.VB,21.1346:VX:av:vavgsh %VD, %VA, %VB:Vector Average Signed Half Word
719 for (i = 0; i < 8; i++) {
720 a = (signed32)(signed16)(*vA).h[i];
721 b = (signed32)(signed16)(*vB).h[i];
723 (*vS).h[i] = (temp >> 1) & 0xffff;
725 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
727 0.4,6.VS,11.VA,16.VB,21.1410:VX:av:vavgsw %VD, %VA, %VB:Vector Average Signed Word
730 for (i = 0; i < 4; i++) {
731 a = (signed64)(signed32)(*vA).w[i];
732 b = (signed64)(signed32)(*vB).w[i];
734 (*vS).w[i] = (temp >> 1) & 0xffffffff;
736 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
738 0.4,6.VS,11.VA,16.VB,21.1026:VX:av:vavgub %VD, %VA, %VB:Vector Average Unsigned Byte
740 unsigned16 temp, a, b;
741 for (i = 0; i < 16; i++) {
745 (*vS).b[i] = (temp >> 1) & 0xff;
747 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
749 0.4,6.VS,11.VA,16.VB,21.1090:VX:av:vavguh %VD, %VA, %VB:Vector Average Unsigned Half Word
751 unsigned32 temp, a, b;
752 for (i = 0; i < 8; i++) {
756 (*vS).h[i] = (temp >> 1) & 0xffff;
758 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
760 0.4,6.VS,11.VA,16.VB,21.1154:VX:av:vavguw %VD, %VA, %VB:Vector Average Unsigned Word
762 unsigned64 temp, a, b;
763 for (i = 0; i < 4; i++) {
767 (*vS).w[i] = (temp >> 1) & 0xffffffff;
769 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
772 # Vector Fixed Point Convert instructions, 6-49, 6-50
775 0.4,6.VS,11.UIMM,16.VB,21.842:VX:av:vcfsx %VD, %VB, %UIMM:Vector Convert From Signed Fixed-Point Word
779 for (i = 0; i < 4; i++) {
780 sim_fpu_32to (&b, (*vB).w[i]);
781 sim_fpu_u32to (&div, 2 << UIMM, sim_fpu_round_default);
782 sim_fpu_div (&d, &b, &div);
783 sim_fpu_to32 (&f, &d);
786 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
788 0.4,6.VS,11.UIMM,16.VB,21.778:VX:av:vcfux %VD, %VA, %UIMM:Vector Convert From Unsigned Fixed-Point Word
792 for (i = 0; i < 4; i++) {
793 sim_fpu_32to (&b, (*vB).w[i]);
794 sim_fpu_u32to (&div, 2 << UIMM, sim_fpu_round_default);
795 sim_fpu_div (&d, &b, &div);
796 sim_fpu_to32u (&f, &d, sim_fpu_round_default);
799 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
802 # Vector Compare instructions, 6-51 ... 6-64
805 0.4,6.VS,11.VA,16.VB,21.RC,22.966:VXR:av:vcmpbpfpx %VD, %VA, %VB:Vector Compare Bounds Floating Point
808 for (i = 0; i < 4; i++) {
809 sim_fpu_32to (&a, (*vA).w[i]);
810 sim_fpu_32to (&b, (*vB).w[i]);
811 le = sim_fpu_is_le(&a, &b);
812 ge = sim_fpu_is_ge(&a, &b);
813 (*vS).w[i] = (le ? 0 : 1 << 31) | (ge ? 0 : 1 << 30);
816 ALTIVEC_SET_CR6(vS, 0);
817 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
819 0.4,6.VS,11.VA,16.VB,21.RC,22.198:VXR:av:vcmpeqfpx %VD, %VA, %VB:Vector Compare Equal-to-Floating Point
822 for (i = 0; i < 4; i++) {
823 sim_fpu_32to (&a, (*vA).w[i]);
824 sim_fpu_32to (&b, (*vB).w[i]);
825 if (sim_fpu_is_eq(&a, &b))
826 (*vS).w[i] = 0xffffffff;
831 ALTIVEC_SET_CR6(vS, 1);
832 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
834 0.4,6.VS,11.VA,16.VB,21.RC,22.6:VXR:av:vcmpequbx %VD, %VA, %VB:Vector Compare Equal-to Unsigned Byte
836 for (i = 0; i < 16; i++)
837 if ((*vA).b[i] == (*vB).b[i])
842 ALTIVEC_SET_CR6(vS, 1);
843 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
845 0.4,6.VS,11.VA,16.VB,21.RC,22.70:VXR:av:vcmpequhx %VD, %VA, %VB:Vector Compare Equal-to Unsigned Half Word
847 for (i = 0; i < 8; i++)
848 if ((*vA).h[i] == (*vB).h[i])
853 ALTIVEC_SET_CR6(vS, 1);
854 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
856 0.4,6.VS,11.VA,16.VB,21.RC,22.134:VXR:av:vcmpequwx %VD, %VA, %VB:Vector Compare Equal-to Unsigned Word
858 for (i = 0; i < 4; i++)
859 if ((*vA).w[i] == (*vB).w[i])
860 (*vS).w[i] = 0xffffffff;
864 ALTIVEC_SET_CR6(vS, 1);
865 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
867 0.4,6.VS,11.VA,16.VB,21.RC,22.454:VXR:av:vcmpgefpx %VD, %VA, %VB:Vector Compare Greater-Than-or-Equal-to Floating Point
870 for (i = 0; i < 4; i++) {
871 sim_fpu_32to (&a, (*vA).w[i]);
872 sim_fpu_32to (&b, (*vB).w[i]);
873 if (sim_fpu_is_ge(&a, &b))
874 (*vS).w[i] = 0xffffffff;
879 ALTIVEC_SET_CR6(vS, 1);
880 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
882 0.4,6.VS,11.VA,16.VB,21.RC,22.710:VXR:av:vcmpgtfpx %VD, %VA, %VB:Vector Compare Greater-Than Floating Point
885 for (i = 0; i < 4; i++) {
886 sim_fpu_32to (&a, (*vA).w[i]);
887 sim_fpu_32to (&b, (*vB).w[i]);
888 if (sim_fpu_is_gt(&a, &b))
889 (*vS).w[i] = 0xffffffff;
894 ALTIVEC_SET_CR6(vS, 1);
895 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
897 0.4,6.VS,11.VA,16.VB,21.RC,22.774:VXR:av:vcmpgtsbx %VD, %VA, %VB:Vector Compare Greater-Than Signed Byte
900 for (i = 0; i < 16; i++) {
909 ALTIVEC_SET_CR6(vS, 1);
910 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
912 0.4,6.VS,11.VA,16.VB,21.RC,22.838:VXR:av:vcmpgtshx %VD, %VA, %VB:Vector Compare Greater-Than Signed Half Word
915 for (i = 0; i < 8; i++) {
924 ALTIVEC_SET_CR6(vS, 1);
925 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
927 0.4,6.VS,11.VA,16.VB,21.RC,22.902:VXR:av:vcmpgtswx %VD, %VA, %VB:Vector Compare Greater-Than Signed Word
930 for (i = 0; i < 4; i++) {
934 (*vS).w[i] = 0xffffffff;
939 ALTIVEC_SET_CR6(vS, 1);
940 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
942 0.4,6.VS,11.VA,16.VB,21.RC,22.518:VXR:av:vcmpgtubx %VD, %VA, %VB:Vector Compare Greater-Than Unsigned Byte
945 for (i = 0; i < 16; i++) {
954 ALTIVEC_SET_CR6(vS, 1);
955 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
957 0.4,6.VS,11.VA,16.VB,21.RC,22.582:VXR:av:vcmpgtuhx %VD, %VA, %VB:Vector Compare Greater-Than Unsigned Half Word
960 for (i = 0; i < 8; i++) {
969 ALTIVEC_SET_CR6(vS, 1);
970 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
972 0.4,6.VS,11.VA,16.VB,21.RC,22.646:VXR:av:vcmpgtuwx %VD, %VA, %VB:Vector Compare Greater-Than Unsigned Word
975 for (i = 0; i < 4; i++) {
979 (*vS).w[i] = 0xffffffff;
984 ALTIVEC_SET_CR6(vS, 1);
985 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
988 # Vector Convert instructions, 6-65, 6-66.
991 0.4,6.VS,11.UIMM,16.VB,21.970:VX:av:vctsxs %VD, %VB, %UIMM:Vector Convert to Signed Fixed-Point Word Saturate
996 for (i = 0; i < 4; i++) {
997 sim_fpu_32to (&b, (*vB).w[i]);
998 sim_fpu_u32to (&m, 2 << UIMM, sim_fpu_round_default);
999 sim_fpu_mul (&a, &b, &m);
1000 sim_fpu_to64i (&temp, &a, sim_fpu_round_default);
1001 (*vS).w[i] = altivec_signed_saturate_32(temp, &tempsat);
1004 ALTIVEC_SET_SAT(sat);
1005 PPC_INSN_VR_VSCR(VS_BITMASK, VB_BITMASK);
1007 0.4,6.VS,11.UIMM,16.VB,21.906:VX:av:vctuxs %VD, %VB, %UIMM:Vector Convert to Unsigned Fixed-Point Word Saturate
1008 int i, sat, tempsat;
1012 for (i = 0; i < 4; i++) {
1013 sim_fpu_32to (&b, (*vB).w[i]);
1014 sim_fpu_u32to (&m, 2 << UIMM, sim_fpu_round_default);
1015 sim_fpu_mul (&a, &b, &m);
1016 sim_fpu_to64u (&temp, &a, sim_fpu_round_default);
1017 (*vS).w[i] = altivec_unsigned_saturate_32(temp, &tempsat);
1020 ALTIVEC_SET_SAT(sat);
1021 PPC_INSN_VR_VSCR(VS_BITMASK, VB_BITMASK);
1024 # Vector Estimate instructions, 6-67 ... 6-70.
1027 0.4,6.VS,11.0,16.VB,21.394:VX:av:vexptefp %VD, %VB:Vector 2 Raised to the Exponent Estimate Floating Point
1032 for (i = 0; i < 4; i++) {
1034 sim_fpu_32to (&b, (*vB).w[i]);
1035 sim_fpu_to32i (&bi, &b, sim_fpu_round_default);
1037 sim_fpu_32to (&d, bi);
1038 sim_fpu_to32 (&f, &d);
1041 PPC_INSN_VR_VSCR(VS_BITMASK, VB_BITMASK);
1043 0.4,6.VS,11.0,16.VB,21.458:VX:av:vlogefp %VD, %VB:Vector Log2 Estimate Floating Point
1047 for (i = 0; i < 4; i++) {
1049 sim_fpu_32to (&b, (*vB).w[i]);
1050 sim_fpu_to32u (&u, &b, sim_fpu_round_default);
1051 for (c = 0; (u /= 2) > 1; c++)
1053 sim_fpu_32to (&cfpu, c);
1054 sim_fpu_add (&d, &b, &cfpu);
1055 sim_fpu_to32 (&f, &d);
1058 PPC_INSN_VR_VSCR(VS_BITMASK, VB_BITMASK);
1061 # Vector Multiply Add instruction, 6-71
1064 0.4,6.VS,11.VA,16.VB,21.VC,26.46:VAX:av:vmaddfp %VD, %VA, %VB, %VC:Vector Multiply Add Floating Point
1067 sim_fpu a, b, c, d, e;
1068 for (i = 0; i < 4; i++) {
1069 sim_fpu_32to (&a, (*vA).w[i]);
1070 sim_fpu_32to (&b, (*vB).w[i]);
1071 sim_fpu_32to (&c, (*vC).w[i]);
1072 sim_fpu_mul (&e, &a, &c);
1073 sim_fpu_add (&d, &e, &b);
1074 sim_fpu_to32 (&f, &d);
1077 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1081 # Vector Maximum instructions, 6-72 ... 6-78.
1084 0.4,6.VS,11.VA,16.VB,21.1034:VX:av:vmaxfp %VD, %VA, %VB:Vector Maximum Floating Point
1088 for (i = 0; i < 4; i++) {
1089 sim_fpu_32to (&a, (*vA).w[i]);
1090 sim_fpu_32to (&b, (*vB).w[i]);
1091 sim_fpu_max (&d, &a, &b);
1092 sim_fpu_to32 (&f, &d);
1095 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1097 0.4,6.VS,11.VA,16.VB,21.258:VX:av:vmaxsb %VD, %VA, %VB:Vector Maximum Signed Byte
1100 for (i = 0; i < 16; i++) {
1108 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1110 0.4,6.VS,11.VA,16.VB,21.322:VX:av:vmaxsh %VD, %VA, %VB:Vector Maximum Signed Half Word
1113 for (i = 0; i < 8; i++) {
1121 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1123 0.4,6.VS,11.VA,16.VB,21.386:VX:av:vmaxsw %VD, %VA, %VB:Vector Maximum Signed Word
1126 for (i = 0; i < 4; i++) {
1134 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1136 0.4,6.VS,11.VA,16.VB,21.2:VX:av:vmaxub %VD, %VA, %VB:Vector Maximum Unsigned Byte
1139 for (i = 0; i < 16; i++) {
1147 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1149 0.4,6.VS,11.VA,16.VB,21.66:VX:av:vmaxus %VD, %VA, %VB:Vector Maximum Unsigned Half Word
1152 for (i = 0; i < 8; i++) {
1160 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1162 0.4,6.VS,11.VA,16.VB,21.130:VX:av:vmaxuw %VD, %VA, %VB:Vector Maximum Unsigned Word
1165 for (i = 0; i < 4; i++) {
1173 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1177 # Vector Multiple High instructions, 6-79, 6-80.
1180 0.4,6.VS,11.VA,16.VB,21.VC,26.32:VAX:av:vmhaddshs %VD, %VA, %VB, %VC:Vector Multiple High and Add Signed Half Word Saturate
1181 int i, sat, tempsat;
1183 signed32 prod, temp, c;
1184 for (i = 0; i < 8; i++) {
1187 c = (signed32)(signed16)(*vC).h[i];
1188 prod = (signed32)a * (signed32)b;
1189 temp = (prod >> 15) + c;
1190 (*vS).h[i] = altivec_signed_saturate_16(temp, &tempsat);
1193 ALTIVEC_SET_SAT(sat);
1194 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1196 0.4,6.VS,11.VA,16.VB,21.VC,26.33:VAX:av:vmhraddshs %VD, %VA, %VB, %VC:Vector Multiple High Round and Add Signed Half Word Saturate
1197 int i, sat, tempsat;
1199 signed32 prod, temp, c;
1200 for (i = 0; i < 8; i++) {
1203 c = (signed32)(signed16)(*vC).h[i];
1204 prod = (signed32)a * (signed32)b;
1206 temp = (prod >> 15) + c;
1207 (*vS).h[i] = altivec_signed_saturate_16(temp, &tempsat);
1210 ALTIVEC_SET_SAT(sat);
1211 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1215 # Vector Minimum instructions, 6-81 ... 6-87
1218 0.4,6.VS,11.VA,16.VB,21.1098:VX:av:vminfp %VD, %VA, %VB:Vector Minimum Floating Point
1222 for (i = 0; i < 4; i++) {
1223 sim_fpu_32to (&a, (*vA).w[i]);
1224 sim_fpu_32to (&b, (*vB).w[i]);
1225 sim_fpu_min (&d, &a, &b);
1226 sim_fpu_to32 (&f, &d);
1229 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1231 0.4,6.VS,11.VA,16.VB,21.770:VX:av:vminsb %VD, %VA, %VB:Vector Minimum Signed Byte
1234 for (i = 0; i < 16; i++) {
1242 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1244 0.4,6.VS,11.VA,16.VB,21.834:VX:av:vminsh %VD, %VA, %VB:Vector Minimum Signed Half Word
1247 for (i = 0; i < 8; i++) {
1255 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1257 0.4,6.VS,11.VA,16.VB,21.898:VX:av:vminsw %VD, %VA, %VB:Vector Minimum Signed Word
1260 for (i = 0; i < 4; i++) {
1268 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1270 0.4,6.VS,11.VA,16.VB,21.514:VX:av:vminub %VD, %VA, %VB:Vector Minimum Unsigned Byte
1273 for (i = 0; i < 16; i++) {
1281 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1283 0.4,6.VS,11.VA,16.VB,21.578:VX:av:vminuh %VD, %VA, %VB:Vector Minimum Unsigned Half Word
1286 for (i = 0; i < 8; i++) {
1294 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1296 0.4,6.VS,11.VA,16.VB,21.642:VX:av:vminuw %VD, %VA, %VB:Vector Minimum Unsigned Word
1299 for (i = 0; i < 4; i++) {
1307 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1311 # Vector Multiply Low instruction, 6-88
1314 0.4,6.VS,11.VA,16.VB,21.VC,26.34:VAX:av:vmladduhm %VD, %VA, %VB, %VC:Vector Multiply Low and Add Unsigned Half Word Modulo
1318 for (i = 0; i < 8; i++) {
1322 prod = (unsigned32)a * (unsigned32)b;
1323 (*vS).h[i] = (prod + c) & 0xffff;
1325 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1329 # Vector Merge instructions, 6-89 ... 6-94
1332 0.4,6.VS,11.VA,16.VB,21.12:VX:av:vmrghb %VD, %VA, %VB:Vector Merge High Byte
1334 for (i = 0; i < 16; i += 2) {
1335 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX(i/2)];
1336 (*vS).b[AV_BINDEX(i+1)] = (*vB).b[AV_BINDEX(i/2)];
1338 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1340 0.4,6.VS,11.VA,16.VB,21.76:VX:av:vmrghh %VD, %VA, %VB:Vector Merge High Half Word
1342 for (i = 0; i < 8; i += 2) {
1343 (*vS).h[AV_HINDEX(i)] = (*vA).h[AV_HINDEX(i/2)];
1344 (*vS).h[AV_HINDEX(i+1)] = (*vB).h[AV_HINDEX(i/2)];
1346 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1348 0.4,6.VS,11.VA,16.VB,21.140:VX:av:vmrghw %VD, %VA, %VB:Vector Merge High Word
1350 for (i = 0; i < 4; i += 2) {
1351 (*vS).w[i] = (*vA).w[i/2];
1352 (*vS).w[i+1] = (*vB).w[i/2];
1354 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1356 0.4,6.VS,11.VA,16.VB,21.268:VX:av:vmrglb %VD, %VA, %VB:Vector Merge Low Byte
1358 for (i = 0; i < 16; i += 2) {
1359 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX((i/2) + 8)];
1360 (*vS).b[AV_BINDEX(i+1)] = (*vB).b[AV_BINDEX((i/2) + 8)];
1362 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1364 0.4,6.VS,11.VA,16.VB,21.332:VX:av:vmrglh %VD, %VA, %VB:Vector Merge Low Half Word
1366 for (i = 0; i < 8; i += 2) {
1367 (*vS).h[AV_HINDEX(i)] = (*vA).h[AV_HINDEX((i/2) + 4)];
1368 (*vS).h[AV_HINDEX(i+1)] = (*vB).h[AV_HINDEX((i/2) + 4)];
1370 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1372 0.4,6.VS,11.VA,16.VB,21.396:VX:av:vmrglw %VD, %VA, %VB:Vector Merge Low Word
1374 for (i = 0; i < 4; i += 2) {
1375 (*vS).w[i] = (*vA).w[(i/2) + 2];
1376 (*vS).w[i+1] = (*vB).w[(i/2) + 2];
1378 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1382 # Vector Multiply Sum instructions, 6-95 ... 6-100
1385 0.4,6.VS,11.VA,16.VB,21.VC,26.37:VAX:av:vmsummbm %VD, %VA, %VB, %VC:Vector Multiply Sum Mixed-Sign Byte Modulo
1390 for (i = 0; i < 4; i++) {
1392 for (j = 0; j < 4; j++) {
1393 a = (signed16)(signed8)(*vA).b[i*4+j];
1396 temp += (signed32)prod;
1400 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1402 0.4,6.VS,11.VA,16.VB,21.VC,26.40:VAX:av:vmsumshm %VD, %VA, %VB, %VC:Vector Multiply Sum Signed Half Word Modulo
1404 signed32 temp, prod, a, b;
1405 for (i = 0; i < 4; i++) {
1407 for (j = 0; j < 2; j++) {
1408 a = (signed32)(signed16)(*vA).h[i*2+j];
1409 b = (signed32)(signed16)(*vB).h[i*2+j];
1415 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1417 0.4,6.VS,11.VA,16.VB,21.VC,26.41:VAX:av:vmsumshs %VD, %VA, %VB, %VC:Vector Multiply Sum Signed Half Word Saturate
1418 int i, j, sat, tempsat;
1420 signed32 prod, a, b;
1422 for (i = 0; i < 4; i++) {
1423 temp = (signed64)(signed32)(*vC).w[i];
1424 for (j = 0; j < 2; j++) {
1425 a = (signed32)(signed16)(*vA).h[i*2+j];
1426 b = (signed32)(signed16)(*vB).h[i*2+j];
1428 temp += (signed64)prod;
1430 (*vS).w[i] = altivec_signed_saturate_32(temp, &tempsat);
1433 ALTIVEC_SET_SAT(sat);
1434 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1436 0.4,6.VS,11.VA,16.VB,21.VC,26.36:VAX:av:vmsumubm %VD, %VA, %VB, %VC:Vector Multiply Sum Unsigned Byte Modulo
1439 unsigned16 prod, a, b;
1440 for (i = 0; i < 4; i++) {
1442 for (j = 0; j < 4; j++) {
1450 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1452 0.4,6.VS,11.VA,16.VB,21.VC,26.38:VAX:av:vmsumuhm %VD, %VA, %VB, %VC:Vector Multiply Sum Unsigned Half Word Modulo
1454 unsigned32 temp, prod, a, b;
1455 for (i = 0; i < 4; i++) {
1457 for (j = 0; j < 2; j++) {
1465 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1467 0.4,6.VS,11.VA,16.VB,21.VC,26.39:VAX:av:vmsumuhs %VD, %VA, %VB, %VC:Vector Multiply Sum Unsigned Half Word Saturate
1468 int i, j, sat, tempsat;
1469 unsigned32 temp, prod, a, b;
1471 for (i = 0; i < 4; i++) {
1473 for (j = 0; j < 2; j++) {
1479 (*vS).w[i] = altivec_unsigned_saturate_32(temp, &tempsat);
1482 ALTIVEC_SET_SAT(sat);
1483 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1487 # Vector Multiply Even/Odd instructions, 6-101 ... 6-108
1490 0.4,6.VS,11.VA,16.VB,21.776:VX:av:vmulesb %VD, %VA, %VB:Vector Multiply Even Signed Byte
1494 for (i = 0; i < 8; i++) {
1495 a = (*vA).b[AV_BINDEX(i*2)];
1496 b = (*vB).b[AV_BINDEX(i*2)];
1498 (*vS).h[AV_HINDEX(i)] = prod;
1500 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1502 0.4,6.VS,11.VA,16.VB,21.840:VX:av:vmulesh %VD, %VA, %VB:Vector Multiply Even Signed Half Word
1506 for (i = 0; i < 4; i++) {
1507 a = (*vA).h[AV_HINDEX(i*2)];
1508 b = (*vB).h[AV_HINDEX(i*2)];
1512 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1514 0.4,6.VS,11.VA,16.VB,21.520:VX:av:vmuleub %VD, %VA, %VB:Vector Multiply Even Unsigned Byte
1518 for (i = 0; i < 8; i++) {
1519 a = (*vA).b[AV_BINDEX(i*2)];
1520 b = (*vB).b[AV_BINDEX(i*2)];
1522 (*vS).h[AV_HINDEX(i)] = prod;
1524 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1526 0.4,6.VS,11.VA,16.VB,21.584:VX:av:vmuleuh %VD, %VA, %VB:Vector Multiply Even Unsigned Half Word
1530 for (i = 0; i < 4; i++) {
1531 a = (*vA).h[AV_HINDEX(i*2)];
1532 b = (*vB).h[AV_HINDEX(i*2)];
1536 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1538 0.4,6.VS,11.VA,16.VB,21.264:VX:av:vmulosb %VD, %VA, %VB:Vector Multiply Odd Signed Byte
1542 for (i = 0; i < 8; i++) {
1543 a = (*vA).b[AV_BINDEX((i*2)+1)];
1544 b = (*vB).b[AV_BINDEX((i*2)+1)];
1546 (*vS).h[AV_HINDEX(i)] = prod;
1548 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1550 0.4,6.VS,11.VA,16.VB,21.328:VX:av:vmulosh %VD, %VA, %VB:Vector Multiply Odd Signed Half Word
1554 for (i = 0; i < 4; i++) {
1555 a = (*vA).h[AV_HINDEX((i*2)+1)];
1556 b = (*vB).h[AV_HINDEX((i*2)+1)];
1560 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1562 0.4,6.VS,11.VA,16.VB,21.8:VX:av:vmuloub %VD, %VA, %VB:Vector Multiply Odd Unsigned Byte
1566 for (i = 0; i < 8; i++) {
1567 a = (*vA).b[AV_BINDEX((i*2)+1)];
1568 b = (*vB).b[AV_BINDEX((i*2)+1)];
1570 (*vS).h[AV_HINDEX(i)] = prod;
1572 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1574 0.4,6.VS,11.VA,16.VB,21.72:VX:av:vmulouh %VD, %VA, %VB:Vector Multiply Odd Unsigned Half Word
1578 for (i = 0; i < 4; i++) {
1579 a = (*vA).h[AV_HINDEX((i*2)+1)];
1580 b = (*vB).h[AV_HINDEX((i*2)+1)];
1584 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1588 # Vector Negative Multiply-Subtract instruction, 6-109
1591 0.4,6.VS,11.VA,16.VB,21.VC,26.47:VX:av:vnmsubfp %VD, %VA, %VB, %VC:Vector Negative Multiply-Subtract Floating Point
1594 sim_fpu a, b, c, d, i1, i2;
1595 for (i = 0; i < 4; i++) {
1596 sim_fpu_32to (&a, (*vA).w[i]);
1597 sim_fpu_32to (&b, (*vB).w[i]);
1598 sim_fpu_32to (&c, (*vC).w[i]);
1599 sim_fpu_mul (&i1, &a, &c);
1600 sim_fpu_sub (&i2, &i1, &b);
1601 sim_fpu_neg (&d, &i2);
1602 sim_fpu_to32 (&f, &d);
1605 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1609 # Vector Logical OR instructions, 6-110, 6-111, 6-177
1612 0.4,6.VS,11.VA,16.VB,21.1284:VX:av:vnor %VD, %VA, %VB:Vector Logical NOR
1614 for (i = 0; i < 4; i++)
1615 (*vS).w[i] = ~((*vA).w[i] | (*vB).w[i]);
1616 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1618 0.4,6.VS,11.VA,16.VB,21.1156:VX:av:vor %VD, %VA, %VB:Vector Logical OR
1620 for (i = 0; i < 4; i++)
1621 (*vS).w[i] = (*vA).w[i] | (*vB).w[i];
1622 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1624 0.4,6.VS,11.VA,16.VB,21.1220:VX:av:vxor %VD, %VA, %VB:Vector Logical XOR
1626 for (i = 0; i < 4; i++)
1627 (*vS).w[i] = (*vA).w[i] ^ (*vB).w[i];
1628 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1632 # Vector Permute instruction, 6-112
1635 0.4,6.VS,11.VA,16.VB,21.VC,26.43:VX:av:vperm %VD, %VA, %VB, %VC:Vector Permute
1637 /* The permutation vector might have us read into the source vectors
1638 back at positions before the iteration index, so we must latch the
1639 sources to prevent early-clobbering in case the destination vector
1640 is the same as one of them. */
1641 vreg myvA = (*vA), myvB = (*vB);
1642 for (i = 0; i < 16; i++) {
1643 who = (*vC).b[AV_BINDEX(i)] & 0x1f;
1645 (*vS).b[AV_BINDEX(i)] = myvB.b[AV_BINDEX(who & 0xf)];
1647 (*vS).b[AV_BINDEX(i)] = myvA.b[AV_BINDEX(who & 0xf)];
1649 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1653 # Vector Pack instructions, 6-113 ... 6-121
1656 0.4,6.VS,11.VA,16.VB,21.782:VX:av:vpkpx %VD, %VA, %VB:Vector Pack Pixel32
1658 for (i = 0; i < 4; i++) {
1659 (*vS).h[AV_HINDEX(i+4)] = ((((*vB).w[i]) >> 9) & 0xfc00)
1660 | ((((*vB).w[i]) >> 6) & 0x03e0)
1661 | ((((*vB).w[i]) >> 3) & 0x001f);
1662 (*vS).h[AV_HINDEX(i)] = ((((*vA).w[i]) >> 9) & 0xfc00)
1663 | ((((*vA).w[i]) >> 6) & 0x03e0)
1664 | ((((*vA).w[i]) >> 3) & 0x001f);
1666 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1668 0.4,6.VS,11.VA,16.VB,21.398:VX:av:vpkshss %VD, %VA, %VB:Vector Pack Signed Half Word Signed Saturate
1669 int i, sat, tempsat;
1672 for (i = 0; i < 16; i++) {
1674 temp = (*vA).h[AV_HINDEX(i)];
1676 temp = (*vB).h[AV_HINDEX(i-8)];
1677 (*vS).b[AV_BINDEX(i)] = altivec_signed_saturate_8(temp, &tempsat);
1680 ALTIVEC_SET_SAT(sat);
1681 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1683 0.4,6.VS,11.VA,16.VB,21.270:VX:av:vpkshus %VD, %VA, %VB:Vector Pack Signed Half Word Unsigned Saturate
1684 int i, sat, tempsat;
1687 for (i = 0; i < 16; i++) {
1689 temp = (*vA).h[AV_HINDEX(i)];
1691 temp = (*vB).h[AV_HINDEX(i-8)];
1692 (*vS).b[AV_BINDEX(i)] = altivec_unsigned_saturate_8(temp, &tempsat);
1695 ALTIVEC_SET_SAT(sat);
1696 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1698 0.4,6.VS,11.VA,16.VB,21.462:VX:av:vpkswss %VD, %VA, %VB:Vector Pack Signed Word Signed Saturate
1699 int i, sat, tempsat;
1702 for (i = 0; i < 8; i++) {
1706 temp = (*vB).w[i-4];
1707 (*vS).h[AV_HINDEX(i)] = altivec_signed_saturate_16(temp, &tempsat);
1710 ALTIVEC_SET_SAT(sat);
1711 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1713 0.4,6.VS,11.VA,16.VB,21.334:VX:av:vpkswus %VD, %VA, %VB:Vector Pack Signed Word Unsigned Saturate
1714 int i, sat, tempsat;
1717 for (i = 0; i < 8; i++) {
1721 temp = (*vB).w[i-4];
1722 (*vS).h[AV_HINDEX(i)] = altivec_unsigned_saturate_16(temp, &tempsat);
1725 ALTIVEC_SET_SAT(sat);
1726 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1728 0.4,6.VS,11.VA,16.VB,21.14:VX:av:vpkuhum %VD, %VA, %VB:Vector Pack Unsigned Half Word Unsigned Modulo
1730 for (i = 0; i < 16; i++)
1732 (*vS).b[AV_BINDEX(i)] = (*vA).h[AV_HINDEX(i)];
1734 (*vS).b[AV_BINDEX(i)] = (*vB).h[AV_HINDEX(i-8)];
1735 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1737 0.4,6.VS,11.VA,16.VB,21.142:VX:av:vpkuhus %VD, %VA, %VB:Vector Pack Unsigned Half Word Unsigned Saturate
1738 int i, sat, tempsat;
1741 for (i = 0; i < 16; i++) {
1743 temp = (*vA).h[AV_HINDEX(i)];
1745 temp = (*vB).h[AV_HINDEX(i-8)];
1746 /* force positive in signed16, ok as we'll toss the bit away anyway */
1748 (*vS).b[AV_BINDEX(i)] = altivec_unsigned_saturate_8(temp, &tempsat);
1751 ALTIVEC_SET_SAT(sat);
1752 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1754 0.4,6.VS,11.VA,16.VB,21.78:VX:av:vpkuwum %VD, %VA, %VB:Vector Pack Unsigned Word Unsigned Modulo
1756 for (i = 0; i < 8; i++)
1758 (*vS).h[AV_HINDEX(i)] = (*vA).w[i];
1760 (*vS).h[AV_HINDEX(i)] = (*vB).w[i-8];
1761 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1763 0.4,6.VS,11.VA,16.VB,21.206:VX:av:vpkuwus %VD, %VA, %VB:Vector Pack Unsigned Word Unsigned Saturate
1764 int i, sat, tempsat;
1767 for (i = 0; i < 8; i++) {
1771 temp = (*vB).w[i-4];
1772 /* force positive in signed32, ok as we'll toss the bit away anyway */
1773 temp &= ~0x80000000;
1774 (*vS).h[AV_HINDEX(i)] = altivec_unsigned_saturate_16(temp, &tempsat);
1777 ALTIVEC_SET_SAT(sat);
1778 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1782 # Vector Reciprocal instructions, 6-122, 6-123, 6-131
1785 0.4,6.VS,11.0,16.VB,21.266:VX:av:vrefp %VD, %VB:Vector Reciprocal Estimate Floating Point
1789 for (i = 0; i < 4; i++) {
1790 sim_fpu_32to (&op, (*vB).w[i]);
1791 sim_fpu_div (&d, &sim_fpu_one, &op);
1792 sim_fpu_to32 (&f, &d);
1795 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1797 0.4,6.VS,11.0,16.VB,21.330:VX:av:vrsqrtefp %VD, %VB:Vector Reciprocal Square Root Estimate Floating Point
1800 sim_fpu op, i1, one, d;
1801 for (i = 0; i < 4; i++) {
1802 sim_fpu_32to (&op, (*vB).w[i]);
1803 sim_fpu_sqrt (&i1, &op);
1804 sim_fpu_div (&d, &sim_fpu_one, &i1);
1805 sim_fpu_to32 (&f, &d);
1808 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1812 # Vector Round instructions, 6-124 ... 6-127
1815 0.4,6.VS,11.0,16.VB,21.714:VX:av:vrfim %VD, %VB:Vector Round to Floating-Point Integer towards Minus Infinity
1819 for (i = 0; i < 4; i++) {
1820 sim_fpu_32to (&op, (*vB).w[i]);
1821 sim_fpu_round_32(&op, sim_fpu_round_down, sim_fpu_denorm_default);
1822 sim_fpu_to32 (&f, &op);
1825 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1827 0.4,6.VS,11.0,16.VB,21.522:VX:av:vrfin %VD, %VB:Vector Round to Floating-Point Integer Nearest
1831 for (i = 0; i < 4; i++) {
1832 sim_fpu_32to (&op, (*vB).w[i]);
1833 sim_fpu_round_32(&op, sim_fpu_round_near, sim_fpu_denorm_default);
1834 sim_fpu_to32 (&f, &op);
1837 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1839 0.4,6.VS,11.0,16.VB,21.650:VX:av:vrfip %VD, %VB:Vector Round to Floating-Point Integer towards Plus Infinity
1843 for (i = 0; i < 4; i++) {
1844 sim_fpu_32to (&op, (*vB).w[i]);
1845 sim_fpu_round_32(&op, sim_fpu_round_up, sim_fpu_denorm_default);
1846 sim_fpu_to32 (&f, &op);
1849 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1851 0.4,6.VS,11.0,16.VB,21.586:VX:av:vrfiz %VD, %VB:Vector Round to Floating-Point Integer towards Zero
1855 for (i = 0; i < 4; i++) {
1856 sim_fpu_32to (&op, (*vB).w[i]);
1857 sim_fpu_round_32(&op, sim_fpu_round_zero, sim_fpu_denorm_default);
1858 sim_fpu_to32 (&f, &op);
1861 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1865 # Vector Rotate Left instructions, 6-128 ... 6-130
1868 0.4,6.VS,11.VA,16.VB,21.4:VX:av:vrlb %VD, %VA, %VB:Vector Rotate Left Integer Byte
1871 for (i = 0; i < 16; i++) {
1872 temp = (unsigned16)(*vA).b[i] << (((*vB).b[i]) & 7);
1873 (*vS).b[i] = (temp & 0xff) | ((temp >> 8) & 0xff);
1875 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1877 0.4,6.VS,11.VA,16.VB,21.68:VX:av:vrlh %VD, %VA, %VB:Vector Rotate Left Integer Half Word
1880 for (i = 0; i < 8; i++) {
1881 temp = (unsigned32)(*vA).h[i] << (((*vB).h[i]) & 0xf);
1882 (*vS).h[i] = (temp & 0xffff) | ((temp >> 16) & 0xffff);
1884 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1886 0.4,6.VS,11.VA,16.VB,21.132:VX:av:vrlw %VD, %VA, %VB:Vector Rotate Left Integer Word
1889 for (i = 0; i < 4; i++) {
1890 temp = (unsigned64)(*vA).w[i] << (((*vB).w[i]) & 0x1f);
1891 (*vS).w[i] = (temp & 0xffffffff) | ((temp >> 32) & 0xffffffff);
1893 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1897 # Vector Conditional Select instruction, 6-133
1900 0.4,6.VS,11.VA,16.VB,21.VC,26.42:VAX:av:vsel %VD, %VA, %VB, %VC:Vector Conditional Select
1903 for (i = 0; i < 4; i++) {
1905 (*vS).w[i] = ((*vB).w[i] & c) | ((*vA).w[i] & ~c);
1907 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1910 # Vector Shift Left instructions, 6-134 ... 6-139
1913 0.4,6.VS,11.VA,16.VB,21.452:VX:av:vsl %VD, %VA, %VB:Vector Shift Left
1914 int sh, i, j, carry, new_carry;
1915 sh = (*vB).b[0] & 7; /* don't bother checking everything */
1917 for (j = 3; j >= 0; j--) {
1918 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
1922 new_carry = (*vA).w[i] >> (32 - sh);
1923 (*vS).w[i] = ((*vA).w[i] << sh) | carry;
1926 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1928 0.4,6.VS,11.VA,16.VB,21.260:VX:av:vslb %VD, %VA, %VB:Vector Shift Left Integer Byte
1930 for (i = 0; i < 16; i++) {
1931 sh = ((*vB).b[i]) & 7;
1932 (*vS).b[i] = (*vA).b[i] << sh;
1934 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1936 0.4,6.VS,11.VA,16.VB,21.0,22.SH,26.44:VX:av:vsldol %VD, %VA, %VB:Vector Shift Left Double by Octet Immediate
1938 for (j = 0, i = SH; i < 16; i++)
1939 (*vS).b[j++] = (*vA).b[i];
1940 for (i = 0; i < SH; i++)
1941 (*vS).b[j++] = (*vB).b[i];
1942 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1944 0.4,6.VS,11.VA,16.VB,21.324:VX:av:vslh %VD, %VA, %VB:Vector Shift Left Half Word
1946 for (i = 0; i < 8; i++) {
1947 sh = ((*vB).h[i]) & 0xf;
1948 (*vS).h[i] = (*vA).h[i] << sh;
1950 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1952 0.4,6.VS,11.VA,16.VB,21.1036:VX:av:vslo %VD, %VA, %VB:Vector Shift Left by Octet
1954 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
1955 sh = ((*vB).b[AV_BINDEX(15)] >> 3) & 0xf;
1957 sh = ((*vB).b[AV_BINDEX(0)] >> 3) & 0xf;
1958 for (i = 0; i < 16; i++) {
1960 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX(i + sh)];
1962 (*vS).b[AV_BINDEX(i)] = 0;
1964 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1966 0.4,6.VS,11.VA,16.VB,21.388:VX:av:vslw %VD, %VA, %VB:Vector Shift Left Integer Word
1968 for (i = 0; i < 4; i++) {
1969 sh = ((*vB).w[i]) & 0x1f;
1970 (*vS).w[i] = (*vA).w[i] << sh;
1972 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1976 # Vector Splat instructions, 6-140 ... 6-145
1979 0.4,6.VS,11.UIMM,16.VB,21.524:VX:av:vspltb %VD, %VB, %UIMM:Vector Splat Byte
1982 b = (*vB).b[AV_BINDEX(UIMM & 0xf)];
1983 for (i = 0; i < 16; i++)
1985 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1987 0.4,6.VS,11.UIMM,16.VB,21.588:VX:av:vsplth %VD, %VB, %UIMM:Vector Splat Half Word
1990 h = (*vB).h[AV_HINDEX(UIMM & 0x7)];
1991 for (i = 0; i < 8; i++)
1993 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1995 0.4,6.VS,11.SIMM,16.0,21.780:VX:av:vspltisb %VD, %SIMM:Vector Splat Immediate Signed Byte
1998 /* manual 5-bit signed extension */
2001 for (i = 0; i < 16; i++)
2003 PPC_INSN_VR(VS_BITMASK, 0);
2005 0.4,6.VS,11.SIMM,16.0,21.844:VX:av:vspltish %VD, %SIMM:Vector Splat Immediate Signed Half Word
2008 /* manual 5-bit signed extension */
2011 for (i = 0; i < 8; i++)
2013 PPC_INSN_VR(VS_BITMASK, 0);
2015 0.4,6.VS,11.SIMM,16.0,21.908:VX:av:vspltisw %VD, %SIMM:Vector Splat Immediate Signed Word
2018 /* manual 5-bit signed extension */
2021 for (i = 0; i < 4; i++)
2023 PPC_INSN_VR(VS_BITMASK, 0);
2025 0.4,6.VS,11.UIMM,16.VB,21.652:VX:av:vspltw %VD, %VB, %UIMM:Vector Splat Word
2028 w = (*vB).w[UIMM & 0x3];
2029 for (i = 0; i < 4; i++)
2031 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2035 # Vector Shift Right instructions, 6-146 ... 6-154
2038 0.4,6.VS,11.VA,16.VB,21.708:VX:av:vsr %VD, %VA, %VB:Vector Shift Right
2039 int sh, i, j, carry, new_carry;
2040 sh = (*vB).b[0] & 7; /* don't bother checking everything */
2042 for (j = 0; j < 4; j++) {
2043 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
2047 new_carry = (*vA).w[i] << (32 - sh);
2048 (*vS).w[i] = ((*vA).w[i] >> sh) | carry;
2051 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2053 0.4,6.VS,11.VA,16.VB,21.772:VX:av:vsrab %VD, %VA, %VB:Vector Shift Right Algebraic Byte
2056 for (i = 0; i < 16; i++) {
2057 sh = ((*vB).b[i]) & 7;
2058 a = (signed16)(signed8)(*vA).b[i];
2059 (*vS).b[i] = (a >> sh) & 0xff;
2061 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2063 0.4,6.VS,11.VA,16.VB,21.836:VX:av:vsrah %VD, %VA, %VB:Vector Shift Right Algebraic Half Word
2066 for (i = 0; i < 8; i++) {
2067 sh = ((*vB).h[i]) & 0xf;
2068 a = (signed32)(signed16)(*vA).h[i];
2069 (*vS).h[i] = (a >> sh) & 0xffff;
2071 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2073 0.4,6.VS,11.VA,16.VB,21.900:VX:av:vsraw %VD, %VA, %VB:Vector Shift Right Algebraic Word
2076 for (i = 0; i < 4; i++) {
2077 sh = ((*vB).w[i]) & 0xf;
2078 a = (signed64)(signed32)(*vA).w[i];
2079 (*vS).w[i] = (a >> sh) & 0xffffffff;
2081 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2083 0.4,6.VS,11.VA,16.VB,21.516:VX:av:vsrb %VD, %VA, %VB:Vector Shift Right Byte
2085 for (i = 0; i < 16; i++) {
2086 sh = ((*vB).b[i]) & 7;
2087 (*vS).b[i] = (*vA).b[i] >> sh;
2089 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2091 0.4,6.VS,11.VA,16.VB,21.580:VX:av:vsrh %VD, %VA, %VB:Vector Shift Right Half Word
2093 for (i = 0; i < 8; i++) {
2094 sh = ((*vB).h[i]) & 0xf;
2095 (*vS).h[i] = (*vA).h[i] >> sh;
2097 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2099 0.4,6.VS,11.VA,16.VB,21.1100:VX:av:vsro %VD, %VA, %VB:Vector Shift Right Octet
2101 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
2102 sh = ((*vB).b[AV_BINDEX(15)] >> 3) & 0xf;
2104 sh = ((*vB).b[AV_BINDEX(0)] >> 3) & 0xf;
2105 for (i = 0; i < 16; i++) {
2107 (*vS).b[AV_BINDEX(i)] = 0;
2109 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX(i - sh)];
2111 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2113 0.4,6.VS,11.VA,16.VB,21.644:VX:av:vsrw %VD, %VA, %VB:Vector Shift Right Word
2115 for (i = 0; i < 4; i++) {
2116 sh = ((*vB).w[i]) & 0x1f;
2117 (*vS).w[i] = (*vA).w[i] >> sh;
2119 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2123 # Vector Subtract instructions, 6-155 ... 6-165
2126 0.4,6.VS,11.VA,16.VB,21.1408:VX:av:vsubcuw %VD, %VA, %VB:Vector Subtract Carryout Unsigned Word
2128 signed64 temp, a, b;
2129 for (i = 0; i < 4; i++) {
2130 a = (signed64)(unsigned32)(*vA).w[i];
2131 b = (signed64)(unsigned32)(*vB).w[i];
2133 (*vS).w[i] = ~(temp >> 32) & 1;
2135 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2137 0.4,6.VS,11.VA,16.VB,21.74:VX:av:vsubfp %VD, %VA, %VB:Vector Subtract Floating Point
2141 for (i = 0; i < 4; i++) {
2142 sim_fpu_32to (&a, (*vA).w[i]);
2143 sim_fpu_32to (&b, (*vB).w[i]);
2144 sim_fpu_sub (&d, &a, &b);
2145 sim_fpu_to32 (&f, &d);
2148 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2150 0.4,6.VS,11.VA,16.VB,21.1792:VX:av:vsubsbs %VD, %VA, %VB:Vector Subtract Signed Byte Saturate
2151 int i, sat, tempsat;
2154 for (i = 0; i < 16; i++) {
2155 temp = (signed16)(signed8)(*vA).b[i] - (signed16)(signed8)(*vB).b[i];
2156 (*vS).b[i] = altivec_signed_saturate_8(temp, &tempsat);
2159 ALTIVEC_SET_SAT(sat);
2160 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2162 0.4,6.VS,11.VA,16.VB,21.1856:VX:av:vsubshs %VD, %VA, %VB:Vector Subtract Signed Half Word Saturate
2163 int i, sat, tempsat;
2166 for (i = 0; i < 8; i++) {
2167 temp = (signed32)(signed16)(*vA).h[i] - (signed32)(signed16)(*vB).h[i];
2168 (*vS).h[i] = altivec_signed_saturate_16(temp, &tempsat);
2171 ALTIVEC_SET_SAT(sat);
2172 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2174 0.4,6.VS,11.VA,16.VB,21.1920:VX:av:vsubsws %VD, %VA, %VB:Vector Subtract Signed Word Saturate
2175 int i, sat, tempsat;
2178 for (i = 0; i < 4; i++) {
2179 temp = (signed64)(signed32)(*vA).w[i] - (signed64)(signed32)(*vB).w[i];
2180 (*vS).w[i] = altivec_signed_saturate_32(temp, &tempsat);
2183 ALTIVEC_SET_SAT(sat);
2184 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2186 0.4,6.VS,11.VA,16.VB,21.1024:VX:av:vsububm %VD, %VA, %VB:Vector Subtract Unsigned Byte Modulo
2188 for (i = 0; i < 16; i++)
2189 (*vS).b[i] = (*vA).b[i] - (*vB).b[i];
2190 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2192 0.4,6.VS,11.VA,16.VB,21.1536:VX:av:vsububs %VD, %VA, %VB:Vector Subtract Unsigned Byte Saturate
2193 int i, sat, tempsat;
2196 for (i = 0; i < 16; i++) {
2197 temp = (signed16)(unsigned8)(*vA).b[i] - (signed16)(unsigned8)(*vB).b[i];
2198 (*vS).b[i] = altivec_unsigned_saturate_8(temp, &tempsat);
2201 ALTIVEC_SET_SAT(sat);
2202 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2204 0.4,6.VS,11.VA,16.VB,21.1088:VX:av:vsubuhm %VD, %VA, %VB:Vector Subtract Unsigned Half Word Modulo
2206 for (i = 0; i < 8; i++)
2207 (*vS).h[i] = ((*vA).h[i] - (*vB).h[i]) & 0xffff;
2208 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2210 0.4,6.VS,11.VA,16.VB,21.1600:VX:av:vsubuhs %VD, %VA, %VB:Vector Subtract Unsigned Half Word Saturate
2211 int i, sat, tempsat;
2213 for (i = 0; i < 8; i++) {
2214 temp = (signed32)(unsigned16)(*vA).h[i] - (signed32)(unsigned16)(*vB).h[i];
2215 (*vS).h[i] = altivec_unsigned_saturate_16(temp, &tempsat);
2218 ALTIVEC_SET_SAT(sat);
2219 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2221 0.4,6.VS,11.VA,16.VB,21.1152:VX:av:vsubuwm %VD, %VA, %VB:Vector Subtract Unsigned Word Modulo
2223 for (i = 0; i < 4; i++)
2224 (*vS).w[i] = (*vA).w[i] - (*vB).w[i];
2225 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2227 0.4,6.VS,11.VA,16.VB,21.1664:VX:av:vsubuws %VD, %VA, %VB:Vector Subtract Unsigned Word Saturate
2228 int i, sat, tempsat;
2230 for (i = 0; i < 4; i++) {
2231 temp = (signed64)(unsigned32)(*vA).w[i] - (signed64)(unsigned32)(*vB).w[i];
2232 (*vS).w[i] = altivec_unsigned_saturate_32(temp, &tempsat);
2235 ALTIVEC_SET_SAT(sat);
2236 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2240 # Vector Sum instructions, 6-166 ... 6-170
2243 0.4,6.VS,11.VA,16.VB,21.1928:VX:av:vsumsws %VD, %VA, %VB:Vector Sum Across Signed Word Saturate
2246 temp = (signed64)(signed32)(*vB).w[3];
2247 for (i = 0; i < 4; i++)
2248 temp += (signed64)(signed32)(*vA).w[i];
2249 (*vS).w[3] = altivec_signed_saturate_32(temp, &sat);
2250 (*vS).w[0] = (*vS).w[1] = (*vS).w[2] = 0;
2251 ALTIVEC_SET_SAT(sat);
2252 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2254 0.4,6.VS,11.VA,16.VB,21.1672:VX:av:vsum2sws %VD, %VA, %VB:Vector Sum Across Partial (1/2) Signed Word Saturate
2255 int i, j, sat, tempsat;
2257 for (j = 0; j < 4; j += 2) {
2258 temp = (signed64)(signed32)(*vB).w[j+1];
2259 temp += (signed64)(signed32)(*vA).w[j] + (signed64)(signed32)(*vA).w[j+1];
2260 (*vS).w[j+1] = altivec_signed_saturate_32(temp, &tempsat);
2263 (*vS).w[0] = (*vS).w[2] = 0;
2264 ALTIVEC_SET_SAT(sat);
2265 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2267 0.4,6.VS,11.VA,16.VB,21.1800:VX:av:vsum4sbs %VD, %VA, %VB:Vector Sum Across Partial (1/4) Signed Byte Saturate
2268 int i, j, sat, tempsat;
2270 for (j = 0; j < 4; j++) {
2271 temp = (signed64)(signed32)(*vB).w[j];
2272 for (i = 0; i < 4; i++)
2273 temp += (signed64)(signed8)(*vA).b[i+(j*4)];
2274 (*vS).w[j] = altivec_signed_saturate_32(temp, &tempsat);
2277 ALTIVEC_SET_SAT(sat);
2278 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2280 0.4,6.VS,11.VA,16.VB,21.1608:VX:av:vsum4shs %VD, %VA, %VB:Vector Sum Across Partial (1/4) Signed Half Word Saturate
2281 int i, j, sat, tempsat;
2283 for (j = 0; j < 4; j++) {
2284 temp = (signed64)(signed32)(*vB).w[j];
2285 for (i = 0; i < 2; i++)
2286 temp += (signed64)(signed16)(*vA).h[i+(j*2)];
2287 (*vS).w[j] = altivec_signed_saturate_32(temp, &tempsat);
2290 ALTIVEC_SET_SAT(sat);
2291 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2293 0.4,6.VS,11.VA,16.VB,21.1544:VX:av:vsum4ubs %VD, %VA, %VB:Vector Sum Across Partial (1/4) Unsigned Byte Saturate
2294 int i, j, sat, tempsat;
2297 for (j = 0; j < 4; j++) {
2298 utemp = (signed64)(unsigned32)(*vB).w[j];
2299 for (i = 0; i < 4; i++)
2300 utemp += (signed64)(unsigned16)(*vA).b[i+(j*4)];
2302 (*vS).w[j] = altivec_unsigned_saturate_32(temp, &tempsat);
2305 ALTIVEC_SET_SAT(sat);
2306 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2310 # Vector Unpack instructions, 6-171 ... 6-176
2313 0.4,6.VS,11.0,16.VB,21.846:VX:av:vupkhpx %VD, %VB:Vector Unpack High Pixel16
2316 for (i = 0; i < 4; i++) {
2317 h = (*vB).h[AV_HINDEX(i)];
2318 (*vS).w[i] = ((h & 0x8000) ? 0xff000000 : 0)
2319 | ((h & 0x7c00) << 6)
2320 | ((h & 0x03e0) << 3)
2323 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2325 0.4,6.VS,11.0,16.VB,21.526:VX:av:vupkhsb %VD, %VB:Vector Unpack High Signed Byte
2327 for (i = 0; i < 8; i++)
2328 (*vS).h[AV_HINDEX(i)] = (signed16)(signed8)(*vB).b[AV_BINDEX(i)];
2329 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2331 0.4,6.VS,11.0,16.VB,21.590:VX:av:vupkhsh %VD, %VB:Vector Unpack High Signed Half Word
2333 for (i = 0; i < 4; i++)
2334 (*vS).w[i] = (signed32)(signed16)(*vB).h[AV_HINDEX(i)];
2335 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2337 0.4,6.VS,11.0,16.VB,21.974:VX:av:vupklpx %VD, %VB:Vector Unpack Low Pixel16
2340 for (i = 0; i < 4; i++) {
2341 h = (*vB).h[AV_HINDEX(i + 4)];
2342 (*vS).w[i] = ((h & 0x8000) ? 0xff000000 : 0)
2343 | ((h & 0x7c00) << 6)
2344 | ((h & 0x03e0) << 3)
2347 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2349 0.4,6.VS,11.0,16.VB,21.654:VX:av:vupklsb %VD, %VB:Vector Unpack Low Signed Byte
2351 for (i = 0; i < 8; i++)
2352 (*vS).h[AV_HINDEX(i)] = (signed16)(signed8)(*vB).b[AV_BINDEX(i + 8)];
2353 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2355 0.4,6.VS,11.0,16.VB,21.718:VX:av:vupklsh %VD, %VB:Vector Unpack Low Signed Half Word
2357 for (i = 0; i < 4; i++)
2358 (*vS).w[i] = (signed32)(signed16)(*vB).h[AV_HINDEX(i + 4)];
2359 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);