1//===-- Utilities for testing stdbit --------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9/*
10 * Declare these BEFORE including stdbit-macros.h so that this test may still be
11 * run even if a given target doesn't yet have these individual entrypoints
12 * enabled.
13 */
14
15#include "include/__llvm-libc-common.h"
16
17#include <stdbool.h> // bool in C
18
19#define STDBIT_STUB_FUNCTION(FUNC_NAME, LEADING_VAL) \
20 unsigned FUNC_NAME##_uc(unsigned char x) __NOEXCEPT { \
21 return LEADING_VAL##AU; \
22 } \
23 unsigned FUNC_NAME##_us(unsigned short x) __NOEXCEPT { \
24 return LEADING_VAL##BU; \
25 } \
26 unsigned FUNC_NAME##_ui(unsigned int x) __NOEXCEPT { \
27 return LEADING_VAL##CU; \
28 } \
29 unsigned FUNC_NAME##_ul(unsigned long x) __NOEXCEPT { \
30 return LEADING_VAL##DU; \
31 } \
32 unsigned FUNC_NAME##_ull(unsigned long long x) __NOEXCEPT { \
33 return LEADING_VAL##EU; \
34 }
35
36__BEGIN_C_DECLS
37
38STDBIT_STUB_FUNCTION(stdc_leading_zeros, 0xA)
39STDBIT_STUB_FUNCTION(stdc_leading_ones, 0xB)
40STDBIT_STUB_FUNCTION(stdc_trailing_zeros, 0xC)
41STDBIT_STUB_FUNCTION(stdc_trailing_ones, 0xD)
42STDBIT_STUB_FUNCTION(stdc_first_leading_zero, 0xE)
43STDBIT_STUB_FUNCTION(stdc_first_leading_one, 0xF)
44STDBIT_STUB_FUNCTION(stdc_first_trailing_zero, 0x0)
45STDBIT_STUB_FUNCTION(stdc_first_trailing_one, 0x1)
46STDBIT_STUB_FUNCTION(stdc_count_zeros, 0x2)
47STDBIT_STUB_FUNCTION(stdc_count_ones, 0x3)
48
49bool stdc_has_single_bit_uc(unsigned char x) __NOEXCEPT { return false; }
50bool stdc_has_single_bit_us(unsigned short x) __NOEXCEPT { return false; }
51bool stdc_has_single_bit_ui(unsigned x) __NOEXCEPT { return false; }
52bool stdc_has_single_bit_ul(unsigned long x) __NOEXCEPT { return false; }
53bool stdc_has_single_bit_ull(unsigned long long x) __NOEXCEPT { return false; }
54
55STDBIT_STUB_FUNCTION(stdc_bit_width, 0x4)
56
57unsigned char stdc_bit_floor_uc(unsigned char x) __NOEXCEPT { return 0x5AU; }
58unsigned short stdc_bit_floor_us(unsigned short x) __NOEXCEPT { return 0x5BU; }
59unsigned stdc_bit_floor_ui(unsigned x) __NOEXCEPT { return 0x5CU; }
60unsigned long stdc_bit_floor_ul(unsigned long x) __NOEXCEPT { return 0x5DUL; }
61unsigned long long stdc_bit_floor_ull(unsigned long long x) __NOEXCEPT {
62 return 0x5EULL;
63}
64
65unsigned char stdc_bit_ceil_uc(unsigned char x) __NOEXCEPT { return 0x6AU; }
66unsigned short stdc_bit_ceil_us(unsigned short x) __NOEXCEPT { return 0x6BU; }
67unsigned stdc_bit_ceil_ui(unsigned x) __NOEXCEPT { return 0x6CU; }
68unsigned long stdc_bit_ceil_ul(unsigned long x) __NOEXCEPT { return 0x6DUL; }
69unsigned long long stdc_bit_ceil_ull(unsigned long long x) __NOEXCEPT {
70 return 0x6EULL;
71}
72
73__END_C_DECLS
74

source code of libc/test/include/stdbit_stub.h