| 1 | /* 386/builtin.h (emx+gcc) */
|
|---|
| 2 |
|
|---|
| 3 | #ifndef _I386_BUILTIN_H
|
|---|
| 4 | #define _I386_BUILTIN_H
|
|---|
| 5 |
|
|---|
| 6 | #if defined (__cplusplus)
|
|---|
| 7 | extern "C" {
|
|---|
| 8 | #endif
|
|---|
| 9 |
|
|---|
| 10 | static __inline__ signed char __cxchg (__volatile__ signed char *p,
|
|---|
| 11 | signed char v)
|
|---|
| 12 | {
|
|---|
| 13 | __asm__ __volatile__ ("xchgb %0, %1" : "=m"(*p), "=r"(v) : "1"(v));
|
|---|
| 14 | return v;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | static __inline__ short __sxchg (__volatile__ short *p, short v)
|
|---|
| 18 | {
|
|---|
| 19 | __asm__ __volatile__ ("xchgw %0, %1" : "=m"(*p), "=r"(v) : "1"(v));
|
|---|
| 20 | return v;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | static __inline__ int __lxchg (__volatile__ int *p, int v)
|
|---|
| 24 | {
|
|---|
| 25 | __asm__ __volatile__ ("xchgl %0, %1" : "=m"(*p), "=r"(v) : "1"(v));
|
|---|
| 26 | return v;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | static __inline__ void __enable (void)
|
|---|
| 30 | {
|
|---|
| 31 | __asm__ __volatile__ ("sti");
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | static __inline__ void __disable (void)
|
|---|
| 35 | {
|
|---|
| 36 | __asm__ __volatile__ ("cli");
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | #define __ROTATE_FUN(F,I,T) \
|
|---|
| 40 | static __inline__ T F (T value, int shift) \
|
|---|
| 41 | { \
|
|---|
| 42 | __asm__ (I " %b2, %0" : "=g"(value) : "0"(value), "c"(shift) : "cc"); \
|
|---|
| 43 | return value; \
|
|---|
| 44 | } \
|
|---|
| 45 | static __inline__ T F##1 (T value) \
|
|---|
| 46 | { \
|
|---|
| 47 | __asm__ (I " $1, %0" : "=g"(value) : "0"(value) : "cc"); \
|
|---|
| 48 | return value; \
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | #define __ROTATE(V,S,F) ((__builtin_constant_p (S) && (int)(S) == 1) \
|
|---|
| 52 | ? F##1 (V) : F (V, S))
|
|---|
| 53 |
|
|---|
| 54 | __ROTATE_FUN (__crotr, "rorb", unsigned char)
|
|---|
| 55 | __ROTATE_FUN (__srotr, "rorw", unsigned short)
|
|---|
| 56 | __ROTATE_FUN (__lrotr, "rorl", unsigned long)
|
|---|
| 57 |
|
|---|
| 58 | __ROTATE_FUN (__crotl, "rolb", unsigned char)
|
|---|
| 59 | __ROTATE_FUN (__srotl, "rolw", unsigned short)
|
|---|
| 60 | __ROTATE_FUN (__lrotl, "roll", unsigned long)
|
|---|
| 61 |
|
|---|
| 62 | #define _crotr(V,S) __ROTATE (V, S, __crotr)
|
|---|
| 63 | #define _srotr(V,S) __ROTATE (V, S, __srotr)
|
|---|
| 64 | #define _lrotr(V,S) __ROTATE (V, S, __lrotr)
|
|---|
| 65 | #define _crotl(V,S) __ROTATE (V, S, __crotl)
|
|---|
| 66 | #define _srotl(V,S) __ROTATE (V, S, __srotl)
|
|---|
| 67 | #define _lrotl(V,S) __ROTATE (V, S, __lrotl)
|
|---|
| 68 |
|
|---|
| 69 | #define _rotr(V,S) _lrotr (V, S)
|
|---|
| 70 | #define _rotl(V,S) _lrotl (V, S)
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | static __inline__ int __fls (int v)
|
|---|
| 74 | {
|
|---|
| 75 | int r;
|
|---|
| 76 |
|
|---|
| 77 | __asm__ __volatile__ ("bsrl %1, %0;"
|
|---|
| 78 | "jnz 1f;"
|
|---|
| 79 | "movl $-1, %0;"
|
|---|
| 80 | ".align 2, 0x90;"
|
|---|
| 81 | "1:"
|
|---|
| 82 | : "=r"(r) : "r"(v) : "cc");
|
|---|
| 83 | return r + 1;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | #if defined (__cplusplus)
|
|---|
| 87 | }
|
|---|
| 88 | #endif
|
|---|
| 89 |
|
|---|
| 90 | #endif /* not _I386_BUILTIN_H */
|
|---|