xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/builtins/int_util.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===-- int_util.h - internal utility functions ---------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file is not part of the interface of this library.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric // This file defines non-inline utilities which are available for use in the
120b57cec5SDimitry Andric // library. The function definitions themselves are all contained in int_util.c
130b57cec5SDimitry Andric // which will always be compiled into any compiler-rt library.
140b57cec5SDimitry Andric //
150b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #ifndef INT_UTIL_H
180b57cec5SDimitry Andric #define INT_UTIL_H
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric /// \brief Trigger a program abort (or panic for kernel code).
210b57cec5SDimitry Andric #define compilerrt_abort() __compilerrt_abort_impl(__FILE__, __LINE__, __func__)
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric NORETURN void __compilerrt_abort_impl(const char *file, int line,
240b57cec5SDimitry Andric                                       const char *function);
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric #define COMPILE_TIME_ASSERT(expr) COMPILE_TIME_ASSERT1(expr, __COUNTER__)
270b57cec5SDimitry Andric #define COMPILE_TIME_ASSERT1(expr, cnt) COMPILE_TIME_ASSERT2(expr, cnt)
280b57cec5SDimitry Andric #define COMPILE_TIME_ASSERT2(expr, cnt)                                        \
290b57cec5SDimitry Andric   typedef char ct_assert_##cnt[(expr) ? 1 : -1] UNUSED
300b57cec5SDimitry Andric 
31*e8d8bef9SDimitry Andric // Force unrolling the code specified to be repeated N times.
32*e8d8bef9SDimitry Andric #define REPEAT_0_TIMES(code_to_repeat) /* do nothing */
33*e8d8bef9SDimitry Andric #define REPEAT_1_TIMES(code_to_repeat) code_to_repeat
34*e8d8bef9SDimitry Andric #define REPEAT_2_TIMES(code_to_repeat)                                         \
35*e8d8bef9SDimitry Andric   REPEAT_1_TIMES(code_to_repeat)                                               \
36*e8d8bef9SDimitry Andric   code_to_repeat
37*e8d8bef9SDimitry Andric #define REPEAT_3_TIMES(code_to_repeat)                                         \
38*e8d8bef9SDimitry Andric   REPEAT_2_TIMES(code_to_repeat)                                               \
39*e8d8bef9SDimitry Andric   code_to_repeat
40*e8d8bef9SDimitry Andric #define REPEAT_4_TIMES(code_to_repeat)                                         \
41*e8d8bef9SDimitry Andric   REPEAT_3_TIMES(code_to_repeat)                                               \
42*e8d8bef9SDimitry Andric   code_to_repeat
43*e8d8bef9SDimitry Andric 
44*e8d8bef9SDimitry Andric #define REPEAT_N_TIMES_(N, code_to_repeat) REPEAT_##N##_TIMES(code_to_repeat)
45*e8d8bef9SDimitry Andric #define REPEAT_N_TIMES(N, code_to_repeat) REPEAT_N_TIMES_(N, code_to_repeat)
46*e8d8bef9SDimitry Andric 
470b57cec5SDimitry Andric #endif // INT_UTIL_H
48