ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / Examples / Multiplatform / Protocol / VP_Os / linux / intrin.h
1
2 #ifndef __INTRIN__H__
3 #define __INTRIN__H__
4
5 #include <VP_Os/vp_os_types.h>
6
7 // #undef always_inline
8
9 #if defined(__GNUC__)
10
11 #if TARGET_CPU_X86 == 1
12
13 static INLINE uint32_t _BitScanReverse(uint32_t* index, uint32_t mask)
14 {
15   __asm__("bsrl %[mask], %[index]" : [index] "=r" (*index) : [mask] "mr" (mask));
16
17   return mask ? 1 : 0;
18 }
19
20
21 static INLINE uint32_t _byteswap_ulong(uint32_t value)
22 {
23   __asm("bswap %0":
24       "=r" (value):
25       "0" (value));
26
27   return value;
28 }
29
30 static inline uint32_t clz(uint32_t code)
31 {
32   uint32_t index = 0;
33   if( code )
34   {
35     _BitScanReverse(&index, code);
36     index ^= 31;
37   }
38
39   return index;
40 }
41
42 #endif // TARGET_CPU_X86
43
44 #if TARGET_CPU_ARM == 1
45
46 #ifdef _IPHONE
47
48 static INLINE uint32_t _byteswap_ulong(uint32_t value)
49 {
50   uint32_t ret;
51
52   __asm __volatile (
53                     " rev %0, %1\n"
54                     : "=r" (ret)
55                     : "r" (value)
56                     );
57
58   return ret;
59 }
60
61 #define usat16( value, imm )      __asm __volatile( "usat16 %0, %1, %0" : "=r" (value) : "0" (value), "I" (imm) )
62 #define usat( value, imm, shift ) __asm __volatile( "usat %0, %2, %0, asr %3" :"=r" (value) :"0" (value), "I" (imm), "I" (shift) )
63
64 #define uxtb( ret, value, imm )   __asm __volatile ( "uxtb    %0, %1, ror %2" : "=r" (ret) : "r" (value), "I" (imm) )
65 #define uxtb16( ret, value, imm ) __asm __volatile ( "uxtb16  %0, %1, ror %2" : "=r" (ret) : "r" (value), "I" (imm) )
66 #define uxth( ret, value, imm )   __asm __volatile ( "uxth    %0, %1, ror %2" : "=r" (ret) : "r" (value), "I" (imm) )
67
68 #else
69
70 static INLINE uint32_t _byteswap_ulong(uint32_t value)
71 {
72   int32_t tmp;
73
74   __asm __volatile(
75     "eor        %1, %2, %2, ror #16\n"
76     "bic        %1, %1, #0x00ff0000\n"
77     "mov        %0, %2, ror #8\n"
78     "eor        %0, %0, %1, lsr #8"
79     : "=r" (value), "=r" (tmp)
80     : "r" (value)
81   );
82
83   return value;
84 }
85
86 #endif // _IPHONE
87
88 #define clz   __builtin_clz
89
90 #endif // TARGET_CPU_ARM
91
92 #define bswap _byteswap_ulong
93
94 #endif // __GNUC__
95
96 #endif // ! __INTRIN__H__
97