1214152Sed/* ===-- absvsi2.c - Implement __absvsi2 -----------------------------------===
2214152Sed *
3214152Sed *                     The LLVM Compiler Infrastructure
4214152Sed *
5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open
6222656Sed * Source Licenses. See LICENSE.TXT for details.
7214152Sed *
8214152Sed * ===----------------------------------------------------------------------===
9214152Sed *
10214152Sed * This file implements __absvsi2 for the compiler_rt library.
11214152Sed *
12214152Sed * ===----------------------------------------------------------------------===
13222656Sed */
14214152Sed
15214152Sed#include "int_lib.h"
16214152Sed
17214152Sed/* Returns: absolute value */
18214152Sed
19214152Sed/* Effects: aborts if abs(x) < 0 */
20214152Sed
21222656SedCOMPILER_RT_ABI si_int
22214152Sed__absvsi2(si_int a)
23214152Sed{
24214152Sed    const int N = (int)(sizeof(si_int) * CHAR_BIT);
25214152Sed    if (a == (1 << (N-1)))
26214152Sed        compilerrt_abort();
27214152Sed    const si_int t = a >> (N - 1);
28214152Sed    return (a ^ t) - t;
29214152Sed}
30