POWER9 TCG enablements - BCD functions part II
v2 cover POWER9 TCG enablements - BCD functions part II
v2:
- use div128 and mul64 functions to make code easier to understand
- fixed int128 neg
- improved functions bcdcpsgn and bcdsetsgn to do less work than necessary
- rebased on ppc-for-2.9
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 | 127 ++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 25 +++++++ target-ppc/translate/vmx-ops.inc.c | 2 +- 4 files changed, 157 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
PATCH v2 1/4 target-ppc: Implement bcdcfsq. instruction
bcdcfsq.: Decimal convert from signed quadword. It is not 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 | 45 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 ++++++ 3 files changed, 53 insertions(+)
target-ppc/helper.h +1 -0
@@ -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 +45 -0
51 lines not on this page · raw message
target-ppc/translate/vmx-impl.inc.c +7 -0
@@ -989,10 +989,14 @@ GEN_BCD2(bcdcfn)GEN_BCD2 (bcdctn)GEN_BCD2 (bcdcfz )GEN_BCD2 (bcdctz) +GEN_BCD2 (bcdcfsq) static voidgen_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
Re: [Qemu-devel] [PATCH v2 1/4] target-ppc: Implement bcdcfsq. instruction
Quoted 29 lines · Jose Ricardo Ziviani
bcdcfsq.: Decimal convert from signed quadword. It is not possible to convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.
Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 45 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 ++++++ 3 files changed, 53 insertions(+)target-ppc/helper.h +1
-0@@ -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@@ -2874,6 +2874,51 @@ 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 2884
Quoted 10 lines
target-ppc/int_helper.c +8
-0} +uint32_t helper_bcdcfsq (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int cr; +int i; +int ox_flag =0 ; +uint64_t lo_value; +uint64_t hi_value; +uint64_t max =0x38d7ea4c68000 ;
This is at heart a decimal number, and should be written as such. Also, you need ULL for a 32-bit host compile.
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2901
Quoted 5 lines
target-ppc/int_helper.c +5
-0+if (divu128 (&lo_value, &hi_value, max)) { + ox_flag =1 ; + }else if (lo_value >= max && hi_value ==0 ) { + ox_flag =1 ; + }
Dispense with ox_flag and set cr = CRF_SO now.
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2909
Quoted 7 lines
target-ppc/int_helper.c +7
-0+for (i =1 ; hi_value; hi_value /=10 , i++) { +bcd_put_digit (&ret, hi_value %10 , i); + } + +for (; lo_value; lo_value /=10 , i++) { +bcd_put_digit (&ret, lo_value %10 , i); + }
How can this possibly work? You know there are 15 digits between high and low, but you continue with i++?
If hi_value == 1 && lo_value == 1, this should not produce 11, but 10000000000000001.
r~
Re: [Qemu-devel] [PATCH v2 1/4] target-ppc: Implement bcdcfsq. instruction
Quoted 60 lines · Richard Henderson
Quoted 29 lines · Jose Ricardo Ziviani
bcdcfsq.: Decimal convert from signed quadword. It is not possible to convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.
Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 45 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 ++++++ 3 files changed, 53 insertions(+)target-ppc/helper.h +1
-0@@ -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@@ -2874,6 +2874,51 @@ 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 2884
Quoted 10 lines
target-ppc/int_helper.c +8
-0} +uint32_t helper_bcdcfsq (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int cr; +int i; +int ox_flag =0 ; +uint64_t lo_value; +uint64_t hi_value; +uint64_t max =0x38d7ea4c68000 ;This is at heart a decimal number, and should be written as such. Also, you need ULL for a 32-bit host compile.
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2901
Quoted 5 lines
target-ppc/int_helper.c +5
-0+if (divu128 (&lo_value, &hi_value, max)) { + ox_flag =1 ; + }else if (lo_value >= max && hi_value ==0 ) { + ox_flag =1 ; + }Dispense with
ox_flagand set cr =CRF_SOnow.target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2909
Quoted 7 lines
target-ppc/int_helper.c +7
-0+for (i =1 ; hi_value; hi_value /=10 , i++) { +bcd_put_digit (&ret, hi_value %10 , i); + } + +for (; lo_value; lo_value /=10 , i++) { +bcd_put_digit (&ret, lo_value %10 , i); + }
Quoted 5 lines
How can this possibly work? You know there are 15 digits between high and low, but you continue with i++?
If
hi_value== 1 &&lo_value== 1, this should not produce 11, but 10000000000000001.
Ah, yes good catch, I missed that. I think it will be clearer to use fixed bounds on each loop, rather than testing the value of the remaining result.
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 1/4] target-ppc: Implement bcdcfsq. instruction
In reply to Richard HendersonHello Richard,
Thank you for your review, please read my answer below.
Quoted 32 lines · Richard Henderson
Quoted 31 lines · Jose Ricardo Ziviani
bcdcfsq.: Decimal convert from signed quadword. It is not possible to convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.
Signed-off-by Jose Ricardo Ziviani <[email protected]>---
target-ppc/helper.h | 1 + target-ppc/int_helper.c | 45 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 ++++++ 3 files changed, 53 insertions(+)target-ppc/helper.h +1
-0@@ -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@@ -2874,6 +2874,51 @@ uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)return cr; }
Quoted 12 lines
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2884
Quoted 8 lines
target-ppc/int_helper.c +8
-0+uint32_t helper_bcdcfsq (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int cr; +int i; +int ox_flag =0 ; +uint64_t lo_value; +uint64_t hi_value; +uint64_t max =0x38d7ea4c68000 ;This is at heart a decimal number, and should be written as such. Also, you need ULL for a 32-bit host compile.
OK
Quoted 8 lines
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2901
Quoted 5 lines
target-ppc/int_helper.c +5
-0+if (divu128 (&lo_value, &hi_value, max)) { + ox_flag =1 ; + }else if (lo_value >= max && hi_value ==0 ) { + ox_flag =1 ; + }Dispense with
ox_flagand set cr =CRF_SOnow.
OK
Quoted 8 lines
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2909
Quoted 7 lines
target-ppc/int_helper.c +7
-0+for (i =1 ; hi_value; hi_value /=10 , i++) { +bcd_put_digit (&ret, hi_value %10 , i); + } + +for (; lo_value; lo_value /=10 , i++) { +bcd_put_digit (&ret, lo_value %10 , i); + }
Quoted 6 lines
How can this possibly work? You know there are 15 digits between high and low, but you continue with i++?
If
hi_value== 1 &&lo_value== 1, this should not produce 11, but 10000000000000001.
Suppose we have hi_value = lo_value = 1
after divu128 above we will havehi_value = 744073709551617lo_value = 18446
then, after the first for loop:hi_value = 0lo_value = 18446
i = 16
ret = u128 = 0x8376822234287792511
finally, after the second loop:hi_value = 0lo_value = 0
i = 21
ret = u128 = 0x0000000000018446744073709551617f
Which is correct, this function converted a signed quadword to bcd correctly, using two doubleword variables:
1 << 64 | 1 = 18446744073709551617
Am I missing anything?
Thank you!
Quoted 3 lines
r~
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 1/4] target-ppc: Implement bcdcfsq. instruction
Quoted 75 lines · On Thu, Nov 24, 2016 at 02:31:21PM -0200, [email protected] wrote:
Hello Richard,
Thank you for your review, please read my answer below.
Quoted 32 lines · Richard Henderson
Quoted 31 lines · Jose Ricardo Ziviani
bcdcfsq.: Decimal convert from signed quadword. It is not possible to convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.
Signed-off-by Jose Ricardo Ziviani <[email protected]>---
target-ppc/helper.h | 1 + target-ppc/int_helper.c | 45 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 ++++++ 3 files changed, 53 insertions(+)target-ppc/helper.h +1
-0@@ -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@@ -2874,6 +2874,51 @@ uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)return cr; }Quoted 12 lines
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2884
Quoted 8 lines
target-ppc/int_helper.c +8
-0+uint32_t helper_bcdcfsq (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int cr; +int i; +int ox_flag =0 ; +uint64_t lo_value; +uint64_t hi_value; +uint64_t max =0x38d7ea4c68000 ;This is at heart a decimal number, and should be written as such. Also, you need ULL for a 32-bit host compile.
OK
Quoted 8 lines
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2901
Quoted 5 lines
target-ppc/int_helper.c +5
-0+if (divu128 (&lo_value, &hi_value, max)) { + ox_flag =1 ; + }else if (lo_value >= max && hi_value ==0 ) { + ox_flag =1 ; + }Dispense with
ox_flagand set cr =CRF_SOnow.OK
Quoted 11 lines
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2909
Quoted 7 lines
target-ppc/int_helper.c +7
-0+for (i =1 ; hi_value; hi_value /=10 , i++) { +bcd_put_digit (&ret, hi_value %10 , i); + } + +for (; lo_value; lo_value /=10 , i++) { +bcd_put_digit (&ret, lo_value %10 , i); + }How can this possibly work? You know there are 15 digits between high and low, but you continue with i++?
Quoted 7 lines
Quoted 3 lines
If
hi_value== 1 &&lo_value== 1, this should not produce 11, but 10000000000000001.Suppose we have
hi_value=lo_value= 1after divu128 above we will have
No, Richard means if you have hi_value == 1 and lo_value == 1 *after* the divide. This will happen if input has *decimal* value 1000000000000001. The point is that 'i' will have the wrong value if the low output word has any leading zeroes.
Quoted 26 lines
hi_value= 744073709551617lo_value= 18446then, after the first for loop:
hi_value= 0lo_value= 18446
i = 16
ret = u128 =0x8376822234287792511finally, after the second loop:
hi_value= 0lo_value= 0
i = 21
ret = u128 =0x0000000000018446744073709551617fWhich is correct, this function converted a signed quadword to bcd correctly, using two doubleword variables:
1 << 64 | 1 = 18446744073709551617Am I missing anything?
Thank you!
Quoted 3 lines
r~
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
Re: [Qemu-devel] [PATCH v2 1/4] target-ppc: Implement bcdcfsq. instruction
In reply to Jose Ricardo ZivianiQuoted 3 lines · Jose Ricardo Ziviani
bcdcfsq.: Decimal convert from signed quadword. It is not possible to convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format.
You have your less than / greater than the wrong way around in the above.
Quoted 26 lines
Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 45 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 ++++++ 3 files changed, 53 insertions(+)target-ppc/helper.h +1
-0@@ -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@@ -2874,6 +2874,51 @@ 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 2884
Quoted 10 lines
target-ppc/int_helper.c +8
-0} +uint32_t helper_bcdcfsq (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int cr; +int i; +int ox_flag =0 ; +uint64_t lo_value; +uint64_t hi_value; +uint64_t max =0x38d7ea4c68000 ;
In this case it would be clearer what's going on if you gave this constant in decimal. "max" is also not a great name - see below.
Quoted 5 lines
target-ppc/int_helper.c +5
-0+ppc_avr_t ret = { .u64 = {0 ,0 } }; + +if (b->s64[HI_IDX ] <0 ) { + lo_value = -b->s64[LO_IDX ]; + hi_value = ~b->u64[HI_IDX ] + !lo_value;
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2899
Quoted 10 lines
target-ppc/int_helper.c +10
-0+bcd_put_digit (&ret,0xD ,0 ); + }else { + lo_value = b->u64[LO_IDX ]; + hi_value = b->u64[HI_IDX ]; +bcd_put_digit (&ret,bcd_preferred_sgn (0 , ps),0 ); + } + +if (divu128 (&lo_value, &hi_value, max)) { + ox_flag =1 ; + }else if (lo_value >= max && hi_value ==0 ) {
This isn't right. max == 10^15, but in fact the dividend can safely be up to 10^16 - 1. I don't see what checking the remainder against 0 has to do with anything, either. No overflow + (dividend < 10^16) should be sufficient.
Quoted 5 lines
target-ppc/int_helper.c +5
-0+ ox_flag =1 ; + } + +for (i =1 ; hi_value; hi_value /=10 , i++) { +bcd_put_digit (&ret, hi_value %10 , i);
target-ppc/int_helper.c uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2914
Quoted 10 lines
target-ppc/int_helper.c +10
-0+ } + +for (; lo_value; lo_value /=10 , i++) { +bcd_put_digit (&ret, lo_value %10 , i); + } + + cr =bcd_cmp_zero (&ret); + +if (unlikely (ox_flag)) { + cr |=1 <<CRF_SO ;
Since you posted I've merged a patch from Nikunj which chanes the meaning of these CRF_* flags to be bit masks instead of shifts. So this will need to become just
cr |= CRF_SO;
Quoted 39 lines
target-ppc/int_helper.c +7
-0+ } + + *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@@ -989,10 +989,14 @@ GEN_BCD2(bcdcfn)GEN_BCD2 (bcdctn)GEN_BCD2 (bcdcfz )GEN_BCD2 (bcdctz) +GEN_BCD2 (bcdcfsq) static voidgen_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
PATCH v2 2/4 target-ppc: Implement bcdctsq. instruction
In reply to Jose Ricardo Zivianibcdctsq.: 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 | 40 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++++++ 3 files changed, 48 insertions(+)
target-ppc/helper.h +1 -0
@@ -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 +40 -0
@@ -2919,6 +2919,46 @@ 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; +uint64_t carry; +uint64_t unused; +uint64_t lo_value; +uint64_t hi_value =0 ; +int sgnb =bcd_get_sgn (b); +int invalid = (sgnb ==0 ); + + lo_value =bcd_get_digit (b,31 , &invalid); +for (i =30 ; i >0 ; i--) { +mulu64 (&lo_value, &carry, lo_value,10ULL ); +mulu64 (&hi_value, &unused, hi_value,10ULL ); + lo_value +=bcd_get_digit (b, i, &invalid); + hi_value += carry; + +if (unlikely (invalid)) { +break ; + } + } + +if (sgnb ==-1 ) { + r->s64[LO_IDX ] = -lo_value; + r->s64[HI_IDX ] = ~hi_value + !r->s64[LO_IDX ]; + }else { + r->s64[LO_IDX ] = lo_value; + r->s64[HI_IDX ] = hi_value; + } + + 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
@@ -990,10 +990,14 @@ GEN_BCD2(bcdctn)GEN_BCD2 (bcdcfz)GEN_BCD2 (bcdctz )GEN_BCD2 (bcdcfsq) +GEN_BCD2 (bcdctsq) static voidgen_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
Re: [Qemu-devel] [PATCH v2 2/4] target-ppc: Implement bcdctsq. instruction
Quoted 4 lines · Jose Ricardo Ziviani
bcdctsq.: Decimal convert to signed quadword. It is possible to convert packed decimal values to signed quadwords.
Signed-off-by Jose Ricardo Ziviani <[email protected]>
Quoted 98 lines
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 40 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++++++ 3 files changed, 48 insertions(+)target-ppc/helper.h +1
-0@@ -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 +40
-0@@ -2919,6 +2919,46 @@ 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; +uint64_t carry; +uint64_t unused; +uint64_t lo_value; +uint64_t hi_value =0 ; +int sgnb =bcd_get_sgn (b); +int invalid = (sgnb ==0 ); + + lo_value =bcd_get_digit (b,31 , &invalid); +for (i =30 ; i >0 ; i--) { +mulu64 (&lo_value, &carry, lo_value,10ULL ); +mulu64 (&hi_value, &unused, hi_value,10ULL ); + lo_value +=bcd_get_digit (b, i, &invalid); + hi_value += carry; + +if (unlikely (invalid)) { +break ; + } + } + +if (sgnb ==-1 ) { + r->s64[LO_IDX ] = -lo_value; + r->s64[HI_IDX ] = ~hi_value + !r->s64[LO_IDX ]; + }else { + r->s64[LO_IDX ] = lo_value; + r->s64[HI_IDX ] = hi_value; + } + + 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@@ -990,10 +990,14 @@ GEN_BCD2(bcdctn)GEN_BCD2 (bcdcfz)GEN_BCD2 (bcdctz )GEN_BCD2 (bcdcfsq) +GEN_BCD2 (bcdctsq) static voidgen_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
PATCH v2 3/4 target-ppc: Implement bcdcpsgn. instruction
In reply to Jose Ricardo Zivianibcdcpsgn.: 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 | 23 +++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 3 +++ target-ppc/translate/vmx-ops.inc.c | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)
target-ppc/helper.h +1 -0
@@ -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 +23 -0
@@ -2959,6 +2959,29 @@ 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 invalid =0 ; + +if (bcd_get_sgn (a) ==0 ||bcd_get_sgn (b) ==0 ) { +return 1 <<CRF_SO ; + } + + *r = *a; +bcd_put_digit (r, b->u8[BCD_DIG_BYTE (0 )] &0xF ,0 ); + +for (i =1 ; i <32 ; i++) { +bcd_get_digit (a, i, &invalid); +bcd_get_digit (b, i, &invalid); +if (unlikely (invalid)) { +return 1 <<CRF_SO ; + } + } + +return bcd_cmp_zero (r); +} +void helper_vsbox (ppc_avr_t *r,ppc_avr_t *a) {int i;
target-ppc/translate/vmx-impl.inc.c +3 -0
@@ -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
@@ -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
Re: [Qemu-devel] [PATCH v2 3/4] target-ppc: Implement bcdcpsgn. instruction
Quoted 4 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.
Signed-off-by Jose Ricardo Ziviani <[email protected]>
Quoted 87 lines
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 23 +++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 3 +++ target-ppc/translate/vmx-ops.inc.c | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)target-ppc/helper.h +1
-0@@ -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 +23
-0@@ -2959,6 +2959,29 @@ 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 invalid =0 ; + +if (bcd_get_sgn (a) ==0 ||bcd_get_sgn (b) ==0 ) { +return 1 <<CRF_SO ; + } + + *r = *a; +bcd_put_digit (r, b->u8[BCD_DIG_BYTE (0 )] &0xF ,0 ); + +for (i =1 ; i <32 ; i++) { +bcd_get_digit (a, i, &invalid); +bcd_get_digit (b, i, &invalid); +if (unlikely (invalid)) { +return 1 <<CRF_SO ; + } + } + +return bcd_cmp_zero (r); +} +void helper_vsbox (ppc_avr_t *r,ppc_avr_t *a) {int i;target-ppc/translate/vmx-impl.inc.c +3
-0@@ -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@@ -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
PATCH v2 4/4 target-ppc: Implement bcdsetsgn. instruction
In reply to Jose Ricardo Zivianibcdsetsgn.: 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 | 19 +++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 8 ++++++++ 3 files changed, 28 insertions(+)
target-ppc/helper.h +1 -0
@@ -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 +19 -0
@@ -2982,6 +2982,25 @@ uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)return bcd_cmp_zero (r); } +uint32_t helper_bcdsetsgn (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i; +int invalid =0 ; +int sgnb =bcd_get_sgn (b); + + *r = *b; +bcd_put_digit (r,bcd_preferred_sgn (sgnb, ps),0 ); + +for (i =1 ; i <32 ; i++) { +bcd_get_digit (b, i, &invalid); +if (unlikely (invalid)) { +return 1 <<CRF_SO ; + } + } + +return bcd_cmp_zero (r); +} +void helper_vsbox (ppc_avr_t *r,ppc_avr_t *a) {int i;
target-ppc/translate/vmx-impl.inc.c +8 -0
@@ -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
Re: [Qemu-devel] [PATCH v2 4/4] target-ppc: Implement bcdsetsgn. instruction
Quoted 5 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.
Signed-off-by Jose Ricardo Ziviani <[email protected]>
Quoted 87 lines
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 19 +++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 8 ++++++++ 3 files changed, 28 insertions(+)target-ppc/helper.h +1
-0@@ -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 +19
-0@@ -2982,6 +2982,25 @@ uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)return bcd_cmp_zero (r); } +uint32_t helper_bcdsetsgn (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i; +int invalid =0 ; +int sgnb =bcd_get_sgn (b); + + *r = *b; +bcd_put_digit (r,bcd_preferred_sgn (sgnb, ps),0 ); + +for (i =1 ; i <32 ; i++) { +bcd_get_digit (b, i, &invalid); +if (unlikely (invalid)) { +return 1 <<CRF_SO ; + } + } + +return bcd_cmp_zero (r); +} +void helper_vsbox (ppc_avr_t *r,ppc_avr_t *a) {int i;target-ppc/translate/vmx-impl.inc.c +8
-0@@ -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
Quoted 7 lines · Jose Ricardo Ziviani
v2:
- use div128 and mul64 functions to make code easier to understand
- fixed int128 neg
- improved functions bcdcpsgn and bcdsetsgn to do less work than necessary
- rebased on ppc-for-2.9
Quoted 6 lines
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
Patch 1/4 has some problems, see comments.
Patches 2..4/4 look ok - except that they'll need to be updated for the recent change I merged from Nikunj (in ppc-for-2.9) which changes the meaning of CRF_*.
Quoted 13 lines
Jose Ricardo Ziviani (4):
target-ppc: Implement bcdcfsq. instruction
target-ppc: Implement bcdctsq. instruction
target-ppc: Implement bcdcpsgn. instruction
target-ppc: Implement bcdsetsgn. instructiontarget-ppc/helper.h | 4 ++ target-ppc/int_helper.c | 127 ++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 25 +++++++ target-ppc/translate/vmx-ops.inc.c | 2 +- 4 files changed, 157 insertions(+), 1 deletion(-)
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
David,
Thank you again for reviewing my code, I'm making the changes. I only have a question about patch 1/4 which I didn't find the issue so I'm waiting for Richard's answer.
Thanks!
Quoted 40 lines · David Gibson
Quoted 7 lines · Jose Ricardo Ziviani
v2:
- use div128 and mul64 functions to make code easier to understand
- fixed int128 neg
- improved functions bcdcpsgn and bcdsetsgn to do less work than necessary
- rebased on ppc-for-2.9Quoted 6 lines
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
Patch 1/4 has some problems, see comments.
Patches 2..4/4 look ok - except that they'll need to be updated for the recent change I merged from Nikunj (in ppc-for-2.9) which changes the meaning of CRF_*.
Quoted 13 lines
Jose Ricardo Ziviani (4):
target-ppc: Implement bcdcfsq. instruction
target-ppc: Implement bcdctsq. instruction
target-ppc: Implement bcdcpsgn. instruction
target-ppc: Implement bcdsetsgn. instructiontarget-ppc/helper.h | 4 ++ target-ppc/int_helper.c | 127 ++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 25 +++++++ target-ppc/translate/vmx-ops.inc.c | 2 +- 4 files changed, 157 insertions(+), 1 deletion(-)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