File tree 3 files changed +52
-12
lines changed
cbmc-library/__builtin_clz-01
3 files changed +52
-12
lines changed Original file line number Diff line number Diff line change 1
1
#include <assert.h>
2
2
3
- #ifndef __GNUC__
4
- int __builtin_clz (unsigned int );
5
- int __builtin_clzl (unsigned long );
6
- int __builtin_clzll (unsigned long long );
3
+ #ifdef _MSC_VER
4
+ # define __builtin_clz (x ) __lzcnt(x)
5
+ # define __builtin_clzll (x ) __lzcnt64(x)
7
6
#endif
8
7
9
8
unsigned int __VERIFIER_nondet_unsigned ();
@@ -39,10 +38,16 @@ int nlz2a(unsigned x)
39
38
40
39
int main ()
41
40
{
41
+ #ifdef _MSC_VER
42
+ unsigned short f = 42 ;
43
+ assert (__lzcnt16 (f ) == 10 );
44
+ #endif
42
45
assert (nlz2a (42 ) == 26 );
43
46
assert (__builtin_clz (42 ) == 26 );
47
+ #ifndef _MSC_VER
44
48
assert (
45
49
__builtin_clzl (42 ) == 26 + (sizeof (unsigned long ) - sizeof (unsigned )) * 8 );
50
+ #endif
46
51
assert (
47
52
__builtin_clzll (42 ) ==
48
53
26 + (sizeof (unsigned long long ) - sizeof (unsigned )) * 8 );
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -51,3 +51,46 @@ inline HANDLE CreateThread(
51
51
return handle ;
52
52
}
53
53
#endif
54
+
55
+ /* FUNCTION: __lzcnt16 */
56
+
57
+ #ifdef _MSC_VER
58
+ int __builtin_clz (unsigned int x );
59
+
60
+ unsigned short __lzcnt16 (unsigned short value )
61
+ {
62
+ if (value == 0 )
63
+ return 16 ;
64
+
65
+ return __builtin_clz (value ) -
66
+ (sizeof (unsigned int ) - sizeof (unsigned short )) * 8 ;
67
+ }
68
+ #endif
69
+
70
+ /* FUNCTION: __lzcnt */
71
+
72
+ #ifdef _MSC_VER
73
+ int __builtin_clz (unsigned int x );
74
+
75
+ unsigned int __lzcnt (unsigned int value )
76
+ {
77
+ if (value == 0 )
78
+ return 32 ;
79
+
80
+ return __builtin_clz (value );
81
+ }
82
+ #endif
83
+
84
+ /* FUNCTION: __lzcnt64 */
85
+
86
+ #ifdef _MSC_VER
87
+ int __builtin_clzll (unsigned long long x );
88
+
89
+ unsigned __int64 __lzcnt64 (unsigned __int64 value )
90
+ {
91
+ if (value == 0 )
92
+ return 64 ;
93
+
94
+ return __builtin_clzll (value );
95
+ }
96
+ #endif
You can’t perform that action at this time.
0 commit comments