1227825Stheraven// -*- C++ -*-
2227825Stheraven//===-----------------------------------------------------------------------===//
3227825Stheraven//
4227825Stheraven// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5227825Stheraven// See https://llvm.org/LICENSE.txt for license information.
6227825Stheraven// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7227825Stheraven//
8227825Stheraven//===----------------------------------------------------------------------===//
9227825Stheraven
10227825Stheraven#ifndef _LIBCPP_SUPPORT_IBM_SUPPORT_H
11227825Stheraven#define _LIBCPP_SUPPORT_IBM_SUPPORT_H
12227825Stheraven
13227825Stheravenextern "builtin" int __popcnt4(unsigned int);
14227825Stheravenextern "builtin" int __popcnt8(unsigned long long);
15227825Stheravenextern "builtin" unsigned int __cnttz4(unsigned int);
16227825Stheravenextern "builtin" unsigned int __cnttz8(unsigned long long);
17227825Stheravenextern "builtin" unsigned int __cntlz4(unsigned int);
18227825Stheravenextern "builtin" unsigned int __cntlz8(unsigned long long);
19227825Stheraven
20227825Stheraven// Builtin functions for counting population
21227825Stheraven#define __builtin_popcount(x) __popcnt4(x)
22227825Stheraven#define __builtin_popcountll(x) __popcnt8(x)
23227825Stheraven#if defined(__64BIT__)
24227825Stheraven#define __builtin_popcountl(x) __builtin_popcountll(x)
25227825Stheraven#else
26227825Stheraven#define __builtin_popcountl(x) __builtin_popcount(x)
27227825Stheraven#endif
28227825Stheraven
29227825Stheraven// Builtin functions for counting trailing zeros
30227825Stheraven#define __builtin_ctz(x) __cnttz4(x)
31227825Stheraven#define __builtin_ctzll(x) __cnttz8(x)
32227825Stheraven#if defined(__64BIT__)
33227825Stheraven#define __builtin_ctzl(x) __builtin_ctzll(x)
34227825Stheraven#else
35227825Stheraven#define __builtin_ctzl(x) __builtin_ctz(x)
36227825Stheraven#endif
37227825Stheraven
38227825Stheraven// Builtin functions for counting leading zeros
39227825Stheraven#define __builtin_clz(x) __cntlz4(x)
40227825Stheraven#define __builtin_clzll(x) __cntlz8(x)
41227825Stheraven#if defined(__64BIT__)
42227825Stheraven#define __builtin_clzl(x) __builtin_clzll(x)
43241903Sdim#else
44241903Sdim#define __builtin_clzl(x) __builtin_clz(x)
45227825Stheraven#endif
46241903Sdim
47227825Stheraven#if defined(__64BIT__)
48227825Stheraven#define __SIZE_WIDTH__ 64
49227825Stheraven#else
50227825Stheraven#define __SIZE_WIDTH__ 32
51227825Stheraven#endif
52227825Stheraven
53227825Stheraven#endif // _LIBCPP_SUPPORT_IBM_SUPPORT_H
54241903Sdim