2 * PowerPC integer and vector emulation helpers for QEMU.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
23 #include "qemu/host-utils.h"
24 #include "qemu/main-loop.h"
26 #include "exec/helper-proto.h"
27 #include "crypto/aes.h"
28 #include "fpu/softfloat.h"
29 #include "qapi/error.h"
30 #include "qemu/guest-random.h"
31 #include "tcg/tcg-gvec-desc.h"
33 #include "helper_regs.h"
34 /*****************************************************************************/
35 /* Fixed point operations helpers */
37 static inline void helper_update_ov_legacy(CPUPPCState
*env
, int ov
)
40 env
->so
= env
->ov
= env
->ov32
= 1;
42 env
->ov
= env
->ov32
= 0;
46 target_ulong
helper_divweu(CPUPPCState
*env
, target_ulong ra
, target_ulong rb
,
52 uint64_t dividend
= (uint64_t)ra
<< 32;
53 uint64_t divisor
= (uint32_t)rb
;
55 if (unlikely(divisor
== 0)) {
58 rt
= dividend
/ divisor
;
59 overflow
= rt
> UINT32_MAX
;
62 if (unlikely(overflow
)) {
63 rt
= 0; /* Undefined */
67 helper_update_ov_legacy(env
, overflow
);
70 return (target_ulong
)rt
;
73 target_ulong
helper_divwe(CPUPPCState
*env
, target_ulong ra
, target_ulong rb
,
79 int64_t dividend
= (int64_t)ra
<< 32;
80 int64_t divisor
= (int64_t)((int32_t)rb
);
82 if (unlikely((divisor
== 0) ||
83 ((divisor
== -1ull) && (dividend
== INT64_MIN
)))) {
86 rt
= dividend
/ divisor
;
87 overflow
= rt
!= (int32_t)rt
;
90 if (unlikely(overflow
)) {
91 rt
= 0; /* Undefined */
95 helper_update_ov_legacy(env
, overflow
);
98 return (target_ulong
)rt
;
101 #if defined(TARGET_PPC64)
103 uint64_t helper_divdeu(CPUPPCState
*env
, uint64_t ra
, uint64_t rb
, uint32_t oe
)
108 if (unlikely(rb
== 0 || ra
>= rb
)) {
110 rt
= 0; /* Undefined */
112 divu128(&rt
, &ra
, rb
);
116 helper_update_ov_legacy(env
, overflow
);
122 uint64_t helper_divde(CPUPPCState
*env
, uint64_t rau
, uint64_t rbu
, uint32_t oe
)
125 int64_t ra
= (int64_t)rau
;
126 int64_t rb
= (int64_t)rbu
;
129 if (unlikely(rb
== 0 || uabs64(ra
) >= uabs64(rb
))) {
131 rt
= 0; /* Undefined */
133 divs128(&rt
, &ra
, rb
);
137 helper_update_ov_legacy(env
, overflow
);
146 #if defined(TARGET_PPC64)
147 /* if x = 0xab, returns 0xababababababababa */
148 #define pattern(x) (((x) & 0xff) * (~(target_ulong)0 / 0xff))
151 * subtract 1 from each byte, and with inverse, check if MSB is set at each
153 * i.e. ((0x00 - 0x01) & ~(0x00)) & 0x80
154 * (0xFF & 0xFF) & 0x80 = 0x80 (zero found)
156 #define haszero(v) (((v) - pattern(0x01)) & ~(v) & pattern(0x80))
158 /* When you XOR the pattern and there is a match, that byte will be zero */
159 #define hasvalue(x, n) (haszero((x) ^ pattern(n)))
161 uint32_t helper_cmpeqb(target_ulong ra
, target_ulong rb
)
163 return hasvalue(rb
, ra
) ? CRF_GT
: 0;
171 * Return a random number.
173 uint64_t helper_darn32(void)
178 if (qemu_guest_getrandom(&ret
, sizeof(ret
), &err
) < 0) {
179 qemu_log_mask(LOG_UNIMP
, "darn: Crypto failure: %s",
180 error_get_pretty(err
));
188 uint64_t helper_darn64(void)
193 if (qemu_guest_getrandom(&ret
, sizeof(ret
), &err
) < 0) {
194 qemu_log_mask(LOG_UNIMP
, "darn: Crypto failure: %s",
195 error_get_pretty(err
));
203 uint64_t helper_bpermd(uint64_t rs
, uint64_t rb
)
208 for (i
= 0; i
< 8; i
++) {
209 int index
= (rs
>> (i
* 8)) & 0xFF;
211 if (rb
& PPC_BIT(index
)) {
221 target_ulong
helper_cmpb(target_ulong rs
, target_ulong rb
)
223 target_ulong mask
= 0xff;
227 for (i
= 0; i
< sizeof(target_ulong
); i
++) {
228 if ((rs
& mask
) == (rb
& mask
)) {
236 /* shift right arithmetic helper */
237 target_ulong
helper_sraw(CPUPPCState
*env
, target_ulong value
,
242 if (likely(!(shift
& 0x20))) {
243 if (likely((uint32_t)shift
!= 0)) {
245 ret
= (int32_t)value
>> shift
;
246 if (likely(ret
>= 0 || (value
& ((1 << shift
) - 1)) == 0)) {
247 env
->ca32
= env
->ca
= 0;
249 env
->ca32
= env
->ca
= 1;
252 ret
= (int32_t)value
;
253 env
->ca32
= env
->ca
= 0;
256 ret
= (int32_t)value
>> 31;
257 env
->ca32
= env
->ca
= (ret
!= 0);
259 return (target_long
)ret
;
262 #if defined(TARGET_PPC64)
263 target_ulong
helper_srad(CPUPPCState
*env
, target_ulong value
,
268 if (likely(!(shift
& 0x40))) {
269 if (likely((uint64_t)shift
!= 0)) {
271 ret
= (int64_t)value
>> shift
;
272 if (likely(ret
>= 0 || (value
& ((1ULL << shift
) - 1)) == 0)) {
273 env
->ca32
= env
->ca
= 0;
275 env
->ca32
= env
->ca
= 1;
278 ret
= (int64_t)value
;
279 env
->ca32
= env
->ca
= 0;
282 ret
= (int64_t)value
>> 63;
283 env
->ca32
= env
->ca
= (ret
!= 0);
289 #if defined(TARGET_PPC64)
290 target_ulong
helper_popcntb(target_ulong val
)
292 /* Note that we don't fold past bytes */
293 val
= (val
& 0x5555555555555555ULL
) + ((val
>> 1) &
294 0x5555555555555555ULL
);
295 val
= (val
& 0x3333333333333333ULL
) + ((val
>> 2) &
296 0x3333333333333333ULL
);
297 val
= (val
& 0x0f0f0f0f0f0f0f0fULL
) + ((val
>> 4) &
298 0x0f0f0f0f0f0f0f0fULL
);
302 target_ulong
helper_popcntw(target_ulong val
)
304 /* Note that we don't fold past words. */
305 val
= (val
& 0x5555555555555555ULL
) + ((val
>> 1) &
306 0x5555555555555555ULL
);
307 val
= (val
& 0x3333333333333333ULL
) + ((val
>> 2) &
308 0x3333333333333333ULL
);
309 val
= (val
& 0x0f0f0f0f0f0f0f0fULL
) + ((val
>> 4) &
310 0x0f0f0f0f0f0f0f0fULL
);
311 val
= (val
& 0x00ff00ff00ff00ffULL
) + ((val
>> 8) &
312 0x00ff00ff00ff00ffULL
);
313 val
= (val
& 0x0000ffff0000ffffULL
) + ((val
>> 16) &
314 0x0000ffff0000ffffULL
);
318 target_ulong
helper_popcntb(target_ulong val
)
320 /* Note that we don't fold past bytes */
321 val
= (val
& 0x55555555) + ((val
>> 1) & 0x55555555);
322 val
= (val
& 0x33333333) + ((val
>> 2) & 0x33333333);
323 val
= (val
& 0x0f0f0f0f) + ((val
>> 4) & 0x0f0f0f0f);
328 uint64_t helper_CFUGED(uint64_t src
, uint64_t mask
)
331 * Instead of processing the mask bit-by-bit from the most significant to
332 * the least significant bit, as described in PowerISA, we'll handle it in
333 * blocks of 'n' zeros/ones from LSB to MSB. To avoid the decision to use
334 * ctz or cto, we negate the mask at the end of the loop.
336 target_ulong m
, left
= 0, right
= 0;
337 unsigned int n
, i
= 64;
338 bool bit
= false; /* tracks if we are processing zeros or ones */
340 if (mask
== 0 || mask
== -1) {
344 /* Processes the mask in blocks, from LSB to MSB */
346 /* Find how many bits we should take */
353 * Extracts 'n' trailing bits of src and put them on the leading 'n'
354 * bits of 'right' or 'left', pushing down the previously extracted
359 right
= ror64(right
| (src
& m
), n
);
361 left
= ror64(left
| (src
& m
), n
);
365 * Discards the processed bits from 'src' and 'mask'. Note that we are
366 * removing 'n' trailing zeros from 'mask', but the logical shift will
367 * add 'n' leading zeros back, so the population count of 'mask' is kept
378 * At the end, right was ror'ed ctpop(mask) times. To put it back in place,
379 * we'll shift it more 64-ctpop(mask) times.
384 n
= 64 - ctpop64(mask
);
387 return left
| (right
>> n
);
390 uint64_t helper_PDEPD(uint64_t src
, uint64_t mask
)
399 for (i
= 0; mask
!= 0; i
++) {
402 result
|= ((src
>> i
) & 1) << o
;
408 uint64_t helper_PEXTD(uint64_t src
, uint64_t mask
)
417 for (o
= 0; mask
!= 0; o
++) {
420 result
|= ((src
>> i
) & 1) << o
;
426 /*****************************************************************************/
427 /* Altivec extension helpers */
429 #define VECTOR_FOR_INORDER_I(index, element) \
430 for (index = 0; index < ARRAY_SIZE(r->element); index++)
432 #define VECTOR_FOR_INORDER_I(index, element) \
433 for (index = ARRAY_SIZE(r->element) - 1; index >= 0; index--)
436 /* Saturating arithmetic helpers. */
437 #define SATCVT(from, to, from_type, to_type, min, max) \
438 static inline to_type cvt##from##to(from_type x, int *sat) \
442 if (x < (from_type)min) { \
445 } else if (x > (from_type)max) { \
453 #define SATCVTU(from, to, from_type, to_type, min, max) \
454 static inline to_type cvt##from##to(from_type x, int *sat) \
458 if (x > (from_type)max) { \
466 SATCVT(sh
, sb
, int16_t, int8_t, INT8_MIN
, INT8_MAX
)
467 SATCVT(sw
, sh
, int32_t, int16_t, INT16_MIN
, INT16_MAX
)
468 SATCVT(sd
, sw
, int64_t, int32_t, INT32_MIN
, INT32_MAX
)
470 SATCVTU(uh
, ub
, uint16_t, uint8_t, 0, UINT8_MAX
)
471 SATCVTU(uw
, uh
, uint32_t, uint16_t, 0, UINT16_MAX
)
472 SATCVTU(ud
, uw
, uint64_t, uint32_t, 0, UINT32_MAX
)
473 SATCVT(sh
, ub
, int16_t, uint8_t, 0, UINT8_MAX
)
474 SATCVT(sw
, uh
, int32_t, uint16_t, 0, UINT16_MAX
)
475 SATCVT(sd
, uw
, int64_t, uint32_t, 0, UINT32_MAX
)
479 void helper_mtvscr(CPUPPCState
*env
, uint32_t vscr
)
481 ppc_store_vscr(env
, vscr
);
484 uint32_t helper_mfvscr(CPUPPCState
*env
)
486 return ppc_get_vscr(env
);
489 static inline void set_vscr_sat(CPUPPCState
*env
)
491 /* The choice of non-zero value is arbitrary. */
492 env
->vscr_sat
.u32
[0] = 1;
496 void helper_VPRTYBQ(ppc_avr_t
*r
, ppc_avr_t
*b
, uint32_t v
)
498 uint64_t res
= b
->u64
[0] ^ b
->u64
[1];
502 r
->VsrD(1) = res
& 1;
506 #define VARITHFP(suffix, func) \
507 void helper_v##suffix(CPUPPCState *env, ppc_avr_t *r, ppc_avr_t *a, \
512 for (i = 0; i < ARRAY_SIZE(r->f32); i++) { \
513 r->f32[i] = func(a->f32[i], b->f32[i], &env->vec_status); \
516 VARITHFP(addfp
, float32_add
)
517 VARITHFP(subfp
, float32_sub
)
518 VARITHFP(minfp
, float32_min
)
519 VARITHFP(maxfp
, float32_max
)
522 #define VARITHFPFMA(suffix, type) \
523 void helper_v##suffix(CPUPPCState *env, ppc_avr_t *r, ppc_avr_t *a, \
524 ppc_avr_t *b, ppc_avr_t *c) \
527 for (i = 0; i < ARRAY_SIZE(r->f32); i++) { \
528 r->f32[i] = float32_muladd(a->f32[i], c->f32[i], b->f32[i], \
529 type, &env->vec_status); \
532 VARITHFPFMA(maddfp
, 0);
533 VARITHFPFMA(nmsubfp
, float_muladd_negate_result
| float_muladd_negate_c
);
536 #define VARITHSAT_CASE(type, op, cvt, element) \
538 type result = (type)a->element[i] op (type)b->element[i]; \
539 r->element[i] = cvt(result, &sat); \
542 #define VARITHSAT_DO(name, op, optype, cvt, element) \
543 void helper_v##name(ppc_avr_t *r, ppc_avr_t *vscr_sat, \
544 ppc_avr_t *a, ppc_avr_t *b, uint32_t desc) \
549 for (i = 0; i < ARRAY_SIZE(r->element); i++) { \
550 VARITHSAT_CASE(optype, op, cvt, element); \
553 vscr_sat->u32[0] = 1; \
556 #define VARITHSAT_SIGNED(suffix, element, optype, cvt) \
557 VARITHSAT_DO(adds##suffix##s, +, optype, cvt, element) \
558 VARITHSAT_DO(subs##suffix##s, -, optype, cvt, element)
559 #define VARITHSAT_UNSIGNED(suffix, element, optype, cvt) \
560 VARITHSAT_DO(addu##suffix##s, +, optype, cvt, element) \
561 VARITHSAT_DO(subu##suffix##s, -, optype, cvt, element)
562 VARITHSAT_SIGNED(b
, s8
, int16_t, cvtshsb
)
563 VARITHSAT_SIGNED(h
, s16
, int32_t, cvtswsh
)
564 VARITHSAT_SIGNED(w
, s32
, int64_t, cvtsdsw
)
565 VARITHSAT_UNSIGNED(b
, u8
, uint16_t, cvtshub
)
566 VARITHSAT_UNSIGNED(h
, u16
, uint32_t, cvtswuh
)
567 VARITHSAT_UNSIGNED(w
, u32
, uint64_t, cvtsduw
)
568 #undef VARITHSAT_CASE
570 #undef VARITHSAT_SIGNED
571 #undef VARITHSAT_UNSIGNED
573 #define VAVG(name, element, etype) \
574 void helper_##name(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t v)\
578 for (i = 0; i < ARRAY_SIZE(r->element); i++) { \
579 etype x = (etype)a->element[i] + (etype)b->element[i] + 1; \
580 r->element[i] = x >> 1; \
584 VAVG(VAVGSB
, s8
, int16_t)
585 VAVG(VAVGUB
, u8
, uint16_t)
586 VAVG(VAVGSH
, s16
, int32_t)
587 VAVG(VAVGUH
, u16
, uint32_t)
588 VAVG(VAVGSW
, s32
, int64_t)
589 VAVG(VAVGUW
, u32
, uint64_t)
592 #define VABSDU(name, element) \
593 void helper_##name(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t v)\
597 for (i = 0; i < ARRAY_SIZE(r->element); i++) { \
598 r->element[i] = (a->element[i] > b->element[i]) ? \
599 (a->element[i] - b->element[i]) : \
600 (b->element[i] - a->element[i]); \
605 * VABSDU - Vector absolute difference unsigned
606 * name - instruction mnemonic suffix (b: byte, h: halfword, w: word)
607 * element - element type to access from vector
614 #define VCF(suffix, cvt, element) \
615 void helper_vcf##suffix(CPUPPCState *env, ppc_avr_t *r, \
616 ppc_avr_t *b, uint32_t uim) \
620 for (i = 0; i < ARRAY_SIZE(r->f32); i++) { \
621 float32 t = cvt(b->element[i], &env->vec_status); \
622 r->f32[i] = float32_scalbn(t, -uim, &env->vec_status); \
625 VCF(ux
, uint32_to_float32
, u32
)
626 VCF(sx
, int32_to_float32
, s32
)
629 #define VCMPNEZ(NAME, ELEM) \
630 void helper_##NAME(ppc_vsr_t *t, ppc_vsr_t *a, ppc_vsr_t *b, uint32_t desc) \
632 for (int i = 0; i < ARRAY_SIZE(t->ELEM); i++) { \
633 t->ELEM[i] = ((a->ELEM[i] == 0) || (b->ELEM[i] == 0) || \
634 (a->ELEM[i] != b->ELEM[i])) ? -1 : 0; \
637 VCMPNEZ(VCMPNEZB
, u8
)
638 VCMPNEZ(VCMPNEZH
, u16
)
639 VCMPNEZ(VCMPNEZW
, u32
)
642 #define VCMPFP_DO(suffix, compare, order, record) \
643 void helper_vcmp##suffix(CPUPPCState *env, ppc_avr_t *r, \
644 ppc_avr_t *a, ppc_avr_t *b) \
646 uint32_t ones = (uint32_t)-1; \
647 uint32_t all = ones; \
651 for (i = 0; i < ARRAY_SIZE(r->f32); i++) { \
653 FloatRelation rel = \
654 float32_compare_quiet(a->f32[i], b->f32[i], \
656 if (rel == float_relation_unordered) { \
658 } else if (rel compare order) { \
663 r->u32[i] = result; \
668 env->crf[6] = ((all != 0) << 3) | ((none == 0) << 1); \
671 #define VCMPFP(suffix, compare, order) \
672 VCMPFP_DO(suffix, compare, order, 0) \
673 VCMPFP_DO(suffix##_dot, compare, order, 1)
674 VCMPFP(eqfp
, ==, float_relation_equal
)
675 VCMPFP(gefp
, !=, float_relation_less
)
676 VCMPFP(gtfp
, ==, float_relation_greater
)
680 static inline void vcmpbfp_internal(CPUPPCState
*env
, ppc_avr_t
*r
,
681 ppc_avr_t
*a
, ppc_avr_t
*b
, int record
)
686 for (i
= 0; i
< ARRAY_SIZE(r
->f32
); i
++) {
687 FloatRelation le_rel
= float32_compare_quiet(a
->f32
[i
], b
->f32
[i
],
689 if (le_rel
== float_relation_unordered
) {
690 r
->u32
[i
] = 0xc0000000;
693 float32 bneg
= float32_chs(b
->f32
[i
]);
694 FloatRelation ge_rel
= float32_compare_quiet(a
->f32
[i
], bneg
,
696 int le
= le_rel
!= float_relation_greater
;
697 int ge
= ge_rel
!= float_relation_less
;
699 r
->u32
[i
] = ((!le
) << 31) | ((!ge
) << 30);
700 all_in
|= (!le
| !ge
);
704 env
->crf
[6] = (all_in
== 0) << 1;
708 void helper_vcmpbfp(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
710 vcmpbfp_internal(env
, r
, a
, b
, 0);
713 void helper_vcmpbfp_dot(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
,
716 vcmpbfp_internal(env
, r
, a
, b
, 1);
719 #define VCT(suffix, satcvt, element) \
720 void helper_vct##suffix(CPUPPCState *env, ppc_avr_t *r, \
721 ppc_avr_t *b, uint32_t uim) \
725 float_status s = env->vec_status; \
727 set_float_rounding_mode(float_round_to_zero, &s); \
728 for (i = 0; i < ARRAY_SIZE(r->f32); i++) { \
729 if (float32_is_any_nan(b->f32[i])) { \
732 float64 t = float32_to_float64(b->f32[i], &s); \
735 t = float64_scalbn(t, uim, &s); \
736 j = float64_to_int64(t, &s); \
737 r->element[i] = satcvt(j, &sat); \
744 VCT(uxs
, cvtsduw
, u32
)
745 VCT(sxs
, cvtsdsw
, s32
)
748 typedef int64_t do_ger(uint32_t, uint32_t, uint32_t);
750 static int64_t ger_rank8(uint32_t a
, uint32_t b
, uint32_t mask
)
753 for (int i
= 0; i
< 8; i
++, mask
>>= 1) {
755 psum
+= (int64_t)sextract32(a
, 4 * i
, 4) * sextract32(b
, 4 * i
, 4);
761 static int64_t ger_rank4(uint32_t a
, uint32_t b
, uint32_t mask
)
764 for (int i
= 0; i
< 4; i
++, mask
>>= 1) {
766 psum
+= sextract32(a
, 8 * i
, 8) * (int64_t)extract32(b
, 8 * i
, 8);
772 static int64_t ger_rank2(uint32_t a
, uint32_t b
, uint32_t mask
)
775 for (int i
= 0; i
< 2; i
++, mask
>>= 1) {
777 psum
+= (int64_t)sextract32(a
, 16 * i
, 16) *
778 sextract32(b
, 16 * i
, 16);
784 static void xviger(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
, ppc_acc_t
*at
,
785 uint32_t mask
, bool sat
, bool acc
, do_ger ger
)
787 uint8_t pmsk
= FIELD_EX32(mask
, GER_MSK
, PMSK
),
788 xmsk
= FIELD_EX32(mask
, GER_MSK
, XMSK
),
789 ymsk
= FIELD_EX32(mask
, GER_MSK
, YMSK
);
790 uint8_t xmsk_bit
, ymsk_bit
;
793 for (i
= 0, xmsk_bit
= 1 << 3; i
< 4; i
++, xmsk_bit
>>= 1) {
794 for (j
= 0, ymsk_bit
= 1 << 3; j
< 4; j
++, ymsk_bit
>>= 1) {
795 if ((xmsk_bit
& xmsk
) && (ymsk_bit
& ymsk
)) {
796 psum
= ger(a
->VsrW(i
), b
->VsrW(j
), pmsk
);
798 psum
+= at
[i
].VsrSW(j
);
800 if (sat
&& psum
> INT32_MAX
) {
802 at
[i
].VsrSW(j
) = INT32_MAX
;
803 } else if (sat
&& psum
< INT32_MIN
) {
805 at
[i
].VsrSW(j
) = INT32_MIN
;
807 at
[i
].VsrSW(j
) = (int32_t) psum
;
817 void helper_XVI4GER8(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
818 ppc_acc_t
*at
, uint32_t mask
)
820 xviger(env
, a
, b
, at
, mask
, false, false, ger_rank8
);
824 void helper_XVI4GER8PP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
825 ppc_acc_t
*at
, uint32_t mask
)
827 xviger(env
, a
, b
, at
, mask
, false, true, ger_rank8
);
831 void helper_XVI8GER4(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
832 ppc_acc_t
*at
, uint32_t mask
)
834 xviger(env
, a
, b
, at
, mask
, false, false, ger_rank4
);
838 void helper_XVI8GER4PP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
839 ppc_acc_t
*at
, uint32_t mask
)
841 xviger(env
, a
, b
, at
, mask
, false, true, ger_rank4
);
845 void helper_XVI8GER4SPP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
846 ppc_acc_t
*at
, uint32_t mask
)
848 xviger(env
, a
, b
, at
, mask
, true, true, ger_rank4
);
852 void helper_XVI16GER2(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
853 ppc_acc_t
*at
, uint32_t mask
)
855 xviger(env
, a
, b
, at
, mask
, false, false, ger_rank2
);
859 void helper_XVI16GER2S(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
860 ppc_acc_t
*at
, uint32_t mask
)
862 xviger(env
, a
, b
, at
, mask
, true, false, ger_rank2
);
866 void helper_XVI16GER2PP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
867 ppc_acc_t
*at
, uint32_t mask
)
869 xviger(env
, a
, b
, at
, mask
, false, true, ger_rank2
);
873 void helper_XVI16GER2SPP(CPUPPCState
*env
, ppc_vsr_t
*a
, ppc_vsr_t
*b
,
874 ppc_acc_t
*at
, uint32_t mask
)
876 xviger(env
, a
, b
, at
, mask
, true, true, ger_rank2
);
879 target_ulong
helper_vclzlsbb(ppc_avr_t
*r
)
881 target_ulong count
= 0;
883 for (i
= 0; i
< ARRAY_SIZE(r
->u8
); i
++) {
884 if (r
->VsrB(i
) & 0x01) {
892 target_ulong
helper_vctzlsbb(ppc_avr_t
*r
)
894 target_ulong count
= 0;
896 for (i
= ARRAY_SIZE(r
->u8
) - 1; i
>= 0; i
--) {
897 if (r
->VsrB(i
) & 0x01) {
905 void helper_VMHADDSHS(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
,
906 ppc_avr_t
*b
, ppc_avr_t
*c
)
911 for (i
= 0; i
< ARRAY_SIZE(r
->s16
); i
++) {
912 int32_t prod
= a
->s16
[i
] * b
->s16
[i
];
913 int32_t t
= (int32_t)c
->s16
[i
] + (prod
>> 15);
915 r
->s16
[i
] = cvtswsh(t
, &sat
);
923 void helper_VMHRADDSHS(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
,
924 ppc_avr_t
*b
, ppc_avr_t
*c
)
929 for (i
= 0; i
< ARRAY_SIZE(r
->s16
); i
++) {
930 int32_t prod
= a
->s16
[i
] * b
->s16
[i
] + 0x00004000;
931 int32_t t
= (int32_t)c
->s16
[i
] + (prod
>> 15);
932 r
->s16
[i
] = cvtswsh(t
, &sat
);
940 void helper_VMLADDUHM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
,
945 for (i
= 0; i
< ARRAY_SIZE(r
->s16
); i
++) {
946 int32_t prod
= a
->s16
[i
] * b
->s16
[i
];
947 r
->s16
[i
] = (int16_t) (prod
+ c
->s16
[i
]);
951 #define VMRG_DO(name, element, access, ofs) \
952 void helper_v##name(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) \
955 int i, half = ARRAY_SIZE(r->element) / 2; \
957 for (i = 0; i < half; i++) { \
958 result.access(i * 2 + 0) = a->access(i + ofs); \
959 result.access(i * 2 + 1) = b->access(i + ofs); \
964 #define VMRG(suffix, element, access) \
965 VMRG_DO(mrgl##suffix, element, access, half) \
966 VMRG_DO(mrgh##suffix, element, access, 0)
973 void helper_VMSUMMBM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
978 for (i
= 0; i
< ARRAY_SIZE(r
->s8
); i
++) {
979 prod
[i
] = (int32_t)a
->s8
[i
] * b
->u8
[i
];
982 VECTOR_FOR_INORDER_I(i
, s32
) {
983 r
->s32
[i
] = c
->s32
[i
] + prod
[4 * i
] + prod
[4 * i
+ 1] +
984 prod
[4 * i
+ 2] + prod
[4 * i
+ 3];
988 void helper_VMSUMSHM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
993 for (i
= 0; i
< ARRAY_SIZE(r
->s16
); i
++) {
994 prod
[i
] = a
->s16
[i
] * b
->s16
[i
];
997 VECTOR_FOR_INORDER_I(i
, s32
) {
998 r
->s32
[i
] = c
->s32
[i
] + prod
[2 * i
] + prod
[2 * i
+ 1];
1002 void helper_VMSUMSHS(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
,
1003 ppc_avr_t
*b
, ppc_avr_t
*c
)
1009 for (i
= 0; i
< ARRAY_SIZE(r
->s16
); i
++) {
1010 prod
[i
] = (int32_t)a
->s16
[i
] * b
->s16
[i
];
1013 VECTOR_FOR_INORDER_I(i
, s32
) {
1014 int64_t t
= (int64_t)c
->s32
[i
] + prod
[2 * i
] + prod
[2 * i
+ 1];
1016 r
->u32
[i
] = cvtsdsw(t
, &sat
);
1024 void helper_VMSUMUBM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
1029 for (i
= 0; i
< ARRAY_SIZE(r
->u8
); i
++) {
1030 prod
[i
] = a
->u8
[i
] * b
->u8
[i
];
1033 VECTOR_FOR_INORDER_I(i
, u32
) {
1034 r
->u32
[i
] = c
->u32
[i
] + prod
[4 * i
] + prod
[4 * i
+ 1] +
1035 prod
[4 * i
+ 2] + prod
[4 * i
+ 3];
1039 void helper_VMSUMUHM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
1044 for (i
= 0; i
< ARRAY_SIZE(r
->u16
); i
++) {
1045 prod
[i
] = a
->u16
[i
] * b
->u16
[i
];
1048 VECTOR_FOR_INORDER_I(i
, u32
) {
1049 r
->u32
[i
] = c
->u32
[i
] + prod
[2 * i
] + prod
[2 * i
+ 1];
1053 void helper_VMSUMUHS(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
,
1054 ppc_avr_t
*b
, ppc_avr_t
*c
)
1060 for (i
= 0; i
< ARRAY_SIZE(r
->u16
); i
++) {
1061 prod
[i
] = a
->u16
[i
] * b
->u16
[i
];
1064 VECTOR_FOR_INORDER_I(i
, s32
) {
1065 uint64_t t
= (uint64_t)c
->u32
[i
] + prod
[2 * i
] + prod
[2 * i
+ 1];
1067 r
->u32
[i
] = cvtuduw(t
, &sat
);
1075 #define VMUL_DO_EVN(name, mul_element, mul_access, prod_access, cast) \
1076 void helper_V##name(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) \
1080 for (i = 0; i < ARRAY_SIZE(r->mul_element); i += 2) { \
1081 r->prod_access(i >> 1) = (cast)a->mul_access(i) * \
1082 (cast)b->mul_access(i); \
1086 #define VMUL_DO_ODD(name, mul_element, mul_access, prod_access, cast) \
1087 void helper_V##name(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) \
1091 for (i = 0; i < ARRAY_SIZE(r->mul_element); i += 2) { \
1092 r->prod_access(i >> 1) = (cast)a->mul_access(i + 1) * \
1093 (cast)b->mul_access(i + 1); \
1097 #define VMUL(suffix, mul_element, mul_access, prod_access, cast) \
1098 VMUL_DO_EVN(MULE##suffix, mul_element, mul_access, prod_access, cast) \
1099 VMUL_DO_ODD(MULO##suffix, mul_element, mul_access, prod_access, cast)
1100 VMUL(SB
, s8
, VsrSB
, VsrSH
, int16_t)
1101 VMUL(SH
, s16
, VsrSH
, VsrSW
, int32_t)
1102 VMUL(SW
, s32
, VsrSW
, VsrSD
, int64_t)
1103 VMUL(UB
, u8
, VsrB
, VsrH
, uint16_t)
1104 VMUL(UH
, u16
, VsrH
, VsrW
, uint32_t)
1105 VMUL(UW
, u32
, VsrW
, VsrD
, uint64_t)
1110 void helper_XXPERMX(ppc_vsr_t
*t
, ppc_vsr_t
*s0
, ppc_vsr_t
*s1
, ppc_vsr_t
*pcv
,
1114 ppc_vsr_t tmp
= { .u64
= {0, 0} };
1116 for (i
= 0; i
< ARRAY_SIZE(t
->u8
); i
++) {
1117 if ((pcv
->VsrB(i
) >> 5) == uim
) {
1118 idx
= pcv
->VsrB(i
) & 0x1f;
1119 if (idx
< ARRAY_SIZE(t
->u8
)) {
1120 tmp
.VsrB(i
) = s0
->VsrB(idx
);
1122 tmp
.VsrB(i
) = s1
->VsrB(idx
- ARRAY_SIZE(t
->u8
));
1130 void helper_VDIVSQ(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1132 Int128 neg1
= int128_makes64(-1);
1133 Int128 int128_min
= int128_make128(0, INT64_MIN
);
1134 if (likely(int128_nz(b
->s128
) &&
1135 (int128_ne(a
->s128
, int128_min
) || int128_ne(b
->s128
, neg1
)))) {
1136 t
->s128
= int128_divs(a
->s128
, b
->s128
);
1138 t
->s128
= a
->s128
; /* Undefined behavior */
1142 void helper_VDIVUQ(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1144 if (int128_nz(b
->s128
)) {
1145 t
->s128
= int128_divu(a
->s128
, b
->s128
);
1147 t
->s128
= a
->s128
; /* Undefined behavior */
1151 void helper_VDIVESD(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1156 for (i
= 0; i
< 2; i
++) {
1159 if (unlikely((high
== INT64_MIN
&& b
->s64
[i
] == -1) || !b
->s64
[i
])) {
1160 t
->s64
[i
] = a
->s64
[i
]; /* Undefined behavior */
1162 divs128(&low
, &high
, b
->s64
[i
]);
1168 void helper_VDIVEUD(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1172 for (i
= 0; i
< 2; i
++) {
1175 if (unlikely(!b
->u64
[i
])) {
1176 t
->u64
[i
] = a
->u64
[i
]; /* Undefined behavior */
1178 divu128(&low
, &high
, b
->u64
[i
]);
1184 void helper_VDIVESQ(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1187 Int128 int128_min
= int128_make128(0, INT64_MIN
);
1188 Int128 neg1
= int128_makes64(-1);
1191 low
= int128_zero();
1192 if (unlikely(!int128_nz(b
->s128
) ||
1193 (int128_eq(b
->s128
, neg1
) && int128_eq(high
, int128_min
)))) {
1194 t
->s128
= a
->s128
; /* Undefined behavior */
1196 divs256(&low
, &high
, b
->s128
);
1201 void helper_VDIVEUQ(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1206 low
= int128_zero();
1207 if (unlikely(!int128_nz(b
->s128
))) {
1208 t
->s128
= a
->s128
; /* Undefined behavior */
1210 divu256(&low
, &high
, b
->s128
);
1215 void helper_VMODSQ(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1217 Int128 neg1
= int128_makes64(-1);
1218 Int128 int128_min
= int128_make128(0, INT64_MIN
);
1219 if (likely(int128_nz(b
->s128
) &&
1220 (int128_ne(a
->s128
, int128_min
) || int128_ne(b
->s128
, neg1
)))) {
1221 t
->s128
= int128_rems(a
->s128
, b
->s128
);
1223 t
->s128
= int128_zero(); /* Undefined behavior */
1227 void helper_VMODUQ(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1229 if (likely(int128_nz(b
->s128
))) {
1230 t
->s128
= int128_remu(a
->s128
, b
->s128
);
1232 t
->s128
= int128_zero(); /* Undefined behavior */
1236 void helper_VPERM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
1241 for (i
= 0; i
< ARRAY_SIZE(r
->u8
); i
++) {
1242 int s
= c
->VsrB(i
) & 0x1f;
1243 int index
= s
& 0xf;
1246 result
.VsrB(i
) = b
->VsrB(index
);
1248 result
.VsrB(i
) = a
->VsrB(index
);
1254 void helper_VPERMR(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
1259 for (i
= 0; i
< ARRAY_SIZE(r
->u8
); i
++) {
1260 int s
= c
->VsrB(i
) & 0x1f;
1261 int index
= 15 - (s
& 0xf);
1264 result
.VsrB(i
) = a
->VsrB(index
);
1266 result
.VsrB(i
) = b
->VsrB(index
);
1272 #define XXGENPCV_BE_EXP(NAME, SZ) \
1273 void glue(helper_, glue(NAME, _be_exp))(ppc_vsr_t *t, ppc_vsr_t *b) \
1277 /* Initialize tmp with the result of an all-zeros mask */ \
1278 tmp.VsrD(0) = 0x1011121314151617; \
1279 tmp.VsrD(1) = 0x18191A1B1C1D1E1F; \
1281 /* Iterate over the most significant byte of each element */ \
1282 for (int i = 0, j = 0; i < ARRAY_SIZE(b->u8); i += SZ) { \
1283 if (b->VsrB(i) & 0x80) { \
1284 /* Update each byte of the element */ \
1285 for (int k = 0; k < SZ; k++) { \
1286 tmp.VsrB(i + k) = j + k; \
1295 #define XXGENPCV_BE_COMP(NAME, SZ) \
1296 void glue(helper_, glue(NAME, _be_comp))(ppc_vsr_t *t, ppc_vsr_t *b)\
1298 ppc_vsr_t tmp = { .u64 = { 0, 0 } }; \
1300 /* Iterate over the most significant byte of each element */ \
1301 for (int i = 0, j = 0; i < ARRAY_SIZE(b->u8); i += SZ) { \
1302 if (b->VsrB(i) & 0x80) { \
1303 /* Update each byte of the element */ \
1304 for (int k = 0; k < SZ; k++) { \
1305 tmp.VsrB(j + k) = i + k; \
1314 #define XXGENPCV_LE_EXP(NAME, SZ) \
1315 void glue(helper_, glue(NAME, _le_exp))(ppc_vsr_t *t, ppc_vsr_t *b) \
1319 /* Initialize tmp with the result of an all-zeros mask */ \
1320 tmp.VsrD(0) = 0x1F1E1D1C1B1A1918; \
1321 tmp.VsrD(1) = 0x1716151413121110; \
1323 /* Iterate over the most significant byte of each element */ \
1324 for (int i = 0, j = 0; i < ARRAY_SIZE(b->u8); i += SZ) { \
1325 /* Reverse indexing of "i" */ \
1326 const int idx = ARRAY_SIZE(b->u8) - i - SZ; \
1327 if (b->VsrB(idx) & 0x80) { \
1328 /* Update each byte of the element */ \
1329 for (int k = 0, rk = SZ - 1; k < SZ; k++, rk--) { \
1330 tmp.VsrB(idx + rk) = j + k; \
1339 #define XXGENPCV_LE_COMP(NAME, SZ) \
1340 void glue(helper_, glue(NAME, _le_comp))(ppc_vsr_t *t, ppc_vsr_t *b)\
1342 ppc_vsr_t tmp = { .u64 = { 0, 0 } }; \
1344 /* Iterate over the most significant byte of each element */ \
1345 for (int i = 0, j = 0; i < ARRAY_SIZE(b->u8); i += SZ) { \
1346 if (b->VsrB(ARRAY_SIZE(b->u8) - i - SZ) & 0x80) { \
1347 /* Update each byte of the element */ \
1348 for (int k = 0, rk = SZ - 1; k < SZ; k++, rk--) { \
1349 /* Reverse indexing of "j" */ \
1350 const int idx = ARRAY_SIZE(b->u8) - j - SZ; \
1351 tmp.VsrB(idx + rk) = i + k; \
1360 #define XXGENPCV(NAME, SZ) \
1361 XXGENPCV_BE_EXP(NAME, SZ) \
1362 XXGENPCV_BE_COMP(NAME, SZ) \
1363 XXGENPCV_LE_EXP(NAME, SZ) \
1364 XXGENPCV_LE_COMP(NAME, SZ) \
1366 XXGENPCV(XXGENPCVBM, 1)
1367 XXGENPCV(XXGENPCVHM
, 2)
1368 XXGENPCV(XXGENPCVWM
, 4)
1369 XXGENPCV(XXGENPCVDM
, 8)
1371 #undef XXGENPCV_BE_EXP
1372 #undef XXGENPCV_BE_COMP
1373 #undef XXGENPCV_LE_EXP
1374 #undef XXGENPCV_LE_COMP
1378 #define VBPERMQ_INDEX(avr, i) ((avr)->u8[(i)])
1379 #define VBPERMD_INDEX(i) (i)
1380 #define VBPERMQ_DW(index) (((index) & 0x40) != 0)
1382 #define VBPERMQ_INDEX(avr, i) ((avr)->u8[15 - (i)])
1383 #define VBPERMD_INDEX(i) (1 - i)
1384 #define VBPERMQ_DW(index) (((index) & 0x40) == 0)
1386 #define EXTRACT_BIT(avr, i, index) \
1387 (extract64((avr)->VsrD(i), 63 - index, 1))
1389 void helper_vbpermd(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1392 ppc_avr_t result
= { .u64
= { 0, 0 } };
1393 VECTOR_FOR_INORDER_I(i
, u64
) {
1394 for (j
= 0; j
< 8; j
++) {
1395 int index
= VBPERMQ_INDEX(b
, (i
* 8) + j
);
1396 if (index
< 64 && EXTRACT_BIT(a
, i
, index
)) {
1397 result
.u64
[VBPERMD_INDEX(i
)] |= (0x80 >> j
);
1404 void helper_vbpermq(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1409 VECTOR_FOR_INORDER_I(i
, u8
) {
1410 int index
= VBPERMQ_INDEX(b
, i
);
1413 uint64_t mask
= (1ull << (63 - (index
& 0x3F)));
1414 if (a
->u64
[VBPERMQ_DW(index
)] & mask
) {
1415 perm
|= (0x8000 >> i
);
1424 #undef VBPERMQ_INDEX
1427 #define PMSUM(name, srcfld, trgfld, trgtyp) \
1428 void helper_##name(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) \
1431 trgtyp prod[sizeof(ppc_avr_t) / sizeof(a->srcfld[0])]; \
1433 VECTOR_FOR_INORDER_I(i, srcfld) { \
1435 for (j = 0; j < sizeof(a->srcfld[0]) * 8; j++) { \
1436 if (a->srcfld[i] & (1ull << j)) { \
1437 prod[i] ^= ((trgtyp)b->srcfld[i] << j); \
1442 VECTOR_FOR_INORDER_I(i, trgfld) { \
1443 r->trgfld[i] = prod[2 * i] ^ prod[2 * i + 1]; \
1447 PMSUM(vpmsumb
, u8
, u16
, uint16_t)
1448 PMSUM(vpmsumh
, u16
, u32
, uint32_t)
1449 PMSUM(vpmsumw
, u32
, u64
, uint64_t)
1451 void helper_VPMSUMD(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1454 Int128 tmp
, prod
[2] = {int128_zero(), int128_zero()};
1456 for (j
= 0; j
< 64; j
++) {
1457 for (i
= 0; i
< ARRAY_SIZE(r
->u64
); i
++) {
1458 if (a
->VsrD(i
) & (1ull << j
)) {
1459 tmp
= int128_make64(b
->VsrD(i
));
1460 tmp
= int128_lshift(tmp
, j
);
1461 prod
[i
] = int128_xor(prod
[i
], tmp
);
1466 r
->s128
= int128_xor(prod
[0], prod
[1]);
1474 void helper_vpkpx(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1479 const ppc_avr_t
*x
[2] = { a
, b
};
1481 const ppc_avr_t
*x
[2] = { b
, a
};
1484 VECTOR_FOR_INORDER_I(i
, u64
) {
1485 VECTOR_FOR_INORDER_I(j
, u32
) {
1486 uint32_t e
= x
[i
]->u32
[j
];
1488 result
.u16
[4 * i
+ j
] = (((e
>> 9) & 0xfc00) |
1489 ((e
>> 6) & 0x3e0) |
1496 #define VPK(suffix, from, to, cvt, dosat) \
1497 void helper_vpk##suffix(CPUPPCState *env, ppc_avr_t *r, \
1498 ppc_avr_t *a, ppc_avr_t *b) \
1503 ppc_avr_t *a0 = PKBIG ? a : b; \
1504 ppc_avr_t *a1 = PKBIG ? b : a; \
1506 VECTOR_FOR_INORDER_I(i, from) { \
1507 result.to[i] = cvt(a0->from[i], &sat); \
1508 result.to[i + ARRAY_SIZE(r->from)] = cvt(a1->from[i], &sat);\
1511 if (dosat && sat) { \
1512 set_vscr_sat(env); \
1516 VPK(shss
, s16
, s8
, cvtshsb
, 1)
1517 VPK(shus
, s16
, u8
, cvtshub
, 1)
1518 VPK(swss
, s32
, s16
, cvtswsh
, 1)
1519 VPK(swus
, s32
, u16
, cvtswuh
, 1)
1520 VPK(sdss
, s64
, s32
, cvtsdsw
, 1)
1521 VPK(sdus
, s64
, u32
, cvtsduw
, 1)
1522 VPK(uhus
, u16
, u8
, cvtuhub
, 1)
1523 VPK(uwus
, u32
, u16
, cvtuwuh
, 1)
1524 VPK(udus
, u64
, u32
, cvtuduw
, 1)
1525 VPK(uhum
, u16
, u8
, I
, 0)
1526 VPK(uwum
, u32
, u16
, I
, 0)
1527 VPK(udum
, u64
, u32
, I
, 0)
1532 void helper_vrefp(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*b
)
1536 for (i
= 0; i
< ARRAY_SIZE(r
->f32
); i
++) {
1537 r
->f32
[i
] = float32_div(float32_one
, b
->f32
[i
], &env
->vec_status
);
1541 #define VRFI(suffix, rounding) \
1542 void helper_vrfi##suffix(CPUPPCState *env, ppc_avr_t *r, \
1546 float_status s = env->vec_status; \
1548 set_float_rounding_mode(rounding, &s); \
1549 for (i = 0; i < ARRAY_SIZE(r->f32); i++) { \
1550 r->f32[i] = float32_round_to_int (b->f32[i], &s); \
1553 VRFI(n
, float_round_nearest_even
)
1554 VRFI(m
, float_round_down
)
1555 VRFI(p
, float_round_up
)
1556 VRFI(z
, float_round_to_zero
)
1559 void helper_vrsqrtefp(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*b
)
1563 for (i
= 0; i
< ARRAY_SIZE(r
->f32
); i
++) {
1564 float32 t
= float32_sqrt(b
->f32
[i
], &env
->vec_status
);
1566 r
->f32
[i
] = float32_div(float32_one
, t
, &env
->vec_status
);
1570 #define VRLMI(name, size, element, insert) \
1571 void helper_##name(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t desc) \
1574 for (i = 0; i < ARRAY_SIZE(r->element); i++) { \
1575 uint##size##_t src1 = a->element[i]; \
1576 uint##size##_t src2 = b->element[i]; \
1577 uint##size##_t src3 = r->element[i]; \
1578 uint##size##_t begin, end, shift, mask, rot_val; \
1580 shift = extract##size(src2, 0, 6); \
1581 end = extract##size(src2, 8, 6); \
1582 begin = extract##size(src2, 16, 6); \
1583 rot_val = rol##size(src1, shift); \
1584 mask = mask_u##size(begin, end); \
1586 r->element[i] = (rot_val & mask) | (src3 & ~mask); \
1588 r->element[i] = (rot_val & mask); \
1593 VRLMI(VRLDMI
, 64, u64
, 1);
1594 VRLMI(VRLWMI
, 32, u32
, 1);
1595 VRLMI(VRLDNM
, 64, u64
, 0);
1596 VRLMI(VRLWNM
, 32, u32
, 0);
1598 void helper_vexptefp(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*b
)
1602 for (i
= 0; i
< ARRAY_SIZE(r
->f32
); i
++) {
1603 r
->f32
[i
] = float32_exp2(b
->f32
[i
], &env
->vec_status
);
1607 void helper_vlogefp(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*b
)
1611 for (i
= 0; i
< ARRAY_SIZE(r
->f32
); i
++) {
1612 r
->f32
[i
] = float32_log2(b
->f32
[i
], &env
->vec_status
);
1616 #define VEXTU_X_DO(name, size, left) \
1617 target_ulong glue(helper_, name)(target_ulong a, ppc_avr_t *b) \
1619 int index = (a & 0xf) * 8; \
1621 index = 128 - index - size; \
1623 return int128_getlo(int128_rshift(b->s128, index)) & \
1624 MAKE_64BIT_MASK(0, size); \
1626 VEXTU_X_DO(vextublx
, 8, 1)
1627 VEXTU_X_DO(vextuhlx
, 16, 1)
1628 VEXTU_X_DO(vextuwlx
, 32, 1)
1629 VEXTU_X_DO(vextubrx
, 8, 0)
1630 VEXTU_X_DO(vextuhrx
, 16, 0)
1631 VEXTU_X_DO(vextuwrx
, 32, 0)
1634 void helper_vslv(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1637 unsigned int shift
, bytes
, size
;
1639 size
= ARRAY_SIZE(r
->u8
);
1640 for (i
= 0; i
< size
; i
++) {
1641 shift
= b
->VsrB(i
) & 0x7; /* extract shift value */
1642 bytes
= (a
->VsrB(i
) << 8) + /* extract adjacent bytes */
1643 (((i
+ 1) < size
) ? a
->VsrB(i
+ 1) : 0);
1644 r
->VsrB(i
) = (bytes
<< shift
) >> 8; /* shift and store result */
1648 void helper_vsrv(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1651 unsigned int shift
, bytes
;
1654 * Use reverse order, as destination and source register can be
1655 * same. Its being modified in place saving temporary, reverse
1656 * order will guarantee that computed result is not fed back.
1658 for (i
= ARRAY_SIZE(r
->u8
) - 1; i
>= 0; i
--) {
1659 shift
= b
->VsrB(i
) & 0x7; /* extract shift value */
1660 bytes
= ((i
? a
->VsrB(i
- 1) : 0) << 8) + a
->VsrB(i
);
1661 /* extract adjacent bytes */
1662 r
->VsrB(i
) = (bytes
>> shift
) & 0xFF; /* shift and store result */
1666 void helper_vsldoi(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t shift
)
1668 int sh
= shift
& 0xf;
1672 for (i
= 0; i
< ARRAY_SIZE(r
->u8
); i
++) {
1675 result
.VsrB(i
) = b
->VsrB(index
- 0x10);
1677 result
.VsrB(i
) = a
->VsrB(index
);
1683 void helper_vslo(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1685 int sh
= (b
->VsrB(0xf) >> 3) & 0xf;
1688 memmove(&r
->u8
[0], &a
->u8
[sh
], 16 - sh
);
1689 memset(&r
->u8
[16 - sh
], 0, sh
);
1691 memmove(&r
->u8
[sh
], &a
->u8
[0], 16 - sh
);
1692 memset(&r
->u8
[0], 0, sh
);
1697 #define ELEM_ADDR(VEC, IDX, SIZE) (&(VEC)->u8[IDX])
1699 #define ELEM_ADDR(VEC, IDX, SIZE) (&(VEC)->u8[15 - (IDX)] - (SIZE) + 1)
1702 #define VINSX(SUFFIX, TYPE) \
1703 void glue(glue(helper_VINS, SUFFIX), LX)(CPUPPCState *env, ppc_avr_t *t, \
1704 uint64_t val, target_ulong index) \
1706 const int maxidx = ARRAY_SIZE(t->u8) - sizeof(TYPE); \
1707 target_long idx = index; \
1709 if (idx < 0 || idx > maxidx) { \
1710 idx = idx < 0 ? sizeof(TYPE) - idx : idx; \
1711 qemu_log_mask(LOG_GUEST_ERROR, \
1712 "Invalid index for Vector Insert Element after 0x" TARGET_FMT_lx \
1713 ", RA = " TARGET_FMT_ld " > %d\n", env->nip, idx, maxidx); \
1716 memcpy(ELEM_ADDR(t, idx, sizeof(TYPE)), &src, sizeof(TYPE)); \
1726 #define VEXTDVLX(NAME, SIZE) \
1727 void helper_##NAME(CPUPPCState *env, ppc_avr_t *t, ppc_avr_t *a, ppc_avr_t *b, \
1728 target_ulong index) \
1730 const target_long idx = index; \
1731 ppc_avr_t tmp[2] = { *a, *b }; \
1732 memset(t, 0, sizeof(*t)); \
1733 if (idx >= 0 && idx + SIZE <= sizeof(tmp)) { \
1734 memcpy(&t->u8[ARRAY_SIZE(t->u8) / 2 - SIZE], (void *)tmp + idx, SIZE); \
1736 qemu_log_mask(LOG_GUEST_ERROR, "Invalid index for " #NAME " after 0x" \
1737 TARGET_FMT_lx ", RC = " TARGET_FMT_ld " > %d\n", \
1738 env->nip, idx < 0 ? SIZE - idx : idx, 32 - SIZE); \
1742 #define VEXTDVLX(NAME, SIZE) \
1743 void helper_##NAME(CPUPPCState *env, ppc_avr_t *t, ppc_avr_t *a, ppc_avr_t *b, \
1744 target_ulong index) \
1746 const target_long idx = index; \
1747 ppc_avr_t tmp[2] = { *b, *a }; \
1748 memset(t, 0, sizeof(*t)); \
1749 if (idx >= 0 && idx + SIZE <= sizeof(tmp)) { \
1750 memcpy(&t->u8[ARRAY_SIZE(t->u8) / 2], \
1751 (void *)tmp + sizeof(tmp) - SIZE - idx, SIZE); \
1753 qemu_log_mask(LOG_GUEST_ERROR, "Invalid index for " #NAME " after 0x" \
1754 TARGET_FMT_lx ", RC = " TARGET_FMT_ld " > %d\n", \
1755 env->nip, idx < 0 ? SIZE - idx : idx, 32 - SIZE); \
1759 VEXTDVLX(VEXTDUBVLX
, 1)
1760 VEXTDVLX(VEXTDUHVLX
, 2)
1761 VEXTDVLX(VEXTDUWVLX
, 4)
1762 VEXTDVLX(VEXTDDVLX
, 8)
1765 #define VEXTRACT(suffix, element) \
1766 void helper_vextract##suffix(ppc_avr_t *r, ppc_avr_t *b, uint32_t index) \
1768 uint32_t es = sizeof(r->element[0]); \
1769 memmove(&r->u8[8 - es], &b->u8[index], es); \
1770 memset(&r->u8[8], 0, 8); \
1771 memset(&r->u8[0], 0, 8 - es); \
1774 #define VEXTRACT(suffix, element) \
1775 void helper_vextract##suffix(ppc_avr_t *r, ppc_avr_t *b, uint32_t index) \
1777 uint32_t es = sizeof(r->element[0]); \
1778 uint32_t s = (16 - index) - es; \
1779 memmove(&r->u8[8], &b->u8[s], es); \
1780 memset(&r->u8[0], 0, 8); \
1781 memset(&r->u8[8 + es], 0, 8 - es); \
1790 #define VSTRI(NAME, ELEM, NUM_ELEMS, LEFT) \
1791 uint32_t helper_##NAME(ppc_avr_t *t, ppc_avr_t *b) \
1793 int i, idx, crf = 0; \
1795 for (i = 0; i < NUM_ELEMS; i++) { \
1796 idx = LEFT ? i : NUM_ELEMS - i - 1; \
1797 if (b->Vsr##ELEM(idx)) { \
1798 t->Vsr##ELEM(idx) = b->Vsr##ELEM(idx); \
1805 for (; i < NUM_ELEMS; i++) { \
1806 idx = LEFT ? i : NUM_ELEMS - i - 1; \
1807 t->Vsr##ELEM(idx) = 0; \
1812 VSTRI(VSTRIBL
, B
, 16, true)
1813 VSTRI(VSTRIBR
, B
, 16, false)
1814 VSTRI(VSTRIHL
, H
, 8, true)
1815 VSTRI(VSTRIHR
, H
, 8, false)
1818 void helper_XXEXTRACTUW(ppc_vsr_t
*xt
, ppc_vsr_t
*xb
, uint32_t index
)
1821 size_t es
= sizeof(uint32_t);
1826 for (i
= 0; i
< es
; i
++, ext_index
++) {
1827 t
.VsrB(8 - es
+ i
) = xb
->VsrB(ext_index
% 16);
1833 void helper_XXINSERTW(ppc_vsr_t
*xt
, ppc_vsr_t
*xb
, uint32_t index
)
1836 size_t es
= sizeof(uint32_t);
1837 int ins_index
, i
= 0;
1840 for (i
= 0; i
< es
&& ins_index
< 16; i
++, ins_index
++) {
1841 t
.VsrB(ins_index
) = xb
->VsrB(8 - es
+ i
);
1847 void helper_XXEVAL(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
,
1851 * Instead of processing imm bit-by-bit, we'll skip the computation of
1852 * conjunctions whose corresponding bit is unset.
1854 int bit
, imm
= simd_data(desc
);
1855 Int128 conj
, disj
= int128_zero();
1857 /* Iterate over set bits from the least to the most significant bit */
1860 * Get the next bit to be processed with ctz64. Invert the result of
1861 * ctz64 to match the indexing used by PowerISA.
1863 bit
= 7 - ctzl(imm
);
1867 conj
= int128_not(a
->s128
);
1870 conj
= int128_and(conj
, b
->s128
);
1872 conj
= int128_and(conj
, int128_not(b
->s128
));
1875 conj
= int128_and(conj
, c
->s128
);
1877 conj
= int128_and(conj
, int128_not(c
->s128
));
1879 disj
= int128_or(disj
, conj
);
1881 /* Unset the least significant bit that is set */
1888 #define XXBLEND(name, sz) \
1889 void glue(helper_XXBLENDV, name)(ppc_avr_t *t, ppc_avr_t *a, ppc_avr_t *b, \
1890 ppc_avr_t *c, uint32_t desc) \
1892 for (int i = 0; i < ARRAY_SIZE(t->glue(u, sz)); i++) { \
1893 t->glue(u, sz)[i] = (c->glue(s, sz)[i] >> (sz - 1)) ? \
1894 b->glue(u, sz)[i] : a->glue(u, sz)[i]; \
1903 void helper_vsro(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1905 int sh
= (b
->VsrB(0xf) >> 3) & 0xf;
1908 memmove(&r
->u8
[sh
], &a
->u8
[0], 16 - sh
);
1909 memset(&r
->u8
[0], 0, sh
);
1911 memmove(&r
->u8
[0], &a
->u8
[sh
], 16 - sh
);
1912 memset(&r
->u8
[16 - sh
], 0, sh
);
1916 void helper_vsumsws(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1923 upper
= ARRAY_SIZE(r
->s32
) - 1;
1924 t
= (int64_t)b
->VsrSW(upper
);
1925 for (i
= 0; i
< ARRAY_SIZE(r
->s32
); i
++) {
1927 result
.VsrSW(i
) = 0;
1929 result
.VsrSW(upper
) = cvtsdsw(t
, &sat
);
1937 void helper_vsum2sws(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1944 for (i
= 0; i
< ARRAY_SIZE(r
->u64
); i
++) {
1945 int64_t t
= (int64_t)b
->VsrSW(upper
+ i
* 2);
1948 for (j
= 0; j
< ARRAY_SIZE(r
->u64
); j
++) {
1949 t
+= a
->VsrSW(2 * i
+ j
);
1951 result
.VsrSW(upper
+ i
* 2) = cvtsdsw(t
, &sat
);
1960 void helper_vsum4sbs(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1965 for (i
= 0; i
< ARRAY_SIZE(r
->s32
); i
++) {
1966 int64_t t
= (int64_t)b
->s32
[i
];
1968 for (j
= 0; j
< ARRAY_SIZE(r
->s32
); j
++) {
1969 t
+= a
->s8
[4 * i
+ j
];
1971 r
->s32
[i
] = cvtsdsw(t
, &sat
);
1979 void helper_vsum4shs(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
1984 for (i
= 0; i
< ARRAY_SIZE(r
->s32
); i
++) {
1985 int64_t t
= (int64_t)b
->s32
[i
];
1987 t
+= a
->s16
[2 * i
] + a
->s16
[2 * i
+ 1];
1988 r
->s32
[i
] = cvtsdsw(t
, &sat
);
1996 void helper_vsum4ubs(CPUPPCState
*env
, ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2001 for (i
= 0; i
< ARRAY_SIZE(r
->u32
); i
++) {
2002 uint64_t t
= (uint64_t)b
->u32
[i
];
2004 for (j
= 0; j
< ARRAY_SIZE(r
->u32
); j
++) {
2005 t
+= a
->u8
[4 * i
+ j
];
2007 r
->u32
[i
] = cvtuduw(t
, &sat
);
2022 #define VUPKPX(suffix, hi) \
2023 void helper_vupk##suffix(ppc_avr_t *r, ppc_avr_t *b) \
2028 for (i = 0; i < ARRAY_SIZE(r->u32); i++) { \
2029 uint16_t e = b->u16[hi ? i : i + 4]; \
2030 uint8_t a = (e >> 15) ? 0xff : 0; \
2031 uint8_t r = (e >> 10) & 0x1f; \
2032 uint8_t g = (e >> 5) & 0x1f; \
2033 uint8_t b = e & 0x1f; \
2035 result.u32[i] = (a << 24) | (r << 16) | (g << 8) | b; \
2043 #define VUPK(suffix, unpacked, packee, hi) \
2044 void helper_vupk##suffix(ppc_avr_t *r, ppc_avr_t *b) \
2050 for (i = 0; i < ARRAY_SIZE(r->unpacked); i++) { \
2051 result.unpacked[i] = b->packee[i]; \
2054 for (i = ARRAY_SIZE(r->unpacked); i < ARRAY_SIZE(r->packee); \
2056 result.unpacked[i - ARRAY_SIZE(r->unpacked)] = b->packee[i]; \
2061 VUPK(hsb
, s16
, s8
, UPKHI
)
2062 VUPK(hsh
, s32
, s16
, UPKHI
)
2063 VUPK(hsw
, s64
, s32
, UPKHI
)
2064 VUPK(lsb
, s16
, s8
, UPKLO
)
2065 VUPK(lsh
, s32
, s16
, UPKLO
)
2066 VUPK(lsw
, s64
, s32
, UPKLO
)
2071 #define VGENERIC_DO(name, element) \
2072 void helper_v##name(ppc_avr_t *r, ppc_avr_t *b) \
2076 for (i = 0; i < ARRAY_SIZE(r->element); i++) { \
2077 r->element[i] = name(b->element[i]); \
2081 #define clzb(v) ((v) ? clz32((uint32_t)(v) << 24) : 8)
2082 #define clzh(v) ((v) ? clz32((uint32_t)(v) << 16) : 16)
2084 VGENERIC_DO(clzb
, u8
)
2085 VGENERIC_DO(clzh
, u16
)
2090 #define ctzb(v) ((v) ? ctz32(v) : 8)
2091 #define ctzh(v) ((v) ? ctz32(v) : 16)
2092 #define ctzw(v) ctz32((v))
2093 #define ctzd(v) ctz64((v))
2095 VGENERIC_DO(ctzb
, u8
)
2096 VGENERIC_DO(ctzh
, u16
)
2097 VGENERIC_DO(ctzw
, u32
)
2098 VGENERIC_DO(ctzd
, u64
)
2105 #define popcntb(v) ctpop8(v)
2106 #define popcnth(v) ctpop16(v)
2107 #define popcntw(v) ctpop32(v)
2108 #define popcntd(v) ctpop64(v)
2110 VGENERIC_DO(popcntb
, u8
)
2111 VGENERIC_DO(popcnth
, u16
)
2112 VGENERIC_DO(popcntw
, u32
)
2113 VGENERIC_DO(popcntd
, u64
)
2122 void helper_VADDUQM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2124 r
->s128
= int128_add(a
->s128
, b
->s128
);
2127 void helper_VADDEUQM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
2129 r
->s128
= int128_add(int128_add(a
->s128
, b
->s128
),
2130 int128_make64(int128_getlo(c
->s128
) & 1));
2133 void helper_VADDCUQ(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2135 r
->VsrD(1) = int128_ult(int128_not(a
->s128
), b
->s128
);
2139 void helper_VADDECUQ(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
2141 bool carry_out
= int128_ult(int128_not(a
->s128
), b
->s128
),
2142 carry_in
= int128_getlo(c
->s128
) & 1;
2144 if (!carry_out
&& carry_in
) {
2145 carry_out
= (int128_nz(a
->s128
) || int128_nz(b
->s128
)) &&
2146 int128_eq(int128_add(a
->s128
, b
->s128
), int128_makes64(-1));
2150 r
->VsrD(1) = carry_out
;
2153 void helper_VSUBUQM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2155 r
->s128
= int128_sub(a
->s128
, b
->s128
);
2158 void helper_VSUBEUQM(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
2160 r
->s128
= int128_add(int128_add(a
->s128
, int128_not(b
->s128
)),
2161 int128_make64(int128_getlo(c
->s128
) & 1));
2164 void helper_VSUBCUQ(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2166 Int128 tmp
= int128_not(b
->s128
);
2168 r
->VsrD(1) = int128_ult(int128_not(a
->s128
), tmp
) ||
2169 int128_eq(int128_add(a
->s128
, tmp
), int128_makes64(-1));
2173 void helper_VSUBECUQ(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
2175 Int128 tmp
= int128_not(b
->s128
);
2176 bool carry_out
= int128_ult(int128_not(a
->s128
), tmp
),
2177 carry_in
= int128_getlo(c
->s128
) & 1;
2179 r
->VsrD(1) = carry_out
|| (carry_in
&& int128_eq(int128_add(a
->s128
, tmp
),
2180 int128_makes64(-1)));
2184 #define BCD_PLUS_PREF_1 0xC
2185 #define BCD_PLUS_PREF_2 0xF
2186 #define BCD_PLUS_ALT_1 0xA
2187 #define BCD_NEG_PREF 0xD
2188 #define BCD_NEG_ALT 0xB
2189 #define BCD_PLUS_ALT_2 0xE
2190 #define NATIONAL_PLUS 0x2B
2191 #define NATIONAL_NEG 0x2D
2193 #define BCD_DIG_BYTE(n) (15 - ((n) / 2))
2195 static int bcd_get_sgn(ppc_avr_t
*bcd
)
2197 switch (bcd
->VsrB(BCD_DIG_BYTE(0)) & 0xF) {
2198 case BCD_PLUS_PREF_1
:
2199 case BCD_PLUS_PREF_2
:
2200 case BCD_PLUS_ALT_1
:
2201 case BCD_PLUS_ALT_2
:
2219 static int bcd_preferred_sgn(int sgn
, int ps
)
2222 return (ps
== 0) ? BCD_PLUS_PREF_1
: BCD_PLUS_PREF_2
;
2224 return BCD_NEG_PREF
;
2228 static uint8_t bcd_get_digit(ppc_avr_t
*bcd
, int n
, int *invalid
)
2232 result
= bcd
->VsrB(BCD_DIG_BYTE(n
)) >> 4;
2234 result
= bcd
->VsrB(BCD_DIG_BYTE(n
)) & 0xF;
2237 if (unlikely(result
> 9)) {
2243 static void bcd_put_digit(ppc_avr_t
*bcd
, uint8_t digit
, int n
)
2246 bcd
->VsrB(BCD_DIG_BYTE(n
)) &= 0x0F;
2247 bcd
->VsrB(BCD_DIG_BYTE(n
)) |= (digit
<< 4);
2249 bcd
->VsrB(BCD_DIG_BYTE(n
)) &= 0xF0;
2250 bcd
->VsrB(BCD_DIG_BYTE(n
)) |= digit
;
2254 static bool bcd_is_valid(ppc_avr_t
*bcd
)
2259 if (bcd_get_sgn(bcd
) == 0) {
2263 for (i
= 1; i
< 32; i
++) {
2264 bcd_get_digit(bcd
, i
, &invalid
);
2265 if (unlikely(invalid
)) {
2272 static int bcd_cmp_zero(ppc_avr_t
*bcd
)
2274 if (bcd
->VsrD(0) == 0 && (bcd
->VsrD(1) >> 4) == 0) {
2277 return (bcd_get_sgn(bcd
) == 1) ? CRF_GT
: CRF_LT
;
2281 static uint16_t get_national_digit(ppc_avr_t
*reg
, int n
)
2283 return reg
->VsrH(7 - n
);
2286 static void set_national_digit(ppc_avr_t
*reg
, uint8_t val
, int n
)
2288 reg
->VsrH(7 - n
) = val
;
2291 static int bcd_cmp_mag(ppc_avr_t
*a
, ppc_avr_t
*b
)
2295 for (i
= 31; i
> 0; i
--) {
2296 uint8_t dig_a
= bcd_get_digit(a
, i
, &invalid
);
2297 uint8_t dig_b
= bcd_get_digit(b
, i
, &invalid
);
2298 if (unlikely(invalid
)) {
2299 return 0; /* doesn't matter */
2300 } else if (dig_a
> dig_b
) {
2302 } else if (dig_a
< dig_b
) {
2310 static int bcd_add_mag(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
, int *invalid
,
2317 for (i
= 1; i
<= 31; i
++) {
2318 uint8_t digit
= bcd_get_digit(a
, i
, invalid
) +
2319 bcd_get_digit(b
, i
, invalid
) + carry
;
2320 is_zero
&= (digit
== 0);
2328 bcd_put_digit(t
, digit
, i
);
2335 static void bcd_sub_mag(ppc_avr_t
*t
, ppc_avr_t
*a
, ppc_avr_t
*b
, int *invalid
,
2341 for (i
= 1; i
<= 31; i
++) {
2342 uint8_t digit
= bcd_get_digit(a
, i
, invalid
) -
2343 bcd_get_digit(b
, i
, invalid
) + carry
;
2351 bcd_put_digit(t
, digit
, i
);
2357 uint32_t helper_bcdadd(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t ps
)
2360 int sgna
= bcd_get_sgn(a
);
2361 int sgnb
= bcd_get_sgn(b
);
2362 int invalid
= (sgna
== 0) || (sgnb
== 0);
2366 ppc_avr_t result
= { .u64
= { 0, 0 } };
2370 result
.VsrB(BCD_DIG_BYTE(0)) = bcd_preferred_sgn(sgna
, ps
);
2371 zero
= bcd_add_mag(&result
, a
, b
, &invalid
, &overflow
);
2372 cr
= (sgna
> 0) ? CRF_GT
: CRF_LT
;
2374 int magnitude
= bcd_cmp_mag(a
, b
);
2375 if (magnitude
> 0) {
2376 result
.VsrB(BCD_DIG_BYTE(0)) = bcd_preferred_sgn(sgna
, ps
);
2377 bcd_sub_mag(&result
, a
, b
, &invalid
, &overflow
);
2378 cr
= (sgna
> 0) ? CRF_GT
: CRF_LT
;
2379 } else if (magnitude
< 0) {
2380 result
.VsrB(BCD_DIG_BYTE(0)) = bcd_preferred_sgn(sgnb
, ps
);
2381 bcd_sub_mag(&result
, b
, a
, &invalid
, &overflow
);
2382 cr
= (sgnb
> 0) ? CRF_GT
: CRF_LT
;
2384 result
.VsrB(BCD_DIG_BYTE(0)) = bcd_preferred_sgn(0, ps
);
2390 if (unlikely(invalid
)) {
2391 result
.VsrD(0) = result
.VsrD(1) = -1;
2393 } else if (overflow
) {
2404 uint32_t helper_bcdsub(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t ps
)
2406 ppc_avr_t bcopy
= *b
;
2407 int sgnb
= bcd_get_sgn(b
);
2409 bcd_put_digit(&bcopy
, BCD_PLUS_PREF_1
, 0);
2410 } else if (sgnb
> 0) {
2411 bcd_put_digit(&bcopy
, BCD_NEG_PREF
, 0);
2413 /* else invalid ... defer to bcdadd code for proper handling */
2415 return helper_bcdadd(r
, a
, &bcopy
, ps
);
2418 uint32_t helper_bcdcfn(ppc_avr_t
*r
, ppc_avr_t
*b
, uint32_t ps
)
2422 uint16_t national
= 0;
2423 uint16_t sgnb
= get_national_digit(b
, 0);
2424 ppc_avr_t ret
= { .u64
= { 0, 0 } };
2425 int invalid
= (sgnb
!= NATIONAL_PLUS
&& sgnb
!= NATIONAL_NEG
);
2427 for (i
= 1; i
< 8; i
++) {
2428 national
= get_national_digit(b
, i
);
2429 if (unlikely(national
< 0x30 || national
> 0x39)) {
2434 bcd_put_digit(&ret
, national
& 0xf, i
);
2437 if (sgnb
== NATIONAL_PLUS
) {
2438 bcd_put_digit(&ret
, (ps
== 0) ? BCD_PLUS_PREF_1
: BCD_PLUS_PREF_2
, 0);
2440 bcd_put_digit(&ret
, BCD_NEG_PREF
, 0);
2443 cr
= bcd_cmp_zero(&ret
);
2445 if (unlikely(invalid
)) {
2454 uint32_t helper_bcdctn(ppc_avr_t
*r
, ppc_avr_t
*b
, uint32_t ps
)
2458 int sgnb
= bcd_get_sgn(b
);
2459 int invalid
= (sgnb
== 0);
2460 ppc_avr_t ret
= { .u64
= { 0, 0 } };
2462 int ox_flag
= (b
->VsrD(0) != 0) || ((b
->VsrD(1) >> 32) != 0);
2464 for (i
= 1; i
< 8; i
++) {
2465 set_national_digit(&ret
, 0x30 + bcd_get_digit(b
, i
, &invalid
), i
);
2467 if (unlikely(invalid
)) {
2471 set_national_digit(&ret
, (sgnb
== -1) ? NATIONAL_NEG
: NATIONAL_PLUS
, 0);
2473 cr
= bcd_cmp_zero(b
);
2479 if (unlikely(invalid
)) {
2488 uint32_t helper_bcdcfz(ppc_avr_t
*r
, ppc_avr_t
*b
, uint32_t ps
)
2494 int zone_lead
= ps
? 0xF : 0x3;
2496 ppc_avr_t ret
= { .u64
= { 0, 0 } };
2497 int sgnb
= b
->VsrB(BCD_DIG_BYTE(0)) >> 4;
2499 if (unlikely((sgnb
< 0xA) && ps
)) {
2503 for (i
= 0; i
< 16; i
++) {
2504 zone_digit
= i
? b
->VsrB(BCD_DIG_BYTE(i
* 2)) >> 4 : zone_lead
;
2505 digit
= b
->VsrB(BCD_DIG_BYTE(i
* 2)) & 0xF;
2506 if (unlikely(zone_digit
!= zone_lead
|| digit
> 0x9)) {
2511 bcd_put_digit(&ret
, digit
, i
+ 1);
2514 if ((ps
&& (sgnb
== 0xB || sgnb
== 0xD)) ||
2515 (!ps
&& (sgnb
& 0x4))) {
2516 bcd_put_digit(&ret
, BCD_NEG_PREF
, 0);
2518 bcd_put_digit(&ret
, BCD_PLUS_PREF_1
, 0);
2521 cr
= bcd_cmp_zero(&ret
);
2523 if (unlikely(invalid
)) {
2532 uint32_t helper_bcdctz(ppc_avr_t
*r
, ppc_avr_t
*b
, uint32_t ps
)
2537 int sgnb
= bcd_get_sgn(b
);
2538 int zone_lead
= (ps
) ? 0xF0 : 0x30;
2539 int invalid
= (sgnb
== 0);
2540 ppc_avr_t ret
= { .u64
= { 0, 0 } };
2542 int ox_flag
= ((b
->VsrD(0) >> 4) != 0);
2544 for (i
= 0; i
< 16; i
++) {
2545 digit
= bcd_get_digit(b
, i
+ 1, &invalid
);
2547 if (unlikely(invalid
)) {
2551 ret
.VsrB(BCD_DIG_BYTE(i
* 2)) = zone_lead
+ digit
;
2555 bcd_put_digit(&ret
, (sgnb
== 1) ? 0xC : 0xD, 1);
2557 bcd_put_digit(&ret
, (sgnb
== 1) ? 0x3 : 0x7, 1);
2560 cr
= bcd_cmp_zero(b
);
2566 if (unlikely(invalid
)) {
2576 * Compare 2 128-bit unsigned integers, passed in as unsigned 64-bit pairs
2579 * > 0 if ahi|alo > bhi|blo,
2580 * 0 if ahi|alo == bhi|blo,
2581 * < 0 if ahi|alo < bhi|blo
2583 static inline int ucmp128(uint64_t alo
, uint64_t ahi
,
2584 uint64_t blo
, uint64_t bhi
)
2586 return (ahi
== bhi
) ?
2587 (alo
> blo
? 1 : (alo
== blo
? 0 : -1)) :
2588 (ahi
> bhi
? 1 : -1);
2591 uint32_t helper_bcdcfsq(ppc_avr_t
*r
, ppc_avr_t
*b
, uint32_t ps
)
2598 ppc_avr_t ret
= { .u64
= { 0, 0 } };
2600 if (b
->VsrSD(0) < 0) {
2601 lo_value
= -b
->VsrSD(1);
2602 hi_value
= ~b
->VsrD(0) + !lo_value
;
2603 bcd_put_digit(&ret
, 0xD, 0);
2607 lo_value
= b
->VsrD(1);
2608 hi_value
= b
->VsrD(0);
2609 bcd_put_digit(&ret
, bcd_preferred_sgn(0, ps
), 0);
2611 if (hi_value
== 0 && lo_value
== 0) {
2619 * Check src limits: abs(src) <= 10^31 - 1
2621 * 10^31 - 1 = 0x0000007e37be2022 c0914b267fffffff
2623 if (ucmp128(lo_value
, hi_value
,
2624 0xc0914b267fffffffULL
, 0x7e37be2022ULL
) > 0) {
2628 * According to the ISA, if src wouldn't fit in the destination
2629 * register, the result is undefined.
2630 * In that case, we leave r unchanged.
2633 rem
= divu128(&lo_value
, &hi_value
, 1000000000000000ULL);
2635 for (i
= 1; i
< 16; rem
/= 10, i
++) {
2636 bcd_put_digit(&ret
, rem
% 10, i
);
2639 for (; i
< 32; lo_value
/= 10, i
++) {
2640 bcd_put_digit(&ret
, lo_value
% 10, i
);
2649 uint32_t helper_bcdctsq(ppc_avr_t
*r
, ppc_avr_t
*b
, uint32_t ps
)
2656 uint64_t hi_value
= 0;
2657 int sgnb
= bcd_get_sgn(b
);
2658 int invalid
= (sgnb
== 0);
2660 lo_value
= bcd_get_digit(b
, 31, &invalid
);
2661 for (i
= 30; i
> 0; i
--) {
2662 mulu64(&lo_value
, &carry
, lo_value
, 10ULL);
2663 mulu64(&hi_value
, &unused
, hi_value
, 10ULL);
2664 lo_value
+= bcd_get_digit(b
, i
, &invalid
);
2667 if (unlikely(invalid
)) {
2673 r
->VsrSD(1) = -lo_value
;
2674 r
->VsrSD(0) = ~hi_value
+ !r
->VsrSD(1);
2676 r
->VsrSD(1) = lo_value
;
2677 r
->VsrSD(0) = hi_value
;
2680 cr
= bcd_cmp_zero(b
);
2682 if (unlikely(invalid
)) {
2689 uint32_t helper_bcdcpsgn(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t ps
)
2694 if (bcd_get_sgn(a
) == 0 || bcd_get_sgn(b
) == 0) {
2699 bcd_put_digit(r
, b
->VsrB(BCD_DIG_BYTE(0)) & 0xF, 0);
2701 for (i
= 1; i
< 32; i
++) {
2702 bcd_get_digit(a
, i
, &invalid
);
2703 bcd_get_digit(b
, i
, &invalid
);
2704 if (unlikely(invalid
)) {
2709 return bcd_cmp_zero(r
);
2712 uint32_t helper_bcdsetsgn(ppc_avr_t
*r
, ppc_avr_t
*b
, uint32_t ps
)
2714 int sgnb
= bcd_get_sgn(b
);
2717 bcd_put_digit(r
, bcd_preferred_sgn(sgnb
, ps
), 0);
2719 if (bcd_is_valid(b
) == false) {
2723 return bcd_cmp_zero(r
);
2726 uint32_t helper_bcds(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t ps
)
2729 int i
= a
->VsrSB(7);
2730 bool ox_flag
= false;
2731 int sgnb
= bcd_get_sgn(b
);
2733 ret
.VsrD(1) &= ~0xf;
2735 if (bcd_is_valid(b
) == false) {
2739 if (unlikely(i
> 31)) {
2741 } else if (unlikely(i
< -31)) {
2746 ulshift(&ret
.VsrD(1), &ret
.VsrD(0), i
* 4, &ox_flag
);
2748 urshift(&ret
.VsrD(1), &ret
.VsrD(0), -i
* 4);
2750 bcd_put_digit(&ret
, bcd_preferred_sgn(sgnb
, ps
), 0);
2754 cr
= bcd_cmp_zero(r
);
2762 uint32_t helper_bcdus(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t ps
)
2767 bool ox_flag
= false;
2770 for (i
= 0; i
< 32; i
++) {
2771 bcd_get_digit(b
, i
, &invalid
);
2773 if (unlikely(invalid
)) {
2781 ret
.VsrD(1) = ret
.VsrD(0) = 0;
2782 } else if (i
<= -32) {
2783 ret
.VsrD(1) = ret
.VsrD(0) = 0;
2785 ulshift(&ret
.VsrD(1), &ret
.VsrD(0), i
* 4, &ox_flag
);
2787 urshift(&ret
.VsrD(1), &ret
.VsrD(0), -i
* 4);
2791 cr
= bcd_cmp_zero(r
);
2799 uint32_t helper_bcdsr(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t ps
)
2804 bool ox_flag
= false;
2805 int sgnb
= bcd_get_sgn(b
);
2807 ret
.VsrD(1) &= ~0xf;
2809 int i
= a
->VsrSB(7);
2812 bcd_one
.VsrD(0) = 0;
2813 bcd_one
.VsrD(1) = 0x10;
2815 if (bcd_is_valid(b
) == false) {
2819 if (unlikely(i
> 31)) {
2821 } else if (unlikely(i
< -31)) {
2826 ulshift(&ret
.VsrD(1), &ret
.VsrD(0), i
* 4, &ox_flag
);
2828 urshift(&ret
.VsrD(1), &ret
.VsrD(0), -i
* 4);
2830 if (bcd_get_digit(&ret
, 0, &invalid
) >= 5) {
2831 bcd_add_mag(&ret
, &ret
, &bcd_one
, &invalid
, &unused
);
2834 bcd_put_digit(&ret
, bcd_preferred_sgn(sgnb
, ps
), 0);
2836 cr
= bcd_cmp_zero(&ret
);
2845 uint32_t helper_bcdtrunc(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t ps
)
2848 uint32_t ox_flag
= 0;
2849 int i
= a
->VsrSH(3) + 1;
2852 if (bcd_is_valid(b
) == false) {
2856 if (i
> 16 && i
< 32) {
2857 mask
= (uint64_t)-1 >> (128 - i
* 4);
2858 if (ret
.VsrD(0) & ~mask
) {
2862 ret
.VsrD(0) &= mask
;
2863 } else if (i
>= 0 && i
<= 16) {
2864 mask
= (uint64_t)-1 >> (64 - i
* 4);
2865 if (ret
.VsrD(0) || (ret
.VsrD(1) & ~mask
)) {
2869 ret
.VsrD(1) &= mask
;
2872 bcd_put_digit(&ret
, bcd_preferred_sgn(bcd_get_sgn(b
), ps
), 0);
2875 return bcd_cmp_zero(&ret
) | ox_flag
;
2878 uint32_t helper_bcdutrunc(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, uint32_t ps
)
2882 uint32_t ox_flag
= 0;
2886 for (i
= 0; i
< 32; i
++) {
2887 bcd_get_digit(b
, i
, &invalid
);
2889 if (unlikely(invalid
)) {
2895 if (i
> 16 && i
< 33) {
2896 mask
= (uint64_t)-1 >> (128 - i
* 4);
2897 if (ret
.VsrD(0) & ~mask
) {
2901 ret
.VsrD(0) &= mask
;
2902 } else if (i
> 0 && i
<= 16) {
2903 mask
= (uint64_t)-1 >> (64 - i
* 4);
2904 if (ret
.VsrD(0) || (ret
.VsrD(1) & ~mask
)) {
2908 ret
.VsrD(1) &= mask
;
2910 } else if (i
== 0) {
2911 if (ret
.VsrD(0) || ret
.VsrD(1)) {
2914 ret
.VsrD(0) = ret
.VsrD(1) = 0;
2918 if (r
->VsrD(0) == 0 && r
->VsrD(1) == 0) {
2919 return ox_flag
| CRF_EQ
;
2922 return ox_flag
| CRF_GT
;
2925 void helper_vsbox(ppc_avr_t
*r
, ppc_avr_t
*a
)
2928 VECTOR_FOR_INORDER_I(i
, u8
) {
2929 r
->u8
[i
] = AES_sbox
[a
->u8
[i
]];
2933 void helper_vcipher(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2938 VECTOR_FOR_INORDER_I(i
, u32
) {
2939 result
.VsrW(i
) = b
->VsrW(i
) ^
2940 (AES_Te0
[a
->VsrB(AES_shifts
[4 * i
+ 0])] ^
2941 AES_Te1
[a
->VsrB(AES_shifts
[4 * i
+ 1])] ^
2942 AES_Te2
[a
->VsrB(AES_shifts
[4 * i
+ 2])] ^
2943 AES_Te3
[a
->VsrB(AES_shifts
[4 * i
+ 3])]);
2948 void helper_vcipherlast(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2953 VECTOR_FOR_INORDER_I(i
, u8
) {
2954 result
.VsrB(i
) = b
->VsrB(i
) ^ (AES_sbox
[a
->VsrB(AES_shifts
[i
])]);
2959 void helper_vncipher(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2961 /* This differs from what is written in ISA V2.07. The RTL is */
2962 /* incorrect and will be fixed in V2.07B. */
2966 VECTOR_FOR_INORDER_I(i
, u8
) {
2967 tmp
.VsrB(i
) = b
->VsrB(i
) ^ AES_isbox
[a
->VsrB(AES_ishifts
[i
])];
2970 VECTOR_FOR_INORDER_I(i
, u32
) {
2972 AES_imc
[tmp
.VsrB(4 * i
+ 0)][0] ^
2973 AES_imc
[tmp
.VsrB(4 * i
+ 1)][1] ^
2974 AES_imc
[tmp
.VsrB(4 * i
+ 2)][2] ^
2975 AES_imc
[tmp
.VsrB(4 * i
+ 3)][3];
2979 void helper_vncipherlast(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
)
2984 VECTOR_FOR_INORDER_I(i
, u8
) {
2985 result
.VsrB(i
) = b
->VsrB(i
) ^ (AES_isbox
[a
->VsrB(AES_ishifts
[i
])]);
2990 void helper_vshasigmaw(ppc_avr_t
*r
, ppc_avr_t
*a
, uint32_t st_six
)
2992 int st
= (st_six
& 0x10) != 0;
2993 int six
= st_six
& 0xF;
2996 for (i
= 0; i
< ARRAY_SIZE(r
->u32
); i
++) {
2998 if ((six
& (0x8 >> i
)) == 0) {
2999 r
->VsrW(i
) = ror32(a
->VsrW(i
), 7) ^
3000 ror32(a
->VsrW(i
), 18) ^
3002 } else { /* six.bit[i] == 1 */
3003 r
->VsrW(i
) = ror32(a
->VsrW(i
), 17) ^
3004 ror32(a
->VsrW(i
), 19) ^
3007 } else { /* st == 1 */
3008 if ((six
& (0x8 >> i
)) == 0) {
3009 r
->VsrW(i
) = ror32(a
->VsrW(i
), 2) ^
3010 ror32(a
->VsrW(i
), 13) ^
3011 ror32(a
->VsrW(i
), 22);
3012 } else { /* six.bit[i] == 1 */
3013 r
->VsrW(i
) = ror32(a
->VsrW(i
), 6) ^
3014 ror32(a
->VsrW(i
), 11) ^
3015 ror32(a
->VsrW(i
), 25);
3021 void helper_vshasigmad(ppc_avr_t
*r
, ppc_avr_t
*a
, uint32_t st_six
)
3023 int st
= (st_six
& 0x10) != 0;
3024 int six
= st_six
& 0xF;
3027 for (i
= 0; i
< ARRAY_SIZE(r
->u64
); i
++) {
3029 if ((six
& (0x8 >> (2 * i
))) == 0) {
3030 r
->VsrD(i
) = ror64(a
->VsrD(i
), 1) ^
3031 ror64(a
->VsrD(i
), 8) ^
3033 } else { /* six.bit[2*i] == 1 */
3034 r
->VsrD(i
) = ror64(a
->VsrD(i
), 19) ^
3035 ror64(a
->VsrD(i
), 61) ^
3038 } else { /* st == 1 */
3039 if ((six
& (0x8 >> (2 * i
))) == 0) {
3040 r
->VsrD(i
) = ror64(a
->VsrD(i
), 28) ^
3041 ror64(a
->VsrD(i
), 34) ^
3042 ror64(a
->VsrD(i
), 39);
3043 } else { /* six.bit[2*i] == 1 */
3044 r
->VsrD(i
) = ror64(a
->VsrD(i
), 14) ^
3045 ror64(a
->VsrD(i
), 18) ^
3046 ror64(a
->VsrD(i
), 41);
3052 void helper_vpermxor(ppc_avr_t
*r
, ppc_avr_t
*a
, ppc_avr_t
*b
, ppc_avr_t
*c
)
3057 for (i
= 0; i
< ARRAY_SIZE(r
->u8
); i
++) {
3058 int indexA
= c
->VsrB(i
) >> 4;
3059 int indexB
= c
->VsrB(i
) & 0xF;
3061 result
.VsrB(i
) = a
->VsrB(indexA
) ^ b
->VsrB(indexB
);
3066 #undef VECTOR_FOR_INORDER_I
3068 /*****************************************************************************/
3069 /* SPE extension helpers */
3070 /* Use a table to make this quicker */
3071 static const uint8_t hbrev
[16] = {
3072 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
3073 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF,
3076 static inline uint8_t byte_reverse(uint8_t val
)
3078 return hbrev
[val
>> 4] | (hbrev
[val
& 0xF] << 4);
3081 static inline uint32_t word_reverse(uint32_t val
)
3083 return byte_reverse(val
>> 24) | (byte_reverse(val
>> 16) << 8) |
3084 (byte_reverse(val
>> 8) << 16) | (byte_reverse(val
) << 24);
3087 #define MASKBITS 16 /* Random value - to be fixed (implementation dependent) */
3088 target_ulong
helper_brinc(target_ulong arg1
, target_ulong arg2
)
3090 uint32_t a
, b
, d
, mask
;
3092 mask
= UINT32_MAX
>> (32 - MASKBITS
);
3095 d
= word_reverse(1 + word_reverse(a
| ~b
));
3096 return (arg1
& ~mask
) | (d
& b
);
3099 uint32_t helper_cntlsw32(uint32_t val
)
3101 if (val
& 0x80000000) {
3108 uint32_t helper_cntlzw32(uint32_t val
)
3114 target_ulong
helper_dlmzb(CPUPPCState
*env
, target_ulong high
,
3115 target_ulong low
, uint32_t update_Rc
)
3121 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
3122 if ((high
& mask
) == 0) {
3130 for (mask
= 0xFF000000; mask
!= 0; mask
= mask
>> 8) {
3131 if ((low
& mask
) == 0) {
3144 env
->xer
= (env
->xer
& ~0x7F) | i
;
3146 env
->crf
[0] |= xer_so
;