1234287Sdim/*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------===
2234287Sdim *
3234287Sdim * Permission is hereby granted, free of charge, to any person obtaining a copy
4234287Sdim * of this software and associated documentation files (the "Software"), to deal
5234287Sdim * in the Software without restriction, including without limitation the rights
6234287Sdim * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7234287Sdim * copies of the Software, and to permit persons to whom the Software is
8234287Sdim * furnished to do so, subject to the following conditions:
9234287Sdim *
10234287Sdim * The above copyright notice and this permission notice shall be included in
11234287Sdim * all copies or substantial portions of the Software.
12234287Sdim *
13234287Sdim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14234287Sdim * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15234287Sdim * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16234287Sdim * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17234287Sdim * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18234287Sdim * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19234287Sdim * THE SOFTWARE.
20234287Sdim *
21234287Sdim *===-----------------------------------------------------------------------===
22234287Sdim */
23234287Sdim
24234287Sdim#if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
25234287Sdim#error "Never use <lzcntintrin.h> directly; include <x86intrin.h> instead."
26234287Sdim#endif
27234287Sdim
28234287Sdim#ifndef __LZCNT__
29234287Sdim# error "LZCNT instruction is not enabled"
30234287Sdim#endif /* __LZCNT__ */
31234287Sdim
32234287Sdim#ifndef __LZCNTINTRIN_H
33234287Sdim#define __LZCNTINTRIN_H
34234287Sdim
35234287Sdimstatic __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
36234287Sdim__lzcnt16(unsigned short __X)
37234287Sdim{
38234287Sdim  return __builtin_clzs(__X);
39234287Sdim}
40234287Sdim
41234287Sdimstatic __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
42234287Sdim__lzcnt32(unsigned int __X)
43234287Sdim{
44234287Sdim  return __builtin_clz(__X);
45234287Sdim}
46234287Sdim
47234287Sdim#ifdef __x86_64__
48234287Sdimstatic __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
49234287Sdim__lzcnt64(unsigned long long __X)
50234287Sdim{
51234287Sdim  return __builtin_clzll(__X);
52234287Sdim}
53234287Sdim#endif
54234287Sdim
55234287Sdim#endif /* __LZCNTINTRIN_H */
56