Revision 7a51ad82 host-utils.h
b/host-utils.h | ||
---|---|---|
23 | 23 |
* THE SOFTWARE. |
24 | 24 |
*/ |
25 | 25 |
|
26 |
#if defined(__x86_64__) |
|
27 |
#define __HAVE_FAST_MULU64__ |
|
28 |
static always_inline void mulu64 (uint64_t *plow, uint64_t *phigh, |
|
29 |
uint64_t a, uint64_t b) |
|
30 |
{ |
|
31 |
__asm__ ("mul %0\n\t" |
|
32 |
: "=d" (*phigh), "=a" (*plow) |
|
33 |
: "a" (a), "0" (b)); |
|
34 |
} |
|
35 |
#define __HAVE_FAST_MULS64__ |
|
36 |
static always_inline void muls64 (uint64_t *plow, uint64_t *phigh, |
|
37 |
int64_t a, int64_t b) |
|
38 |
{ |
|
39 |
__asm__ ("imul %0\n\t" |
|
40 |
: "=d" (*phigh), "=a" (*plow) |
|
41 |
: "a" (a), "0" (b)); |
|
42 |
} |
|
43 |
#else |
|
44 |
void muls64(int64_t *phigh, int64_t *plow, int64_t a, int64_t b); |
|
45 |
void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b); |
|
46 |
#endif |
|
47 |
|
|
26 | 48 |
/* Note that some of those functions may end up calling libgcc functions, |
27 | 49 |
depending on the host machine. It is up to the target emulation to |
28 | 50 |
cope with that. */ |
... | ... | |
68 | 90 |
{ |
69 | 91 |
int cnt = 0; |
70 | 92 |
|
71 |
if (!(val & 0xFFFFFFFF00000000ULL)) {
|
|
93 |
if (!(val >> 32)) {
|
|
72 | 94 |
cnt += 32; |
73 |
val <<= 32; |
|
74 |
} |
|
75 |
if (!(val & 0xFFFF000000000000ULL)) { |
|
76 |
cnt += 16; |
|
77 |
val <<= 16; |
|
78 |
} |
|
79 |
if (!(val & 0xFF00000000000000ULL)) { |
|
80 |
cnt += 8; |
|
81 |
val <<= 8; |
|
82 |
} |
|
83 |
if (!(val & 0xF000000000000000ULL)) { |
|
84 |
cnt += 4; |
|
85 |
val <<= 4; |
|
86 |
} |
|
87 |
if (!(val & 0xC000000000000000ULL)) { |
|
88 |
cnt += 2; |
|
89 |
val <<= 2; |
|
90 |
} |
|
91 |
if (!(val & 0x8000000000000000ULL)) { |
|
92 |
cnt++; |
|
93 |
val <<= 1; |
|
94 |
} |
|
95 |
if (!(val & 0x8000000000000000ULL)) { |
|
96 |
cnt++; |
|
95 |
} else { |
|
96 |
val >>= 32; |
|
97 | 97 |
} |
98 |
return cnt; |
|
98 |
|
|
99 |
return cnt + clz32(val); |
|
99 | 100 |
} |
100 | 101 |
|
101 | 102 |
static always_inline int clo64(uint64_t val) |
Also available in: Unified diff