1156cd587Sjoerg /* ===-- absvti2.c - Implement __absvdi2 -----------------------------------=== 2156cd587Sjoerg * 3156cd587Sjoerg * The LLVM Compiler Infrastructure 4156cd587Sjoerg * 5156cd587Sjoerg * This file is dual licensed under the MIT and the University of Illinois Open 6156cd587Sjoerg * Source Licenses. See LICENSE.TXT for details. 7156cd587Sjoerg * 8156cd587Sjoerg * ===----------------------------------------------------------------------=== 9156cd587Sjoerg * 10156cd587Sjoerg * This file implements __absvti2 for the compiler_rt library. 11156cd587Sjoerg * 12156cd587Sjoerg * ===----------------------------------------------------------------------=== 13156cd587Sjoerg */ 14156cd587Sjoerg 15156cd587Sjoerg #include "int_lib.h" 16156cd587Sjoerg 17156cd587Sjoerg #ifdef CRT_HAS_128BIT 18156cd587Sjoerg 19156cd587Sjoerg /* Returns: absolute value */ 20156cd587Sjoerg 21156cd587Sjoerg /* Effects: aborts if abs(x) < 0 */ 22156cd587Sjoerg 23*f7f78b33Sjoerg COMPILER_RT_ABI ti_int __absvti2(ti_int a)24156cd587Sjoerg__absvti2(ti_int a) 25156cd587Sjoerg { 26156cd587Sjoerg const int N = (int)(sizeof(ti_int) * CHAR_BIT); 27156cd587Sjoerg if (a == ((ti_int)1 << (N-1))) 28156cd587Sjoerg compilerrt_abort(); 29156cd587Sjoerg const ti_int s = a >> (N - 1); 30156cd587Sjoerg return (a ^ s) - s; 31156cd587Sjoerg } 32156cd587Sjoerg 33156cd587Sjoerg #endif /* CRT_HAS_128BIT */ 34156cd587Sjoerg 35