Skip to contentSkip to conversation

POWER9 TCG enablements - BCD functions part II

PATCH Superseded Jose Ricardo Ziviani 2 participants 11 messages Nov 16, 2016 – Nov 17, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover POWER9 TCG enablements - BCD functions part II

This serie contains 4 new instructions for POWER9 ISA3.0

bcdcfsq.: Convert signed quadword to packed BCD bcdctsq.: Convert packed BCD to signed quadword bcdcpsgn.: Copy the sign of a register to another bcdsetsgn.: Set the BCD sign according to a preferred sign

Jose Ricardo Ziviani (4):
target-ppc: Implement bcdcfsq. instruction
target-ppc: Implement bcdctsq. instruction
target-ppc: Implement bcdcpsgn. instruction
target-ppc: Implement bcdsetsgn. instruction

 target-ppc/helper.h                 |   4 ++
 target-ppc/int_helper.c             | 126 ++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  25 +++++++
 target-ppc/translate/vmx-ops.inc.c  |   2 +-
 4 files changed, 156 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 target-ppc: Implement bcdcfsq. instruction

bcdcfsq.: Decimal convert from signed quadword. It is possible to convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 48 +++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  7 ++++++
 3 files changed, 56 insertions(+)
target-ppc/helper.h +1 -0
index da00f0a..87f533c 100644
@@ -382,6 +382,7 @@ DEF_HELPER_3(bcdcfn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
+DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +48 -0

54 lines not on this page · raw message

target-ppc/translate/vmx-impl.inc.c +7 -0
index 7143eb3..36141e5 100644
@@ -989,10 +989,14 @@ GEN_BCD2(bcdcfn)
 GEN_BCD2(bcdctn)
 GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
+GEN_BCD2(bcdcfsq)
 
 static void gen_xpnd04_1(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 2:
+        gen_bcdcfsq(ctx);
+        break;
     case 4:
         gen_bcdctz(ctx);
         break;
@@ -1014,6 +1018,9 @@ static void gen_xpnd04_1(DisasContext *ctx)
 static void gen_xpnd04_2(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 2:
+        gen_bcdcfsq(ctx);
+        break;
     case 4:
         gen_bcdctz(ctx);
         break;
Signature · 1 line
2.7.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] target-ppc: Implement bcdcfsq. instruction

Quoted 1 line · Jose Ricardo Ziviani

bcdcfsq.: Decimal convert from signed quadword. It is possible to

I think there should be a "not" in there.

Quoted 29 lines

convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 48 +++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  7 ++++++
 3 files changed, 56 insertions(+)
target-ppc/helper.h +1 -0
index da00f0a..87f533c 100644
@@ -382,6 +382,7 @@ DEF_HELPER_3(bcdcfn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
+DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +0 -0
index 9ac204a..db65a51 100644
@@ -2874,6 +2874,54 @@ uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
     return cr;
 }

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2885

Quoted 10 lines
target-ppc/int_helper.c +9 -0
 
+uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
+{
+    int i;
+    int cr = 0;
+    int ox_flag = 0;
+    uint64_t digit = 0;
+    uint64_t carry = 0;
+    uint64_t lo_value = 0;
+    uint64_t hi_value = 0;

Most of the variables above don't need initializers.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2891

Quoted 6 lines
target-ppc/int_helper.c +6 -0
+    uint64_t max = ULLONG_MAX;
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    if (b->s64[HI_IDX] < 0) {
+        hi_value = -b->s64[HI_IDX];
+        lo_value = b->s64[LO_IDX];

I'm pretty sure this is wrong. Take for example 128-bit -1:
ffffffff ffffffff ffffffff ffffffff
Upper word is negative (64-bit -1), so

	hi_value = 00000000 00000001
	lo_value = ffffffff ffffffff

0x1 ffffffff ffffffff != +1

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2902

Quoted 11 lines
target-ppc/int_helper.c +11 -0
+        bcd_put_digit(&ret, 0xD, 0);
+    } else if (b->s64[HI_IDX] == 0 && b->s64[LO_IDX] < 0) {
+        lo_value = -b->s64[LO_IDX];
+        bcd_put_digit(&ret, 0xD, 0);
+    } else {
+        hi_value = b->s64[HI_IDX];
+        lo_value = b->s64[LO_IDX];
+        bcd_put_digit(&ret, bcd_preferred_sgn(0, ps), 0);
+    }
+
+    if (unlikely(hi_value > 0x7e37be2022)) {

This doesn't look right. Unless by chance 10^31-1 is equal to (k*2^64
- 1) you need to look at the lo_value as well.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2903

Quoted 1 line
target-ppc/int_helper.c +1 -0
+        ox_flag = 1;

You might as well just return 1<< CRF_SO here - no point actually computing a meaningless value.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2907

Quoted 4 lines
target-ppc/int_helper.c +4 -0
+    }
+
+    carry = hi_value;
+    for (i = 0; i < 32; i++, max /= 10, lo_value /= 10) {

Looks like this loop has one too many iterations - there are 32 iterations, but you only have 31 digits.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2911

Quoted 4 lines
target-ppc/int_helper.c +4 -0
+        digit = ((max % 10) * hi_value) + (lo_value % 10) + carry;
+        carry = (digit > 9) ? digit / 10 : 0;
+
+        bcd_put_digit(&ret, (carry) ? digit % 10 : digit, i + 1);

Ugh, this is hard to follow. We're already using an Int128 library in the memory region code; wonder if we should just use that here as well.

Quoted 45 lines
target-ppc/int_helper.c +13 -0
+    }
+
+    cr = bcd_cmp_zero(&ret);
+
+    if (unlikely(ox_flag)) {
+        cr |= 1 << CRF_SO;
+    }
+
+    *r = ret;
+
+    return cr;
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +7 -0
index 7143eb3..36141e5 100644
@@ -989,10 +989,14 @@ GEN_BCD2(bcdcfn)
 GEN_BCD2(bcdctn)
 GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
+GEN_BCD2(bcdcfsq)
 
 static void gen_xpnd04_1(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 2:
+        gen_bcdcfsq(ctx);
+        break;
     case 4:
         gen_bcdctz(ctx);
         break;
@@ -1014,6 +1018,9 @@ static void gen_xpnd04_1(DisasContext *ctx)
 static void gen_xpnd04_2(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 2:
+        gen_bcdcfsq(ctx);
+        break;
     case 4:
         gen_bcdctz(ctx);
         break;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] target-ppc: Implement bcdcfsq. instruction

Hello David,

Thank you for your review. I have just one question below, could you help me to address it please?

Thank you!

Ziviani

Quoted 90 lines · David Gibson
Quoted 1 line · Jose Ricardo Ziviani

bcdcfsq.: Decimal convert from signed quadword. It is possible to

I think there should be a "not" in there.

Quoted 29 lines

convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 48 +++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  7 ++++++
 3 files changed, 56 insertions(+)
target-ppc/helper.h +1 -0
index da00f0a..87f533c 100644
@@ -382,6 +382,7 @@ DEF_HELPER_3(bcdcfn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
+DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +0 -0
index 9ac204a..db65a51 100644
@@ -2874,6 +2874,54 @@ uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
     return cr;
 }

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2885

Quoted 10 lines
target-ppc/int_helper.c +9 -0
 
+uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
+{
+    int i;
+    int cr = 0;
+    int ox_flag = 0;
+    uint64_t digit = 0;
+    uint64_t carry = 0;
+    uint64_t lo_value = 0;
+    uint64_t hi_value = 0;

Most of the variables above don't need initializers.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2891

Quoted 6 lines
target-ppc/int_helper.c +6 -0
+    uint64_t max = ULLONG_MAX;
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    if (b->s64[HI_IDX] < 0) {
+        hi_value = -b->s64[HI_IDX];
+        lo_value = b->s64[LO_IDX];

I'm pretty sure this is wrong. Take for example 128-bit -1:
ffffffff ffffffff ffffffff ffffffff
Upper word is negative (64-bit -1), so

	hi_value = 00000000 00000001
	lo_value = ffffffff ffffffff

0x1 ffffffff ffffffff != +1

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2902

Quoted 11 lines
target-ppc/int_helper.c +11 -0
+        bcd_put_digit(&ret, 0xD, 0);
+    } else if (b->s64[HI_IDX] == 0 && b->s64[LO_IDX] < 0) {
+        lo_value = -b->s64[LO_IDX];
+        bcd_put_digit(&ret, 0xD, 0);
+    } else {
+        hi_value = b->s64[HI_IDX];
+        lo_value = b->s64[LO_IDX];
+        bcd_put_digit(&ret, bcd_preferred_sgn(0, ps), 0);
+    }
+
+    if (unlikely(hi_value > 0x7e37be2022)) {

This doesn't look right. Unless by chance 10^31-1 is equal to (k*2^64
- 1) you need to look at the lo_value as well.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2903

Quoted 1 line
target-ppc/int_helper.c +1 -0
+        ox_flag = 1;

You might as well just return 1<< CRF_SO here - no point actually computing a meaningless value.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2907

Quoted 4 lines
target-ppc/int_helper.c +4 -0
+    }
+
+    carry = hi_value;
+    for (i = 0; i < 32; i++, max /= 10, lo_value /= 10) {

Looks like this loop has one too many iterations - there are 32 iterations, but you only have 31 digits.

Quoted 8 lines

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2911

Quoted 4 lines
target-ppc/int_helper.c +4 -0
+        digit = ((max % 10) * hi_value) + (lo_value % 10) + carry;
+        carry = (digit > 9) ? digit / 10 : 0;
+
+        bcd_put_digit(&ret, (carry) ? digit % 10 : digit, i + 1);

Ugh, this is hard to follow. We're already using an Int128 library in the memory region code; wonder if we should just use that here as well.

today we have divu128 (host-utils.h) but it doesn't work for me because it coerces the 128bits result in a 64bits variable:

__uint128_t result = dividend / divisor;
*plow = result; // -> plow is an uint64_t

So I wonder if you suggest me (like the idea) to implement div and mod in Int128 lib. Something like:

static inline Int128 int128_div64(Int128 a, uint64_t b); static inline Int128 int128_mod64(Int128 a, uint64_t b);

But, anyway, these functions would have to implement those hi/lo multiplications for the case "!CONFIG_INT128".

Quoted 51 lines
Quoted 45 lines
target-ppc/int_helper.c +13 -0
+    }
+
+    cr = bcd_cmp_zero(&ret);
+
+    if (unlikely(ox_flag)) {
+        cr |= 1 << CRF_SO;
+    }
+
+    *r = ret;
+
+    return cr;
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +7 -0
index 7143eb3..36141e5 100644
@@ -989,10 +989,14 @@ GEN_BCD2(bcdcfn)
 GEN_BCD2(bcdctn)
 GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
+GEN_BCD2(bcdcfsq)
 
 static void gen_xpnd04_1(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 2:
+        gen_bcdcfsq(ctx);
+        break;
     case 4:
         gen_bcdctz(ctx);
         break;
@@ -1014,6 +1018,9 @@ static void gen_xpnd04_1(DisasContext *ctx)
 static void gen_xpnd04_2(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 2:
+        gen_bcdcfsq(ctx);
+        break;
     case 4:
         gen_bcdctz(ctx);
         break;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#4 lore raw

Re: [Qemu-devel] [PATCH 1/4] target-ppc: Implement bcdcfsq. instruction

Quoted 112 lines · On Thu, Nov 17, 2016 at 03:31:48PM -0200, [email protected] wrote:

Hello David,

Thank you for your review. I have just one question below, could you help me to address it please?

Thank you!

Ziviani

Quoted 90 lines · David Gibson
Quoted 1 line · Jose Ricardo Ziviani

bcdcfsq.: Decimal convert from signed quadword. It is possible to

I think there should be a "not" in there.

Quoted 29 lines

convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 48 +++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  7 ++++++
 3 files changed, 56 insertions(+)
target-ppc/helper.h +1 -0
index da00f0a..87f533c 100644
@@ -382,6 +382,7 @@ DEF_HELPER_3(bcdcfn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
+DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +0 -0
index 9ac204a..db65a51 100644
@@ -2874,6 +2874,54 @@ uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
     return cr;
 }

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2885

Quoted 10 lines
target-ppc/int_helper.c +9 -0
 
+uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
+{
+    int i;
+    int cr = 0;
+    int ox_flag = 0;
+    uint64_t digit = 0;
+    uint64_t carry = 0;
+    uint64_t lo_value = 0;
+    uint64_t hi_value = 0;

Most of the variables above don't need initializers.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2891

Quoted 6 lines
target-ppc/int_helper.c +6 -0
+    uint64_t max = ULLONG_MAX;
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    if (b->s64[HI_IDX] < 0) {
+        hi_value = -b->s64[HI_IDX];
+        lo_value = b->s64[LO_IDX];

I'm pretty sure this is wrong. Take for example 128-bit -1:
ffffffff ffffffff ffffffff ffffffff
Upper word is negative (64-bit -1), so

	hi_value = 00000000 00000001
	lo_value = ffffffff ffffffff

0x1 ffffffff ffffffff != +1

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2902

Quoted 11 lines
target-ppc/int_helper.c +11 -0
+        bcd_put_digit(&ret, 0xD, 0);
+    } else if (b->s64[HI_IDX] == 0 && b->s64[LO_IDX] < 0) {
+        lo_value = -b->s64[LO_IDX];
+        bcd_put_digit(&ret, 0xD, 0);
+    } else {
+        hi_value = b->s64[HI_IDX];
+        lo_value = b->s64[LO_IDX];
+        bcd_put_digit(&ret, bcd_preferred_sgn(0, ps), 0);
+    }
+
+    if (unlikely(hi_value > 0x7e37be2022)) {

This doesn't look right. Unless by chance 10^31-1 is equal to (k*2^64
- 1) you need to look at the lo_value as well.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2903

Quoted 1 line
target-ppc/int_helper.c +1 -0
+        ox_flag = 1;

You might as well just return 1<< CRF_SO here - no point actually computing a meaningless value.

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2907

Quoted 4 lines
target-ppc/int_helper.c +4 -0
+    }
+
+    carry = hi_value;
+    for (i = 0; i < 32; i++, max /= 10, lo_value /= 10) {

Looks like this loop has one too many iterations - there are 32 iterations, but you only have 31 digits.

Quoted 8 lines

target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2911

Quoted 4 lines
target-ppc/int_helper.c +4 -0
+        digit = ((max % 10) * hi_value) + (lo_value % 10) + carry;
+        carry = (digit > 9) ? digit / 10 : 0;
+
+        bcd_put_digit(&ret, (carry) ? digit % 10 : digit, i + 1);

Ugh, this is hard to follow. We're already using an Int128 library in the memory region code; wonder if we should just use that here as well.

today we have divu128 (host-utils.h) but it doesn't work for me because it coerces the 128bits result in a 64bits variable:

Quoted 8 lines

__uint128_t result = dividend / divisor;
*plow = result; // -> plow is an uint64_t

So I wonder if you suggest me (like the idea) to implement div and mod in Int128 lib. Something like:

static inline Int128 int128_div64(Int128 a, uint64_t b); static inline Int128 int128_mod64(Int128 a, uint64_t b);

*thinks* no.. it's simpler than that.

You can use divu128() to divide your input by 10^15, and it gives you both the dividend and the remainder. The dividend gives you the value you need in the upper BCD word, and the remainder gives you the value needed in the lower BCD word. If the dividend doesn't fit in 64-bits, you'ver overflowed (bceause the original value was > 2^64*10^15 which is greater than 10^31)

Then you can use regular 64-bit arithmetic to split up those two halves into individual digits.

Quoted 2 lines

But, anyway, these functions would have to implement those hi/lo multiplications for the case "!CONFIG_INT128".

They are already implemented for !CONFIG_INT128 - see the #else case and util/host-utils.c

Quoted 50 lines
Quoted 48 lines
Quoted 47 lines
target-ppc/int_helper.c +13 -0
+    }
+
+    cr = bcd_cmp_zero(&ret);
+
+    if (unlikely(ox_flag)) {
+        cr |= 1 << CRF_SO;
+    }
+
+    *r = ret;
+
+    return cr;
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +7 -0
index 7143eb3..36141e5 100644
@@ -989,10 +989,14 @@ GEN_BCD2(bcdcfn)
 GEN_BCD2(bcdctn)
 GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
+GEN_BCD2(bcdcfsq)
 
 static void gen_xpnd04_1(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 2:
+        gen_bcdcfsq(ctx);
+        break;
     case 4:
         gen_bcdctz(ctx);
         break;
@@ -1014,6 +1018,9 @@ static void gen_xpnd04_1(DisasContext *ctx)
 static void gen_xpnd04_2(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 2:
+        gen_bcdcfsq(ctx);
+        break;
     case 4:
         gen_bcdctz(ctx);
         break;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#5 lore raw

PATCH 2/4 target-ppc: Implement bcdctsq. instruction

In reply to Jose Ricardo Ziviani

bcdctsq.: Decimal convert to signed quadword. It is possible to convert packed decimal values to signed quadwords.

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 39 +++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  7 +++++++
 3 files changed, 47 insertions(+)
target-ppc/helper.h +1 -0
index 87f533c..503f257 100644
@@ -383,6 +383,7 @@ DEF_HELPER_3(bcdctn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
+DEF_HELPER_3(bcdctsq, i32, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +39 -0
index db65a51..1025438 100644
@@ -2922,6 +2922,45 @@ uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
     return cr;
 }
 
+uint32_t helper_bcdctsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
+{
+    uint8_t i;
+    int cr = 0;
+    uint64_t hi = 0;
+    int sgnb = bcd_get_sgn(b);
+    int invalid = (sgnb == 0);
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    ret.u64[LO_IDX] = bcd_get_digit(b, 31, &invalid);
+    for (i = 30; i > 0; i--) {
+        mulu64(&ret.u64[LO_IDX], &hi,
+                ret.u64[LO_IDX], 10ULL);
+
+        ret.u64[HI_IDX] = (ret.u64[HI_IDX]) ? ret.u64[HI_IDX] * 10 + hi : hi;
+        ret.u64[LO_IDX] += bcd_get_digit(b, i, &invalid);
+
+        if (unlikely(invalid)) {
+            break;
+        }
+    }
+
+    if (sgnb == -1) {
+        if (ret.s64[HI_IDX] > 0) {
+            ret.s64[HI_IDX] = -ret.s64[HI_IDX];
+        } else {
+            ret.s64[LO_IDX] = -ret.s64[LO_IDX];
+        }
+    }
+
+    cr = bcd_cmp_zero(b);
+
+    if (unlikely(invalid)) {
+        cr = 1 << CRF_SO;
+    }
+
+    return cr;
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +7 -0
index 36141e5..1579b58 100644
@@ -990,10 +990,14 @@ GEN_BCD2(bcdctn)
 GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
 GEN_BCD2(bcdcfsq)
+GEN_BCD2(bcdctsq)
 
 static void gen_xpnd04_1(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 0:
+        gen_bcdctsq(ctx);
+        break;
     case 2:
         gen_bcdcfsq(ctx);
         break;
@@ -1018,6 +1022,9 @@ static void gen_xpnd04_1(DisasContext *ctx)
 static void gen_xpnd04_2(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 0:
+        gen_bcdctsq(ctx);
+        break;
     case 2:
         gen_bcdcfsq(ctx);
         break;
Signature · 1 line
2.7.4
#6 lore raw

Re: [Qemu-devel] [PATCH 2/4] target-ppc: Implement bcdctsq. instruction

Quoted 36 lines · Jose Ricardo Ziviani

bcdctsq.: Decimal convert to signed quadword. It is possible to convert packed decimal values to signed quadwords.

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 39 +++++++++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  7 +++++++
 3 files changed, 47 insertions(+)
target-ppc/helper.h +1 -0
index 87f533c..503f257 100644
@@ -383,6 +383,7 @@ DEF_HELPER_3(bcdctn, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
+DEF_HELPER_3(bcdctsq, i32, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +6 -0
index db65a51..1025438 100644
@@ -2922,6 +2922,45 @@ uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
     return cr;
 }
 
+uint32_t helper_bcdctsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
+{
+    uint8_t i;
+    int cr = 0;
+    uint64_t hi = 0;
+    int sgnb = bcd_get_sgn(b);

target-ppc/int_helper.c uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2940

Quoted 10 lines
target-ppc/int_helper.c +10 -0
+    int invalid = (sgnb == 0);
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    ret.u64[LO_IDX] = bcd_get_digit(b, 31, &invalid);
+    for (i = 30; i > 0; i--) {
+        mulu64(&ret.u64[LO_IDX], &hi,
+                ret.u64[LO_IDX], 10ULL);
+
+        ret.u64[HI_IDX] = (ret.u64[HI_IDX]) ? ret.u64[HI_IDX] * 10 + hi : hi;
+        ret.u64[LO_IDX] += bcd_get_digit(b, i, &invalid);

Again, it might be simpler to use the int128 code we already have in qemu.

target-ppc/int_helper.c uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2952

Quoted 11 lines
target-ppc/int_helper.c +11 -0
+        if (unlikely(invalid)) {
+            break;
+        }
+    }
+
+    if (sgnb == -1) {
+        if (ret.s64[HI_IDX] > 0) {
+            ret.s64[HI_IDX] = -ret.s64[HI_IDX];
+        } else {
+            ret.s64[LO_IDX] = -ret.s64[LO_IDX];
+        }

As on the other direction, I don't think this looks like a correct 128-bit negate.

Quoted 43 lines
target-ppc/int_helper.c +11 -0
+    }
+
+    cr = bcd_cmp_zero(b);
+
+    if (unlikely(invalid)) {
+        cr = 1 << CRF_SO;
+    }
+
+    return cr;
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +7 -0
index 36141e5..1579b58 100644
@@ -990,10 +990,14 @@ GEN_BCD2(bcdctn)
 GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
 GEN_BCD2(bcdcfsq)
+GEN_BCD2(bcdctsq)
 
 static void gen_xpnd04_1(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 0:
+        gen_bcdctsq(ctx);
+        break;
     case 2:
         gen_bcdcfsq(ctx);
         break;
@@ -1018,6 +1022,9 @@ static void gen_xpnd04_1(DisasContext *ctx)
 static void gen_xpnd04_2(DisasContext *ctx)
 {
     switch (opc4(ctx->opcode)) {
+    case 0:
+        gen_bcdctsq(ctx);
+        break;
     case 2:
         gen_bcdcfsq(ctx);
         break;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw

PATCH 3/4 target-ppc: Implement bcdcpsgn. instruction

In reply to Jose Ricardo Ziviani

bcdcpsgn.: Decimal copy sign. Given two registers vra and vrb, it copies the vra value with vrb sign to the result register vrt.

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 30 ++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  3 +++
 target-ppc/translate/vmx-ops.inc.c  |  2 +-
 4 files changed, 35 insertions(+), 1 deletion(-)
target-ppc/helper.h +1 -0
index 503f257..dada48e 100644
@@ -384,6 +384,7 @@ DEF_HELPER_3(bcdcfz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctsq, i32, avr, avr, i32)
+DEF_HELPER_4(bcdcpsgn, i32, avr, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +30 -0
index 1025438..a215bfe 100644
@@ -2961,6 +2961,36 @@ uint32_t helper_bcdctsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
     return cr;
 }
 
+uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)
+{
+    int i;
+    int cr = 0;
+    int sgna = bcd_get_sgn(a);
+    int sgnb = bcd_get_sgn(b);
+    int invalid = (sgna == 0) || (sgnb == 0);
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    for (i = 1; i < 32; i++) {
+        bcd_put_digit(&ret, bcd_get_digit(a, i, &invalid), i);
+        bcd_get_digit(b, i, &invalid);
+
+        if (unlikely(invalid)) {
+            break;
+        }
+    }
+    bcd_put_digit(&ret, bcd_get_digit(b, 0, &invalid), 0);
+
+    cr = bcd_cmp_zero(a);
+
+    if (unlikely(invalid)) {
+        cr = 1 << CRF_SO;
+    }
+
+    *r = ret;
+
+    return cr;
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +3 -0
index 1579b58..c14b666 100644
@@ -991,6 +991,7 @@ GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
 GEN_BCD2(bcdcfsq)
 GEN_BCD2(bcdctsq)
+GEN_BCD(bcdcpsgn);
 
 static void gen_xpnd04_1(DisasContext *ctx)
 {
@@ -1056,6 +1057,8 @@ GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
                 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
 GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
                 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
+GEN_VXFORM_DUAL(vaddshs, PPC_ALTIVEC, PPC_NONE, \
+                bcdcpsgn, PPC_NONE, PPC2_ISA300)
 
 static void gen_vsbox(DisasContext *ctx)
 {
target-ppc/translate/vmx-ops.inc.c +1 -1
index f02b3be..70d7d2b 100644
@@ -131,7 +131,7 @@ GEN_VXFORM_DUAL(vaddubs, vmul10uq, 0, 8, PPC_ALTIVEC, PPC_NONE),
 GEN_VXFORM_DUAL(vadduhs, vmul10euq, 0, 9, PPC_ALTIVEC, PPC_NONE),
 GEN_VXFORM(vadduws, 0, 10),
 GEN_VXFORM(vaddsbs, 0, 12),
-GEN_VXFORM(vaddshs, 0, 13),
+GEN_VXFORM_DUAL(vaddshs, bcdcpsgn, 0, 13, PPC_ALTIVEC, PPC_NONE),
 GEN_VXFORM(vaddsws, 0, 14),
 GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
 GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
Signature · 1 line
2.7.4
#8 lore raw

Re: [Qemu-devel] [PATCH 3/4] target-ppc: Implement bcdcpsgn. instruction

Quoted 33 lines · Jose Ricardo Ziviani

bcdcpsgn.: Decimal copy sign. Given two registers vra and vrb, it copies the vra value with vrb sign to the result register vrt.

---
 target-ppc/helper.h                 |  1 +
 target-ppc/int_helper.c             | 30 ++++++++++++++++++++++++++++++
 target-ppc/translate/vmx-impl.inc.c |  3 +++
 target-ppc/translate/vmx-ops.inc.c  |  2 +-
 4 files changed, 35 insertions(+), 1 deletion(-)
target-ppc/helper.h +1 -0
index 503f257..dada48e 100644
@@ -384,6 +384,7 @@ DEF_HELPER_3(bcdcfz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctsq, i32, avr, avr, i32)
+DEF_HELPER_4(bcdcpsgn, i32, avr, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +2 -0
index 1025438..a215bfe 100644
@@ -2961,6 +2961,36 @@ uint32_t helper_bcdctsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
     return cr;
 }
 
+uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)
+{

target-ppc/int_helper.c uint32_t helper_bcdctsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2975

Quoted 10 lines
target-ppc/int_helper.c +10 -0
+    int i;
+    int cr = 0;
+    int sgna = bcd_get_sgn(a);
+    int sgnb = bcd_get_sgn(b);
+    int invalid = (sgna == 0) || (sgnb == 0);
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    for (i = 1; i < 32; i++) {
+        bcd_put_digit(&ret, bcd_get_digit(a, i, &invalid), i);
+        bcd_get_digit(b, i, &invalid);

This is a lot of bit fiddling to accomplish what you could pretty much do just by copying the entire register. Checking for invalid input makes it a bit more complex than that, of course, but you still don't need to assemble every digit separately in the target.

target-ppc/int_helper.c uint32_t helper_bcdctsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2981

Quoted 6 lines
target-ppc/int_helper.c +6 -0
+
+        if (unlikely(invalid)) {
+            break;
+        }
+    }
+    bcd_put_digit(&ret, bcd_get_digit(b, 0, &invalid), 0);

This won't work. bcd_get_digit() will set invalid if digit 0 is an invalid *digit*. But some valid sign indicators are not valid digits, so this will erroneously set invalid in those cases.

Quoted 49 lines
target-ppc/int_helper.c +12 -0
+
+    cr = bcd_cmp_zero(a);
+
+    if (unlikely(invalid)) {
+        cr = 1 << CRF_SO;
+    }
+
+    *r = ret;
+
+    return cr;
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +3 -0
index 1579b58..c14b666 100644
@@ -991,6 +991,7 @@ GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
 GEN_BCD2(bcdcfsq)
 GEN_BCD2(bcdctsq)
+GEN_BCD(bcdcpsgn);
 
 static void gen_xpnd04_1(DisasContext *ctx)
 {
@@ -1056,6 +1057,8 @@ GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
                 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
 GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
                 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
+GEN_VXFORM_DUAL(vaddshs, PPC_ALTIVEC, PPC_NONE, \
+                bcdcpsgn, PPC_NONE, PPC2_ISA300)
 
 static void gen_vsbox(DisasContext *ctx)
 {
target-ppc/translate/vmx-ops.inc.c +1 -1
index f02b3be..70d7d2b 100644
@@ -131,7 +131,7 @@ GEN_VXFORM_DUAL(vaddubs, vmul10uq, 0, 8, PPC_ALTIVEC, PPC_NONE),
 GEN_VXFORM_DUAL(vadduhs, vmul10euq, 0, 9, PPC_ALTIVEC, PPC_NONE),
 GEN_VXFORM(vadduws, 0, 10),
 GEN_VXFORM(vaddsbs, 0, 12),
-GEN_VXFORM(vaddshs, 0, 13),
+GEN_VXFORM_DUAL(vaddshs, bcdcpsgn, 0, 13, PPC_ALTIVEC, PPC_NONE),
 GEN_VXFORM(vaddsws, 0, 14),
 GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
 GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#9 lore raw

PATCH 4/4 target-ppc: Implement bcdsetsgn. instruction

In reply to Jose Ricardo Ziviani

bcdsetsgn.: Decimal set sign. This instruction copies the register value to the result register but adjust the signal according to the preferred sign value.

---
 target-ppc/helper.h                 | 1 +
 target-ppc/int_helper.c             | 9 +++++++++
 target-ppc/translate/vmx-impl.inc.c | 8 ++++++++
 3 files changed, 18 insertions(+)
target-ppc/helper.h +1 -0
index dada48e..cddac8e 100644
@@ -385,6 +385,7 @@ DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctsq, i32, avr, avr, i32)
 DEF_HELPER_4(bcdcpsgn, i32, avr, avr, avr, i32)
+DEF_HELPER_3(bcdsetsgn, i32, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +9 -0
index a215bfe..38af503 100644
@@ -2991,6 +2991,15 @@ uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)
     return cr;
 }
 
+uint32_t helper_bcdsetsgn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
+{
+    int sgnb = bcd_get_sgn(b);
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    bcd_put_digit(&ret, bcd_preferred_sgn(sgnb, ps), 0);
+    return helper_bcdcpsgn(r, b, &ret, ps);
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +8 -0
index c14b666..b188e60 100644
@@ -991,6 +991,7 @@ GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
 GEN_BCD2(bcdcfsq)
 GEN_BCD2(bcdctsq)
+GEN_BCD2(bcdsetsgn)
 GEN_BCD(bcdcpsgn);
 
 static void gen_xpnd04_1(DisasContext *ctx)
@@ -1014,6 +1015,9 @@ static void gen_xpnd04_1(DisasContext *ctx)
     case 7:
         gen_bcdcfn(ctx);
         break;
+    case 31:
+        gen_bcdsetsgn(ctx);
+        break;
     default:
         gen_invalid(ctx);
         break;
@@ -1038,12 +1042,16 @@ static void gen_xpnd04_2(DisasContext *ctx)
     case 7:
         gen_bcdcfn(ctx);
         break;
+    case 31:
+        gen_bcdsetsgn(ctx);
+        break;
     default:
         gen_invalid(ctx);
         break;
     }
 }
 
+
 GEN_VXFORM_DUAL(vsubcuw, PPC_ALTIVEC, PPC_NONE, \
                 xpnd04_1, PPC_NONE, PPC2_ISA300)
 GEN_VXFORM_DUAL(vsubsws, PPC_ALTIVEC, PPC_NONE, \
Signature · 1 line
2.7.4
#10 lore raw

Re: [Qemu-devel] [PATCH 4/4] target-ppc: Implement bcdsetsgn. instruction

Quoted 28 lines · Jose Ricardo Ziviani

bcdsetsgn.: Decimal set sign. This instruction copies the register value to the result register but adjust the signal according to the preferred sign value.

---
 target-ppc/helper.h                 | 1 +
 target-ppc/int_helper.c             | 9 +++++++++
 target-ppc/translate/vmx-impl.inc.c | 8 ++++++++
 3 files changed, 18 insertions(+)
target-ppc/helper.h +1 -0
index dada48e..cddac8e 100644
@@ -385,6 +385,7 @@ DEF_HELPER_3(bcdctz, i32, avr, avr, i32)
 DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32)
 DEF_HELPER_3(bcdctsq, i32, avr, avr, i32)
 DEF_HELPER_4(bcdcpsgn, i32, avr, avr, avr, i32)
+DEF_HELPER_3(bcdsetsgn, i32, avr, avr, i32)
 
 DEF_HELPER_2(xsadddp, void, env, i32)
 DEF_HELPER_2(xssubdp, void, env, i32)
target-ppc/int_helper.c +0 -0
index a215bfe..38af503 100644

target-ppc/int_helper.c uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) · line 3000

Quoted 10 lines
target-ppc/int_helper.c +7 -0
@@ -2991,6 +2991,15 @@ uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)
     return cr;
 }
 
+uint32_t helper_bcdsetsgn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)
+{
+    int sgnb = bcd_get_sgn(b);
+    ppc_avr_t ret = { .u64 = { 0, 0 } };
+
+    bcd_put_digit(&ret, bcd_preferred_sgn(sgnb, ps), 0);
+    return helper_bcdcpsgn(r, b, &ret, ps);

This is doing a lot of work just to canonicalize the sign indicator.

Quoted 44 lines
target-ppc/int_helper.c +2 -0
+}
+
 void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a)
 {
     int i;
target-ppc/translate/vmx-impl.inc.c +8 -0
index c14b666..b188e60 100644
@@ -991,6 +991,7 @@ GEN_BCD2(bcdcfz)
 GEN_BCD2(bcdctz)
 GEN_BCD2(bcdcfsq)
 GEN_BCD2(bcdctsq)
+GEN_BCD2(bcdsetsgn)
 GEN_BCD(bcdcpsgn);
 
 static void gen_xpnd04_1(DisasContext *ctx)
@@ -1014,6 +1015,9 @@ static void gen_xpnd04_1(DisasContext *ctx)
     case 7:
         gen_bcdcfn(ctx);
         break;
+    case 31:
+        gen_bcdsetsgn(ctx);
+        break;
     default:
         gen_invalid(ctx);
         break;
@@ -1038,12 +1042,16 @@ static void gen_xpnd04_2(DisasContext *ctx)
     case 7:
         gen_bcdcfn(ctx);
         break;
+    case 31:
+        gen_bcdsetsgn(ctx);
+        break;
     default:
         gen_invalid(ctx);
         break;
     }
 }
 
+
 GEN_VXFORM_DUAL(vsubcuw, PPC_ALTIVEC, PPC_NONE, \
                 xpnd04_1, PPC_NONE, PPC2_ISA300)
 GEN_VXFORM_DUAL(vsubsws, PPC_ALTIVEC, PPC_NONE, \
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson