FreeRDP
Loading...
Searching...
No Matches
intrin.h
1
22#ifndef WINPR_INTRIN_H
23#define WINPR_INTRIN_H
24
25#if !defined(_WIN32) || defined(__MINGW32__) || defined(_M_ARM64)
26
34#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
35
36static INLINE UINT32 __lzcnt(UINT32 _val32)
37{
38 return ((UINT32)__builtin_clz(_val32));
39}
40
41#if !(defined(__MINGW32__) && defined(__clang__))
42static INLINE UINT16 __lzcnt16(UINT16 _val16)
43{
44 return ((UINT16)(__builtin_clz((UINT32)_val16) - 16));
45}
46#endif /* !(defined(__MINGW32__) && defined(__clang__)) */
47
48#else /* (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2) */
49
50static INLINE UINT32 __lzcnt(UINT32 x)
51{
52 unsigned y;
53 int n = 32;
54 y = x >> 16;
55 if (y != 0)
56 {
57 n = n - 16;
58 x = y;
59 }
60 y = x >> 8;
61 if (y != 0)
62 {
63 n = n - 8;
64 x = y;
65 }
66 y = x >> 4;
67 if (y != 0)
68 {
69 n = n - 4;
70 x = y;
71 }
72 y = x >> 2;
73 if (y != 0)
74 {
75 n = n - 2;
76 x = y;
77 }
78 y = x >> 1;
79 if (y != 0)
80 return n - 2;
81 return n - x;
82}
83
84static INLINE UINT16 __lzcnt16(UINT16 x)
85{
86 return ((UINT16)__lzcnt((UINT32)x));
87}
88
89#endif /* (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2) */
90
91#endif /* !defined(_WIN32) || defined(__MINGW32__) */
92
93#endif /* WINPR_INTRIN_H */