From: "J. Mayer" <l_indien@magic.fr>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Proposal for host-utils
Date: Sun, 28 Oct 2007 14:02:40 +0100 [thread overview]
Message-ID: <1193576560.16781.322.camel@rapid> (raw)
In-Reply-To: <1193525625.16781.318.camel@rapid>
[-- Attachment #1: Type: text/plain, Size: 1118 bytes --]
On Sun, 2007-10-28 at 00:53 +0200, J. Mayer wrote:
> 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
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.
--
J. Mayer <l_indien@magic.fr>
Never organized
[-- Attachment #2: host-utils.diff --]
[-- Type: text/x-patch, Size: 5263 bytes --]
Index: exec-all.h
===================================================================
RCS file: /sources/qemu/qemu/exec-all.h,v
retrieving revision 1.69
diff -u -d -d -p -r1.69 exec-all.h
--- exec-all.h 20 Oct 2007 19:45:43 -0000 1.69
+++ exec-all.h 28 Oct 2007 12:59:46 -0000
@@ -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
diff -u -d -d -p -r1.4 host-utils.c
--- host-utils.c 26 Oct 2007 22:35:01 -0000 1.4
+++ host-utils.c 28 Oct 2007 12:59:46 -0000
@@ -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 *p
if (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
diff -u -d -d -p -r1.2 host-utils.h
--- host-utils.h 28 Oct 2007 12:52:38 -0000 1.2
+++ host-utils.h 28 Oct 2007 12:59:46 -0000
@@ -23,6 +23,26 @@
* THE SOFTWARE.
*/
+#if defined(__x86_64__)
+static always_inline void mulu64 (uint64_t *plow, uint64_t *phigh,
+ uint64_t a, uint64_t b)
+{
+ __asm__ ("mul %0\n\t"
+ : "=d" (*phigh), "=a" (*plow)
+ : "a" (a), "0" (b));
+}
+static always_inline void muls64 (uint64_t *plow, uint64_t *phigh,
+ int64_t a, int64_t b)
+{
+ __asm__ ("imul %0\n\t"
+ : "=d" (*phigh), "=a" (*plow)
+ : "a" (a), "0" (b));
+}
+#else
+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);
+#endif
+
/* Note that some of those functions may end up calling libgcc functions,
depending on the host machine. It is up to the target emulation to
cope with that. */
@@ -68,34 +88,13 @@ static always_inline int clz64(uint64_t
{
int cnt = 0;
- if (!(val & 0xFFFFFFFF00000000ULL)) {
+ if (!(val >> 32)) {
cnt += 32;
- val <<= 32;
- }
- if (!(val & 0xFFFF000000000000ULL)) {
- cnt += 16;
- val <<= 16;
- }
- if (!(val & 0xFF00000000000000ULL)) {
- cnt += 8;
- val <<= 8;
- }
- if (!(val & 0xF000000000000000ULL)) {
- cnt += 4;
- val <<= 4;
- }
- if (!(val & 0xC000000000000000ULL)) {
- cnt += 2;
- val <<= 2;
- }
- if (!(val & 0x8000000000000000ULL)) {
- cnt++;
- val <<= 1;
- }
- if (!(val & 0x8000000000000000ULL)) {
- cnt++;
+ } else {
+ val >>= 32;
}
- return cnt;
+
+ return cnt + clz32(val);
}
static always_inline int clo64(uint64_t val)
Index: target-alpha/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op.c,v
retrieving revision 1.4
diff -u -d -d -p -r1.4 op.c
--- target-alpha/op.c 25 Oct 2007 23:34:44 -0000 1.4
+++ target-alpha/op.c 28 Oct 2007 12:59:46 -0000
@@ -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
diff -u -d -d -p -r1.91 helper.c
--- target-i386/helper.c 26 Oct 2007 22:35:02 -0000 1.91
+++ target-i386/helper.c 28 Oct 2007 12:59:47 -0000
@@ -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
next prev parent reply other threads:[~2007-10-28 13:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-27 22:53 [Qemu-devel] Proposal for host-utils J. Mayer
2007-10-28 13:02 ` J. Mayer [this message]
2007-10-28 16:13 ` Thiemo Seufer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1193576560.16781.322.camel@rapid \
--to=l_indien@magic.fr \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.