-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath386.h
79 lines (69 loc) · 1.19 KB
/
math386.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef MATH386_H
#define MATH386_H
#include <stdint.h>
static inline uint32_t clz_u32(uint32_t a) {
aw_assert(a != 0);
#if 0
uint32_t r = 32;
if (a >= 0x00010000) { a >>= 16; r -= 16; }
if (a >= 0x00000100) { a >>= 8; r -= 8; }
if (a >= 0x00000010) { a >>= 4; r -= 4; }
if (a >= 0x00000004) { a >>= 2; r -= 2; }
r -= a - (a & (a >> 1));
return r;
#else
__asm {
.386
mov ecx, a
bsr eax, ecx
mov ebx, 31
sub ebx, eax
mov a, ebx
}
return a;
#endif
}
static inline uint32_t mul32(uint32_t x, uint32_t y) {
#if 0
return x * y;
#else
__asm {
.386
mov eax, x
mov ebx, y
mul ebx
mov x, eax
}
return x;
#endif
}
static inline int32_t imul32(int32_t x, int32_t y) {
#if 0
return x * y;
#else
__asm {
.386
mov eax, x
mov ebx, y
imul ebx
mov x, eax
}
return x;
#endif
}
static inline uint32_t div32(uint32_t x, uint32_t y) {
#if 0
return x / y;
#else
__asm {
.386
mov eax, x
mov ebx, y
xor edx, edx
div ebx
mov x, eax
}
return x;
#endif
}
#endif