POWER9 TCG enablements - BCD functions - final part
v3 cover POWER9 TCG enablements - BCD functions - final part
v3:
- moves shift functions to host-utils.c and added config_int128 guard
- changes Makefile to always compile host-utils.c
- redesigns bcd[u]trunc to use bitwise operations
- removes "target-ppc: Implement bcd_is_valid function" (merged)
v2:
- bcd[s,sr,us] uses 1 byte for shifting instead of 4 bytes
- left/right functions in host-utils are out of CONFIG_INT128
- fixes overflowing issue in left shift and added a testcase
This serie contains 5 new instructions for POWER9 ISA3.0, left/right shifts for unsigned quadwords and a small improvement to check whether a bcd value is valid or not.
bcds.: Decimal signed shift
bcdus.: Decimal unsigned shift
bcdsr.: Decimal shift and round
bcdtrunc.: Decimal signed trucate
bcdutrunc.: Decimal unsigned truncate
Jose Ricardo Ziviani (6):
target-ppc: Implement unsigned quadword left/right shift and unit
tests
target-ppc: Implement bcds. instruction
target-ppc: Implement bcdus. instruction
target-ppc: Implement bcdsr. instruction
target-ppc: Implement bcdtrunc. instruction
target-ppc: Implement bcdutrunc. instruction
include/qemu/host-utils.h | 3 + target-ppc/helper.h | 5 + target-ppc/int_helper.c | 220 ++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 16 +++ target-ppc/translate/vmx-ops.inc.c | 13 ++- tests/Makefile.include | 5 +- tests/test-shift128.c | 98 ++++++++++++++++ util/Makefile.objs | 2 +- util/host-utils.c | 44 ++++++++ 9 files changed, 399 insertions(+), 7 deletions(-) create mode 100644 tests/test-shift128.c
Signature · 1 line
2.7.4
PATCH v3 1/6 target-ppc: Implement unsigned quadword left/right shift and unit tests
This commit implements functions to right and left shifts and the unittest for them. Such functions is needed due to instructions that requires them.
Today, there is already a right shift implementation in int128.h but it's designed for signed numbers.
--- include/qemu/host-utils.h | 3 ++ tests/Makefile.include | 5 ++- tests/test-shift128.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++ util/Makefile.objs | 2 +- util/host-utils.c | 44 +++++++++++++++++++++ 5 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 tests/test-shift128.c
include/qemu/host-utils.h +3 -0
@@ -516,4 +516,7 @@ static inline uint64_t pow2ceil(uint64_t value) return 1ULL << (64 - nlz); } +void urshift (uint64_t *plow,uint64_t *phigh,uint32_t shift); +void ulshift (uint64_t *plow,uint64_t *phigh,uint32_t shift,bool *overflow); +#endif
tests/Makefile.include +4 -1
@@ -65,6 +65,8 @@ check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF) endif check-unit-y += tests/test-cutils$(EXESUF) gcov-files-test-cutils-y += util/cutils.c +check-unit-y += tests/test-shift128$(EXESUF) +gcov-files-test-shift128-y = util/host-utils.c check-unit-y += tests/test-mul64$(EXESUF) gcov-files-test-mul64-y = util/host-utils.c check-unit-y += tests/test-int128$(EXESUF)
@@ -460,7 +462,7 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \ tests/test-opts-visitor.o tests/test-qmp-event.o \ tests/rcutorture.o tests/test-rcu-list.o \ - tests/test-qdist.o \ + tests/test-qdist.o tests/test-shift128.o \ tests/test-qht.o tests/qht-bench.o tests/test-qht-par.o \ tests/atomic_add-bench.o
@@ -568,6 +570,7 @@ tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marsh tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y) +tests/test-shift128$(EXESUF): tests/test-shift128.o $(test-util-obj-y) tests/test-mul64$(EXESUF): tests/test-mul64.o $(test-util-obj-y) tests/test-bitops$(EXESUF): tests/test-bitops.o $(test-util-obj-y) tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-crypto-obj-y)
tests/test-shift128.c new file +98 -0
98 lines not on this page · raw message
util/Makefile.objs +1 -1
@@ -11,7 +11,7 @@ util-obj-$(CONFIG_POSIX) += memfd.o util-obj-$(CONFIG_WIN32) += oslib-win32.o util-obj-$(CONFIG_WIN32) += qemu-thread-win32.o util-obj-y += envlist.o path.o module.o -util-obj-$(call lnot,$(CONFIG_INT128)) += host-utils.o +util-obj-y += host-utils.o util-obj-y += bitmap.o bitops.o hbitmap.o util-obj-y += fifo8.o util-obj-y += acl.o
util/host-utils.c +44 -0
54 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 2/6 target-ppc: Implement bcds. instruction
In reply to Jose Ricardo Zivianibcds.: Decimal shift. Given two registers vra and vrb, this instruction shift the vrb value by vra bits into the result register.
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 38 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 3 +++ target-ppc/translate/vmx-ops.inc.c | 3 ++- 4 files changed, 44 insertions(+), 1 deletion(-)
target-ppc/helper.h +1 -0
@@ -392,6 +392,7 @@ 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_4(bcds, i32, avr, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)
target-ppc/int_helper.c +38 -0
@@ -3043,6 +3043,44 @@ uint32_t helper_bcdsetsgn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps)return bcd_cmp_zero (r); } +uint32_t helper_bcds (ppc_avr_t *r,ppc_avr_t *a,ppc_avr_t *b,uint32_t ps) +{ +int cr; +int i =0 ; +bool ox_flag = false; +int sgnb =bcd_get_sgn (b); +ppc_avr_t ret = *b; + ret.u64[LO_IDX ] &= ~0xf ; + +#if defined(HOST_WORDS_BIGENDIAN ) +int upper =ARRAY_SIZE (a->s8) -1 ; +#else +int upper =0 ; +#endif + +if (bcd_is_valid (b) == false) { +return CRF_SO ; + } + +if (a->s8[upper] >0 ) { + i = (a->s8[upper] >31 ) ?31 : a->s8[upper]; +ulshift (&ret.u64[LO_IDX ], &ret.u64[HI_IDX ], i *4 , &ox_flag); + }else { + i = (a->s8[upper] <-31 ) ?31 : -a->s8[upper]; +urshift (&ret.u64[LO_IDX ], &ret.u64[HI_IDX ], i *4 ); + } +bcd_put_digit (&ret,bcd_preferred_sgn (sgnb, ps),0 ); + + *r = ret; + + cr =bcd_cmp_zero (r); +if (unlikely (ox_flag)) { + cr |=CRF_SO ; + } + +return cr; +} +void helper_vsbox (ppc_avr_t *r,ppc_avr_t *a) {int i;
target-ppc/translate/vmx-impl.inc.c +3 -0
@@ -1016,6 +1016,7 @@ GEN_BCD2(bcdcfsq)GEN_BCD2 (bcdctsq)GEN_BCD2 (bcdsetsgn)GEN_BCD (bcdcpsgn); +GEN_BCD (bcds); static void gen_xpnd04_1(DisasContext *ctx) {
@@ -1090,6 +1091,8 @@ 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) +GEN_VXFORM_DUAL(vsubudm, PPC2_ALTIVEC_207, PPC_NONE, \ + bcds, PPC_NONE, PPC2_ISA300)static void gen_vsbox (DisasContext *ctx) {
target-ppc/translate/vmx-ops.inc.c +2 -1
@@ -62,7 +62,8 @@ GEN_VXFORM_207(vaddudm, 0, 3),GEN_VXFORM_DUAL (vsububm, bcdadd,0 ,16 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM_DUAL (vsubuhm, bcdsub,0 ,17 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM (vsubuwm,0 ,18 ), -GEN_VXFORM_207 (vsubudm,0 ,19 ), +GEN_VXFORM_DUAL (vsubudm, bcds,0 ,19 ,PPC2_ALTIVEC_207 ,PPC2_ISA300 ), +GEN_VXFORM_300 (bcds,0 ,27 ),GEN_VXFORM (vmaxub,1 ,0 ),GEN_VXFORM (vmaxuh,1 ,1 ), GEN_VXFORM(vmaxuw, 1, 2),
Signature · 1 line
2.7.4
PATCH v3 3/6 target-ppc: Implement bcdus. instruction
In reply to Jose Ricardo Zivianibcdus.: Decimal unsigned shift. This instruction works like bcds. but considers only unsigned BCDs (no sign in least meaning 4 bits).
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 43 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 3 +++ target-ppc/translate/vmx-ops.inc.c | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-)
target-ppc/helper.h +1 -0
@@ -393,6 +393,7 @@ 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_4(bcds, i32, avr, avr, avr, i32) +DEF_HELPER_4(bcdus, i32, avr, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)
target-ppc/int_helper.c +43 -0
49 lines not on this page · raw message
target-ppc/translate/vmx-impl.inc.c +3 -0
@@ -1017,6 +1017,7 @@ GEN_BCD2(bcdctsq)GEN_BCD2 (bcdsetsgn)GEN_BCD (bcdcpsgn);GEN_BCD (bcds); +GEN_BCD (bcdus);static void gen_xpnd04_1 (DisasContext *ctx) {
@@ -1093,6 +1094,8 @@ GEN_VXFORM_DUAL(vaddshs, PPC_ALTIVEC, PPC_NONE, \ bcdcpsgn, PPC_NONE, PPC2_ISA300) GEN_VXFORM_DUAL(vsubudm, PPC2_ALTIVEC_207, PPC_NONE, \ bcds, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL(vsubuwm, PPC_ALTIVEC, PPC_NONE, \ + bcdus, PPC_NONE, PPC2_ISA300)static void gen_vsbox (DisasContext *ctx) {
target-ppc/translate/vmx-ops.inc.c +1 -1
@@ -61,7 +61,7 @@ GEN_VXFORM(vadduwm, 0, 2),GEN_VXFORM_207 (vaddudm,0 ,3 ),GEN_VXFORM_DUAL (vsububm, bcdadd,0 ,16 ,PPC_ALTIVEC ,PPC_NONE ),GEN_VXFORM_DUAL (vsubuhm, bcdsub,0 ,17 ,PPC_ALTIVEC ,PPC_NONE ), -GEN_VXFORM (vsubuwm,0 ,18 ), +GEN_VXFORM_DUAL (vsubuwm, bcdus,0 ,18 ,PPC_ALTIVEC ,PPC2_ISA300 ),GEN_VXFORM_DUAL (vsubudm, bcds,0 ,19 ,PPC2_ALTIVEC_207 ,PPC2_ISA300 ),GEN_VXFORM_300 (bcds,0 ,27 ), GEN_VXFORM(vmaxub, 1, 0),
Signature · 1 line
2.7.4
PATCH v3 4/6 target-ppc: Implement bcdsr. instruction
In reply to Jose Ricardo Zivianibcdsr.: Decimal shift and round. This instruction works like bcds. however, when performing right shift, 1 will be added to the result if the last digit was >= 5.
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 45 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 1 + target-ppc/translate/vmx-ops.inc.c | 2 ++ 4 files changed, 49 insertions(+)
target-ppc/helper.h +1 -0
@@ -394,6 +394,7 @@ DEF_HELPER_4(bcdcpsgn, i32, avr, avr, avr, i32) DEF_HELPER_3(bcdsetsgn, i32, avr, avr, i32) DEF_HELPER_4(bcds, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdus, i32, avr, avr, avr, i32) +DEF_HELPER_4(bcdsr, i32, avr, 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 +1 -0
@@ -1018,6 +1018,7 @@ GEN_BCD2(bcdsetsgn)GEN_BCD (bcdcpsgn);GEN_BCD (bcds);GEN_BCD (bcdus); +GEN_BCD (bcdsr);static void gen_xpnd04_1 (DisasContext *ctx) {
target-ppc/translate/vmx-ops.inc.c +2 -0
@@ -132,6 +132,8 @@ GEN_HANDLER_E_2(vprtybd, 0x4, 0x1, 0x18, 9, 0, PPC_NONE, PPC2_ISA300),GEN_HANDLER_E_2 (vprtybq,0x4 ,0x1 ,0x18 ,10 ,0 ,PPC_NONE ,PPC2_ISA300 ),GEN_VXFORM_DUAL (vsubcuw, xpnd04_1,0 ,22 ,PPC_ALTIVEC ,PPC_NONE ), +GEN_VXFORM_300 (bcdsr,0 ,23 ), +GEN_VXFORM_300 (bcdsr,0 ,31 ),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),
Signature · 1 line
2.7.4
PATCH v3 5/6 target-ppc: Implement bcdtrunc. instruction
In reply to Jose Ricardo Zivianibcdtrunc.: Decimal integer truncate. Given a BCD number in vrb and the number of bytes to truncate in vra, the return register will have vrb with such bits truncated.
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 40 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 5 +++++ target-ppc/translate/vmx-ops.inc.c | 4 ++-- 4 files changed, 48 insertions(+), 2 deletions(-)
target-ppc/helper.h +1 -0
@@ -395,6 +395,7 @@ DEF_HELPER_3(bcdsetsgn, i32, avr, avr, i32) DEF_HELPER_4(bcds, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdus, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsr, i32, avr, avr, avr, i32) +DEF_HELPER_4(bcdtrunc, i32, avr, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)
target-ppc/int_helper.c +40 -0
@@ -3169,6 +3169,46 @@ uint32_t helper_bcdsr(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)return cr; } +uint32_t helper_bcdtrunc (ppc_avr_t *r,ppc_avr_t *a,ppc_avr_t *b,uint32_t ps) +{ +uint64_t mask; +uint32_t bits; +uint32_t ox_flag =0 ; +ppc_avr_t ret = *b; + +#if defined(HOST_WORDS_BIGENDIAN ) +int upper =ARRAY_SIZE (a->u16) -1 ; +#else +int upper =0 ; +#endif + +if (bcd_is_valid (b) == false) { +return CRF_SO ; + } + + bits = (a->u16[upper] &31 ) <<2 ; +if (bits >=64 ) { +if (ret.u64[HI_IDX ] || (ret.u64[LO_IDX ] >> (128 - bits))) { + ox_flag =CRF_SO ; + } + + mask = (uint64_t )-1 >> (bits -64 ); + ret.u64[HI_IDX ] =0 ; + ret.u64[LO_IDX ] &= mask; + }else { +if (ret.u64[HI_IDX ] >> (64 - bits)) { + ox_flag =CRF_SO ; + } + + mask = (uint64_t )-1 >> bits; + ret.u64[HI_IDX ] &= mask; + } +bcd_put_digit (&ret,bcd_preferred_sgn (bcd_get_sgn (b), ps),0 ); + *r = ret; + +return bcd_cmp_zero (&ret) | ox_flag; +} +void helper_vsbox (ppc_avr_t *r,ppc_avr_t *a) {int i;
target-ppc/translate/vmx-impl.inc.c +5 -0
@@ -1019,6 +1019,7 @@ GEN_BCD(bcdcpsgn);GEN_BCD (bcds);GEN_BCD (bcdus);GEN_BCD (bcdsr); +GEN_BCD (bcdtrunc);static void gen_xpnd04_1 (DisasContext *ctx) {
@@ -1097,6 +1098,10 @@ GEN_VXFORM_DUAL(vsubudm, PPC2_ALTIVEC_207, PPC_NONE, \ bcds, PPC_NONE, PPC2_ISA300) GEN_VXFORM_DUAL(vsubuwm, PPC_ALTIVEC, PPC_NONE, \ bcdus, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL(vsubsbs, PPC_ALTIVEC, PPC_NONE, \ + bcdtrunc, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL(vsubuqm, PPC2_ALTIVEC_207, PPC_NONE, \ + bcdtrunc, PPC_NONE, PPC2_ISA300)static void gen_vsbox (DisasContext *ctx) {
target-ppc/translate/vmx-ops.inc.c +2 -2
@@ -143,14 +143,14 @@ 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 ),GEN_VXFORM (vsubuws,0 ,26 ), -GEN_VXFORM (vsubsbs,0 ,28 ), +GEN_VXFORM_DUAL (vsubsbs, bcdtrunc,0 ,28 ,PPC_NONE ,PPC2_ISA300 ),GEN_VXFORM (vsubshs,0 ,29 ),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 ), -GEN_VXFORM_207 (vsubuqm,0 ,20 ),GEN_VXFORM_207 (vsubcuq,0 ,21 ), +GEN_VXFORM_DUAL (vsubuqm, bcdtrunc,0 ,20 ,PPC2_ALTIVEC_207 ,PPC2_ISA300 ),GEN_VXFORM_DUAL (vsubeuqm, vsubecuq,31 ,0xFF ,PPC_NONE ,PPC2_ALTIVEC_207 ),GEN_VXFORM (vrlb,2 ,0 ), GEN_VXFORM(vrlh, 2, 1),
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v3 5/6] target-ppc: Implement bcdtrunc. instruction
Quoted 5 lines · Jose Ricardo Ziviani
bcdtrunc.: Decimal integer truncate. Given a BCD number in vrb and the number of bytes to truncate in vra, the return register will have vrb with such bits truncated.
Signed-off-by Jose Ricardo Ziviani <[email protected]>
Um.. this is wrong on multiple accounts. Have you actually tested this with any input at all?
Quoted 35 lines
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 40 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 5 +++++ target-ppc/translate/vmx-ops.inc.c | 4 ++-- 4 files changed, 48 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -395,6 +395,7 @@ DEF_HELPER_3(bcdsetsgn, i32, avr, avr, i32) DEF_HELPER_4(bcds, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdus, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsr, i32, avr, avr, avr, i32) +DEF_HELPER_4(bcdtrunc, i32, avr, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +8
-0@@ -3169,6 +3169,46 @@ uint32_t helper_bcdsr(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)return cr; } +uint32_t helper_bcdtrunc (ppc_avr_t *r,ppc_avr_t *a,ppc_avr_t *b,uint32_t ps) +{ +uint64_t mask; +uint32_t bits; +uint32_t ox_flag =0 ; +ppc_avr_t ret = *b; + +#if defined(HOST_WORDS_BIGENDIAN )
target-ppc/int_helper.c uint32_t helper_bcdsr(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) · line 3189
Quoted 10 lines
target-ppc/int_helper.c +10
-0+int upper =ARRAY_SIZE (a->u16) -1 ; +#else +int upper =0 ; +#endif + +if (bcd_is_valid (b) == false) { +return CRF_SO ; + } + + bits = (a->u16[upper] &31 ) <<2 ;
According to the ISA, the value here gives the number of digits to *retain*, you're treating it as the number of digits to clear. You're also not accounting for the sign marker, which should be retained in any case.
Finally, the ISA says the value in bits 48:63 are treated as length with no mention of being truncated to 5 bits. Which means it's not clear what should happen if length > 31. You'll need to check with the hardware people about this.
Quoted 69 lines
target-ppc/int_helper.c +22
-0+if (bits >=64 ) { +if (ret.u64[HI_IDX ] || (ret.u64[LO_IDX ] >> (128 - bits))) { + ox_flag =CRF_SO ; + } + + mask = (uint64_t )-1 >> (bits -64 ); + ret.u64[HI_IDX ] =0 ; + ret.u64[LO_IDX ] &= mask; + }else { +if (ret.u64[HI_IDX ] >> (64 - bits)) { + ox_flag =CRF_SO ; + } + + mask = (uint64_t )-1 >> bits; + ret.u64[HI_IDX ] &= mask; + } +bcd_put_digit (&ret,bcd_preferred_sgn (bcd_get_sgn (b), ps),0 ); + *r = ret; + +return bcd_cmp_zero (&ret) | ox_flag; +} +void helper_vsbox (ppc_avr_t *r,ppc_avr_t *a) {int i;target-ppc/translate/vmx-impl.inc.c +5
-0@@ -1019,6 +1019,7 @@ GEN_BCD(bcdcpsgn);GEN_BCD (bcds);GEN_BCD (bcdus);GEN_BCD (bcdsr); +GEN_BCD (bcdtrunc);static void gen_xpnd04_1 (DisasContext *ctx) {@@ -1097,6 +1098,10 @@ GEN_VXFORM_DUAL(vsubudm, PPC2_ALTIVEC_207, PPC_NONE, \ bcds, PPC_NONE, PPC2_ISA300) GEN_VXFORM_DUAL(vsubuwm, PPC_ALTIVEC, PPC_NONE, \ bcdus, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL(vsubsbs, PPC_ALTIVEC, PPC_NONE, \ + bcdtrunc, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL(vsubuqm, PPC2_ALTIVEC_207, PPC_NONE, \ + bcdtrunc, PPC_NONE, PPC2_ISA300)static void gen_vsbox (DisasContext *ctx) {target-ppc/translate/vmx-ops.inc.c +2
-2@@ -143,14 +143,14 @@ 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 ),GEN_VXFORM (vsubuws,0 ,26 ), -GEN_VXFORM (vsubsbs,0 ,28 ), +GEN_VXFORM_DUAL (vsubsbs, bcdtrunc,0 ,28 ,PPC_NONE ,PPC2_ISA300 ),GEN_VXFORM (vsubshs,0 ,29 ),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 ), -GEN_VXFORM_207 (vsubuqm,0 ,20 ),GEN_VXFORM_207 (vsubcuq,0 ,21 ), +GEN_VXFORM_DUAL (vsubuqm, bcdtrunc,0 ,20 ,PPC2_ALTIVEC_207 ,PPC2_ISA300 ),GEN_VXFORM_DUAL (vsubeuqm, vsubecuq,31 ,0xFF ,PPC_NONE ,PPC2_ALTIVEC_207 ),GEN_VXFORM (vrlb,2 ,0 ), GEN_VXFORM(vrlh, 2, 1),
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 v3 5/6] target-ppc: Implement bcdtrunc. instruction
Quoted 9 lines · David Gibson
Quoted 5 lines · Jose Ricardo Ziviani
bcdtrunc.: Decimal integer truncate. Given a BCD number in vrb and the number of bytes to truncate in vra, the return register will have vrb with such bits truncated.
Signed-off-by Jose Ricardo Ziviani <[email protected]>Um.. this is wrong on multiple accounts. Have you actually tested this with any input at all?
yes I did, a lot but it's possible that I get the idea wrong.
Quoted 43 lines
Quoted 43 lines
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 40 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 5 +++++ target-ppc/translate/vmx-ops.inc.c | 4 ++-- 4 files changed, 48 insertions(+), 2 deletions(-)target-ppc/helper.h +1
-0@@ -395,6 +395,7 @@ DEF_HELPER_3(bcdsetsgn, i32, avr, avr, i32) DEF_HELPER_4(bcds, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdus, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsr, i32, avr, avr, avr, i32) +DEF_HELPER_4(bcdtrunc, i32, avr, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32)DEF_HELPER_2 (xssubdp, void, env, i32)target-ppc/int_helper.c +15
-0@@ -3169,6 +3169,46 @@ uint32_t helper_bcdsr(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps)return cr; } +uint32_t helper_bcdtrunc (ppc_avr_t *r,ppc_avr_t *a,ppc_avr_t *b,uint32_t ps) +{ +uint64_t mask; +uint32_t bits; +uint32_t ox_flag =0 ; +ppc_avr_t ret = *b; + +#if defined(HOST_WORDS_BIGENDIAN ) +int upper =ARRAY_SIZE (a->u16) -1 ; +#else +int upper =0 ; +#endif + +if (bcd_is_valid (b) == false) { +return CRF_SO ;
Quoted 8 lines
target-ppc/int_helper.c uint32_t helper_bcdsr(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) · line 3189
Quoted 3 lines
target-ppc/int_helper.c +3
-0+ } + + bits = (a->u16[upper] &31 ) <<2 ;According to the ISA, the value here gives the number of digits to *retain*, you're treating it as the number of digits to clear. You're also not accounting for the sign marker, which should be retained in any case.
I understood it is the number of bits to clear, I'll review it.
Quoted 5 lines
Finally, the ISA says the value in bits 48:63 are treated as length with no mention of being truncated to 5 bits. Which means it's not clear what should happen if length > 31. You'll need to check with the hardware people about this.
ok
Quoted 76 lines
Quoted 70 lines
target-ppc/int_helper.c +22
-0+if (bits >=64 ) { +if (ret.u64[HI_IDX ] || (ret.u64[LO_IDX ] >> (128 - bits))) { + ox_flag =CRF_SO ; + } + + mask = (uint64_t )-1 >> (bits -64 ); + ret.u64[HI_IDX ] =0 ; + ret.u64[LO_IDX ] &= mask; + }else { +if (ret.u64[HI_IDX ] >> (64 - bits)) { + ox_flag =CRF_SO ; + } + + mask = (uint64_t )-1 >> bits; + ret.u64[HI_IDX ] &= mask; + } +bcd_put_digit (&ret,bcd_preferred_sgn (bcd_get_sgn (b), ps),0 ); + *r = ret; + +return bcd_cmp_zero (&ret) | ox_flag; +} +void helper_vsbox (ppc_avr_t *r,ppc_avr_t *a) {int i;target-ppc/translate/vmx-impl.inc.c +5
-0@@ -1019,6 +1019,7 @@ GEN_BCD(bcdcpsgn);GEN_BCD (bcds);GEN_BCD (bcdus);GEN_BCD (bcdsr); +GEN_BCD (bcdtrunc);static void gen_xpnd04_1 (DisasContext *ctx) {@@ -1097,6 +1098,10 @@ GEN_VXFORM_DUAL(vsubudm, PPC2_ALTIVEC_207, PPC_NONE, \ bcds, PPC_NONE, PPC2_ISA300) GEN_VXFORM_DUAL(vsubuwm, PPC_ALTIVEC, PPC_NONE, \ bcdus, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL(vsubsbs, PPC_ALTIVEC, PPC_NONE, \ + bcdtrunc, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL(vsubuqm, PPC2_ALTIVEC_207, PPC_NONE, \ + bcdtrunc, PPC_NONE, PPC2_ISA300)static void gen_vsbox (DisasContext *ctx) {target-ppc/translate/vmx-ops.inc.c +2
-2@@ -143,14 +143,14 @@ 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 ),GEN_VXFORM (vsubuws,0 ,26 ), -GEN_VXFORM (vsubsbs,0 ,28 ), +GEN_VXFORM_DUAL (vsubsbs, bcdtrunc,0 ,28 ,PPC_NONE ,PPC2_ISA300 ),GEN_VXFORM (vsubshs,0 ,29 ),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 ), -GEN_VXFORM_207 (vsubuqm,0 ,20 ),GEN_VXFORM_207 (vsubcuq,0 ,21 ), +GEN_VXFORM_DUAL (vsubuqm, bcdtrunc,0 ,20 ,PPC2_ALTIVEC_207 ,PPC2_ISA300 ),GEN_VXFORM_DUAL (vsubeuqm, vsubecuq,31 ,0xFF ,PPC_NONE ,PPC2_ALTIVEC_207 ),GEN_VXFORM (vrlb,2 ,0 ), GEN_VXFORM(vrlh, 2, 1),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 v3 6/6 target-ppc: Implement bcdutrunc. instruction
In reply to Jose Ricardo Zivianibcdutrunc. Decimal unsigned truncate. Works like bcdtrunc. with unsigned BCD numbers.
--- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 54 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 4 +++ target-ppc/translate/vmx-ops.inc.c | 2 +- 4 files changed, 60 insertions(+), 1 deletion(-)
target-ppc/helper.h +1 -0
@@ -396,6 +396,7 @@ DEF_HELPER_4(bcds, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdus, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdsr, i32, avr, avr, avr, i32) DEF_HELPER_4(bcdtrunc, i32, avr, avr, avr, i32) +DEF_HELPER_4(bcdutrunc, i32, avr, 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 +4 -0
@@ -1020,6 +1020,7 @@ GEN_BCD(bcds);GEN_BCD (bcdus);GEN_BCD (bcdsr);GEN_BCD (bcdtrunc); +GEN_BCD (bcdutrunc);static void gen_xpnd04_1 (DisasContext *ctx) {
@@ -1102,6 +1103,9 @@ GEN_VXFORM_DUAL(vsubsbs, PPC_ALTIVEC, PPC_NONE, \ bcdtrunc, PPC_NONE, PPC2_ISA300) GEN_VXFORM_DUAL(vsubuqm, PPC2_ALTIVEC_207, PPC_NONE, \ bcdtrunc, PPC_NONE, PPC2_ISA300) +GEN_VXFORM_DUAL(vsubcuq, PPC2_ALTIVEC_207, PPC_NONE, \ + bcdutrunc, PPC_NONE, PPC2_ISA300) +static void gen_vsbox (DisasContext *ctx) {
target-ppc/translate/vmx-ops.inc.c +1 -1
@@ -149,8 +149,8 @@ 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 ), -GEN_VXFORM_207 (vsubcuq,0 ,21 ),GEN_VXFORM_DUAL (vsubuqm, bcdtrunc,0 ,20 ,PPC2_ALTIVEC_207 ,PPC2_ISA300 ), +GEN_VXFORM_DUAL (vsubcuq, bcdutrunc,0 ,21 ,PPC2_ALTIVEC_207 ,PPC2_ISA300 ),GEN_VXFORM_DUAL (vsubeuqm, vsubecuq,31 ,0xFF ,PPC_NONE ,PPC2_ALTIVEC_207 ),GEN_VXFORM (vrlb,2 ,0 ), GEN_VXFORM(vrlh, 2, 1),
Signature · 1 line
2.7.4