aboutsummaryrefslogtreecommitdiffstats
path: root/host-utils.h
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2009-09-14 14:32:27 -0700
committerDavid 'Digit' Turner <digit@google.com>2009-09-14 14:32:27 -0700
commit5d8f37ad78fc66901af50c762029a501561f3b23 (patch)
tree206790f8f21000850a98c4f9590a79e779106278 /host-utils.h
parentcd059b15f2c7df69f4a087bd66900eb172e41d1c (diff)
downloadexternal_qemu-5d8f37ad78fc66901af50c762029a501561f3b23.zip
external_qemu-5d8f37ad78fc66901af50c762029a501561f3b23.tar.gz
external_qemu-5d8f37ad78fc66901af50c762029a501561f3b23.tar.bz2
Merge upstream QEMU 10.0.50 into the Android source tree.
This change integrates many changes from the upstream QEMU sources. Its main purpose is to enable correct ARMv6 and ARMv7 support to the Android emulator. Due to the nature of the upstream code base, this unfortunately also required changes to many other parts of the source. Note that to ensure easier integrations in the future, some source files and directories that have heavy Android-specific customization have been renamed with an -android suffix. The original files are still there for easier integration tracking, but *never* compiled. For example: net.c net-android.c qemu-char.c qemu-char-android.c slirp/ slirp-android/ etc... Tested on linux-x86, darwin-x86 and windows host machines.
Diffstat (limited to 'host-utils.h')
-rw-r--r--host-utils.h90
1 files changed, 61 insertions, 29 deletions
diff --git a/host-utils.h b/host-utils.h
index b1e799e..2128615 100644
--- a/host-utils.h
+++ b/host-utils.h
@@ -47,14 +47,16 @@ void muls64(uint64_t *phigh, uint64_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. */
-
/* Binary search for leading zeros. */
static always_inline int clz32(uint32_t val)
{
+#if QEMU_GNUC_PREREQ(3, 4)
+ if (val)
+ return __builtin_clz(val);
+ else
+ return 32;
+#else
int cnt = 0;
if (!(val & 0xFFFF0000U)) {
@@ -81,6 +83,7 @@ static always_inline int clz32(uint32_t val)
cnt++;
}
return cnt;
+#endif
}
static always_inline int clo32(uint32_t val)
@@ -90,6 +93,12 @@ static always_inline int clo32(uint32_t val)
static always_inline int clz64(uint64_t val)
{
+#if QEMU_GNUC_PREREQ(3, 4)
+ if (val)
+ return __builtin_clzll(val);
+ else
+ return 64;
+#else
int cnt = 0;
if (!(val >> 32)) {
@@ -99,6 +108,7 @@ static always_inline int clz64(uint64_t val)
}
return cnt + clz32(val);
+#endif
}
static always_inline int clo64(uint64_t val)
@@ -106,45 +116,58 @@ static always_inline int clo64(uint64_t val)
return clz64(~val);
}
-static always_inline int ctz32 (uint32_t val)
+static always_inline int ctz32(uint32_t val)
{
+#if QEMU_GNUC_PREREQ(3, 4)
+ if (val)
+ return __builtin_ctz(val);
+ else
+ return 32;
+#else
int cnt;
cnt = 0;
if (!(val & 0x0000FFFFUL)) {
- cnt += 16;
+ cnt += 16;
val >>= 16;
- }
+ }
if (!(val & 0x000000FFUL)) {
- cnt += 8;
+ cnt += 8;
val >>= 8;
- }
+ }
if (!(val & 0x0000000FUL)) {
- cnt += 4;
+ cnt += 4;
val >>= 4;
- }
+ }
if (!(val & 0x00000003UL)) {
- cnt += 2;
+ cnt += 2;
val >>= 2;
- }
+ }
if (!(val & 0x00000001UL)) {
- cnt++;
+ cnt++;
val >>= 1;
- }
+ }
if (!(val & 0x00000001UL)) {
- cnt++;
- }
-
- return cnt;
- }
-
-static always_inline int cto32 (uint32_t val)
- {
+ cnt++;
+ }
+
+ return cnt;
+#endif
+}
+
+static always_inline int cto32(uint32_t val)
+{
return ctz32(~val);
}
-static always_inline int ctz64 (uint64_t val)
+static always_inline int ctz64(uint64_t val)
{
+#if QEMU_GNUC_PREREQ(3, 4)
+ if (val)
+ return __builtin_ctz(val);
+ else
+ return 64;
+#else
int cnt;
cnt = 0;
@@ -154,14 +177,15 @@ static always_inline int ctz64 (uint64_t val)
}
return cnt + ctz32(val);
+#endif
}
-static always_inline int cto64 (uint64_t val)
+static always_inline int cto64(uint64_t val)
{
return ctz64(~val);
}
-static always_inline int ctpop8 (uint8_t val)
+static always_inline int ctpop8(uint8_t val)
{
val = (val & 0x55) + ((val >> 1) & 0x55);
val = (val & 0x33) + ((val >> 2) & 0x33);
@@ -170,7 +194,7 @@ static always_inline int ctpop8 (uint8_t val)
return val;
}
-static always_inline int ctpop16 (uint16_t val)
+static always_inline int ctpop16(uint16_t val)
{
val = (val & 0x5555) + ((val >> 1) & 0x5555);
val = (val & 0x3333) + ((val >> 2) & 0x3333);
@@ -180,8 +204,11 @@ static always_inline int ctpop16 (uint16_t val)
return val;
}
-static always_inline int ctpop32 (uint32_t val)
+static always_inline int ctpop32(uint32_t val)
{
+#if QEMU_GNUC_PREREQ(3, 4)
+ return __builtin_popcount(val);
+#else
val = (val & 0x55555555) + ((val >> 1) & 0x55555555);
val = (val & 0x33333333) + ((val >> 2) & 0x33333333);
val = (val & 0x0f0f0f0f) + ((val >> 4) & 0x0f0f0f0f);
@@ -189,10 +216,14 @@ static always_inline int ctpop32 (uint32_t val)
val = (val & 0x0000ffff) + ((val >> 16) & 0x0000ffff);
return val;
+#endif
}
-static always_inline int ctpop64 (uint64_t val)
+static always_inline int ctpop64(uint64_t val)
{
+#if QEMU_GNUC_PREREQ(3, 4)
+ return __builtin_popcountll(val);
+#else
val = (val & 0x5555555555555555ULL) + ((val >> 1) & 0x5555555555555555ULL);
val = (val & 0x3333333333333333ULL) + ((val >> 2) & 0x3333333333333333ULL);
val = (val & 0x0f0f0f0f0f0f0f0fULL) + ((val >> 4) & 0x0f0f0f0f0f0f0f0fULL);
@@ -201,4 +232,5 @@ static always_inline int ctpop64 (uint64_t val)
val = (val & 0x00000000ffffffffULL) + ((val >> 32) & 0x00000000ffffffffULL);
return val;
+#endif
}