source: vendor/emx/current/include/386/builtin.h

Last change on this file was 18, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.2 KB
Line 
1/* 386/builtin.h (emx+gcc) */
2
3#ifndef _I386_BUILTIN_H
4#define _I386_BUILTIN_H
5
6#if defined (__cplusplus)
7extern "C" {
8#endif
9
10static __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
17static __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
23static __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
29static __inline__ void __enable (void)
30{
31 __asm__ __volatile__ ("sti");
32}
33
34static __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
73static __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 */
Note: See TracBrowser for help on using the repository browser.