Optimize emulation of some Altivec instructions
v9 cover Optimize emulation of some Altivec instructions
Optimize emulation of twelve Altivec instructions: lvsl, lvsr, vsl, vsr, vpkpx, vgbbd, vclzb, vclzh, vclzw, vclzd, vupkhpx and vupklpx.
This series builds up on and complements recent work of Thomas Murta, Mark Cave-Ayland and Richard Henderson in the same area. It is based on devising TCG translation implementation for selected instructions rather than using helpers. The selected instructions are most of the time idiosyncratic to ppc platform, so relatively complex TCG translation (without direct mapping to host instruction that is not possible in these cases) seems to be the best option, and that approach is presented in this series. The performance improvements are significant in all cases.
V9:
Fixed comments and commit messages.
V8:
Addressed Aleksandar Markovic's suggestions.
V7:
Added optimization for vupkhpx and vupklpx instructions.
V6:
Rebased series to the latest qemu code.
Excluded all patches that are already accepted.
V5:
Fixed vpkpx bug and added it back in patch.
Fixed graphical distortions on OSX 10.3 and 10.4.
Removed conversion of vmrgh and vmrgl instructions to vector operations for further investigation.
V4:
Addressed Richard's Henderson's suggestions.
Removed vpkpx's optimization for further investigation on graphical distortions it caused on OSX 10.2-4 guests.
Added opcodes for vector vmrgh(b|h|w) and vmrgl(b|h|w) in tcg. Implemented vector vmrgh and vmrgl instructions for i386. Converted vmrgh and vmrgl instructions to vector operations.
V3:
Fixed problem during build.
V2:
Addressed Richard's Henderson's suggestions.
Fixed problem during build on patch 2/8.
Rebased series to the latest qemu code.
Stefan Brankovic (3):
target/ppc: Optimize emulation of vclzh and vclzb instructions target/ppc: Optimize emulation of vpkpx instruction target/ppc: Optimize emulation of vupkhpx and vupklpx instructions
target/ppc/helper.h | 5 - target/ppc/int_helper.c | 50 ------ target/ppc/translate/vmx-impl.inc.c | 307 +++++++++++++++++++++++++++++++++++- 3 files changed, 302 insertions(+), 60 deletions(-)
Signature · 1 line
2.7.4
PATCH v9 1/3 target/ppc: Optimize emulation of vclzh and vclzb instructions
Optimize emulation of Altivec instructions vclzh (Vector Count Leading Zeros Halfword) and vclzb (Vector Count Leading Zeros Byte).This instructions count the number of leading zeros of each halfword/byte element in source register and place result in the appropriate halfword/byte element of the destination register.
Emulation of vclzh instruction is implemented in two 'for' loops. In each iteration of the outer 'for' loop count operation is performed on one doubleword element of source register vB. In the first iteration, a higher doubleword element of vB is placed in variable 'avr', and then counting for every halfword element is performed by using 'tcg_gen_clzi_i64'. Since it counts leading zeros on 64 bit lenght, ith halword element has to be moved to the highest 16 bits of variable 'tmp', or-ed with 'mask'(in order to get all ones in the lowest 48 bits), then perform 'tcg_gen_clzi_i64' and move it's result in the appropriate halfword element of variable 'result'. This is done in inner 'for' loop. After the operation is finished, the 'result' is saved in the appropriate doubleword element of the destination register vD. The same sequence of orders is to be applied again to the lower doubleword element of vB.
Emulation of vclzb instruction is implemented in two 'for' loops. In each iteration of the outer 'for' loop count operation is performed on one doubleword element of source register vB. In the first iteration, the higher doubleword element of vB is placed in variable 'avr', and then counting for every byte element is performed using 'tcg_gen_clzi_i64'. Since it counts leading zeros on 64 bit length, ith byte element has to be moved to the highest 8 bits of variable 'tmp', or-ed with 'mask'(in order to get all ones in the lowest 56 bits), then perform 'tcg_gen_clzi_i64' and move it's result in the appropriate byte element of variable 'result'. This is done in inner 'for' loop. After the operation is finished, the 'result' is saved in the appropriate doubleword element of the destination register vD. The same sequence of orders is to be applied again for the lower doubleword element of vB.
--- target/ppc/helper.h | 2 - target/ppc/int_helper.c | 9 --- target/ppc/translate/vmx-impl.inc.c | 132 +++++++++++++++++++++++++++++++++++- 3 files changed, 130 insertions(+), 13 deletions(-)
target/ppc/helper.h +0 -2
@@ -308,8 +308,6 @@ DEF_HELPER_4(vcfsx, void, env, avr, avr, i32) DEF_HELPER_4(vctuxs, void, env, avr, avr, i32) DEF_HELPER_4(vctsxs, void, env, avr, avr, i32) -DEF_HELPER_2(vclzb, void, avr, avr) -DEF_HELPER_2(vclzh, void, avr, avr) DEF_HELPER_2(vctzb, void, avr, avr) DEF_HELPER_2(vctzh, void, avr, avr)DEF_HELPER_2 (vctzw, void, avr, avr)
target/ppc/int_helper.c +0 -9
@@ -1817,15 +1817,6 @@ VUPK(lsw, s64, s32, UPKLO) } \ } -#define clzb (v) ((v) ? clz32((uint32_t)(v) << 24) : 8) -#define clzh (v) ((v) ? clz32((uint32_t)(v) << 16) : 16) - -VGENERIC_DO(clzb, u8) -VGENERIC_DO(clzh, u16) - -#undef clzb -#undef clzh -#define ctzb (v) ((v) ? ctz32(v) : 8)#define ctzh (v) ((v) ? ctz32(v) : 16)#define ctzw (v) ctz32((v))
target/ppc/translate/vmx-impl.inc.c +130 -2
144 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v9 2/3 target/ppc: Optimize emulation of vpkpx instruction
In reply to Stefan BrankovicOptimize altivec instruction vpkpx (Vector Pack Pixel). Rearranges 8 pixels coded in 6-5-5 pattern (4 from each source register) into a contigous array of bits in the destination register.
In each iteration of outer loop, the instruction is to be done with the 6-5-5 pack for 2 pixels of each doubleword element of each source register. The first thing to be done in outer loop is choosing which doubleword element of which register is to be used in the current iteration and it is to be placed in 'avr' variable. The next step is to perform 6-5-5 pack of pixels on 'avr' variable in inner 'for' loop(2 iterations, 1 for each pixel) and save result in 'tmp' variable. At the end of the outer 'for' loop, the result is merged in the variable called 'result' and saved in the appropriate doubleword element of vD if the whole doubleword is finished(every second iteration). The outer loop has 4 iterations.
--- target/ppc/helper.h | 1 - target/ppc/int_helper.c | 21 --------- target/ppc/translate/vmx-impl.inc.c | 93 ++++++++++++++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 23 deletions(-)
target/ppc/helper.h +0 -1
@@ -258,7 +258,6 @@ DEF_HELPER_4(vpkudus, void, env, avr, avr, avr) DEF_HELPER_4(vpkuhum, void, env, avr, avr, avr) DEF_HELPER_4(vpkuwum, void, env, avr, avr, avr) DEF_HELPER_4(vpkudum, void, env, avr, avr, avr) -DEF_HELPER_3(vpkpx, void, avr, avr, avr) DEF_HELPER_5(vmhaddshs, void, env, avr, avr, avr, avr) DEF_HELPER_5(vmhraddshs, void, env, avr, avr, avr, avr)DEF_HELPER_5 (vmsumuhm, void, env, avr, avr, avr, avr)
target/ppc/int_helper.c +0 -21
@@ -1262,27 +1262,6 @@ void helper_vpmsumd(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b)#else #define PKBIG 0#endif -void helper_vpkpx (ppc_avr_t *r,ppc_avr_t *a,ppc_avr_t *b) -{ -int i, j; -ppc_avr_t result; -#if defined(HOST_WORDS_BIGENDIAN ) -const ppc_avr_t *x[2 ] = { a, b }; -#else -const ppc_avr_t *x[2 ] = { b, a }; -#endif - - VECTOR_FOR_INORDER_I(i, u64) { - VECTOR_FOR_INORDER_I(j, u32) { -uint32_t e = x[i]->u32[j]; - - result.u16[4 * i + j] = (((e >>9 ) &0xfc00 ) | - ((e >>6 ) &0x3e0 ) | - ((e >>3 ) &0x1f )); - } - } - *r = result; -}#define VPK (suffix, from, to, cvt, dosat) \ void helper_vpk##suffix(CPUPPCState *env, ppc_avr_t *r, \
target/ppc/translate/vmx-impl.inc.c +92 -1
105 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v9 3/3 target/ppc: Optimize emulation of vupkhpx and vupklpx instructions
In reply to Stefan BrankovicOptimize altivec instructions vupkhpx and vupklpx (Vector Unpack High/Low Pixel). Unpacks 4 pixels coded in 1-5-5-5 pattern from source register into a contigous array of bits in the destination register.
'trans_vupkpx' function implements emulation of both vupkhpx and vupklpx instructions, while its argument 'high' determines which instruction is processed. Instructions are implemented in two 'for' loops. Outer 'for' loop repeats unpacking two times, since both doubleword elements of the destination register are formed the same way. It also stores result of every iteration in a temporary variable 'result', that is later transferred to the destination register. Inner 'for' loop does unpacking of pixels in two iterations. Each iteration takes 16 bits from source register and unpacks them into 32 bits of the destination register.
--- target/ppc/helper.h | 2 - target/ppc/int_helper.c | 20 --------- target/ppc/translate/vmx-impl.inc.c | 82 ++++++++++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 24 deletions(-)
target/ppc/helper.h +0 -2
@@ -233,8 +233,6 @@ DEF_HELPER_2(vextsh2d, void, avr, avr) DEF_HELPER_2(vextsw2d, void, avr, avr) DEF_HELPER_2(vnegw, void, avr, avr) DEF_HELPER_2(vnegd, void, avr, avr) -DEF_HELPER_2(vupkhpx, void, avr, avr) -DEF_HELPER_2(vupklpx, void, avr, avr) DEF_HELPER_2(vupkhsb, void, avr, avr) DEF_HELPER_2(vupkhsh, void, avr, avr)DEF_HELPER_2 (vupkhsw, void, avr, avr)
target/ppc/int_helper.c +0 -20
@@ -1737,26 +1737,6 @@ void helper_vsum4ubs(CPUPPCState *env, ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b)#define UPKHI 0#define UPKLO 1#endif -#define VUPKPX (suffix, hi) \ - void helper_vupk##suffix(ppc_avr_t *r, ppc_avr_t *b) \ - { \ - int i; \ - ppc_avr_t result; \ - \ - for (i = 0; i < ARRAY_SIZE(r->u32); i++) { \ - uint16_t e = b->u16[hi ? i : i + 4]; \ - uint8_t a = (e >> 15) ? 0xff : 0; \ - uint8_t r = (e >> 10) & 0x1f; \ - uint8_t g = (e >> 5) & 0x1f; \ - uint8_t b = e & 0x1f; \ - \ - result.u32[i] = (a << 24) | (r << 16) | (g << 8) | b; \ - } \ - *r = result; \ - } -VUPKPX(lpx, UPKLO) -VUPKPX(hpx, UPKHI) -#undef VUPKPX#define VUPK (suffix, unpacked, packee, hi) \ void helper_vupk##suffix(ppc_avr_t *r, ppc_avr_t *b) \
target/ppc/translate/vmx-impl.inc.c +80 -2
94 lines not on this page · raw message
Signature · 1 line
2.7.4