1 # Altivec instruction set, for PSIM, the PowerPC simulator.
3 # Copyright 2003 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 2 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, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330,
23 # Boston, MA 02111-1307, USA. */
27 # Motorola AltiVec instructions.
31 :cache:av::vreg *:vS:VS:(cpu_registers(processor)->altivec.vr + VS)
32 :cache:av::unsigned32:VS_BITMASK:VS:(1 << VS)
34 :cache:av::vreg *:vA:VA:(cpu_registers(processor)->altivec.vr + VA)
35 :cache:av::unsigned32:VA_BITMASK:VA:(1 << VA)
37 :cache:av::vreg *:vB:VB:(cpu_registers(processor)->altivec.vr + VB)
38 :cache:av::unsigned32:VB_BITMASK:VB:(1 << VB)
40 :cache:av::vreg *:vC:VC:(cpu_registers(processor)->altivec.vr + VC)
41 :cache:av::unsigned32:VC_BITMASK:VC:(1 << VC)
45 #define PPC_INSN_INT_VR(OUT_MASK, IN_MASK, OUT_VMASK, IN_VMASK) \
47 if (CURRENT_MODEL_ISSUE > 0) \
48 ppc_insn_int_vr(MY_INDEX, cpu_model(processor), OUT_MASK, IN_MASK, OUT_VMASK, IN_VMASK); \
51 #define PPC_INSN_VR(OUT_VMASK, IN_VMASK) \
53 if (CURRENT_MODEL_ISSUE > 0) \
54 ppc_insn_vr(MY_INDEX, cpu_model(processor), OUT_VMASK, IN_VMASK); \
57 #define PPC_INSN_VR_CR(OUT_VMASK, IN_VMASK, CR_MASK) \
59 if (CURRENT_MODEL_ISSUE > 0) \
60 ppc_insn_vr_cr(MY_INDEX, cpu_model(processor), OUT_VMASK, IN_VMASK, CR_MASK); \
63 #define PPC_INSN_VR_VSCR(OUT_VMASK, IN_VMASK) \
65 if (CURRENT_MODEL_ISSUE > 0) \
66 ppc_insn_vr_vscr(MY_INDEX, cpu_model(processor), OUT_VMASK, IN_VMASK); \
69 #define PPC_INSN_FROM_VSCR(VR_MASK) \
71 if (CURRENT_MODEL_ISSUE > 0) \
72 ppc_insn_from_vscr(MY_INDEX, cpu_model(processor), VR_MASK); \
75 #define PPC_INSN_TO_VSCR(VR_MASK) \
77 if (CURRENT_MODEL_ISSUE > 0) \
78 ppc_insn_to_vscr(MY_INDEX, cpu_model(processor), VR_MASK); \
81 # Trace waiting for AltiVec registers to become available
82 void::model-static::model_trace_altivec_busy_p:model_data *model_ptr, unsigned32 vr_busy
85 vr_busy &= model_ptr->vr_busy;
86 for(i = 0; i < 32; i++) {
87 if (((1 << i) & vr_busy) != 0) {
88 TRACE(trace_model, ("Waiting for register v%d.\n", i));
92 if (model_ptr->vscr_busy)
93 TRACE(trace_model, ("Waiting for VSCR\n"));
95 # Trace making AltiVec registers busy
96 void::model-static::model_trace_altivec_make_busy:model_data *model_ptr, unsigned32 vr_mask, unsigned32 cr_mask
99 for(i = 0; i < 32; i++) {
100 if (((1 << i) & vr_mask) != 0) {
101 TRACE(trace_model, ("Register v%d is now busy.\n", i));
106 for(i = 0; i < 8; i++) {
107 if (((1 << i) & cr_mask) != 0) {
108 TRACE(trace_model, ("Register cr%d is now busy.\n", i));
113 # Schedule an AltiVec instruction that takes integer input registers and produces output registers
114 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
115 const unsigned32 int_mask = out_mask | in_mask;
116 const unsigned32 vr_mask = out_vmask | in_vmask;
117 model_busy *busy_ptr;
119 if ((model_ptr->int_busy & int_mask) != 0 || (model_ptr->vr_busy & vr_mask)) {
120 model_new_cycle(model_ptr); /* don't count first dependency as a stall */
122 while ((model_ptr->int_busy & int_mask) != 0 || (model_ptr->vr_busy & vr_mask)) {
123 if (WITH_TRACE && ppc_trace[trace_model]) {
124 model_trace_busy_p(model_ptr, int_mask, 0, 0, PPC_NO_SPR);
125 model_trace_altivec_busy_p(model_ptr, vr_mask);
128 model_ptr->nr_stalls_data++;
129 model_new_cycle(model_ptr);
133 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
134 model_ptr->int_busy |= out_mask;
135 busy_ptr->int_busy |= out_mask;
136 model_ptr->vr_busy |= out_vmask;
137 busy_ptr->vr_busy |= out_vmask;
140 busy_ptr->nr_writebacks = (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
143 busy_ptr->nr_writebacks += (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
145 if (WITH_TRACE && ppc_trace[trace_model]) {
146 model_trace_make_busy(model_ptr, out_mask, 0, 0);
147 model_trace_altivec_make_busy(model_ptr, vr_mask, 0);
150 # Schedule an AltiVec instruction that takes vector input registers and produces vector output registers
151 void::model-function::ppc_insn_vr:itable_index index, model_data *model_ptr, const unsigned32 out_vmask, const unsigned32 in_vmask
152 const unsigned32 vr_mask = out_vmask | in_vmask;
153 model_busy *busy_ptr;
155 if (model_ptr->vr_busy & vr_mask) {
156 model_new_cycle(model_ptr); /* don't count first dependency as a stall */
158 while (model_ptr->vr_busy & vr_mask) {
159 if (WITH_TRACE && ppc_trace[trace_model]) {
160 model_trace_altivec_busy_p(model_ptr, vr_mask);
163 model_ptr->nr_stalls_data++;
164 model_new_cycle(model_ptr);
168 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
169 model_ptr->vr_busy |= out_vmask;
170 busy_ptr->vr_busy |= out_vmask;
172 busy_ptr->nr_writebacks = (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
174 if (WITH_TRACE && ppc_trace[trace_model]) {
175 model_trace_altivec_make_busy(model_ptr, vr_mask, 0);
178 # Schedule an AltiVec instruction that takes vector input registers and produces vector output registers, touches CR
179 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
180 const unsigned32 vr_mask = out_vmask | in_vmask;
181 model_busy *busy_ptr;
183 if ((model_ptr->vr_busy & vr_mask) || (model_ptr->cr_fpscr_busy & cr_mask)) {
184 model_new_cycle(model_ptr); /* don't count first dependency as a stall */
186 while ((model_ptr->vr_busy & vr_mask) || (model_ptr->cr_fpscr_busy & cr_mask)) {
187 if (WITH_TRACE && ppc_trace[trace_model]) {
188 model_trace_busy_p(model_ptr, 0, 0, cr_mask, PPC_NO_SPR);
189 model_trace_altivec_busy_p(model_ptr, vr_mask);
192 model_ptr->nr_stalls_data++;
193 model_new_cycle(model_ptr);
197 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
198 model_ptr->cr_fpscr_busy |= cr_mask;
199 busy_ptr->cr_fpscr_busy |= cr_mask;
200 model_ptr->vr_busy |= out_vmask;
201 busy_ptr->vr_busy |= out_vmask;
204 busy_ptr->nr_writebacks = (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
207 busy_ptr->nr_writebacks++;
209 if (WITH_TRACE && ppc_trace[trace_model])
210 model_trace_altivec_make_busy(model_ptr, vr_mask, cr_mask);
212 # Schedule an AltiVec instruction that takes vector input registers and produces vector output registers, touches VSCR
213 void::model-function::ppc_insn_vr_vscr:itable_index index, model_data *model_ptr, const unsigned32 out_vmask, const unsigned32 in_vmask
214 const unsigned32 vr_mask = out_vmask | in_vmask;
215 model_busy *busy_ptr;
217 if ((model_ptr->vr_busy & vr_mask) != 0 || model_ptr->vscr_busy != 0) {
218 model_new_cycle(model_ptr); /* don't count first dependency as a stall */
220 while ((model_ptr->vr_busy & vr_mask) != 0 || model_ptr->vscr_busy != 0) {
221 if (WITH_TRACE && ppc_trace[trace_model])
222 model_trace_altivec_busy_p(model_ptr, vr_mask);
224 model_ptr->nr_stalls_data++;
225 model_new_cycle(model_ptr);
229 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
230 model_ptr->vr_busy |= out_vmask;
231 busy_ptr->vr_busy |= out_vmask;
232 model_ptr->vscr_busy = 1;
233 busy_ptr->vscr_busy = 1;
236 busy_ptr->nr_writebacks = 1 + (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
238 if (WITH_TRACE && ppc_trace[trace_model])
239 model_trace_altivec_make_busy(model_ptr, vr_mask, 0);
241 # Schedule an MFVSCR instruction that VSCR input register and produces an AltiVec output register
242 void::model-function::ppc_insn_from_vscr:itable_index index, model_data *model_ptr, const unsigned32 vr_mask
243 model_busy *busy_ptr;
245 while ((model_ptr->vr_busy & vr_mask) != 0 || model_ptr->vscr_busy != 0) {
246 if (WITH_TRACE && ppc_trace[trace_model])
247 model_trace_altivec_busy_p(model_ptr, vr_mask);
249 model_ptr->nr_stalls_data++;
250 model_new_cycle(model_ptr);
252 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
253 model_ptr->cr_fpscr_busy |= vr_mask;
254 busy_ptr->cr_fpscr_busy |= vr_mask;
257 busy_ptr->nr_writebacks = 1;
259 model_ptr->vr_busy |= vr_mask;
260 if (WITH_TRACE && ppc_trace[trace_model])
261 model_trace_altivec_make_busy(model_ptr, vr_mask, 0);
263 # Schedule an MTVSCR instruction that one AltiVec input register and produces a vscr output register
264 void::model-function::ppc_insn_to_vscr:itable_index index, model_data *model_ptr, const unsigned32 vr_mask
265 model_busy *busy_ptr;
267 while ((model_ptr->vr_busy & vr_mask) != 0 || model_ptr->vscr_busy != 0) {
268 if (WITH_TRACE && ppc_trace[trace_model])
269 model_trace_altivec_busy_p(model_ptr, vr_mask);
271 model_ptr->nr_stalls_data++;
272 model_new_cycle(model_ptr);
274 busy_ptr = model_wait_for_unit(index, model_ptr, &model_ptr->timing[index]);
275 busy_ptr ->vscr_busy = 1;
276 model_ptr->vscr_busy = 1;
277 busy_ptr->nr_writebacks = 1;
279 TRACE(trace_model,("Making VSCR busy.\n"));
281 # The follow are AltiVec saturate operations
283 signed8::model-function::altivec_signed_saturate_8:signed16 val, int *sat
288 } else if (val < -128) {
297 signed16::model-function::altivec_signed_saturate_16:signed32 val, int *sat
302 } else if (val < -32768) {
311 signed32::model-function::altivec_signed_saturate_32:signed64 val, int *sat
313 if (val > 2147483647) {
316 } else if (val < -2147483648LL) {
325 unsigned8::model-function::altivec_unsigned_saturate_8:signed16 val, int *sat
330 } else if (val < 0) {
339 unsigned16::model-function::altivec_unsigned_saturate_16:signed32 val, int *sat
344 } else if (val < 0) {
353 unsigned32::model-function::altivec_unsigned_saturate_32:signed64 val, int *sat
355 if (val > 4294967295LL) {
358 } else if (val < 0) {
368 # Load instructions, 6-14 ... 6-22.
371 0.31,6.VS,11.RA,16.RB,21.7,31.0:X:av:lvebx %VD, %RA, %RB:Load Vector Element Byte Indexed
379 (*vS).b[AV_BINDEX(eb)] = MEM(unsigned, EA, 1);
380 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
382 0.31,6.VS,11.RA,16.RB,21.39,31.0:X:av:lvehx %VD, %RA, %RB:Load Vector Element Half Word Indexed
390 (*vS).h[AV_HINDEX(eb/2)] = MEM(unsigned, EA, 2);
391 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
393 0.31,6.VS,11.RA,16.RB,21.71,31.0:X:av:lvewx %VD, %RA, %RB:Load Vector Element Word Indexed
401 (*vS).w[eb/4] = MEM(unsigned, EA, 4);
402 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
405 0.31,6.VS,11.RA,16.RB,21.6,31.0:X:av:lvsl %VD, %RA, %RB:Load Vector for Shift Left
413 for (i = 0; i < 16; i++)
414 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
415 (*vS).b[AV_BINDEX(i)] = j++;
417 (*vS).b[AV_BINDEX(15 - i)] = j++;
418 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
420 0.31,6.VS,11.RA,16.RB,21.38,31.0:X:av:lvsr %VD, %RA, %RB:Load Vector for Shift Right
427 j = 0x10 - (addr & 0xf);
428 for (i = 0; i < 16; i++)
429 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
430 (*vS).b[AV_BINDEX(i)] = j++;
432 (*vS).b[AV_BINDEX(15 - i)] = j++;
433 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
436 0.31,6.VS,11.RA,16.RB,21.103,31.0:X:av:lvx %VD, %RA, %RB:Load Vector Indexed
441 EA = (b + *rB) & ~0xf;
442 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
443 (*vS).w[0] = MEM(unsigned, EA + 0, 4);
444 (*vS).w[1] = MEM(unsigned, EA + 4, 4);
445 (*vS).w[2] = MEM(unsigned, EA + 8, 4);
446 (*vS).w[3] = MEM(unsigned, EA + 12, 4);
448 (*vS).w[0] = MEM(unsigned, EA + 12, 4);
449 (*vS).w[1] = MEM(unsigned, EA + 8, 4);
450 (*vS).w[2] = MEM(unsigned, EA + 4, 4);
451 (*vS).w[3] = MEM(unsigned, EA + 0, 4);
453 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
455 0.31,6.VS,11.RA,16.RB,21.359,31.0:X:av:lvxl %VD, %RA, %RB:Load Vector Indexed LRU
460 EA = (b + *rB) & ~0xf;
461 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
462 (*vS).w[0] = MEM(unsigned, EA + 0, 4);
463 (*vS).w[1] = MEM(unsigned, EA + 4, 4);
464 (*vS).w[2] = MEM(unsigned, EA + 8, 4);
465 (*vS).w[3] = MEM(unsigned, EA + 12, 4);
467 (*vS).w[0] = MEM(unsigned, EA + 12, 4);
468 (*vS).w[1] = MEM(unsigned, EA + 8, 4);
469 (*vS).w[2] = MEM(unsigned, EA + 4, 4);
470 (*vS).w[3] = MEM(unsigned, EA + 0, 4);
472 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
475 # Move to/from VSCR instructions, 6-23 & 6-24.
478 0.4,6.VS,11.0,16.0,21.1540:VX:av:mfvscr %VS:Move from Vector Status and Control Register
483 PPC_INSN_FROM_VSCR(VS_BITMASK);
485 0.4,6.0,11.0,16.VB,21.1604:VX:av:mtvscr %VB:Move to Vector Status and Control Register
487 PPC_INSN_TO_VSCR(VB_BITMASK);
490 # Store instructions, 6-25 ... 6-29.
493 0.31,6.VS,11.RA,16.RB,21.135,31.0:X:av:stvebx %VD, %RA, %RB:Store Vector Element Byte Indexed
501 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
502 STORE(EA, 1, (*vS).b[eb]);
504 STORE(EA, 1, (*vS).b[15-eb]);
505 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
507 0.31,6.VS,11.RA,16.RB,21.167,31.0:X:av:stvehx %VD, %RA, %RB:Store Vector Element Half Word Indexed
515 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
516 STORE(EA, 2, (*vS).h[eb/2]);
518 STORE(EA, 2, (*vS).h[7-eb]);
519 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
521 0.31,6.VS,11.RA,16.RB,21.199,31.0:X:av:stvewx %VD, %RA, %RB:Store Vector Element Word Indexed
529 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
530 STORE(EA, 4, (*vS).w[eb/4]);
532 STORE(EA, 4, (*vS).w[3-(eb/4)]);
533 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
535 0.31,6.VS,11.RA,16.RB,21.231,31.0:X:av:stvx %VD, %RA, %RB:Store Vector Indexed
540 EA = (b + *rB) & ~0xf;
541 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
542 STORE(EA + 0, 4, (*vS).w[0]);
543 STORE(EA + 4, 4, (*vS).w[1]);
544 STORE(EA + 8, 4, (*vS).w[2]);
545 STORE(EA + 12, 4, (*vS).w[3]);
547 STORE(EA + 12, 4, (*vS).w[0]);
548 STORE(EA + 8, 4, (*vS).w[1]);
549 STORE(EA + 4, 4, (*vS).w[2]);
550 STORE(EA + 0, 4, (*vS).w[3]);
552 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
554 0.31,6.VS,11.RA,16.RB,21.487,31.0:X:av:stvxl %VD, %RA, %RB:Store Vector Indexed LRU
559 EA = (b + *rB) & ~0xf;
560 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
561 STORE(EA + 0, 4, (*vS).w[0]);
562 STORE(EA + 4, 4, (*vS).w[1]);
563 STORE(EA + 8, 4, (*vS).w[2]);
564 STORE(EA + 12, 4, (*vS).w[3]);
566 STORE(EA + 12, 4, (*vS).w[0]);
567 STORE(EA + 8, 4, (*vS).w[1]);
568 STORE(EA + 4, 4, (*vS).w[2]);
569 STORE(EA + 0, 4, (*vS).w[3]);
571 PPC_INSN_INT_VR(0, RA_BITMASK | RB_BITMASK, VS_BITMASK, 0);
574 # Vector Add instructions, 6-30 ... 6-40.
577 0.4,6.VS,11.VA,16.VB,21.384:VX:av:vaddcuw %VD, %VA, %VB:Vector Add Carryout Unsigned Word
580 for (i = 0; i < 4; i++) {
581 temp = (unsigned64)(*vA).w[i] + (unsigned64)(*vB).w[i];
582 (*vS).w[i] = temp >> 32;
584 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
586 0.4,6.VS,11.VA,16.VB,21.10:VX:av:vaddfp %VD, %VA, %VB:Vector Add Floating Point
590 for (i = 0; i < 4; i++) {
591 sim_fpu_32to (&a, (*vA).w[i]);
592 sim_fpu_32to (&b, (*vB).w[i]);
593 sim_fpu_add (&d, &a, &b);
594 sim_fpu_to32 (&f, &d);
597 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
599 0.4,6.VS,11.VA,16.VB,21.768:VX:av:vaddsbs %VD, %VA, %VB:Vector Add Signed Byte Saturate
602 for (i = 0; i < 16; i++) {
603 temp = (signed16)(signed8)(*vA).b[i] + (signed16)(signed8)(*vB).b[i];
604 (*vS).b[i] = altivec_signed_saturate_8(temp, &tempsat);
607 ALTIVEC_SET_SAT(sat);
608 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
610 0.4,6.VS,11.VA,16.VB,21.832:VX:av:vaddshs %VD, %VA, %VB:Vector Add Signed Half Word Saturate
613 for (i = 0; i < 8; i++) {
614 a = (signed32)(signed16)(*vA).h[i];
615 b = (signed32)(signed16)(*vB).h[i];
617 (*vS).h[i] = altivec_signed_saturate_16(temp, &tempsat);
620 ALTIVEC_SET_SAT(sat);
621 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
623 0.4,6.VS,11.VA,16.VB,21.896:VX:av:vaddsws %VD, %VA, %VB:Vector Add Signed Word Saturate
626 for (i = 0; i < 4; i++) {
627 temp = (signed64)(signed32)(*vA).w[i] + (signed64)(signed32)(*vB).w[i];
628 (*vS).w[i] = altivec_signed_saturate_32(temp, &tempsat);
631 ALTIVEC_SET_SAT(sat);
632 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
634 0.4,6.VS,11.VA,16.VB,21.0:VX:av:vaddubm %VD, %VA, %VB:Vector Add Unsigned Byte Modulo
636 for (i = 0; i < 16; i++)
637 (*vS).b[i] = ((*vA).b[i] + (*vB).b[i]) & 0xff;
638 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
640 0.4,6.VS,11.VA,16.VB,21.512:VX:av:vaddubs %VD, %VA, %VB:Vector Add Unsigned Byte Saturate
644 for (i = 0; i < 16; i++) {
645 temp = (signed16)(unsigned8)(*vA).b[i] + (signed16)(unsigned8)(*vB).b[i];
646 (*vS).b[i] = altivec_unsigned_saturate_8(temp, &tempsat);
649 ALTIVEC_SET_SAT(sat);
650 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
652 0.4,6.VS,11.VA,16.VB,21.64:VX:av:vadduhm %VD, %VA, %VB:Vector Add Unsigned Half Word Modulo
654 for (i = 0; i < 8; i++)
655 (*vS).h[i] = ((*vA).h[i] + (*vB).h[i]) & 0xffff;
656 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
658 0.4,6.VS,11.VA,16.VB,21.576:VX:av:vadduhs %VD, %VA, %VB:Vector Add Unsigned Half Word Saturate
661 for (i = 0; i < 8; i++) {
662 temp = (signed32)(unsigned16)(*vA).h[i] + (signed32)(unsigned16)(*vB).h[i];
663 (*vS).h[i] = altivec_unsigned_saturate_16(temp, &tempsat);
666 ALTIVEC_SET_SAT(sat);
667 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
669 0.4,6.VS,11.VA,16.VB,21.128:VX:av:vadduwm %VD, %VA, %VB:Vector Add Unsigned Word Modulo
671 for (i = 0; i < 4; i++)
672 (*vS).w[i] = (*vA).w[i] + (*vB).w[i];
673 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
675 0.4,6.VS,11.VA,16.VB,21.640:VX:av:vadduws %VD, %VA, %VB:Vector Add Unsigned Word Saturate
678 for (i = 0; i < 4; i++) {
679 temp = (signed64)(unsigned32)(*vA).w[i] + (signed64)(unsigned32)(*vB).w[i];
680 (*vS).w[i] = altivec_unsigned_saturate_32(temp, &tempsat);
683 ALTIVEC_SET_SAT(sat);
684 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
687 # Vector AND instructions, 6-41, 6-42
690 0.4,6.VS,11.VA,16.VB,21.1028:VX:av:vand %VD, %VA, %VB:Vector Logical AND
692 for (i = 0; i < 4; i++)
693 (*vS).w[i] = (*vA).w[i] & (*vB).w[i];
694 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
696 0.4,6.VS,11.VA,16.VB,21.1092:VX:av:vandc %VD, %VA, %VB:Vector Logical AND with Compliment
698 for (i = 0; i < 4; i++)
699 (*vS).w[i] = (*vA).w[i] & ~((*vB).w[i]);
700 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
704 # Vector Average instructions, 6-43, 6-48
707 0.4,6.VS,11.VA,16.VB,21.1282:VX:av:vavgsb %VD, %VA, %VB:Vector Average Signed Byte
710 for (i = 0; i < 16; i++) {
711 a = (signed16)(signed8)(*vA).b[i];
712 b = (signed16)(signed8)(*vB).b[i];
714 (*vS).b[i] = (temp >> 1) & 0xff;
716 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
718 0.4,6.VS,11.VA,16.VB,21.1346:VX:av:vavgsh %VD, %VA, %VB:Vector Average Signed Half Word
721 for (i = 0; i < 8; i++) {
722 a = (signed32)(signed16)(*vA).h[i];
723 b = (signed32)(signed16)(*vB).h[i];
725 (*vS).h[i] = (temp >> 1) & 0xffff;
727 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
729 0.4,6.VS,11.VA,16.VB,21.1410:VX:av:vavgsw %VD, %VA, %VB:Vector Average Signed Word
732 for (i = 0; i < 4; i++) {
733 a = (signed64)(signed32)(*vA).w[i];
734 b = (signed64)(signed32)(*vB).w[i];
736 (*vS).w[i] = (temp >> 1) & 0xffffffff;
738 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
740 0.4,6.VS,11.VA,16.VB,21.1026:VX:av:vavgub %VD, %VA, %VB:Vector Average Unsigned Byte
742 unsigned16 temp, a, b;
743 for (i = 0; i < 16; i++) {
747 (*vS).b[i] = (temp >> 1) & 0xff;
749 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
751 0.4,6.VS,11.VA,16.VB,21.1090:VX:av:vavguh %VD, %VA, %VB:Vector Average Unsigned Half Word
753 unsigned32 temp, a, b;
754 for (i = 0; i < 8; i++) {
758 (*vS).h[i] = (temp >> 1) & 0xffff;
760 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
762 0.4,6.VS,11.VA,16.VB,21.1154:VX:av:vavguw %VD, %VA, %VB:Vector Average Unsigned Word
764 unsigned64 temp, a, b;
765 for (i = 0; i < 4; i++) {
769 (*vS).w[i] = (temp >> 1) & 0xffffffff;
771 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
774 # Vector Fixed Point Convert instructions, 6-49, 6-50
777 0.4,6.VS,11.UIMM,16.VB,21.842:VX:av:vcfsx %VD, %VB, %UIMM:Vector Convert From Signed Fixed-Point Word
781 for (i = 0; i < 4; i++) {
782 sim_fpu_32to (&b, (*vB).w[i]);
783 sim_fpu_u32to (&div, 2 << UIMM, sim_fpu_round_default);
784 sim_fpu_div (&d, &b, &div);
785 sim_fpu_to32 (&f, &d);
788 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
790 0.4,6.VS,11.UIMM,16.VB,21.778:VX:av:vcfux %VD, %VA, %UIMM:Vector Convert From Unsigned Fixed-Point Word
794 for (i = 0; i < 4; i++) {
795 sim_fpu_32to (&b, (*vB).w[i]);
796 sim_fpu_u32to (&div, 2 << UIMM, sim_fpu_round_default);
797 sim_fpu_div (&d, &b, &div);
798 sim_fpu_to32u (&f, &d, sim_fpu_round_default);
801 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
804 # Vector Compare instructions, 6-51 ... 6-64
807 0.4,6.VS,11.VA,16.VB,21.RC,22.966:VXR:av:vcmpbpfpx %VD, %VA, %VB:Vector Compare Bounds Floating Point
810 for (i = 0; i < 4; i++) {
811 sim_fpu_32to (&a, (*vA).w[i]);
812 sim_fpu_32to (&b, (*vB).w[i]);
813 le = sim_fpu_is_le(&a, &b);
814 ge = sim_fpu_is_ge(&a, &b);
815 (*vS).w[i] = (le ? 0 : 1 << 31) | (ge ? 0 : 1 << 30);
818 ALTIVEC_SET_CR6(vS, 0);
819 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
821 0.4,6.VS,11.VA,16.VB,21.RC,22.198:VXR:av:vcmpeqfpx %VD, %VA, %VB:Vector Compare Equal-to-Floating Point
824 for (i = 0; i < 4; i++) {
825 sim_fpu_32to (&a, (*vA).w[i]);
826 sim_fpu_32to (&b, (*vB).w[i]);
827 if (sim_fpu_is_eq(&a, &b))
828 (*vS).w[i] = 0xffffffff;
833 ALTIVEC_SET_CR6(vS, 1);
834 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
836 0.4,6.VS,11.VA,16.VB,21.RC,22.6:VXR:av:vcmpequbx %VD, %VA, %VB:Vector Compare Equal-to Unsigned Byte
838 for (i = 0; i < 16; i++)
839 if ((*vA).b[i] == (*vB).b[i])
844 ALTIVEC_SET_CR6(vS, 1);
845 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
847 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
849 for (i = 0; i < 8; i++)
850 if ((*vA).h[i] == (*vB).h[i])
855 ALTIVEC_SET_CR6(vS, 1);
856 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
858 0.4,6.VS,11.VA,16.VB,21.RC,22.134:VXR:av:vcmpequwx %VD, %VA, %VB:Vector Compare Equal-to Unsigned Word
860 for (i = 0; i < 4; i++)
861 if ((*vA).w[i] == (*vB).w[i])
862 (*vS).w[i] = 0xffffffff;
866 ALTIVEC_SET_CR6(vS, 1);
867 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
869 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
872 for (i = 0; i < 4; i++) {
873 sim_fpu_32to (&a, (*vA).w[i]);
874 sim_fpu_32to (&b, (*vB).w[i]);
875 if (sim_fpu_is_ge(&a, &b))
876 (*vS).w[i] = 0xffffffff;
881 ALTIVEC_SET_CR6(vS, 1);
882 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
884 0.4,6.VS,11.VA,16.VB,21.RC,22.710:VXR:av:vcmpgtfpx %VD, %VA, %VB:Vector Compare Greater-Than Floating Point
887 for (i = 0; i < 4; i++) {
888 sim_fpu_32to (&a, (*vA).w[i]);
889 sim_fpu_32to (&b, (*vB).w[i]);
890 if (sim_fpu_is_gt(&a, &b))
891 (*vS).w[i] = 0xffffffff;
896 ALTIVEC_SET_CR6(vS, 1);
897 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
899 0.4,6.VS,11.VA,16.VB,21.RC,22.774:VXR:av:vcmpgtsbx %VD, %VA, %VB:Vector Compare Greater-Than Signed Byte
902 for (i = 0; i < 16; i++) {
911 ALTIVEC_SET_CR6(vS, 1);
912 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
914 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
917 for (i = 0; i < 8; i++) {
926 ALTIVEC_SET_CR6(vS, 1);
927 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
929 0.4,6.VS,11.VA,16.VB,21.RC,22.902:VXR:av:vcmpgtswx %VD, %VA, %VB:Vector Compare Greater-Than Signed Word
932 for (i = 0; i < 4; i++) {
936 (*vS).w[i] = 0xffffffff;
941 ALTIVEC_SET_CR6(vS, 1);
942 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
944 0.4,6.VS,11.VA,16.VB,21.RC,22.518:VXR:av:vcmpgtubx %VD, %VA, %VB:Vector Compare Greater-Than Unsigned Byte
947 for (i = 0; i < 16; i++) {
956 ALTIVEC_SET_CR6(vS, 1);
957 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
959 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
962 for (i = 0; i < 8; i++) {
971 ALTIVEC_SET_CR6(vS, 1);
972 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
974 0.4,6.VS,11.VA,16.VB,21.RC,22.646:VXR:av:vcmpgtuwx %VD, %VA, %VB:Vector Compare Greater-Than Unsigned Word
977 for (i = 0; i < 4; i++) {
981 (*vS).w[i] = 0xffffffff;
986 ALTIVEC_SET_CR6(vS, 1);
987 PPC_INSN_VR_CR(VS_BITMASK, VA_BITMASK | VB_BITMASK, RC ? 0x000000f0 : 0);
990 # Vector Convert instructions, 6-65, 6-66.
993 0.4,6.VS,11.UIMM,16.VB,21.970:VX:av:vctsxs %VD, %VB, %UIMM:Vector Convert to Signed Fixed-Point Word Saturate
998 for (i = 0; i < 4; i++) {
999 sim_fpu_32to (&b, (*vB).w[i]);
1000 sim_fpu_u32to (&m, 2 << UIMM, sim_fpu_round_default);
1001 sim_fpu_mul (&a, &b, &m);
1002 sim_fpu_to64i (&temp, &a, sim_fpu_round_default);
1003 (*vS).w[i] = altivec_signed_saturate_32(temp, &tempsat);
1006 ALTIVEC_SET_SAT(sat);
1007 PPC_INSN_VR_VSCR(VS_BITMASK, VB_BITMASK);
1009 0.4,6.VS,11.UIMM,16.VB,21.906:VX:av:vctuxs %VD, %VB, %UIMM:Vector Convert to Unsigned Fixed-Point Word Saturate
1010 int i, sat, tempsat;
1014 for (i = 0; i < 4; i++) {
1015 sim_fpu_32to (&b, (*vB).w[i]);
1016 sim_fpu_u32to (&m, 2 << UIMM, sim_fpu_round_default);
1017 sim_fpu_mul (&a, &b, &m);
1018 sim_fpu_to64u (&temp, &a, sim_fpu_round_default);
1019 (*vS).w[i] = altivec_unsigned_saturate_32(temp, &tempsat);
1022 ALTIVEC_SET_SAT(sat);
1023 PPC_INSN_VR_VSCR(VS_BITMASK, VB_BITMASK);
1026 # Vector Estimate instructions, 6-67 ... 6-70.
1029 0.4,6.VS,11.0,16.VB,21.394:VX:av:vexptefp %VD, %VB:Vector 2 Raised to the Exponent Estimate Floating Point
1034 for (i = 0; i < 4; i++) {
1036 sim_fpu_32to (&b, (*vB).w[i]);
1037 sim_fpu_to32i (&bi, &b, sim_fpu_round_default);
1039 sim_fpu_32to (&d, bi);
1040 sim_fpu_to32 (&f, &d);
1043 PPC_INSN_VR_VSCR(VS_BITMASK, VB_BITMASK);
1045 0.4,6.VS,11.0,16.VB,21.458:VX:av:vlogefp %VD, %VB:Vector Log2 Estimate Floating Point
1049 for (i = 0; i < 4; i++) {
1051 sim_fpu_32to (&b, (*vB).w[i]);
1052 sim_fpu_to32u (&u, &b, sim_fpu_round_default);
1053 for (c = 0; (u /= 2) > 1; c++)
1055 sim_fpu_32to (&cfpu, c);
1056 sim_fpu_add (&d, &b, &cfpu);
1057 sim_fpu_to32 (&f, &d);
1060 PPC_INSN_VR_VSCR(VS_BITMASK, VB_BITMASK);
1063 # Vector Multiply Add instruction, 6-71
1066 0.4,6.VS,11.VA,16.VB,21.VC,26.46:VAX:av:vmaddfp %VD, %VA, %VB, %VC:Vector Multiply Add Floating Point
1069 sim_fpu a, b, c, d, e;
1070 for (i = 0; i < 4; i++) {
1071 sim_fpu_32to (&a, (*vA).w[i]);
1072 sim_fpu_32to (&b, (*vB).w[i]);
1073 sim_fpu_32to (&c, (*vC).w[i]);
1074 sim_fpu_mul (&e, &a, &c);
1075 sim_fpu_add (&d, &e, &b);
1076 sim_fpu_to32 (&f, &d);
1079 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1083 # Vector Maximum instructions, 6-72 ... 6-78.
1086 0.4,6.VS,11.VA,16.VB,21.1034:VX:av:vmaxfp %VD, %VA, %VB:Vector Maximum Floating Point
1090 for (i = 0; i < 4; i++) {
1091 sim_fpu_32to (&a, (*vA).w[i]);
1092 sim_fpu_32to (&b, (*vB).w[i]);
1093 sim_fpu_max (&d, &a, &b);
1094 sim_fpu_to32 (&f, &d);
1097 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1099 0.4,6.VS,11.VA,16.VB,21.258:VX:av:vmaxsb %VD, %VA, %VB:Vector Maximum Signed Byte
1102 for (i = 0; i < 16; i++) {
1110 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1112 0.4,6.VS,11.VA,16.VB,21.322:VX:av:vmaxsh %VD, %VA, %VB:Vector Maximum Signed Half Word
1115 for (i = 0; i < 8; i++) {
1123 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1125 0.4,6.VS,11.VA,16.VB,21.386:VX:av:vmaxsw %VD, %VA, %VB:Vector Maximum Signed Word
1128 for (i = 0; i < 4; i++) {
1136 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1138 0.4,6.VS,11.VA,16.VB,21.2:VX:av:vmaxub %VD, %VA, %VB:Vector Maximum Unsigned Byte
1141 for (i = 0; i < 16; i++) {
1149 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1151 0.4,6.VS,11.VA,16.VB,21.66:VX:av:vmaxus %VD, %VA, %VB:Vector Maximum Unsigned Half Word
1154 for (i = 0; i < 8; i++) {
1162 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1164 0.4,6.VS,11.VA,16.VB,21.130:VX:av:vmaxuw %VD, %VA, %VB:Vector Maximum Unsigned Word
1167 for (i = 0; i < 4; i++) {
1175 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1179 # Vector Multiple High instructions, 6-79, 6-80.
1182 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
1183 int i, sat, tempsat;
1185 signed32 prod, temp, c;
1186 for (i = 0; i < 8; i++) {
1189 c = (signed32)(signed16)(*vC).h[i];
1190 prod = (signed32)a * (signed32)b;
1191 temp = (prod >> 15) + c;
1192 (*vS).h[i] = altivec_signed_saturate_16(temp, &tempsat);
1195 ALTIVEC_SET_SAT(sat);
1196 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1198 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
1199 int i, sat, tempsat;
1201 signed32 prod, temp, c;
1202 for (i = 0; i < 8; i++) {
1205 c = (signed32)(signed16)(*vC).h[i];
1206 prod = (signed32)a * (signed32)b;
1208 temp = (prod >> 15) + c;
1209 (*vS).h[i] = altivec_signed_saturate_16(temp, &tempsat);
1212 ALTIVEC_SET_SAT(sat);
1213 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1217 # Vector Minimum instructions, 6-81 ... 6-87
1220 0.4,6.VS,11.VA,16.VB,21.1098:VX:av:vminfp %VD, %VA, %VB:Vector Minimum Floating Point
1224 for (i = 0; i < 4; i++) {
1225 sim_fpu_32to (&a, (*vA).w[i]);
1226 sim_fpu_32to (&b, (*vB).w[i]);
1227 sim_fpu_min (&d, &a, &b);
1228 sim_fpu_to32 (&f, &d);
1231 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1233 0.4,6.VS,11.VA,16.VB,21.770:VX:av:vminsb %VD, %VA, %VB:Vector Minimum Signed Byte
1236 for (i = 0; i < 16; i++) {
1244 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1246 0.4,6.VS,11.VA,16.VB,21.834:VX:av:vminsh %VD, %VA, %VB:Vector Minimum Signed Half Word
1249 for (i = 0; i < 8; i++) {
1257 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1259 0.4,6.VS,11.VA,16.VB,21.898:VX:av:vminsw %VD, %VA, %VB:Vector Minimum Signed Word
1262 for (i = 0; i < 4; i++) {
1270 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1272 0.4,6.VS,11.VA,16.VB,21.514:VX:av:vminub %VD, %VA, %VB:Vector Minimum Unsigned Byte
1275 for (i = 0; i < 16; i++) {
1283 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1285 0.4,6.VS,11.VA,16.VB,21.578:VX:av:vminuh %VD, %VA, %VB:Vector Minimum Unsigned Half Word
1288 for (i = 0; i < 8; i++) {
1296 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1298 0.4,6.VS,11.VA,16.VB,21.642:VX:av:vminuw %VD, %VA, %VB:Vector Minimum Unsigned Word
1301 for (i = 0; i < 4; i++) {
1309 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1313 # Vector Multiply Low instruction, 6-88
1316 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
1320 for (i = 0; i < 8; i++) {
1324 prod = (unsigned32)a * (unsigned32)b;
1325 (*vS).h[i] = (prod + c) & 0xffff;
1327 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1331 # Vector Merge instructions, 6-89 ... 6-94
1334 0.4,6.VS,11.VA,16.VB,21.12:VX:av:vmrghb %VD, %VA, %VB:Vector Merge High Byte
1336 for (i = 0; i < 16; i += 2) {
1337 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX(i/2)];
1338 (*vS).b[AV_BINDEX(i+1)] = (*vB).b[AV_BINDEX(i/2)];
1340 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1342 0.4,6.VS,11.VA,16.VB,21.76:VX:av:vmrghh %VD, %VA, %VB:Vector Merge High Half Word
1344 for (i = 0; i < 8; i += 2) {
1345 (*vS).h[AV_HINDEX(i)] = (*vA).h[AV_HINDEX(i/2)];
1346 (*vS).h[AV_HINDEX(i+1)] = (*vB).h[AV_HINDEX(i/2)];
1348 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1350 0.4,6.VS,11.VA,16.VB,21.140:VX:av:vmrghw %VD, %VA, %VB:Vector Merge High Word
1352 for (i = 0; i < 4; i += 2) {
1353 (*vS).w[i] = (*vA).w[i/2];
1354 (*vS).w[i+1] = (*vB).w[i/2];
1356 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1358 0.4,6.VS,11.VA,16.VB,21.268:VX:av:vmrglb %VD, %VA, %VB:Vector Merge Low Byte
1360 for (i = 0; i < 16; i += 2) {
1361 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX((i/2) + 8)];
1362 (*vS).b[AV_BINDEX(i+1)] = (*vB).b[AV_BINDEX((i/2) + 8)];
1364 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1366 0.4,6.VS,11.VA,16.VB,21.332:VX:av:vmrglh %VD, %VA, %VB:Vector Merge Low Half Word
1368 for (i = 0; i < 8; i += 2) {
1369 (*vS).h[AV_HINDEX(i)] = (*vA).h[AV_HINDEX((i/2) + 4)];
1370 (*vS).h[AV_HINDEX(i+1)] = (*vB).h[AV_HINDEX((i/2) + 4)];
1372 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1374 0.4,6.VS,11.VA,16.VB,21.396:VX:av:vmrglw %VD, %VA, %VB:Vector Merge Low Word
1376 for (i = 0; i < 4; i += 2) {
1377 (*vS).w[i] = (*vA).w[(i/2) + 2];
1378 (*vS).w[i+1] = (*vB).w[(i/2) + 2];
1380 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1384 # Vector Multiply Sum instructions, 6-95 ... 6-100
1387 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
1392 for (i = 0; i < 4; i++) {
1394 for (j = 0; j < 4; j++) {
1395 a = (signed16)(signed8)(*vA).b[i*4+j];
1398 temp += (signed32)prod;
1402 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1404 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
1406 signed32 temp, prod, a, b;
1407 for (i = 0; i < 4; i++) {
1409 for (j = 0; j < 2; j++) {
1410 a = (signed32)(signed16)(*vA).h[i*2+j];
1411 b = (signed32)(signed16)(*vB).h[i*2+j];
1417 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1419 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
1420 int i, j, sat, tempsat;
1422 signed32 prod, a, b;
1424 for (i = 0; i < 4; i++) {
1425 temp = (signed64)(signed32)(*vC).w[i];
1426 for (j = 0; j < 2; j++) {
1427 a = (signed32)(signed16)(*vA).h[i*2+j];
1428 b = (signed32)(signed16)(*vB).h[i*2+j];
1430 temp += (signed64)prod;
1432 (*vS).w[i] = altivec_signed_saturate_32(temp, &tempsat);
1435 ALTIVEC_SET_SAT(sat);
1436 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1438 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
1441 unsigned16 prod, a, b;
1442 for (i = 0; i < 4; i++) {
1444 for (j = 0; j < 4; j++) {
1452 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1454 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
1456 unsigned32 temp, prod, a, b;
1457 for (i = 0; i < 4; i++) {
1459 for (j = 0; j < 2; j++) {
1467 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1469 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
1470 int i, j, sat, tempsat;
1471 unsigned32 temp, prod, a, b;
1473 for (i = 0; i < 4; i++) {
1475 for (j = 0; j < 2; j++) {
1481 (*vS).w[i] = altivec_unsigned_saturate_32(temp, &tempsat);
1484 ALTIVEC_SET_SAT(sat);
1485 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1489 # Vector Multiply Even/Odd instructions, 6-101 ... 6-108
1492 0.4,6.VS,11.VA,16.VB,21.776:VX:av:vmulesb %VD, %VA, %VB:Vector Multiply Even Signed Byte
1496 for (i = 0; i < 8; i++) {
1497 a = (*vA).b[AV_BINDEX(i*2)];
1498 b = (*vB).b[AV_BINDEX(i*2)];
1500 (*vS).h[AV_HINDEX(i)] = prod;
1502 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1504 0.4,6.VS,11.VA,16.VB,21.840:VX:av:vmulesh %VD, %VA, %VB:Vector Multiply Even Signed Half Word
1508 for (i = 0; i < 4; i++) {
1509 a = (*vA).h[AV_HINDEX(i*2)];
1510 b = (*vB).h[AV_HINDEX(i*2)];
1514 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1516 0.4,6.VS,11.VA,16.VB,21.520:VX:av:vmuleub %VD, %VA, %VB:Vector Multiply Even Unsigned Byte
1520 for (i = 0; i < 8; i++) {
1521 a = (*vA).b[AV_BINDEX(i*2)];
1522 b = (*vB).b[AV_BINDEX(i*2)];
1524 (*vS).h[AV_HINDEX(i)] = prod;
1526 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1528 0.4,6.VS,11.VA,16.VB,21.584:VX:av:vmuleuh %VD, %VA, %VB:Vector Multiply Even Unsigned Half Word
1532 for (i = 0; i < 4; i++) {
1533 a = (*vA).h[AV_HINDEX(i*2)];
1534 b = (*vB).h[AV_HINDEX(i*2)];
1538 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1540 0.4,6.VS,11.VA,16.VB,21.264:VX:av:vmulosb %VD, %VA, %VB:Vector Multiply Odd Signed Byte
1544 for (i = 0; i < 8; i++) {
1545 a = (*vA).b[AV_BINDEX((i*2)+1)];
1546 b = (*vB).b[AV_BINDEX((i*2)+1)];
1548 (*vS).h[AV_HINDEX(i)] = prod;
1550 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1552 0.4,6.VS,11.VA,16.VB,21.328:VX:av:vmulosh %VD, %VA, %VB:Vector Multiply Odd Signed Half Word
1556 for (i = 0; i < 4; i++) {
1557 a = (*vA).h[AV_HINDEX((i*2)+1)];
1558 b = (*vB).h[AV_HINDEX((i*2)+1)];
1562 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1564 0.4,6.VS,11.VA,16.VB,21.8:VX:av:vmuloub %VD, %VA, %VB:Vector Multiply Odd Unsigned Byte
1568 for (i = 0; i < 8; i++) {
1569 a = (*vA).b[AV_BINDEX((i*2)+1)];
1570 b = (*vB).b[AV_BINDEX((i*2)+1)];
1572 (*vS).h[AV_HINDEX(i)] = prod;
1574 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1576 0.4,6.VS,11.VA,16.VB,21.72:VX:av:vmulouh %VD, %VA, %VB:Vector Multiply Odd Unsigned Half Word
1580 for (i = 0; i < 4; i++) {
1581 a = (*vA).h[AV_HINDEX((i*2)+1)];
1582 b = (*vB).h[AV_HINDEX((i*2)+1)];
1586 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1590 # Vector Negative Multiply-Subtract instruction, 6-109
1593 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
1596 sim_fpu a, b, c, d, i1, i2;
1597 for (i = 0; i < 4; i++) {
1598 sim_fpu_32to (&a, (*vA).w[i]);
1599 sim_fpu_32to (&b, (*vB).w[i]);
1600 sim_fpu_32to (&c, (*vC).w[i]);
1601 sim_fpu_mul (&i1, &a, &c);
1602 sim_fpu_sub (&i2, &i1, &b);
1603 sim_fpu_neg (&d, &i2);
1604 sim_fpu_to32 (&f, &d);
1607 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1611 # Vector Logical OR instructions, 6-110, 6-111, 6-177
1614 0.4,6.VS,11.VA,16.VB,21.1284:VX:av:vnor %VD, %VA, %VB:Vector Logical NOR
1616 for (i = 0; i < 4; i++)
1617 (*vS).w[i] = ~((*vA).w[i] | (*vB).w[i]);
1618 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1620 0.4,6.VS,11.VA,16.VB,21.1156:VX:av:vor %VD, %VA, %VB:Vector Logical OR
1622 for (i = 0; i < 4; i++)
1623 (*vS).w[i] = (*vA).w[i] | (*vB).w[i];
1624 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1626 0.4,6.VS,11.VA,16.VB,21.1220:VX:av:vxor %VD, %VA, %VB:Vector Logical XOR
1628 for (i = 0; i < 4; i++)
1629 (*vS).w[i] = (*vA).w[i] ^ (*vB).w[i];
1630 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1634 # Vector Permute instruction, 6-112
1637 0.4,6.VS,11.VA,16.VB,21.VC,26.43:VX:av:vperm %VD, %VA, %VB, %VC:Vector Permute
1639 for (i = 0; i < 16; i++) {
1640 who = (*vC).b[AV_BINDEX(i)] & 0x1f;
1642 (*vS).b[AV_BINDEX(i)] = (*vB).b[AV_BINDEX(who & 0xf)];
1644 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX(who & 0xf)];
1646 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1650 # Vector Pack instructions, 6-113 ... 6-121
1653 0.4,6.VS,11.VA,16.VB,21.782:VX:av:vpkpx %VD, %VA, %VB:Vector Pack Pixel32
1655 for (i = 0; i < 4; i++) {
1656 (*vS).h[AV_HINDEX(i+4)] = ((((*vB).w[i]) >> 9) & 0xfc00)
1657 | ((((*vB).w[i]) >> 6) & 0x03e0)
1658 | ((((*vB).w[i]) >> 3) & 0x001f);
1659 (*vS).h[AV_HINDEX(i)] = ((((*vA).w[i]) >> 9) & 0xfc00)
1660 | ((((*vA).w[i]) >> 6) & 0x03e0)
1661 | ((((*vA).w[i]) >> 3) & 0x001f);
1663 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1665 0.4,6.VS,11.VA,16.VB,21.398:VX:av:vpkshss %VD, %VA, %VB:Vector Pack Signed Half Word Signed Saturate
1666 int i, sat, tempsat;
1669 for (i = 0; i < 16; i++) {
1671 temp = (*vA).h[AV_HINDEX(i)];
1673 temp = (*vB).h[AV_HINDEX(i-8)];
1674 (*vS).b[AV_BINDEX(i)] = altivec_signed_saturate_8(temp, &tempsat);
1677 ALTIVEC_SET_SAT(sat);
1678 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1680 0.4,6.VS,11.VA,16.VB,21.270:VX:av:vpkshus %VD, %VA, %VB:Vector Pack Signed Half Word Unsigned Saturate
1681 int i, sat, tempsat;
1684 for (i = 0; i < 16; i++) {
1686 temp = (*vA).h[AV_HINDEX(i)];
1688 temp = (*vB).h[AV_HINDEX(i-8)];
1689 (*vS).b[AV_BINDEX(i)] = altivec_unsigned_saturate_8(temp, &tempsat);
1692 ALTIVEC_SET_SAT(sat);
1693 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1695 0.4,6.VS,11.VA,16.VB,21.462:VX:av:vpkswss %VD, %VA, %VB:Vector Pack Signed Word Signed Saturate
1696 int i, sat, tempsat;
1699 for (i = 0; i < 8; i++) {
1703 temp = (*vB).w[i-4];
1704 (*vS).h[AV_HINDEX(i)] = altivec_signed_saturate_16(temp, &tempsat);
1707 ALTIVEC_SET_SAT(sat);
1708 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1710 0.4,6.VS,11.VA,16.VB,21.334:VX:av:vpkswus %VD, %VA, %VB:Vector Pack Signed Word Unsigned Saturate
1711 int i, sat, tempsat;
1714 for (i = 0; i < 8; i++) {
1718 temp = (*vB).w[i-4];
1719 (*vS).h[AV_HINDEX(i)] = altivec_unsigned_saturate_16(temp, &tempsat);
1722 ALTIVEC_SET_SAT(sat);
1723 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1725 0.4,6.VS,11.VA,16.VB,21.14:VX:av:vpkuhum %VD, %VA, %VB:Vector Pack Unsigned Half Word Unsigned Modulo
1727 for (i = 0; i < 16; i++)
1729 (*vS).b[AV_BINDEX(i)] = (*vA).h[AV_HINDEX(i)];
1731 (*vS).b[AV_BINDEX(i)] = (*vB).h[AV_HINDEX(i-8)];
1732 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1734 0.4,6.VS,11.VA,16.VB,21.142:VX:av:vpkuhus %VD, %VA, %VB:Vector Pack Unsigned Half Word Unsigned Saturate
1735 int i, sat, tempsat;
1738 for (i = 0; i < 16; i++) {
1740 temp = (*vA).h[AV_HINDEX(i)];
1742 temp = (*vB).h[AV_HINDEX(i-8)];
1743 /* force positive in signed16, ok as we'll toss the bit away anyway */
1745 (*vS).b[AV_BINDEX(i)] = altivec_unsigned_saturate_8(temp, &tempsat);
1748 ALTIVEC_SET_SAT(sat);
1749 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1751 0.4,6.VS,11.VA,16.VB,21.78:VX:av:vpkuwum %VD, %VA, %VB:Vector Pack Unsigned Word Unsigned Modulo
1753 for (i = 0; i < 8; i++)
1755 (*vS).h[AV_HINDEX(i)] = (*vA).w[i];
1757 (*vS).h[AV_HINDEX(i)] = (*vB).w[i-8];
1758 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1760 0.4,6.VS,11.VA,16.VB,21.206:VX:av:vpkuwus %VD, %VA, %VB:Vector Pack Unsigned Word Unsigned Saturate
1761 int i, sat, tempsat;
1764 for (i = 0; i < 8; i++) {
1768 temp = (*vB).w[i-4];
1769 /* force positive in signed32, ok as we'll toss the bit away anyway */
1770 temp &= ~0x80000000;
1771 (*vS).h[AV_HINDEX(i)] = altivec_unsigned_saturate_16(temp, &tempsat);
1774 ALTIVEC_SET_SAT(sat);
1775 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1779 # Vector Reciprocal instructions, 6-122, 6-123, 6-131
1782 0.4,6.VS,11.0,16.VB,21.266:VX:av:vrefp %VD, %VB:Vector Reciprocal Estimate Floating Point
1786 for (i = 0; i < 4; i++) {
1787 sim_fpu_32to (&op, (*vB).w[i]);
1788 sim_fpu_div (&d, &sim_fpu_one, &op);
1789 sim_fpu_to32 (&f, &d);
1792 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1794 0.4,6.VS,11.0,16.VB,21.330:VX:av:vrsqrtefp %VD, %VB:Vector Reciprocal Square Root Estimate Floating Point
1797 sim_fpu op, i1, one, d;
1798 for (i = 0; i < 4; i++) {
1799 sim_fpu_32to (&op, (*vB).w[i]);
1800 sim_fpu_sqrt (&i1, &op);
1801 sim_fpu_div (&d, &sim_fpu_one, &i1);
1802 sim_fpu_to32 (&f, &d);
1805 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1809 # Vector Round instructions, 6-124 ... 6-127
1812 0.4,6.VS,11.0,16.VB,21.714:VX:av:vrfim %VD, %VB:Vector Round to Floating-Point Integer towards Minus Infinity
1816 for (i = 0; i < 4; i++) {
1817 sim_fpu_32to (&op, (*vB).w[i]);
1818 sim_fpu_round_32(&op, sim_fpu_round_down, sim_fpu_denorm_default);
1819 sim_fpu_to32 (&f, &op);
1822 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1824 0.4,6.VS,11.0,16.VB,21.522:VX:av:vrfin %VD, %VB:Vector Round to Floating-Point Integer Nearest
1828 for (i = 0; i < 4; i++) {
1829 sim_fpu_32to (&op, (*vB).w[i]);
1830 sim_fpu_round_32(&op, sim_fpu_round_near, sim_fpu_denorm_default);
1831 sim_fpu_to32 (&f, &op);
1834 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1836 0.4,6.VS,11.0,16.VB,21.650:VX:av:vrfip %VD, %VB:Vector Round to Floating-Point Integer towards Plus Infinity
1840 for (i = 0; i < 4; i++) {
1841 sim_fpu_32to (&op, (*vB).w[i]);
1842 sim_fpu_round_32(&op, sim_fpu_round_up, sim_fpu_denorm_default);
1843 sim_fpu_to32 (&f, &op);
1846 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1848 0.4,6.VS,11.0,16.VB,21.586:VX:av:vrfiz %VD, %VB:Vector Round to Floating-Point Integer towards Zero
1852 for (i = 0; i < 4; i++) {
1853 sim_fpu_32to (&op, (*vB).w[i]);
1854 sim_fpu_round_32(&op, sim_fpu_round_zero, sim_fpu_denorm_default);
1855 sim_fpu_to32 (&f, &op);
1858 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1862 # Vector Rotate Left instructions, 6-128 ... 6-130
1865 0.4,6.VS,11.VA,16.VB,21.4:VX:av:vrlb %VD, %VA, %VB:Vector Rotate Left Integer Byte
1868 for (i = 0; i < 16; i++) {
1869 temp = (unsigned16)(*vA).b[i] << (((*vB).b[i]) & 7);
1870 (*vS).b[i] = (temp & 0xff) | ((temp >> 8) & 0xff);
1872 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1874 0.4,6.VS,11.VA,16.VB,21.68:VX:av:vrlh %VD, %VA, %VB:Vector Rotate Left Integer Half Word
1877 for (i = 0; i < 8; i++) {
1878 temp = (unsigned32)(*vA).h[i] << (((*vB).h[i]) & 0xf);
1879 (*vS).h[i] = (temp & 0xffff) | ((temp >> 16) & 0xffff);
1881 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1883 0.4,6.VS,11.VA,16.VB,21.132:VX:av:vrlw %VD, %VA, %VB:Vector Rotate Left Integer Word
1886 for (i = 0; i < 4; i++) {
1887 temp = (unsigned64)(*vA).w[i] << (((*vB).w[i]) & 0x1f);
1888 (*vS).w[i] = (temp & 0xffffffff) | ((temp >> 32) & 0xffffffff);
1890 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1894 # Vector Conditional Select instruction, 6-133
1897 0.4,6.VS,11.VA,16.VB,21.VC,26.42:VAX:av:vsel %VD, %VA, %VB, %VC:Vector Conditional Select
1900 for (i = 0; i < 4; i++) {
1902 (*vS).w[i] = ((*vB).w[i] & c) | ((*vA).w[i] & ~c);
1904 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK | VC_BITMASK);
1907 # Vector Shift Left instructions, 6-134 ... 6-139
1910 0.4,6.VS,11.VA,16.VB,21.452:VX:av:vsl %VD, %VA, %VB:Vector Shift Left
1911 int sh, i, j, carry, new_carry;
1912 sh = (*vB).b[0] & 7; /* don't bother checking everything */
1914 for (j = 3; j >= 0; j--) {
1915 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
1919 new_carry = (*vA).w[i] >> (32 - sh);
1920 (*vS).w[i] = ((*vA).w[i] << sh) | carry;
1923 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1925 0.4,6.VS,11.VA,16.VB,21.260:VX:av:vslb %VD, %VA, %VB:Vector Shift Left Integer Byte
1927 for (i = 0; i < 16; i++) {
1928 sh = ((*vB).b[i]) & 7;
1929 (*vS).b[i] = (*vA).b[i] << sh;
1931 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1933 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
1935 for (j = 0, i = SH; i < 16; i++)
1936 (*vS).b[j++] = (*vA).b[i];
1937 for (i = 0; i < SH; i++)
1938 (*vS).b[j++] = (*vB).b[i];
1939 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1941 0.4,6.VS,11.VA,16.VB,21.324:VX:av:vslh %VD, %VA, %VB:Vector Shift Left Half Word
1943 for (i = 0; i < 8; i++) {
1944 sh = ((*vB).h[i]) & 0xf;
1945 (*vS).h[i] = (*vA).h[i] << sh;
1947 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1949 0.4,6.VS,11.VA,16.VB,21.1036:VX:av:vslo %VD, %VA, %VB:Vector Shift Left by Octet
1951 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
1952 sh = ((*vB).b[AV_BINDEX(15)] >> 3) & 0xf;
1954 sh = ((*vB).b[AV_BINDEX(0)] >> 3) & 0xf;
1955 for (i = 0; i < 16; i++) {
1957 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX(i + sh)];
1959 (*vS).b[AV_BINDEX(i)] = 0;
1961 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1963 0.4,6.VS,11.VA,16.VB,21.388:VX:av:vslw %VD, %VA, %VB:Vector Shift Left Integer Word
1965 for (i = 0; i < 4; i++) {
1966 sh = ((*vB).w[i]) & 0x1f;
1967 (*vS).w[i] = (*vA).w[i] << sh;
1969 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
1973 # Vector Splat instructions, 6-140 ... 6-145
1976 0.4,6.VS,11.UIMM,16.VB,21.524:VX:av:vspltb %VD, %VB, %UIMM:Vector Splat Byte
1979 b = (*vB).b[AV_BINDEX(UIMM & 0xf)];
1980 for (i = 0; i < 16; i++)
1982 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1984 0.4,6.VS,11.UIMM,16.VB,21.588:VX:av:vsplth %VD, %VB, %UIMM:Vector Splat Half Word
1987 h = (*vB).h[AV_HINDEX(UIMM & 0x7)];
1988 for (i = 0; i < 8; i++)
1990 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
1992 0.4,6.VS,11.SIMM,16.0,21.780:VX:av:vspltisb %VD, %SIMM:Vector Splat Immediate Signed Byte
1995 /* manual 5-bit signed extension */
1998 for (i = 0; i < 16; i++)
2000 PPC_INSN_VR(VS_BITMASK, 0);
2002 0.4,6.VS,11.SIMM,16.0,21.844:VX:av:vspltish %VD, %SIMM:Vector Splat Immediate Signed Half Word
2005 /* manual 5-bit signed extension */
2008 for (i = 0; i < 8; i++)
2010 PPC_INSN_VR(VS_BITMASK, 0);
2012 0.4,6.VS,11.SIMM,16.0,21.908:VX:av:vspltisw %VD, %SIMM:Vector Splat Immediate Signed Word
2015 /* manual 5-bit signed extension */
2018 for (i = 0; i < 4; i++)
2020 PPC_INSN_VR(VS_BITMASK, 0);
2022 0.4,6.VS,11.UIMM,16.VB,21.652:VX:av:vspltw %VD, %VB, %UIMM:Vector Splat Word
2025 w = (*vB).w[UIMM & 0x3];
2026 for (i = 0; i < 4; i++)
2028 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2032 # Vector Shift Right instructions, 6-146 ... 6-154
2035 0.4,6.VS,11.VA,16.VB,21.708:VX:av:vsr %VD, %VA, %VB:Vector Shift Right
2036 int sh, i, j, carry, new_carry;
2037 sh = (*vB).b[0] & 7; /* don't bother checking everything */
2039 for (j = 0; j < 4; j++) {
2040 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
2044 new_carry = (*vA).w[i] << (32 - sh);
2045 (*vS).w[i] = ((*vA).w[i] >> sh) | carry;
2048 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2050 0.4,6.VS,11.VA,16.VB,21.772:VX:av:vsrab %VD, %VA, %VB:Vector Shift Right Algebraic Byte
2053 for (i = 0; i < 16; i++) {
2054 sh = ((*vB).b[i]) & 7;
2055 a = (signed16)(signed8)(*vA).b[i];
2056 (*vS).b[i] = (a >> sh) & 0xff;
2058 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2060 0.4,6.VS,11.VA,16.VB,21.836:VX:av:vsrah %VD, %VA, %VB:Vector Shift Right Algebraic Half Word
2063 for (i = 0; i < 8; i++) {
2064 sh = ((*vB).h[i]) & 0xf;
2065 a = (signed32)(signed16)(*vA).h[i];
2066 (*vS).h[i] = (a >> sh) & 0xffff;
2068 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2070 0.4,6.VS,11.VA,16.VB,21.900:VX:av:vsraw %VD, %VA, %VB:Vector Shift Right Algebraic Word
2073 for (i = 0; i < 4; i++) {
2074 sh = ((*vB).w[i]) & 0xf;
2075 a = (signed64)(signed32)(*vA).w[i];
2076 (*vS).w[i] = (a >> sh) & 0xffffffff;
2078 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2080 0.4,6.VS,11.VA,16.VB,21.516:VX:av:vsrb %VD, %VA, %VB:Vector Shift Right Byte
2082 for (i = 0; i < 16; i++) {
2083 sh = ((*vB).b[i]) & 7;
2084 (*vS).b[i] = (*vA).b[i] >> sh;
2086 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2088 0.4,6.VS,11.VA,16.VB,21.580:VX:av:vsrh %VD, %VA, %VB:Vector Shift Right Half Word
2090 for (i = 0; i < 8; i++) {
2091 sh = ((*vB).h[i]) & 0xf;
2092 (*vS).h[i] = (*vA).h[i] >> sh;
2094 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2096 0.4,6.VS,11.VA,16.VB,21.1100:VX:av:vsro %VD, %VA, %VB:Vector Shift Right Octet
2098 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
2099 sh = ((*vB).b[AV_BINDEX(15)] >> 3) & 0xf;
2101 sh = ((*vB).b[AV_BINDEX(0)] >> 3) & 0xf;
2102 for (i = 0; i < 16; i++) {
2104 (*vS).b[AV_BINDEX(i)] = 0;
2106 (*vS).b[AV_BINDEX(i)] = (*vA).b[AV_BINDEX(i - sh)];
2108 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2110 0.4,6.VS,11.VA,16.VB,21.644:VX:av:vsrw %VD, %VA, %VB:Vector Shift Right Word
2112 for (i = 0; i < 4; i++) {
2113 sh = ((*vB).w[i]) & 0x1f;
2114 (*vS).w[i] = (*vA).w[i] >> sh;
2116 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2120 # Vector Subtract instructions, 6-155 ... 6-165
2123 0.4,6.VS,11.VA,16.VB,21.1408:VX:av:vsubcuw %VD, %VA, %VB:Vector Subtract Carryout Unsigned Word
2125 signed64 temp, a, b;
2126 for (i = 0; i < 4; i++) {
2127 a = (signed64)(unsigned32)(*vA).w[i];
2128 b = (signed64)(unsigned32)(*vB).w[i];
2130 (*vS).w[i] = ~(temp >> 32) & 1;
2132 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2134 0.4,6.VS,11.VA,16.VB,21.74:VX:av:vsubfp %VD, %VA, %VB:Vector Subtract Floating Point
2138 for (i = 0; i < 4; i++) {
2139 sim_fpu_32to (&a, (*vA).w[i]);
2140 sim_fpu_32to (&b, (*vB).w[i]);
2141 sim_fpu_sub (&d, &a, &b);
2142 sim_fpu_to32 (&f, &d);
2145 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2147 0.4,6.VS,11.VA,16.VB,21.1792:VX:av:vsubsbs %VD, %VA, %VB:Vector Subtract Signed Byte Saturate
2148 int i, sat, tempsat;
2151 for (i = 0; i < 16; i++) {
2152 temp = (signed16)(signed8)(*vA).b[i] - (signed16)(signed8)(*vB).b[i];
2153 (*vS).b[i] = altivec_signed_saturate_8(temp, &tempsat);
2156 ALTIVEC_SET_SAT(sat);
2157 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2159 0.4,6.VS,11.VA,16.VB,21.1856:VX:av:vsubshs %VD, %VA, %VB:Vector Subtract Signed Half Word Saturate
2160 int i, sat, tempsat;
2163 for (i = 0; i < 8; i++) {
2164 temp = (signed32)(signed16)(*vA).h[i] - (signed32)(signed16)(*vB).h[i];
2165 (*vS).h[i] = altivec_signed_saturate_16(temp, &tempsat);
2168 ALTIVEC_SET_SAT(sat);
2169 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2171 0.4,6.VS,11.VA,16.VB,21.1920:VX:av:vsubsws %VD, %VA, %VB:Vector Subtract Signed Word Saturate
2172 int i, sat, tempsat;
2175 for (i = 0; i < 4; i++) {
2176 temp = (signed64)(signed32)(*vA).w[i] - (signed64)(signed32)(*vB).w[i];
2177 (*vS).w[i] = altivec_signed_saturate_32(temp, &tempsat);
2180 ALTIVEC_SET_SAT(sat);
2181 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2183 0.4,6.VS,11.VA,16.VB,21.1024:VX:av:vsububm %VD, %VA, %VB:Vector Subtract Unsigned Byte Modulo
2185 for (i = 0; i < 16; i++)
2186 (*vS).b[i] = (*vA).b[i] - (*vB).b[i];
2187 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2189 0.4,6.VS,11.VA,16.VB,21.1536:VX:av:vsububs %VD, %VA, %VB:Vector Subtract Unsigned Byte Saturate
2190 int i, sat, tempsat;
2193 for (i = 0; i < 16; i++) {
2194 temp = (signed16)(unsigned8)(*vA).b[i] - (signed16)(unsigned8)(*vB).b[i];
2195 (*vS).b[i] = altivec_unsigned_saturate_8(temp, &tempsat);
2198 ALTIVEC_SET_SAT(sat);
2199 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2201 0.4,6.VS,11.VA,16.VB,21.1088:VX:av:vsubuhm %VD, %VA, %VB:Vector Subtract Unsigned Half Word Modulo
2203 for (i = 0; i < 8; i++)
2204 (*vS).h[i] = ((*vA).h[i] - (*vB).h[i]) & 0xffff;
2205 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2207 0.4,6.VS,11.VA,16.VB,21.1600:VX:av:vsubuhs %VD, %VA, %VB:Vector Subtract Unsigned Half Word Saturate
2208 int i, sat, tempsat;
2210 for (i = 0; i < 8; i++) {
2211 temp = (signed32)(unsigned16)(*vA).h[i] - (signed32)(unsigned16)(*vB).h[i];
2212 (*vS).h[i] = altivec_unsigned_saturate_16(temp, &tempsat);
2215 ALTIVEC_SET_SAT(sat);
2216 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2218 0.4,6.VS,11.VA,16.VB,21.1152:VX:av:vsubuwm %VD, %VA, %VB:Vector Subtract Unsigned Word Modulo
2220 for (i = 0; i < 4; i++)
2221 (*vS).w[i] = (*vA).w[i] - (*vB).w[i];
2222 PPC_INSN_VR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2224 0.4,6.VS,11.VA,16.VB,21.1664:VX:av:vsubuws %VD, %VA, %VB:Vector Subtract Unsigned Word Saturate
2225 int i, sat, tempsat;
2227 for (i = 0; i < 4; i++) {
2228 temp = (signed64)(unsigned32)(*vA).w[i] - (signed64)(unsigned32)(*vB).w[i];
2229 (*vS).w[i] = altivec_unsigned_saturate_32(temp, &tempsat);
2232 ALTIVEC_SET_SAT(sat);
2233 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2237 # Vector Sum instructions, 6-166 ... 6-170
2240 0.4,6.VS,11.VA,16.VB,21.1928:VX:av:vsumsws %VD, %VA, %VB:Vector Sum Across Signed Word Saturate
2243 temp = (signed64)(signed32)(*vB).w[3];
2244 for (i = 0; i < 4; i++)
2245 temp += (signed64)(signed32)(*vA).w[i];
2246 (*vS).w[3] = altivec_signed_saturate_32(temp, &sat);
2247 (*vS).w[0] = (*vS).w[1] = (*vS).w[2] = 0;
2248 ALTIVEC_SET_SAT(sat);
2249 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2251 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
2252 int i, j, sat, tempsat;
2254 for (j = 0; j < 4; j += 2) {
2255 temp = (signed64)(signed32)(*vB).w[j+1];
2256 temp += (signed64)(signed32)(*vA).w[j] + (signed64)(signed32)(*vA).w[j+1];
2257 (*vS).w[j+1] = altivec_signed_saturate_32(temp, &tempsat);
2260 (*vS).w[0] = (*vS).w[2] = 0;
2261 ALTIVEC_SET_SAT(sat);
2262 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2264 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
2265 int i, j, sat, tempsat;
2267 for (j = 0; j < 4; j++) {
2268 temp = (signed64)(signed32)(*vB).w[j];
2269 for (i = 0; i < 4; i++)
2270 temp += (signed64)(signed8)(*vA).b[i+(j*4)];
2271 (*vS).w[j] = altivec_signed_saturate_32(temp, &tempsat);
2274 ALTIVEC_SET_SAT(sat);
2275 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2277 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
2278 int i, j, sat, tempsat;
2280 for (j = 0; j < 4; j++) {
2281 temp = (signed64)(signed32)(*vB).w[j];
2282 for (i = 0; i < 2; i++)
2283 temp += (signed64)(signed16)(*vA).h[i+(j*2)];
2284 (*vS).w[j] = altivec_signed_saturate_32(temp, &tempsat);
2287 ALTIVEC_SET_SAT(sat);
2288 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2290 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
2291 int i, j, sat, tempsat;
2294 for (j = 0; j < 4; j++) {
2295 utemp = (signed64)(unsigned32)(*vB).w[j];
2296 for (i = 0; i < 4; i++)
2297 utemp += (signed64)(unsigned16)(*vA).b[i+(j*4)];
2299 (*vS).w[j] = altivec_unsigned_saturate_32(temp, &tempsat);
2302 ALTIVEC_SET_SAT(sat);
2303 PPC_INSN_VR_VSCR(VS_BITMASK, VA_BITMASK | VB_BITMASK);
2307 # Vector Unpack instructions, 6-171 ... 6-176
2310 0.4,6.VS,11.0,16.VB,21.846:VX:av:vupkhpx %VD, %VB:Vector Unpack High Pixel16
2313 for (i = 0; i < 4; i++) {
2314 h = (*vB).h[AV_HINDEX(i)];
2315 (*vS).w[i] = ((h & 0x8000) ? 0xff000000 : 0)
2316 | ((h & 0x7c00) << 6)
2317 | ((h & 0x03e0) << 3)
2320 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2322 0.4,6.VS,11.0,16.VB,21.526:VX:av:vupkhsb %VD, %VB:Vector Unpack High Signed Byte
2324 for (i = 0; i < 8; i++)
2325 (*vS).h[AV_HINDEX(i)] = (signed16)(signed8)(*vB).b[AV_BINDEX(i)];
2326 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2328 0.4,6.VS,11.0,16.VB,21.590:VX:av:vupkhsh %VD, %VB:Vector Unpack High Signed Half Word
2330 for (i = 0; i < 4; i++)
2331 (*vS).w[i] = (signed32)(signed16)(*vB).h[AV_HINDEX(i)];
2332 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2334 0.4,6.VS,11.0,16.VB,21.974:VX:av:vupklpx %VD, %VB:Vector Unpack Low Pixel16
2337 for (i = 0; i < 4; i++) {
2338 h = (*vB).h[AV_HINDEX(i + 4)];
2339 (*vS).w[i] = ((h & 0x8000) ? 0xff000000 : 0)
2340 | ((h & 0x7c00) << 6)
2341 | ((h & 0x03e0) << 3)
2344 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2346 0.4,6.VS,11.0,16.VB,21.654:VX:av:vupklsb %VD, %VB:Vector Unpack Low Signed Byte
2348 for (i = 0; i < 8; i++)
2349 (*vS).h[AV_HINDEX(i)] = (signed16)(signed8)(*vB).b[AV_BINDEX(i + 8)];
2350 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);
2352 0.4,6.VS,11.0,16.VB,21.718:VX:av:vupklsh %VD, %VB:Vector Unpack Low Signed Half Word
2354 for (i = 0; i < 4; i++)
2355 (*vS).w[i] = (signed32)(signed16)(*vB).h[AV_HINDEX(i + 4)];
2356 PPC_INSN_VR(VS_BITMASK, VB_BITMASK);