xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/builtins/negvti2.c (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===-- negvti2.c - Implement __negvti2 -----------------------------------===//
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 implements __negvti2 for the compiler_rt library.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "int_lib.h"
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #ifdef CRT_HAS_128BIT
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric // Returns: -a
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric // Effects: aborts if -a overflows
200b57cec5SDimitry Andric 
__negvti2(ti_int a)210b57cec5SDimitry Andric COMPILER_RT_ABI ti_int __negvti2(ti_int a) {
22*5f757f3fSDimitry Andric   const ti_int MIN = (tu_int)1 << ((int)(sizeof(ti_int) * CHAR_BIT) - 1);
230b57cec5SDimitry Andric   if (a == MIN)
240b57cec5SDimitry Andric     compilerrt_abort();
250b57cec5SDimitry Andric   return -a;
260b57cec5SDimitry Andric }
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric #endif // CRT_HAS_128BIT
29