1// -*- C++ -*-
2//===----------------------- support/ibm/support.h ----------------------===//
3//
4//                     The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_SUPPORT_IBM_SUPPORT_H
12#define _LIBCPP_SUPPORT_IBM_SUPPORT_H
13
14extern "builtin" int __popcnt4(unsigned int);
15extern "builtin" int __popcnt8(unsigned long long);
16extern "builtin" unsigned int __cnttz4(unsigned int);
17extern "builtin" unsigned int __cnttz8(unsigned long long);
18extern "builtin" unsigned int __cntlz4(unsigned int);
19extern "builtin" unsigned int __cntlz8(unsigned long long);
20
21// Builtin functions for counting population
22#define __builtin_popcount(x) __popcnt4(x)
23#define __builtin_popcountll(x) __popcnt8(x)
24#if defined(__64BIT__)
25#define __builtin_popcountl(x) __builtin_popcountll(x)
26#else
27#define __builtin_popcountl(x) __builtin_popcount(x)
28#endif
29
30// Builtin functions for counting trailing zeros
31#define __builtin_ctz(x) __cnttz4(x)
32#define __builtin_ctzll(x) __cnttz8(x)
33#if defined(__64BIT__)
34#define __builtin_ctzl(x) __builtin_ctzll(x)
35#else
36#define __builtin_ctzl(x) __builtin_ctz(x)
37#endif
38
39// Builtin functions for counting leading zeros
40#define __builtin_clz(x) __cntlz4(x)
41#define __builtin_clzll(x) __cntlz8(x)
42#if defined(__64BIT__)
43#define __builtin_clzl(x) __builtin_clzll(x)
44#else
45#define __builtin_clzl(x) __builtin_clz(x)
46#endif
47
48#if defined(__64BIT__)
49#define __SIZE_WIDTH__ 64
50#else
51#define __SIZE_WIDTH__ 32
52#endif
53
54#endif // _LIBCPP_SUPPORT_IBM_SUPPORT_H
55