llvm-project
61 строка · 2.4 Кб
1//===-- Unittests for 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* The intent of this test is validate that:
11* 1. We provide the definition of the various type generic macros of stdbit.h
12* (the macros are transitively included from stdbit-macros.h by stdbit.h).
13* 2. It dispatches to the correct underlying function.
14* Because unit tests build without public packaging, the object files produced
15* do not contain non-namespaced symbols.
16*/
17
18/*
19* Declare these BEFORE including stdbit-macros.h so that this test may still be
20* run even if a given target doesn't yet have these individual entrypoints
21* enabled.
22*/
23#include "stdbit_stub.h"24
25#include "include/llvm-libc-macros/stdbit-macros.h"26
27#include <assert.h>28
29#define CHECK_FUNCTION(FUNC_NAME, VAL) \30do { \31assert(FUNC_NAME((unsigned char)0U) == VAL##AU); \32assert(FUNC_NAME((unsigned short)0U) == VAL##BU); \33assert(FUNC_NAME(0U) == VAL##CU); \34assert(FUNC_NAME(0UL) == VAL##DU); \35assert(FUNC_NAME(0ULL) == VAL##EU); \36} while (0)37
38int main(void) {39CHECK_FUNCTION(stdc_leading_zeros, 0xA);40CHECK_FUNCTION(stdc_leading_ones, 0xB);41CHECK_FUNCTION(stdc_trailing_zeros, 0xC);42CHECK_FUNCTION(stdc_trailing_ones, 0xD);43CHECK_FUNCTION(stdc_first_leading_zero, 0xE);44CHECK_FUNCTION(stdc_first_leading_one, 0xF);45CHECK_FUNCTION(stdc_first_trailing_zero, 0x0);46CHECK_FUNCTION(stdc_first_trailing_one, 0x1);47CHECK_FUNCTION(stdc_count_zeros, 0x2);48CHECK_FUNCTION(stdc_count_ones, 0x3);49
50assert(!stdc_has_single_bit((unsigned char)1U));51assert(!stdc_has_single_bit((unsigned short)1U));52assert(!stdc_has_single_bit(1U));53assert(!stdc_has_single_bit(1UL));54assert(!stdc_has_single_bit(1ULL));55
56CHECK_FUNCTION(stdc_bit_width, 0x4);57CHECK_FUNCTION(stdc_bit_floor, 0x5);58CHECK_FUNCTION(stdc_bit_ceil, 0x6);59
60return 0;61}
62