0/4] POWER9 TCG enablements - BCD functions part I
PATCH 1/1 0/4] POWER9 TCG enablements - BCD functions part I
This serie contains 4 new instructions for POWER9 ISA3.0
bcdcfn.: Decimal Convert From National
bcdctn.: Decimal Convert To National
bcdcfz.: Decimal Convert From Zoned
bcdctz.: Decimal Convert to Zoned
Jose Ricardo Ziviani (4):
target-ppc: Implement bcdcfn. instruction
target-ppc: Implement bcdctn. instruction
target-ppc: Implement bcdcfz. instruction
target-ppc: Implement bcdctz. instruction
target-ppc/helper.h | 4 + target-ppc/int_helper.c | 209 ++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 103 ++++++++++++++++++ target-ppc/translate/vmx-ops.inc.c | 4 +- 4 files changed, 318 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/1 1/4] target-ppc: Implement bcdcfn. instruction
bcdcfn. converts from National numeric format to BCD. National format uses a byte to represent a digit where the most significant nibble is always 0x3 and the least sign. nibbles is the digit itself.
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 ++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 75 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-ops.inc.c | 4 +- 4 files changed, 132 insertions(+), 2 deletions(-)
target-ppc/helper.h +1 -0
@@ -369,6 +369,7 @@ DEF_HELPER_4(vpermxor, void, avr, avr, avr, avr) DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) +DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)
target-ppc/int_helper.c +54 -0
72 lines not on this page · raw message
target-ppc/translate/vmx-impl.inc.c +75 -0
86 lines not on this page · raw message
target-ppc/translate/vmx-ops.inc.c +2 -2
@@ -122,7 +122,7 @@ GEN_VXFORM_300(vslv, 2, 29),GEN_VXFORM (vslo,6 ,16 ),GEN_VXFORM (vsro,6 ,17 ),GEN_VXFORM (vaddcuw,0 ,6 ), -GEN_VXFORM (vsubcuw,0 ,22 ), +GEN_VXFORM_DUAL (vsubcuw, xpnd04_1,0 ,22 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM (vaddubs,0 ,8 ),GEN_VXFORM (vadduhs,0 ,9 ), GEN_VXFORM(vadduws, 0, 10),
@@ -134,7 +134,7 @@ GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),GEN_VXFORM (vsubuws,0 ,26 ),GEN_VXFORM (vsubsbs,0 ,28 ),GEN_VXFORM (vsubshs,0 ,29 ), -GEN_VXFORM (vsubsws,0 ,30 ), +GEN_VXFORM_DUAL (vsubsws, xpnd04_2,0 ,30 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM_207 (vadduqm,0 ,4 ),GEN_VXFORM_207 (vaddcuq,0 ,5 ), GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH] 1/4] target-ppc: Implement bcdcfn. instruction
Quoted 38 lines · Jose Ricardo Ziviani
bcdcfn. converts from National numeric format to BCD. National format uses a byte to represent a digit where the most significant nibble is always
0x3and the least sign. nibbles is the digit itself.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 ++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 75 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-ops.inc.c | 4 +- 4 files changed, 132 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -369,6 +369,7 @@ DEF_HELPER_4(vpermxor, void, avr, avr, avr, avr) DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) +DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +2
-0@@ -2417,6 +2417,8 @@ void helper_vsubecuq(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, ppc_avr_t *c)#define BCD_NEG_PREF 0xD#define BCD_NEG_ALT 0xB#define BCD_PLUS_ALT_2 0xE +#define NATIONAL_PLUS 0x2B +#define NATIONAL_NEG 0x2D#if defined(HOST_WORDS_BIGENDIAN )#define BCD_DIG_BYTE (n) (15 - (n/2))
target-ppc/int_helper.c static void bcd_put_digit(ppc_avr_t *bcd, uint8_t digit, int n) · line 2494
Quoted 10 lines
target-ppc/int_helper.c +7
-0@@ -2483,6 +2485,15 @@ static void bcd_put_digit(ppc_avr_t *bcd, uint8_t digit, int n) } } +static uint8_t get_national_digit (ppc_avr_t *reg,int n) +{ +#if defined(HOST_WORDS_BIGENDIAN ) +return reg->u16[8 - n] &0xFF ; +#else +return reg->u16[n] &0xFF ; +#endif
You're discarding the high byte of each digit here, which means you won't detect badly encoded values that have correct low bytes.
Quoted 22 lines
target-ppc/int_helper.c +15
-0+} +static int bcd_cmp_mag (ppc_avr_t *a,ppc_avr_t *b) {int i;@@ -2613,6 +2624,49 @@ uint32_t helper_bcdsub(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)return helper_bcdadd (r, a, &bcopy, ps); } +uint32_t helper_bcdcfn (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i; +int is_zero =0 ; +int cr =0 ; +int national =0 ; +ppc_avr_t ret = { .u64 = {0 ,0 } }; +uint16_t sgnb =get_national_digit (b,0 ); +int invalid = (sgnb !=NATIONAL_PLUS && sgnb !=NATIONAL_NEG ); + +for (i =1 ; i <8 ; i++) { + national =get_national_digit (b, i); +
target-ppc/int_helper.c uint32_t helper_bcdsub(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) · line 2649
Quoted 10 lines
target-ppc/int_helper.c +10
-0+ is_zero += (national ==0x30 ); +if (unlikely (national <0x30 || national >0x39 )) { + invalid =1 ; + } + +bcd_put_digit (&ret, national &0xf , i); + } + +if (sgnb ==NATIONAL_PLUS || + (b->u64[0 ] ==0 && b->u64[1 ] ==0 )) {
The second part of this test doesn't seem to make much sense. I think you're trying to always put a positive sign on a zero result. But you're testing the national encoded input, not the BCD encoded output, and zero will *not* be all zero bits in national encoding.
target-ppc/int_helper.c uint32_t helper_bcdsub(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) · line 2655
Quoted 6 lines
target-ppc/int_helper.c +6
-0+bcd_put_digit (&ret, (ps ==0 ) ?BCD_PLUS_PREF_1 :BCD_PLUS_PREF_2 ,0 ); + }else { +bcd_put_digit (&ret,BCD_NEG_PREF ,0 ); + } + +if (!is_zero) {
From the logic above, 'is_zero' is currently a count of how many 0 digits the value has, not whether the value as a whole is zero. That means you will get the wrong result here.
Quoted 85 lines
target-ppc/int_helper.c +14
-0+ cr = (sgnb ==NATIONAL_PLUS ) ?1 <<CRF_GT :1 <<CRF_LT ; + }else { + cr =1 <<CRF_EQ ; + } + +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 +58
-0@@ -871,8 +871,81 @@ static void gen_##op(DisasContext *ctx) \tcg_temp_free_i32 (ps); \ } +#define GEN_BCD2 (op) \ +static void gen_##op(DisasContext *ctx) \ +{ \ + TCGv_ptr rd, rb; \ + TCGv_i32 ps; \ + \ + if (unlikely(!ctx->altivec_enabled)) { \ + gen_exception(ctx, POWERPC_EXCP_VPU); \ + return; \ + } \ + \ + rb = gen_avr_ptr(rB(ctx->opcode)); \ + rd = gen_avr_ptr(rD(ctx->opcode)); \ + \ + ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \ + \ + gen_helper_##op(cpu_crf[6], rd, rb, ps); \ + \ + tcg_temp_free_ptr(rb); \ + tcg_temp_free_ptr(rd); \ + tcg_temp_free_i32(ps); \ +} +GEN_BCD (bcdadd)GEN_BCD (bcdsub ) +GEN_BCD2 (bcdcfn) + +static voidgen_xpnd04_1 (DisasContext *ctx) +{ +switch (opc4 (ctx->opcode)) { +case 0 : +break ;/* bcdctsq. */ +case 2 : +break ;/* bcdcfsq. */ +case 4 : +break ;/* bcdctz. */ +case 5 : +break ;/* bcdctn. */ +case 6 : +break ;/* bcdcfz. */ +case 7 : +gen_bcdcfn (ctx); +break ; +case 31 : +break ;/* bcdsetsgn. */ +default : +break ; + } +} + +static void gen_xpnd04_2 (DisasContext *ctx) +{ +switch (opc4 (ctx->opcode)) { +case 0 : +break ;/* bcdctsq. */ +case 2 : +break ;/* bcdcfsq. */ +case 4 : +break ;/* bcdctz. */ +case 6 :
target-ppc/translate/vmx-impl.inc.c static void gen_##op(DisasContext *ctx) \ · line 943
Quoted 10 lines
target-ppc/translate/vmx-impl.inc.c +10
-0+break ;/* bcdcfz. */ +case 7 : +gen_bcdcfn (ctx); +break ; +case 31 : +break ;/* bcdsetsgn. */ +default : +break ; + } +}
I thougt the main opcode table now had support for opc4, so you shouldn't need these special expanders.
Quoted 35 lines
target-ppc/translate/vmx-impl.inc.c +6
-0+GEN_VXFORM_DUAL (vsubcuw,PPC_ALTIVEC ,PPC_NONE , \ + xpnd04_1, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL (vsubsws,PPC_ALTIVEC ,PPC_NONE , \ + xpnd04_2, PPC_NONE, PPC2_ISA300)GEN_VXFORM_DUAL (vsububm,PPC_ALTIVEC ,PPC_NONE , \ bcdadd,PPC_NONE ,PPC2_ALTIVEC_207 )@@ -949,3 +1022,5 @@ GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,#undef GEN_VXFORM_NOA#undef GEN_VXFORM_UIMM#undef GEN_VAFORM_PAIRED + +#undef GEN_BCD2target-ppc/translate/vmx-ops.inc.c +2
-2@@ -122,7 +122,7 @@ GEN_VXFORM_300(vslv, 2, 29),GEN_VXFORM (vslo,6 ,16 ),GEN_VXFORM (vsro,6 ,17 ),GEN_VXFORM (vaddcuw,0 ,6 ), -GEN_VXFORM (vsubcuw,0 ,22 ), +GEN_VXFORM_DUAL (vsubcuw, xpnd04_1,0 ,22 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM (vaddubs,0 ,8 ),GEN_VXFORM (vadduhs,0 ,9 ), GEN_VXFORM(vadduws, 0, 10),@@ -134,7 +134,7 @@ GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),GEN_VXFORM (vsubuws,0 ,26 ),GEN_VXFORM (vsubsbs,0 ,28 ),GEN_VXFORM (vsubshs,0 ,29 ), -GEN_VXFORM (vsubsws,0 ,30 ), +GEN_VXFORM_DUAL (vsubsws, xpnd04_2,0 ,30 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM_207 (vadduqm,0 ,4 ),GEN_VXFORM_207 (vaddcuq,0 ,5 ), GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
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] 1/4] target-ppc: Implement bcdcfn. instruction
Hello David,
Thank you very much for your review. As you might have noticed this is my first patch so I hope you don't mind about my newbie questions/explanations below.
Quoted 42 lines · David Gibson
Quoted 41 lines · Jose Ricardo Ziviani
bcdcfn. converts from National numeric format to BCD. National format uses a byte to represent a digit where the most significant nibble is always
0x3and the least sign. nibbles is the digit itself.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 ++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 75 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-ops.inc.c | 4 +- 4 files changed, 132 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -369,6 +369,7 @@ DEF_HELPER_4(vpermxor, void, avr, avr, avr, avr) DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) +DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +2
-0@@ -2417,6 +2417,8 @@ void helper_vsubecuq(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, ppc_avr_t *c)#define BCD_NEG_PREF 0xD#define BCD_NEG_ALT 0xB#define BCD_PLUS_ALT_2 0xE +#define NATIONAL_PLUS 0x2B +#define NATIONAL_NEG 0x2D#if defined(HOST_WORDS_BIGENDIAN )#define BCD_DIG_BYTE (n) (15 - (n/2))@@ -2483,6 +2485,15 @@ static void bcd_put_digit(ppc_avr_t *bcd, uint8_t digit, int n) } }
Quoted 10 lines
target-ppc/int_helper.c static void bcd_put_digit(ppc_avr_t *bcd, uint8_t digit, int n) · line 2494
Quoted 7 lines
target-ppc/int_helper.c +7
-0+static uint8_t get_national_digit (ppc_avr_t *reg,int n) +{ +#if defined(HOST_WORDS_BIGENDIAN ) +return reg->u16[8 - n] &0xFF ; +#else +return reg->u16[n] &0xFF ; +#endif You're discarding the high byte of each digit here, which means you won't detect badly encoded values that have correct low bytes.
OK! The high byte is expected to be 0, I'll check if it's != 0 and set a flag like:
*invalid = (reg->u16[n] >> 8) != 0;
makes sense?
Quoted 30 lines
Quoted 30 lines
target-ppc/int_helper.c +22
-0+} +static int bcd_cmp_mag (ppc_avr_t *a,ppc_avr_t *b) {int i;@@ -2613,6 +2624,49 @@ uint32_t helper_bcdsub(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)return helper_bcdadd (r, a, &bcopy, ps); } +uint32_t helper_bcdcfn (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i; +int is_zero =0 ; +int cr =0 ; +int national =0 ; +ppc_avr_t ret = { .u64 = {0 ,0 } }; +uint16_t sgnb =get_national_digit (b,0 ); +int invalid = (sgnb !=NATIONAL_PLUS && sgnb !=NATIONAL_NEG ); + +for (i =1 ; i <8 ; i++) { + national =get_national_digit (b, i); + + is_zero += (national ==0x30 ); +if (unlikely (national <0x30 || national >0x39 )) { + invalid =1 ; + } + +bcd_put_digit (&ret, national &0xf , i); + }
Quoted 8 lines
target-ppc/int_helper.c uint32_t helper_bcdsub(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) · line 2649
Quoted 3 lines
target-ppc/int_helper.c +3
-0+ +if (sgnb ==NATIONAL_PLUS || + (b->u64[0 ] ==0 && b->u64[1 ] ==0 )) {The second part of this test doesn't seem to make much sense. I think you're trying to always put a positive sign on a zero result. But you're testing the national encoded input, not the BCD encoded output, and zero will *not* be all zero bits in national encoding.
OK! ISA defines invalid encoding as undefined behavior. I forced a positive sign to vrt when vrb = 0 (invalid enc.) but it is not necessary. I'll remove it in v2.
Quoted 8 lines
target-ppc/int_helper.c uint32_t helper_bcdsub(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) · line 2655
Quoted 7 lines
target-ppc/int_helper.c +6
-0+bcd_put_digit (&ret, (ps ==0 ) ?BCD_PLUS_PREF_1 :BCD_PLUS_PREF_2 ,0 ); + }else { +bcd_put_digit (&ret,BCD_NEG_PREF ,0 ); + } + +if (!is_zero) {
Quoted 4 lines
From the logic above, '
is_zero' is currently a count of how many 0 digits the value has, not whether the value as a whole is zero. That means you will get the wrong result here.
OK! I'll fix that logic.
Quoted 90 lines
Quoted 90 lines
target-ppc/int_helper.c +14
-0+ cr = (sgnb ==NATIONAL_PLUS ) ?1 <<CRF_GT :1 <<CRF_LT ; + }else { + cr =1 <<CRF_EQ ; + } + +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 +63
-0@@ -871,8 +871,81 @@ static void gen_##op(DisasContext *ctx) \tcg_temp_free_i32 (ps); \ } +#define GEN_BCD2 (op) \ +static void gen_##op(DisasContext *ctx) \ +{ \ + TCGv_ptr rd, rb; \ + TCGv_i32 ps; \ + \ + if (unlikely(!ctx->altivec_enabled)) { \ + gen_exception(ctx, POWERPC_EXCP_VPU); \ + return; \ + } \ + \ + rb = gen_avr_ptr(rB(ctx->opcode)); \ + rd = gen_avr_ptr(rD(ctx->opcode)); \ + \ + ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \ + \ + gen_helper_##op(cpu_crf[6], rd, rb, ps); \ + \ + tcg_temp_free_ptr(rb); \ + tcg_temp_free_ptr(rd); \ + tcg_temp_free_i32(ps); \ +} +GEN_BCD (bcdadd)GEN_BCD (bcdsub ) +GEN_BCD2 (bcdcfn) + +static voidgen_xpnd04_1 (DisasContext *ctx) +{ +switch (opc4 (ctx->opcode)) { +case 0 : +break ;/* bcdctsq. */ +case 2 : +break ;/* bcdcfsq. */ +case 4 : +break ;/* bcdctz. */ +case 5 : +break ;/* bcdctn. */ +case 6 : +break ;/* bcdcfz. */ +case 7 : +gen_bcdcfn (ctx); +break ; +case 31 : +break ;/* bcdsetsgn. */ +default : +break ; + } +} + +static void gen_xpnd04_2 (DisasContext *ctx) +{ +switch (opc4 (ctx->opcode)) { +case 0 : +break ;/* bcdctsq. */ +case 2 : +break ;/* bcdcfsq. */ +case 4 : +break ;/* bcdctz. */ +case 6 : +break ;/* bcdcfz. */ +case 7 : +gen_bcdcfn (ctx); +break ; +case 31 :
Quoted 8 lines
target-ppc/translate/vmx-impl.inc.c static void gen_##op(DisasContext *ctx) \ · line 922
Quoted 5 lines
target-ppc/translate/vmx-impl.inc.c +5
-0+break ;/* bcdsetsgn. */ +default : +break ; + } +}I thougt the main opcode table now had support for opc4, so you shouldn't need these special expanders.
This is the hardest one. :)
For all the functions above we have opcode collisions today. Let's take the bcdcfn case, its opcodes are:
000100 vrt:5 00111 vrb:5 11110 00000 1, when ps=1
000100 vrt:5 00111 vrb:5 10110 00000 1, when ps=0
Registering the opcode in the opcode table at translate_init.c, the following sequence is assumed:
0x4 -> 0x0 -> 0x1e (ps=1) or 0x16 (ps=0) -> 0x7
However,
0x4, 0x0, 0x1e already maps to a direct opcode:
vsubsws 000100 vrt:5 vra:5 vrb:5 11110 00000 0
as well as 0x4, 0x0, 0x16, that maps to:
vsubcuw 000100 vrt:5 vra:5 vrb:5 10110 00000 0
I this case, gen_xpnd04_1 handles ps=0 collisions and gen_xpnd04_2 does the same when ps=1. So Nikunj gave me this great idea to handle these exceptional cases.
Quoted 42 lines
Quoted 36 lines
target-ppc/translate/vmx-impl.inc.c +6
-0+GEN_VXFORM_DUAL (vsubcuw,PPC_ALTIVEC ,PPC_NONE , \ + xpnd04_1, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL (vsubsws,PPC_ALTIVEC ,PPC_NONE , \ + xpnd04_2, PPC_NONE, PPC2_ISA300)GEN_VXFORM_DUAL (vsububm,PPC_ALTIVEC ,PPC_NONE , \ bcdadd,PPC_NONE ,PPC2_ALTIVEC_207 )@@ -949,3 +1022,5 @@ GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,#undef GEN_VXFORM_NOA#undef GEN_VXFORM_UIMM#undef GEN_VAFORM_PAIRED + +#undef GEN_BCD2target-ppc/translate/vmx-ops.inc.c +2
-2@@ -122,7 +122,7 @@ GEN_VXFORM_300(vslv, 2, 29),GEN_VXFORM (vslo,6 ,16 ),GEN_VXFORM (vsro,6 ,17 ),GEN_VXFORM (vaddcuw,0 ,6 ), -GEN_VXFORM (vsubcuw,0 ,22 ), +GEN_VXFORM_DUAL (vsubcuw, xpnd04_1,0 ,22 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM (vaddubs,0 ,8 ),GEN_VXFORM (vadduhs,0 ,9 ), GEN_VXFORM(vadduws, 0, 10),@@ -134,7 +134,7 @@ GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),GEN_VXFORM (vsubuws,0 ,26 ),GEN_VXFORM (vsubsbs,0 ,28 ),GEN_VXFORM (vsubshs,0 ,29 ), -GEN_VXFORM (vsubsws,0 ,30 ), +GEN_VXFORM_DUAL (vsubsws, xpnd04_2,0 ,30 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM_207 (vadduqm,0 ,4 ),GEN_VXFORM_207 (vaddcuq,0 ,5 ), GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),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 1/1 2/4] target-ppc: Implement bcdctn. instruction
In reply to Jose Ricardo Zivianibcdctn. converts from BCD to National numeric format. National format uses a byte to represent a digit where the most significant nibble is always 0x3 and the least sign. nibbles is the digit itself.
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 46 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 24 ++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-)
target-ppc/helper.h +1 -0
@@ -370,6 +370,7 @@ DEF_HELPER_4(vpermxor, void, avr, avr, avr, avr) DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) +DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)
target-ppc/int_helper.c +46 -0
58 lines not on this page · raw message
target-ppc/translate/vmx-impl.inc.c +23 -1
@@ -894,9 +894,29 @@ static void gen_##op(DisasContext *ctx) \tcg_temp_free_i32 (ps); \ } +#define GEN_BCD3 (op) \ +static void gen_##op(DisasContext *ctx) \ +{ \ + TCGv_ptr rb, rd; \ + \ + if (unlikely(!ctx->altivec_enabled)) { \ + gen_exception(ctx, POWERPC_EXCP_VPU); \ + return; \ + } \ + \ + rb = gen_avr_ptr(rB(ctx->opcode)); \ + rd = gen_avr_ptr(rD(ctx->opcode)); \ + \ + gen_helper_##op(cpu_crf[6], rd, rb); \ + \ + tcg_temp_free_ptr(rb); \ + tcg_temp_free_ptr(rd); \ +} +GEN_BCD (bcdadd)GEN_BCD (bcdsub )GEN_BCD2 (bcdcfn) +GEN_BCD3 (bcdctn) static voidgen_xpnd04_1 (DisasContext *ctx) {
@@ -908,7 +928,8 @@ static void gen_xpnd04_1(DisasContext *ctx)case 4 :break ;/* bcdctz. */ case 5 : -break ;/* bcdctn. */ +gen_bcdctn (ctx); +break ;case 6 :break ;/* bcdcfz. */ case 7 :
@@ -1024,3 +1045,4 @@ GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,#undef GEN_VAFORM_PAIRED#undef GEN_BCD2 +#undef GEN_BCD3
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH] 2/4] target-ppc: Implement bcdctn. instruction
Quoted 28 lines · Jose Ricardo Ziviani
bcdctn. converts from BCD to National numeric format. National format uses a byte to represent a digit where the most significant nibble is always
0x3and the least sign. nibbles is the digit itself.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 46 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 24 ++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-)target-ppc/helper.h +1
-0@@ -370,6 +370,7 @@ DEF_HELPER_4(vpermxor, void, avr, avr, avr, avr) DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) +DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +0
-0
target-ppc/int_helper.c static uint8_t get_national_digit(ppc_avr_t *reg, int n) · line 2501
Quoted 8 lines
target-ppc/int_helper.c +5
-0@@ -2494,6 +2494,17 @@ static uint8_t get_national_digit(ppc_avr_t *reg, int n)#endif } +static void set_national_digit (ppc_avr_t *reg,uint8_t val,int n) +{ +#if defined(HOST_WORDS_BIGENDIAN ) + reg->u16[8 - n] &=0 ; + reg->u16[8 - n] |= val;
The &= always sets the value to 0, so you might as well just use a plain assignment in place of the &=, |=.
Quoted 13 lines
target-ppc/int_helper.c +6
-0+#else + reg->u16[n] &=0 ; + reg->u16[n] |= val; +#endif +} +static int bcd_cmp_mag (ppc_avr_t *a,ppc_avr_t *b) {int i;@@ -2667,6 +2678,41 @@ uint32_t helper_bcdcfn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)return cr; }
target-ppc/int_helper.c uint32_t helper_bcdcfn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2690
Quoted 10 lines
target-ppc/int_helper.c +10
-0+uint32_t helper_bcdctn (ppc_avr_t *r,ppc_avr_t *b) +{ +int i; +int cr =0 ; +int invalid =0 ; +int sgnb =bcd_get_sgn (b); +ppc_avr_t ret = { .u64 = {0 ,0 } }; + +int eq_flag = (b->u64[HI_IDX ] ==0 ) && ((b->u64[LO_IDX ] >>4 ) ==0 ); +int ox_flag = (b->u64[HI_IDX ] !=0 ) || ((b->u64[LO_IDX ] >>8 ) !=0 );
This looks wrong. You're shifing the low half right 8 bits == 2 nybbles == 1 digit + sign. So this will set the overflow flag if your input is a number of >1 digit. I think you want >>32, so it only sets overflow if the input exceeds 7 decimal digits + sign.
Quoted 61 lines
target-ppc/int_helper.c +24
-0+for (i =1 ; i <8 ; i++) { +set_national_digit (&ret,0x30 +bcd_get_digit (b, i, &invalid), i); + } +set_national_digit (&ret, (sgnb ==-1 ) ?NATIONAL_NEG :NATIONAL_PLUS ,0 ); + +if (!eq_flag) { + cr = (sgnb ==-1 ) ?1 <<CRF_LT :1 <<CRF_GT ; + }else { + cr =1 <<CRF_EQ ; + } + +if (ox_flag) { + cr |=1 <<CRF_SO ; + } + +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 +19
-0@@ -894,9 +894,29 @@ static void gen_##op(DisasContext *ctx) \tcg_temp_free_i32 (ps); \ } +#define GEN_BCD3 (op) \ +static void gen_##op(DisasContext *ctx) \ +{ \ + TCGv_ptr rb, rd; \ + \ + if (unlikely(!ctx->altivec_enabled)) { \ + gen_exception(ctx, POWERPC_EXCP_VPU); \ + return; \ + } \ + \ + rb = gen_avr_ptr(rB(ctx->opcode)); \ + rd = gen_avr_ptr(rD(ctx->opcode)); \ + \ + gen_helper_##op(cpu_crf[6], rd, rb); \ + \ + tcg_temp_free_ptr(rb); \ + tcg_temp_free_ptr(rd); \ +}GEN_BCD (bcdadd)GEN_BCD (bcdsub )GEN_BCD2 (bcdcfn) +GEN_BCD3 (bcdctn) static voidgen_xpnd04_1 (DisasContext *ctx) {
target-ppc/translate/vmx-impl.inc.c static void gen_xpnd04_1(DisasContext *ctx) · line 935
Quoted 9 lines
target-ppc/translate/vmx-impl.inc.c +2
-1@@ -908,7 +928,8 @@ static void gen_xpnd04_1(DisasContext *ctx)case 4 :break ;/* bcdctz. */ case 5 : -break ;/* bcdctn. */ +gen_bcdctn (ctx); +break ;case 6 :break ;/* bcdcfz. */ case 7 :
Uh.. doesn't adding bcdctn to this make it identical to gen_xpnd04_2?
Quoted 5 lines
target-ppc/translate/vmx-impl.inc.c +1
-0@@ -1024,3 +1045,4 @@ GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,#undef GEN_VAFORM_PAIRED#undef GEN_BCD2 +#undef GEN_BCD3
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] 2/4] target-ppc: Implement bcdctn. instruction
Quoted 32 lines · David Gibson
Quoted 31 lines · Jose Ricardo Ziviani
bcdctn. converts from BCD to National numeric format. National format uses a byte to represent a digit where the most significant nibble is always
0x3and the least sign. nibbles is the digit itself.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 46 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 24 ++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-)target-ppc/helper.h +1
-0@@ -370,6 +370,7 @@ DEF_HELPER_4(vpermxor, void, avr, avr, avr, avr) DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) +DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +0
-0@@ -2494,6 +2494,17 @@ static uint8_t get_national_digit(ppc_avr_t *reg, int n)#endif }
Quoted 8 lines
target-ppc/int_helper.c static uint8_t get_national_digit(ppc_avr_t *reg, int n) · line 2501
Quoted 5 lines
target-ppc/int_helper.c +5
-0+static void set_national_digit (ppc_avr_t *reg,uint8_t val,int n) +{ +#if defined(HOST_WORDS_BIGENDIAN ) + reg->u16[8 - n] &=0 ; + reg->u16[8 - n] |= val;The &= always sets the value to 0, so you might as well just use a plain assignment in place of the &=, |=.
OK! I'll fix it in v2.
Quoted 14 lines
Quoted 14 lines
target-ppc/int_helper.c +6
-0+#else + reg->u16[n] &=0 ; + reg->u16[n] |= val; +#endif +} +static int bcd_cmp_mag (ppc_avr_t *a,ppc_avr_t *b) {int i;@@ -2667,6 +2678,41 @@ uint32_t helper_bcdcfn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)return cr; }
Quoted 15 lines
target-ppc/int_helper.c uint32_t helper_bcdcfn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2690
Quoted 10 lines
target-ppc/int_helper.c +10
-0+uint32_t helper_bcdctn (ppc_avr_t *r,ppc_avr_t *b) +{ +int i; +int cr =0 ; +int invalid =0 ; +int sgnb =bcd_get_sgn (b); +ppc_avr_t ret = { .u64 = {0 ,0 } }; + +int eq_flag = (b->u64[HI_IDX ] ==0 ) && ((b->u64[LO_IDX ] >>4 ) ==0 ); +int ox_flag = (b->u64[HI_IDX ] !=0 ) || ((b->u64[LO_IDX ] >>8 ) !=0 );This looks wrong. You're shifing the low half right 8 bits == 2 nybbles == 1 digit + sign. So this will set the overflow flag if your input is a number of >1 digit. I think you want >>32, so it only sets overflow if the input exceeds 7 decimal digits + sign.
OK! I'll fix it in v2.
Quoted 59 lines
Quoted 59 lines
target-ppc/int_helper.c +24
-0+for (i =1 ; i <8 ; i++) { +set_national_digit (&ret,0x30 +bcd_get_digit (b, i, &invalid), i); + } +set_national_digit (&ret, (sgnb ==-1 ) ?NATIONAL_NEG :NATIONAL_PLUS ,0 ); + +if (!eq_flag) { + cr = (sgnb ==-1 ) ?1 <<CRF_LT :1 <<CRF_GT ; + }else { + cr =1 <<CRF_EQ ; + } + +if (ox_flag) { + cr |=1 <<CRF_SO ; + } + +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 +19
-0@@ -894,9 +894,29 @@ static void gen_##op(DisasContext *ctx) \tcg_temp_free_i32 (ps); \ } +#define GEN_BCD3 (op) \ +static void gen_##op(DisasContext *ctx) \ +{ \ + TCGv_ptr rb, rd; \ + \ + if (unlikely(!ctx->altivec_enabled)) { \ + gen_exception(ctx, POWERPC_EXCP_VPU); \ + return; \ + } \ + \ + rb = gen_avr_ptr(rB(ctx->opcode)); \ + rd = gen_avr_ptr(rD(ctx->opcode)); \ + \ + gen_helper_##op(cpu_crf[6], rd, rb); \ + \ + tcg_temp_free_ptr(rb); \ + tcg_temp_free_ptr(rd); \ +} GEN_BCD(bcdadd) GEN_BCD(bcdsub) GEN_BCD2(bcdcfn) +GEN_BCD3(bcdctn)
Quoted 14 lines
target-ppc/translate/vmx-impl.inc.c static void gen_xpnd04_1(DisasContext *ctx) · line 935
Quoted 12 lines
target-ppc/translate/vmx-impl.inc.c +2
-1static void gen_xpnd04_1 (DisasContext *ctx) {@@ -908,7 +928,8 @@ static void gen_xpnd04_1(DisasContext *ctx)case 4 :break ;/* bcdctz. */ case 5 : -break ;/* bcdctn. */ +gen_bcdctn (ctx); +break ;case 6 :break ;/* bcdcfz. */ case 7 :Uh.. doesn't adding bcdctn to this make it identical to
gen_xpnd04_2?
Actually this opcode is invalid for bcdctn as per ISA3.0.
Do you think that I should throw something like a SIGILL for this particular case?
Quoted 12 lines
Quoted 6 lines
target-ppc/translate/vmx-impl.inc.c +1
-0@@ -1024,3 +1045,4 @@ GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,#undef GEN_VAFORM_PAIRED#undef GEN_BCD2 +#undef GEN_BCD3Signature · 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] 2/4] target-ppc: Implement bcdctn. instruction
Quoted 150 lines · On Thu, Oct 27, 2016 at 02:13:13PM -0200, [email protected] wrote:
Quoted 32 lines · David Gibson
Quoted 31 lines · Jose Ricardo Ziviani
bcdctn. converts from BCD to National numeric format. National format uses a byte to represent a digit where the most significant nibble is always
0x3and the least sign. nibbles is the digit itself.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 46 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 24 ++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-)target-ppc/helper.h +1
-0@@ -370,6 +370,7 @@ DEF_HELPER_4(vpermxor, void, avr, avr, avr, avr) DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) +DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +0
-0@@ -2494,6 +2494,17 @@ static uint8_t get_national_digit(ppc_avr_t *reg, int n)#endif }Quoted 8 lines
target-ppc/int_helper.c static uint8_t get_national_digit(ppc_avr_t *reg, int n) · line 2501
Quoted 5 lines
target-ppc/int_helper.c +5
-0+static void set_national_digit (ppc_avr_t *reg,uint8_t val,int n) +{ +#if defined(HOST_WORDS_BIGENDIAN ) + reg->u16[8 - n] &=0 ; + reg->u16[8 - n] |= val;The &= always sets the value to 0, so you might as well just use a plain assignment in place of the &=, |=.
OK! I'll fix it in v2.
Quoted 14 lines
Quoted 14 lines
target-ppc/int_helper.c +6
-0+#else + reg->u16[n] &=0 ; + reg->u16[n] |= val; +#endif +} +static int bcd_cmp_mag (ppc_avr_t *a,ppc_avr_t *b) {int i;@@ -2667,6 +2678,41 @@ uint32_t helper_bcdcfn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)return cr; }Quoted 15 lines
target-ppc/int_helper.c uint32_t helper_bcdcfn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2690
Quoted 10 lines
target-ppc/int_helper.c +10
-0+uint32_t helper_bcdctn (ppc_avr_t *r,ppc_avr_t *b) +{ +int i; +int cr =0 ; +int invalid =0 ; +int sgnb =bcd_get_sgn (b); +ppc_avr_t ret = { .u64 = {0 ,0 } }; + +int eq_flag = (b->u64[HI_IDX ] ==0 ) && ((b->u64[LO_IDX ] >>4 ) ==0 ); +int ox_flag = (b->u64[HI_IDX ] !=0 ) || ((b->u64[LO_IDX ] >>8 ) !=0 );This looks wrong. You're shifing the low half right 8 bits == 2 nybbles == 1 digit + sign. So this will set the overflow flag if your input is a number of >1 digit. I think you want >>32, so it only sets overflow if the input exceeds 7 decimal digits + sign.
OK! I'll fix it in v2.
Quoted 59 lines
Quoted 59 lines
target-ppc/int_helper.c +24
-0+for (i =1 ; i <8 ; i++) { +set_national_digit (&ret,0x30 +bcd_get_digit (b, i, &invalid), i); + } +set_national_digit (&ret, (sgnb ==-1 ) ?NATIONAL_NEG :NATIONAL_PLUS ,0 ); + +if (!eq_flag) { + cr = (sgnb ==-1 ) ?1 <<CRF_LT :1 <<CRF_GT ; + }else { + cr =1 <<CRF_EQ ; + } + +if (ox_flag) { + cr |=1 <<CRF_SO ; + } + +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 +19
-0@@ -894,9 +894,29 @@ static void gen_##op(DisasContext *ctx) \tcg_temp_free_i32 (ps); \ } +#define GEN_BCD3 (op) \ +static void gen_##op(DisasContext *ctx) \ +{ \ + TCGv_ptr rb, rd; \ + \ + if (unlikely(!ctx->altivec_enabled)) { \ + gen_exception(ctx, POWERPC_EXCP_VPU); \ + return; \ + } \ + \ + rb = gen_avr_ptr(rB(ctx->opcode)); \ + rd = gen_avr_ptr(rD(ctx->opcode)); \ + \ + gen_helper_##op(cpu_crf[6], rd, rb); \ + \ + tcg_temp_free_ptr(rb); \ + tcg_temp_free_ptr(rd); \ +} GEN_BCD(bcdadd) GEN_BCD(bcdsub) GEN_BCD2(bcdcfn) +GEN_BCD3(bcdctn)Quoted 14 lines
target-ppc/translate/vmx-impl.inc.c static void gen_xpnd04_1(DisasContext *ctx) · line 935
Quoted 12 lines
target-ppc/translate/vmx-impl.inc.c +2
-1static void gen_xpnd04_1 (DisasContext *ctx) {@@ -908,7 +928,8 @@ static void gen_xpnd04_1(DisasContext *ctx)case 4 :break ;/* bcdctz. */ case 5 : -break ;/* bcdctn. */ +gen_bcdctn (ctx); +break ;case 6 :break ;/* bcdcfz. */ case 7 :Uh.. doesn't adding bcdctn to this make it identical to
gen_xpnd04_2?
Quoted 3 lines
Actually this opcode is invalid for bcdctn as per ISA3.0.
Do you think that I should throw something like a SIGILL for this particular case?
Yes, if the opcode is invalid, you absolutely should be throwing an invalid instruction exception.
Quoted 9 lines
Quoted 7 lines
Quoted 6 lines
target-ppc/translate/vmx-impl.inc.c +1
-0@@ -1024,3 +1045,4 @@ GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,#undef GEN_VAFORM_PAIRED#undef GEN_BCD2 +#undef GEN_BCD3
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 1/1 4/4] target-ppc: Implement bcdctz. instruction
In reply to Jose Ricardo Zivianibcdctz. converts from BCD to Zoned numeric format. Zoned format uses a byte to represent a digit where the most significant nibble is 0x3 or 0xf, depending on the preferred signal.
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++-- 3 files changed, 60 insertions(+), 2 deletions(-)
target-ppc/helper.h +1 -0
@@ -372,6 +372,7 @@ DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_3(bcdcfz, i32, avr, avr, i32) +DEF_HELPER_3(bcdctz, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)
target-ppc/int_helper.c +54 -0
60 lines not on this page · raw message
target-ppc/translate/vmx-impl.inc.c +5 -2
@@ -918,6 +918,7 @@ GEN_BCD(bcdsub)GEN_BCD2 (bcdcfn)GEN_BCD3 (bcdctn )GEN_BCD2 (bcdcfz) +GEN_BCD2 (bcdctz) static voidgen_xpnd04_1 (DisasContext *ctx) {
@@ -927,7 +928,8 @@ static void gen_xpnd04_1(DisasContext *ctx)case 2 :break ;/* bcdcfsq. */ case 4 : -break ;/* bcdctz. */ +gen_bcdctz (ctx); +break ;case 5 :gen_bcdctn (ctx);break ;
@@ -952,7 +954,8 @@ static void gen_xpnd04_2(DisasContext *ctx)case 2 :break ;/* bcdcfsq. */ case 4 : -break ;/* bcdctz. */ +gen_bcdctz (ctx); +break ;case 6 :gen_bcdcfz (ctx);break ;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH] 4/4] target-ppc: Implement bcdctz. instruction
Quoted 35 lines · Jose Ricardo Ziviani
bcdctz. converts from BCD to Zoned numeric format. Zoned format uses a byte to represent a digit where the most significant nibble is
0x3or0xf, depending on the preferred signal.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++-- 3 files changed, 60 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -372,6 +372,7 @@ DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_3(bcdcfz, i32, avr, avr, i32) +DEF_HELPER_3(bcdctz, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +4
-0@@ -2768,6 +2768,60 @@ uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) *r = ret;return cr; } + +uint32_t helper_bcdctz (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i;
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2784
Quoted 10 lines
target-ppc/int_helper.c +10
-0+int j; +int cr =0 ; +int invalid =0 ; +uint8_t digit =0 ; +int sgnb =bcd_get_sgn (b); +int zone_lead = (ps) ?0xF0 :0x30 ; +ppc_avr_t ret = { .u64 = {0 ,0 } }; + +int eq_flag = (b->u64[HI_IDX ] ==0 ) && ((b->u64[LO_IDX ] >>4 ) ==0 ); +int ox_flag = (b->u64[HI_IDX ] !=0 );
This doesn't look right. The zoned format can accomodate 16 digits. The low word of the packed format can accomodate 15 digits + sign. So it should be possible to convert a packed for with a value in the low nibble of the upper word.
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2786
Quoted 1 line
target-ppc/int_helper.c +1
-0+for (i =31 , j =16 ; i >1 ; i -=2 , j--) {
Again not seeing any point for the reverse order.
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2797
Quoted 11 lines
target-ppc/int_helper.c +11
-0+ digit =get_nibble (b, j); + ret.u8[BCD_DIG_BYTE (i)] = zone_lead + digit; + +if (unlikely (digit >9 )) { + invalid =1 ; + } + } + +if (unlikely (!sgnb)) { + sgnb = (!get_nibble (b,0 )) ?1 :-1 ; + }
Doesn't bcd_get_sgn() returning 0 indicate a badly encoded sign point. In which case you should set invalid, rather than making up a sign according to this apparently arbitrary scheme.
Quoted 62 lines
target-ppc/int_helper.c +27
-0+ +if (ps) { +bcd_put_digit (&ret, (sgnb ==1 ) ?0xC :0xD ,1 ); + }else { +bcd_put_digit (&ret, (sgnb ==1 ) ?0x3 :0x7 ,1 ); + } +bcd_put_digit (&ret,get_nibble (b,1 ),0 ); + +if (!eq_flag) { + cr = (sgnb ==1 ) ?1 <<CRF_GT :1 <<CRF_LT ; + }else { + cr =1 <<CRF_EQ ; + } + +if (ox_flag) { + cr |=1 <<CRF_SO ; + } + +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 +5
-2@@ -918,6 +918,7 @@ GEN_BCD(bcdsub)GEN_BCD2 (bcdcfn)GEN_BCD3 (bcdctn )GEN_BCD2 (bcdcfz) +GEN_BCD2 (bcdctz) static voidgen_xpnd04_1 (DisasContext *ctx) {@@ -927,7 +928,8 @@ static void gen_xpnd04_1(DisasContext *ctx)case 2 :break ;/* bcdcfsq. */ case 4 : -break ;/* bcdctz. */ +gen_bcdctz (ctx); +break ;case 5 :gen_bcdctn (ctx);break ;@@ -952,7 +954,8 @@ static void gen_xpnd04_2(DisasContext *ctx)case 2 :break ;/* bcdcfsq. */ case 4 : -break ;/* bcdctz. */ +gen_bcdctz (ctx); +break ;case 6 :gen_bcdcfz (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
Re: [Qemu-devel] [PATCH] 4/4] target-ppc: Implement bcdctz. instruction
Everything will be fixed in v2.
Thanks for reviewing it!
Quoted 140 lines · David Gibson
Quoted 35 lines · Jose Ricardo Ziviani
bcdctz. converts from BCD to Zoned numeric format. Zoned format uses a byte to represent a digit where the most significant nibble is
0x3or0xf, depending on the preferred signal.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++-- 3 files changed, 60 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -372,6 +372,7 @@ DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_3(bcdcfz, i32, avr, avr, i32) +DEF_HELPER_3(bcdctz, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +4
-0@@ -2768,6 +2768,60 @@ uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) *r = ret;return cr; } + +uint32_t helper_bcdctz (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i;target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2784
Quoted 10 lines
target-ppc/int_helper.c +10
-0+int j; +int cr =0 ; +int invalid =0 ; +uint8_t digit =0 ; +int sgnb =bcd_get_sgn (b); +int zone_lead = (ps) ?0xF0 :0x30 ; +ppc_avr_t ret = { .u64 = {0 ,0 } }; + +int eq_flag = (b->u64[HI_IDX ] ==0 ) && ((b->u64[LO_IDX ] >>4 ) ==0 ); +int ox_flag = (b->u64[HI_IDX ] !=0 );This doesn't look right. The zoned format can accomodate 16 digits. The low word of the packed format can accomodate 15 digits + sign. So it should be possible to convert a packed for with a value in the low nibble of the upper word.
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2786
Quoted 1 line
target-ppc/int_helper.c +1
-0+for (i =31 , j =16 ; i >1 ; i -=2 , j--) {Again not seeing any point for the reverse order.
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2797
Quoted 11 lines
target-ppc/int_helper.c +11
-0+ digit =get_nibble (b, j); + ret.u8[BCD_DIG_BYTE (i)] = zone_lead + digit; + +if (unlikely (digit >9 )) { + invalid =1 ; + } + } + +if (unlikely (!sgnb)) { + sgnb = (!get_nibble (b,0 )) ?1 :-1 ; + }Doesn't
bcd_get_sgn()returning 0 indicate a badly encoded sign point. In which case you should set invalid, rather than making up a sign according to this apparently arbitrary scheme.Quoted 62 lines
target-ppc/int_helper.c +27
-0+ +if (ps) { +bcd_put_digit (&ret, (sgnb ==1 ) ?0xC :0xD ,1 ); + }else { +bcd_put_digit (&ret, (sgnb ==1 ) ?0x3 :0x7 ,1 ); + } +bcd_put_digit (&ret,get_nibble (b,1 ),0 ); + +if (!eq_flag) { + cr = (sgnb ==1 ) ?1 <<CRF_GT :1 <<CRF_LT ; + }else { + cr =1 <<CRF_EQ ; + } + +if (ox_flag) { + cr |=1 <<CRF_SO ; + } + +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 +5
-2@@ -918,6 +918,7 @@ GEN_BCD(bcdsub)GEN_BCD2 (bcdcfn)GEN_BCD3 (bcdctn )GEN_BCD2 (bcdcfz) +GEN_BCD2 (bcdctz) static voidgen_xpnd04_1 (DisasContext *ctx) {@@ -927,7 +928,8 @@ static void gen_xpnd04_1(DisasContext *ctx)case 2 :break ;/* bcdcfsq. */ case 4 : -break ;/* bcdctz. */ +gen_bcdctz (ctx); +break ;case 5 :gen_bcdctn (ctx);break ;@@ -952,7 +954,8 @@ static void gen_xpnd04_2(DisasContext *ctx)case 2 :break ;/* bcdcfsq. */ case 4 : -break ;/* bcdctz. */ +gen_bcdctz (ctx); +break ;case 6 :gen_bcdcfz (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
Re: [Qemu-devel] [Qemu-ppc] [PATCH] 4/4] target-ppc: Implement bcdctz. instruction
In reply to David GibsonQuoted 43 lines · David Gibson
Quoted 42 lines · Jose Ricardo Ziviani
bcdctz. converts from BCD to Zoned numeric format. Zoned format uses a byte to represent a digit where the most significant nibble is
0x3or0xf, depending on the preferred signal.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++-- 3 files changed, 60 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -372,6 +372,7 @@ DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_3(bcdcfz, i32, avr, avr, i32) +DEF_HELPER_3(bcdctz, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +11
-0@@ -2768,6 +2768,60 @@ uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) *r = ret;return cr; } + +uint32_t helper_bcdctz (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i; +int j; +int cr =0 ; +int invalid =0 ; +uint8_t digit =0 ; +int sgnb =bcd_get_sgn (b); +int zone_lead = (ps) ?0xF0 :0x30 ; +ppc_avr_t ret = { .u64 = {0 ,0 } };
Quoted 8 lines
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2784
Quoted 3 lines
target-ppc/int_helper.c +3
-0+ +int eq_flag = (b->u64[HI_IDX ] ==0 ) && ((b->u64[LO_IDX ] >>4 ) ==0 ); +int ox_flag = (b->u64[HI_IDX ] !=0 );This doesn't look right. The zoned format can accomodate 16 digits. The low word of the packed format can accomodate 15 digits + sign. So it should be possible to convert a packed for with a value in the low nibble of the upper word.
David, it seems that zoned format can accommodate 15 digits + sign at most. Suppose I have this 16 bytes zoned number: f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9xx. Converting it to packed bcd will give 999999999999999x. Do you agree? can I keep that ox_flag logic?
Quoted 89 lines
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2786
Quoted 2 lines
target-ppc/int_helper.c +1
-0+for (i =31 , j =16 ; i >1 ; i -=2 , j--) {Again not seeing any point for the reverse order.
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2797
Quoted 11 lines
target-ppc/int_helper.c +11
-0+ digit =get_nibble (b, j); + ret.u8[BCD_DIG_BYTE (i)] = zone_lead + digit; + +if (unlikely (digit >9 )) { + invalid =1 ; + } + } + +if (unlikely (!sgnb)) { + sgnb = (!get_nibble (b,0 )) ?1 :-1 ; + }Doesn't
bcd_get_sgn()returning 0 indicate a badly encoded sign point. In which case you should set invalid, rather than making up a sign according to this apparently arbitrary scheme.Quoted 62 lines
target-ppc/int_helper.c +27
-0+ +if (ps) { +bcd_put_digit (&ret, (sgnb ==1 ) ?0xC :0xD ,1 ); + }else { +bcd_put_digit (&ret, (sgnb ==1 ) ?0x3 :0x7 ,1 ); + } +bcd_put_digit (&ret,get_nibble (b,1 ),0 ); + +if (!eq_flag) { + cr = (sgnb ==1 ) ?1 <<CRF_GT :1 <<CRF_LT ; + }else { + cr =1 <<CRF_EQ ; + } + +if (ox_flag) { + cr |=1 <<CRF_SO ; + } + +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 +5
-2@@ -918,6 +918,7 @@ GEN_BCD(bcdsub)GEN_BCD2 (bcdcfn)GEN_BCD3 (bcdctn )GEN_BCD2 (bcdcfz) +GEN_BCD2 (bcdctz) static voidgen_xpnd04_1 (DisasContext *ctx) {@@ -927,7 +928,8 @@ static void gen_xpnd04_1(DisasContext *ctx)case 2 :break ;/* bcdcfsq. */ case 4 : -break ;/* bcdctz. */ +gen_bcdctz (ctx); +break ;case 5 :gen_bcdctn (ctx);break ;@@ -952,7 +954,8 @@ static void gen_xpnd04_2(DisasContext *ctx)case 2 :break ;/* bcdcfsq. */ case 4 : -break ;/* bcdctz. */ +gen_bcdctz (ctx); +break ;case 6 :gen_bcdcfz (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
Re: [Qemu-devel] [Qemu-ppc] [PATCH] 4/4] target-ppc: Implement bcdctz. instruction
Quoted 53 lines · On Thu, Oct 27, 2016 at 06:08:20PM -0200, [email protected] wrote:
Quoted 43 lines · David Gibson
Quoted 42 lines · Jose Ricardo Ziviani
bcdctz. converts from BCD to Zoned numeric format. Zoned format uses a byte to represent a digit where the most significant nibble is
0x3or0xf, depending on the preferred signal.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++-- 3 files changed, 60 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -372,6 +372,7 @@ DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(bcdctn, i32, avr, avr) DEF_HELPER_3(bcdcfz, i32, avr, avr, i32) +DEF_HELPER_3(bcdctz, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +11
-0@@ -2768,6 +2768,60 @@ uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) *r = ret;return cr; } + +uint32_t helper_bcdctz (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i; +int j; +int cr =0 ; +int invalid =0 ; +uint8_t digit =0 ; +int sgnb =bcd_get_sgn (b); +int zone_lead = (ps) ?0xF0 :0x30 ; +ppc_avr_t ret = { .u64 = {0 ,0 } };Quoted 8 lines
target-ppc/int_helper.c uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) · line 2784
Quoted 3 lines
target-ppc/int_helper.c +3
-0+ +int eq_flag = (b->u64[HI_IDX ] ==0 ) && ((b->u64[LO_IDX ] >>4 ) ==0 ); +int ox_flag = (b->u64[HI_IDX ] !=0 );This doesn't look right. The zoned format can accomodate 16 digits. The low word of the packed format can accomodate 15 digits + sign. So it should be possible to convert a packed for with a value in the low nibble of the upper word.
Quoted 4 lines
David, it seems that zoned format can accommodate 15 digits + sign at most. Suppose I have this 16 bytes zoned number:
f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9xx. Converting it to packed bcd will give 999999999999999x. Do you agree? can I keep thatox_flaglogic?
Uh.. no. AFAICT from the description of the instruction the last byte of a zoned number contains *both* a sign nibble *and* the least significant digit of the number. So zoned format can represent 16 digits + sign.
But IIRC you changed this in v2, so maybe you realised that already.
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 1/1 3/4] target-ppc: Implement bcdcfz. instruction
In reply to Jose Ricardo Zivianibcdcfz. converts from Zoned numeric format to BCD. Zoned format uses a byte to represent a digit where the most significant nibble is 0x3 or 0xf, depending on the preferred signal.
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 55 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++-- 3 files changed, 61 insertions(+), 2 deletions(-)
target-ppc/helper.h +1 -0
@@ -371,6 +371,7 @@ DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(bcdctn, i32, avr, avr) +DEF_HELPER_3(bcdcfz, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)
target-ppc/int_helper.c +55 -0
67 lines not on this page · raw message
target-ppc/translate/vmx-impl.inc.c +5 -2
@@ -917,6 +917,7 @@ GEN_BCD(bcdadd)GEN_BCD (bcdsub)GEN_BCD2 (bcdcfn )GEN_BCD3 (bcdctn) +GEN_BCD2 (bcdcfz) static voidgen_xpnd04_1 (DisasContext *ctx) {
@@ -931,7 +932,8 @@ static void gen_xpnd04_1(DisasContext *ctx)gen_bcdctn (ctx);break ;case 6 : -break ;/* bcdcfz. */ +gen_bcdcfz (ctx); +break ;case 7 :gen_bcdcfn (ctx);break ;
@@ -952,7 +954,8 @@ static void gen_xpnd04_2(DisasContext *ctx)case 4 :break ;/* bcdctz. */ case 6 : -break ;/* bcdcfz. */ +gen_bcdcfz (ctx); +break ;case 7 :gen_bcdcfn (ctx);break ;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH] 3/4] target-ppc: Implement bcdcfz. instruction
Quoted 31 lines · Jose Ricardo Ziviani
bcdcfz. converts from Zoned numeric format to BCD. Zoned format uses a byte to represent a digit where the most significant nibble is
0x3or0xf, depending on the preferred signal.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 55 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++-- 3 files changed, 61 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -371,6 +371,7 @@ DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(bcdctn, i32, avr, avr) +DEF_HELPER_3(bcdcfz, 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@@ -2459,6 +2459,17 @@ static int bcd_preferred_sgn(int sgn, int ps) } }
target-ppc/int_helper.c static int bcd_preferred_sgn(int sgn, int ps) · line 2471
Quoted 10 lines
target-ppc/int_helper.c +10
-0+static uint8_t get_nibble (ppc_avr_t *bcd,int n) +{ +uint8_t result; +if (!(n &1 )) { + result = bcd->u8[BCD_DIG_BYTE (n)] &0xF ; + }else { + result = bcd->u8[BCD_DIG_BYTE (n)] >>4 ; + } +return result; +}
This can be merged with bcd_get_digit() without too much effort.
Quoted 10 lines
target-ppc/int_helper.c +3
-0static uint8_t bcd_get_digit (ppc_avr_t *bcd,int n,int *invalid) {uint8_t result;@@ -2713,6 +2724,50 @@ uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b)return cr; } +uint32_t helper_bcdcfz (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i;
target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2739
Quoted 10 lines
target-ppc/int_helper.c +10
-0+int j =0 ; +int cr =0 ; +int invalid =0 ; +int eq_flag =0 ; +int zone_digit =0 ; +ppc_avr_t ret = { .u64 = {0 ,0 } }; +int sgnb =get_nibble (b,1 ); + +if (unlikely (((sgnb <0xA ) && ps) || + ((get_nibble (b,0 ) >0x9 ) && !ps))) {
The second half of this condition doesn't belong here. It's a requirement for both ps values, and would make more sense applied along with the same test on the other digits.
target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2743
Quoted 4 lines
target-ppc/int_helper.c +4
-0+ invalid =1 ; + } + +for (i =31 , j =16 ; i >1 ; i -=2 , j--) {
I don't see why you're doing this in reverse order.
target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2747
Quoted 4 lines
target-ppc/int_helper.c +4
-0+ zone_digit =get_nibble (b, i); +if (unlikely ((ps && zone_digit !=0xF ) || + (!ps && zone_digit !=0x3 ))) { + invalid =1 ;
In this and the other instructions it would make sense to break out of the function as soon as you detect an invalid encoding.
target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2748
Quoted 1 line
target-ppc/int_helper.c +1
-0+ }
You never check for invalid encoding in the low input nibble (i.e. value > 0x9).
target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2750
Quoted 1 line
target-ppc/int_helper.c +1
-0+ eq_flag += zone_digit;
What?? How on earth does adding up the zone digits help you. For a valid encoding the answer should always be either 0x2d (PS=0) or 0xe1 (PS=1).
Quoted 55 lines
target-ppc/int_helper.c +20
-0+bcd_put_digit (&ret,get_nibble (b, i -1 ), j); + } +bcd_put_digit (&ret,get_nibble (b,0 ),1 ); + +if ((ps && (sgnb ==0xB || sgnb ==0xD )) || + (!ps && (sgnb &0x4 ))) { +bcd_put_digit (&ret,BCD_NEG_PREF ,0 ); + cr = (!eq_flag) ?1 <<CRF_LT :1 <<CRF_EQ ; + }else { +bcd_put_digit (&ret,BCD_PLUS_PREF_1 ,0 ); + cr = (!eq_flag) ?1 <<CRF_GT :1 <<CRF_EQ ; + } + +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 +5
-2@@ -917,6 +917,7 @@ GEN_BCD(bcdadd)GEN_BCD (bcdsub)GEN_BCD2 (bcdcfn )GEN_BCD3 (bcdctn) +GEN_BCD2 (bcdcfz) static voidgen_xpnd04_1 (DisasContext *ctx) {@@ -931,7 +932,8 @@ static void gen_xpnd04_1(DisasContext *ctx)gen_bcdctn (ctx);break ;case 6 : -break ;/* bcdcfz. */ +gen_bcdcfz (ctx); +break ;case 7 :gen_bcdcfn (ctx);break ;@@ -952,7 +954,8 @@ static void gen_xpnd04_2(DisasContext *ctx)case 4 :break ;/* bcdctz. */ case 6 : -break ;/* bcdcfz. */ +gen_bcdcfz (ctx); +break ;case 7 :gen_bcdcfn (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
Re: [Qemu-devel] [PATCH] 3/4] target-ppc: Implement bcdcfz. instruction
I'll send an improved version in v2.
Thank you for reviewing it.
Quoted 157 lines · David Gibson
Quoted 31 lines · Jose Ricardo Ziviani
bcdcfz. converts from Zoned numeric format to BCD. Zoned format uses a byte to represent a digit where the most significant nibble is
0x3or0xf, depending on the preferred signal.Signed-off-by Jose Ricardo Ziviani <[email protected]>--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 55 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 +++-- 3 files changed, 61 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -371,6 +371,7 @@ DEF_HELPER_4(bcdadd, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_2(bcdctn, i32, avr, avr) +DEF_HELPER_3(bcdcfz, 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@@ -2459,6 +2459,17 @@ static int bcd_preferred_sgn(int sgn, int ps) } }target-ppc/int_helper.c static int bcd_preferred_sgn(int sgn, int ps) · line 2471
Quoted 10 lines
target-ppc/int_helper.c +10
-0+static uint8_t get_nibble (ppc_avr_t *bcd,int n) +{ +uint8_t result; +if (!(n &1 )) { + result = bcd->u8[BCD_DIG_BYTE (n)] &0xF ; + }else { + result = bcd->u8[BCD_DIG_BYTE (n)] >>4 ; + } +return result; +}This can be merged with
bcd_get_digit()without too much effort.Quoted 10 lines
target-ppc/int_helper.c +3
-0static uint8_t bcd_get_digit (ppc_avr_t *bcd,int n,int *invalid) {uint8_t result;@@ -2713,6 +2724,50 @@ uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b)return cr; } +uint32_t helper_bcdcfz (ppc_avr_t *r,ppc_avr_t *b,uint32_t ps) +{ +int i;target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2739
Quoted 10 lines
target-ppc/int_helper.c +10
-0+int j =0 ; +int cr =0 ; +int invalid =0 ; +int eq_flag =0 ; +int zone_digit =0 ; +ppc_avr_t ret = { .u64 = {0 ,0 } }; +int sgnb =get_nibble (b,1 ); + +if (unlikely (((sgnb <0xA ) && ps) || + ((get_nibble (b,0 ) >0x9 ) && !ps))) {The second half of this condition doesn't belong here. It's a requirement for both ps values, and would make more sense applied along with the same test on the other digits.
target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2743
Quoted 4 lines
target-ppc/int_helper.c +4
-0+ invalid =1 ; + } + +for (i =31 , j =16 ; i >1 ; i -=2 , j--) {I don't see why you're doing this in reverse order.
target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2747
Quoted 4 lines
target-ppc/int_helper.c +4
-0+ zone_digit =get_nibble (b, i); +if (unlikely ((ps && zone_digit !=0xF ) || + (!ps && zone_digit !=0x3 ))) { + invalid =1 ;In this and the other instructions it would make sense to break out of the function as soon as you detect an invalid encoding.
target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2748
Quoted 1 line
target-ppc/int_helper.c +1
-0+ }You never check for invalid encoding in the low input nibble (i.e. value >
0x9).target-ppc/int_helper.c uint32_t helper_bcdctn(ppc_avr_t *r, ppc_avr_t *b) · line 2750
Quoted 1 line
target-ppc/int_helper.c +1
-0+ eq_flag += zone_digit;What?? How on earth does adding up the zone digits help you. For a valid encoding the answer should always be either
0x2d(PS=0) or0xe1(PS=1).Quoted 55 lines
target-ppc/int_helper.c +20
-0+bcd_put_digit (&ret,get_nibble (b, i -1 ), j); + } +bcd_put_digit (&ret,get_nibble (b,0 ),1 ); + +if ((ps && (sgnb ==0xB || sgnb ==0xD )) || + (!ps && (sgnb &0x4 ))) { +bcd_put_digit (&ret,BCD_NEG_PREF ,0 ); + cr = (!eq_flag) ?1 <<CRF_LT :1 <<CRF_EQ ; + }else { +bcd_put_digit (&ret,BCD_PLUS_PREF_1 ,0 ); + cr = (!eq_flag) ?1 <<CRF_GT :1 <<CRF_EQ ; + } + +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 +5
-2@@ -917,6 +917,7 @@ GEN_BCD(bcdadd)GEN_BCD (bcdsub)GEN_BCD2 (bcdcfn )GEN_BCD3 (bcdctn) +GEN_BCD2 (bcdcfz) static voidgen_xpnd04_1 (DisasContext *ctx) {@@ -931,7 +932,8 @@ static void gen_xpnd04_1(DisasContext *ctx)gen_bcdctn (ctx);break ;case 6 : -break ;/* bcdcfz. */ +gen_bcdcfz (ctx); +break ;case 7 :gen_bcdcfn (ctx);break ;@@ -952,7 +954,8 @@ static void gen_xpnd04_2(DisasContext *ctx)case 4 :break ;/* bcdctz. */ case 6 : -break ;/* bcdcfz. */ +gen_bcdcfz (ctx); +break ;case 7 :gen_bcdcfn (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