• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // SPDX-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) { return LEADING_VAL##AU; }         \
21   unsigned FUNC_NAME##_us(unsigned short x) { return LEADING_VAL##BU; }        \
22   unsigned FUNC_NAME##_ui(unsigned int x) { return LEADING_VAL##CU; }          \
23   unsigned FUNC_NAME##_ul(unsigned long x) { return LEADING_VAL##DU; }         \
24   unsigned FUNC_NAME##_ull(unsigned long long x) { return LEADING_VAL##EU; }
25 
26 __BEGIN_C_DECLS
27 
28 STDBIT_STUB_FUNCTION(stdc_leading_zeros, 0xA)
29 STDBIT_STUB_FUNCTION(stdc_leading_ones, 0xB)
30 STDBIT_STUB_FUNCTION(stdc_trailing_zeros, 0xC)
31 STDBIT_STUB_FUNCTION(stdc_trailing_ones, 0xD)
32 STDBIT_STUB_FUNCTION(stdc_first_leading_zero, 0xE)
33 STDBIT_STUB_FUNCTION(stdc_first_leading_one, 0xF)
34 STDBIT_STUB_FUNCTION(stdc_first_trailing_zero, 0x0)
35 STDBIT_STUB_FUNCTION(stdc_first_trailing_one, 0x1)
36 STDBIT_STUB_FUNCTION(stdc_count_zeros, 0x2)
37 STDBIT_STUB_FUNCTION(stdc_count_ones, 0x3)
38 
stdc_has_single_bit_uc(unsigned char x)39 bool stdc_has_single_bit_uc(unsigned char x) { return false; }
stdc_has_single_bit_us(unsigned short x)40 bool stdc_has_single_bit_us(unsigned short x) { return false; }
stdc_has_single_bit_ui(unsigned x)41 bool stdc_has_single_bit_ui(unsigned x) { return false; }
stdc_has_single_bit_ul(unsigned long x)42 bool stdc_has_single_bit_ul(unsigned long x) { return false; }
stdc_has_single_bit_ull(unsigned long long x)43 bool stdc_has_single_bit_ull(unsigned long long x) { return false; }
44 
45 STDBIT_STUB_FUNCTION(stdc_bit_width, 0x4)
46 
stdc_bit_floor_uc(unsigned char x)47 unsigned char stdc_bit_floor_uc(unsigned char x) { return 0x5AU; }
stdc_bit_floor_us(unsigned short x)48 unsigned short stdc_bit_floor_us(unsigned short x) { return 0x5BU; }
stdc_bit_floor_ui(unsigned x)49 unsigned stdc_bit_floor_ui(unsigned x) { return 0x5CU; }
stdc_bit_floor_ul(unsigned long x)50 unsigned long stdc_bit_floor_ul(unsigned long x) { return 0x5DUL; }
stdc_bit_floor_ull(unsigned long long x)51 unsigned long long stdc_bit_floor_ull(unsigned long long x) { return 0x5EULL; }
52 
stdc_bit_ceil_uc(unsigned char x)53 unsigned char stdc_bit_ceil_uc(unsigned char x) { return 0x6AU; }
stdc_bit_ceil_us(unsigned short x)54 unsigned short stdc_bit_ceil_us(unsigned short x) { return 0x6BU; }
stdc_bit_ceil_ui(unsigned x)55 unsigned stdc_bit_ceil_ui(unsigned x) { return 0x6CU; }
stdc_bit_ceil_ul(unsigned long x)56 unsigned long stdc_bit_ceil_ul(unsigned long x) { return 0x6DUL; }
stdc_bit_ceil_ull(unsigned long long x)57 unsigned long long stdc_bit_ceil_ull(unsigned long long x) { return 0x6EULL; }
58 
59 __END_C_DECLS
60