Proposal for host-utils
Following the previous discussions about host-utils implementations, here's a patch with the following changes:
- move mulu64 and muls64 definitions from exec.h to host-utils.h, for consistency
- include host-utils.h in more files to reflect this change
- make the optimized version of mulu64 / muls64 for amd64 hosts static inline
- change clz64 to avoid 64 bits logical operations to optimize the 32 bits host case
- add ctz32, ctz64, cto32 and cto64, using the same method than ctlzxx / cloxx implementations
- add ctpop8, ctpop16, ctpop32 and ctpop64, using the Sparc target implementation method
ctpop8 is used by the PowerPC target, I added ctpop16 for consistency
- change the Alpha and the PowerPC targets to use those helpers
Please comment.
Signature · 2 lines
J. Mayer <[email protected]> Never organized
Index: exec-all.h
===================================================================
RCS file: /sources/qemu/qemu/exec-all.h,v
retrieving revision 1.69
exec-all.h +0 -3
@@ -91,9 +91,6 @@ void optimize_flags_init(void);extern FILE *logfile;extern int loglevel; -void muls64 (int64_t *phigh,int64_t *plow,int64_t a,int64_t b); -void mulu64 (uint64_t *phigh,uint64_t *plow,uint64_t a,uint64_t b); -int gen_intermediate_code (CPUState *env,struct TranslationBlock *tb);int gen_intermediate_code_pc (CPUState *env,struct TranslationBlock *tb);void dump_ops (const uint16_t *opc_buf,const uint32_t *opparam_buf);
Index: host-utils.c
===================================================================
RCS file: /sources/qemu/qemu/host-utils.c,v
retrieving revision 1.4
host-utils.c +2 -13
@@ -28,6 +28,7 @@//#define DEBUG_MULDIV /* Long integer helpers */ +#if !defined(__x86_64__)static void add128 (uint64_t *plow,uint64_t *phigh,uint64_t a,uint64_t b) { *plow += a;
@@ -69,17 +70,10 @@ static void mul64 (uint64_t *plow, uint6 *phigh += v; } -/* Unsigned 64x64 -> 128 multiplication */ void mulu64 (uint64_t *plow,uint64_t *phigh,uint64_t a,uint64_t b) { -#if defined(__x86_64__) - __asm__ ("mul %0\n\t" - :"=d" (*phigh),"=a" (*plow) - :"a" (a),"0" (b)); -#else mul64 (plow, phigh, a, b); -#endif #if defined(DEBUG_MULDIV )printf ("mulu64: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n" , a, b, *phigh, *plow);
@@ -89,11 +83,6 @@ void mulu64 (uint64_t *plow, uint64_t *p/* Signed 64x64 -> 128 multiplication */ void muls64 (uint64_t *plow,uint64_t *phigh,int64_t a,int64_t b) { -#if defined(__x86_64__) - __asm__ ("imul %0\n\t" - :"=d" (*phigh),"=a" (*plow) - :"a" (a),"0" (b)); -#else int sa, sb; sa = (a <0 );
@@ -106,9 +95,9 @@ void muls64 (uint64_t *plow, uint64_t *pif (sa ^ sb) {neg128 (plow, phigh); } -#endif #if defined(DEBUG_MULDIV )printf ("muls64: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n" , a, b, *phigh, *plow); #endif } +#endif /* !defined(__x86_64__) */
Index: host-utils.h
===================================================================
RCS file: /sources/qemu/qemu/host-utils.h,v
retrieving revision 1.1
host-utils.h +111 -15
154 lines not on this page · raw message
Index: target-alpha/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op.c,v
retrieving revision 1.4
op.c +1 -0
@@ -22,6 +22,7 @@#include "config.h" #include "exec.h" +#include "host-utils.h" #include "op_helper.h"
Index: target-alpha/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op_helper.c,v retrieving revision 1.5
op_helper.c +4 -73
97 lines not on this page · raw message
Index: target-i386/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper.c,v retrieving revision 1.91
helper.c +1 -0
@@ -18,6 +18,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "exec.h" +#include "host-utils.h" //#define DEBUG_PCALL
Index: target-ppc/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op.c,v
retrieving revision 1.59
op.c +3 -2
@@ -22,6 +22,7 @@#include "config.h" #include "exec.h" +#include "host-utils.h" #include "helper_regs.h" #include "op_helper.h"
@@ -1508,14 +1509,14 @@ void OPPROTO op_andi_T1_64 (void)/* count leading zero */ void OPPROTO op_cntlzw (void) { -T0 =_do_cntlzw (T0 ); +do_cntlzw ();RETURN (); }#if defined(TARGET_PPC64 ) void OPPROTO op_cntlzd (void) { -T0 =_do_cntlzd (T0 ); +do_cntlzd ();RETURN (); }#endif
Index: target-ppc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.c,v retrieving revision 1.56
op_helper.c +18 -15
@@ -18,6 +18,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "exec.h" +#include "host-utils.h" #include "helper_regs.h" #include "op_helper.h"
@@ -381,6 +382,18 @@ void do_subfzeo_64 (void) }#endif +void do_cntlzw (void ) +{ +T0 =clz32 (T0 ); +} + +#if defined(TARGET_PPC64 ) +void do_cntlzd (void ) +{ +T0 =clz64 (T0 ); +} +#endif +/* shift right arithmetic helper */ void do_sraw (void ) {
@@ -438,16 +451,6 @@ void do_srad (void) }#endif -static always_inline int popcnt (uint32_t val) -{ -int i; - -for (i =0 ; val !=0 ;) - val = val ^ (val -1 ); - -return i; -} -void do_popcntb (void ) {uint32_t ret;
@@ -455,7 +458,7 @@ void do_popcntb (void) ret =0 ;for (i =0 ; i <32 ; i +=8 ) - ret |=popcnt ((T0 >> i) &0xFF ) << i; + ret |=ctpop8 ((T0 >> i) &0xFF ) << i;T0 = ret; }
@@ -467,7 +470,7 @@ void do_popcntb_64 (void) ret =0 ;for (i =0 ; i <64 ; i +=8 ) - ret |=popcnt ((T0 >> i) &0xFF ) << i; + ret |=ctpop8 ((T0 >> i) &0xFF ) << i; T0 = ret; }#endif
@@ -1925,14 +1928,14 @@ static always_inline uint32_t _do_eaddw static always_inline int _do_ecntlsw (uint32_t val) {if (val &0x80000000 ) -return _do_cntlzw (~val); +return clz32 (~val);else -return _do_cntlzw (val); +return clz32 (val); } static always_inline int _do_ecntlzw (uint32_t val) { -return _do_cntlzw (val); +return clz32 (val); } static always_inline uint32_t _do_eneg (uint32_t val)
Index: target-ppc/op_helper.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.h,v retrieving revision 1.24
op_helper.h +4 -72
88 lines not on this page · raw message
Quoted 7 lines · J. Mayer
Following the previous discussions about host-utils implementations, here's a patch with the following changes:
- move mulu64 and muls64 definitions fromexec.htohost-utils.h, for consistency
- includehost-utils.hin more files to reflect this change
- make the optimized version of mulu64 / muls64 for amd64 hosts static inline
Quoted 8 lines
- change clz64 to avoid 64 bits logical operations to optimize the 32 bits host case
- add ctz32, ctz64, cto32 and cto64, using the same method than ctlzxx / cloxx implementations
- add ctpop8, ctpop16, ctpop32 and ctpop64, using the Sparc target implementation method
ctpop8 is used by the PowerPC target, I added ctpop16 for consistency
- change the Alpha and the PowerPC targets to use those helpers
I did commit the ctz, cto and ctpop helpers. I have a remaining patch that contains the changes for mulu64 / muls64 and optimize clz64 and clo64, avoiding 64 bits values manipulation, which may help when running on a 32 bits host.
Please comment.
Signature · 2 lines
J. Mayer <[email protected]> Never organized
Index: exec-all.h
===================================================================
RCS file: /sources/qemu/qemu/exec-all.h,v
retrieving revision 1.69
exec-all.h +0 -3
@@ -91,9 +91,6 @@ void optimize_flags_init(void);extern FILE *logfile;extern int loglevel; -void muls64 (int64_t *phigh,int64_t *plow,int64_t a,int64_t b); -void mulu64 (uint64_t *phigh,uint64_t *plow,uint64_t a,uint64_t b); -int gen_intermediate_code (CPUState *env,struct TranslationBlock *tb);int gen_intermediate_code_pc (CPUState *env,struct TranslationBlock *tb);void dump_ops (const uint16_t *opc_buf,const uint32_t *opparam_buf);
Index: host-utils.c
===================================================================
RCS file: /sources/qemu/qemu/host-utils.c,v
retrieving revision 1.4
host-utils.c +2 -13
@@ -28,6 +28,7 @@//#define DEBUG_MULDIV /* Long integer helpers */ +#if !defined(__x86_64__)static void add128 (uint64_t *plow,uint64_t *phigh,uint64_t a,uint64_t b) { *plow += a;
@@ -69,17 +70,10 @@ static void mul64 (uint64_t *plow, uint6 *phigh += v; } -/* Unsigned 64x64 -> 128 multiplication */ void mulu64 (uint64_t *plow,uint64_t *phigh,uint64_t a,uint64_t b) { -#if defined(__x86_64__) - __asm__ ("mul %0\n\t" - :"=d" (*phigh),"=a" (*plow) - :"a" (a),"0" (b)); -#else mul64 (plow, phigh, a, b); -#endif #if defined(DEBUG_MULDIV )printf ("mulu64: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n" , a, b, *phigh, *plow);
@@ -89,11 +83,6 @@ void mulu64 (uint64_t *plow, uint64_t *p/* Signed 64x64 -> 128 multiplication */ void muls64 (uint64_t *plow,uint64_t *phigh,int64_t a,int64_t b) { -#if defined(__x86_64__) - __asm__ ("imul %0\n\t" - :"=d" (*phigh),"=a" (*plow) - :"a" (a),"0" (b)); -#else int sa, sb; sa = (a <0 );
@@ -106,9 +95,9 @@ void muls64 (uint64_t *plow, uint64_t *pif (sa ^ sb) {neg128 (plow, phigh); } -#endif #if defined(DEBUG_MULDIV )printf ("muls64: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n" , a, b, *phigh, *plow); #endif } +#endif /* !defined(__x86_64__) */
Index: host-utils.h
===================================================================
RCS file: /sources/qemu/qemu/host-utils.h,v
retrieving revision 1.2
host-utils.h +25 -26
65 lines not on this page · raw message
Index: target-alpha/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op.c,v
retrieving revision 1.4
op.c +1 -0
@@ -22,6 +22,7 @@#include "config.h" #include "exec.h" +#include "host-utils.h" #include "op_helper.h"
Index: target-i386/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper.c,v retrieving revision 1.91
helper.c +1 -0
@@ -18,6 +18,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "exec.h" +#include "host-utils.h" //#define DEBUG_PCALL
Quoted 18 lines · J. Mayer
Quoted 7 lines · J. Mayer
Following the previous discussions about host-utils implementations, here's a patch with the following changes:
- move mulu64 and muls64 definitions fromexec.htohost-utils.h, for consistency
- includehost-utils.hin more files to reflect this change
- make the optimized version of mulu64 / muls64 for amd64 hosts static inlineQuoted 8 lines
- change clz64 to avoid 64 bits logical operations to optimize the 32 bits host case
- add ctz32, ctz64, cto32 and cto64, using the same method than ctlzxx / cloxx implementations
- add ctpop8, ctpop16, ctpop32 and ctpop64, using the Sparc target implementation method
ctpop8 is used by the PowerPC target, I added ctpop16 for consistency
- change the Alpha and the PowerPC targets to use those helpers
Quoted 6 lines
I did commit the ctz, cto and ctpop helpers. I have a remaining patch that contains the changes for mulu64 / muls64 and optimize clz64 and clo64, avoiding 64 bits values manipulation, which may help when running on a 32 bits host.
Please comment.
I like it.
Thiemo