blob: 5b28da089aebb1e64017f82b0b82c2aa799a23d5 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- absvsi2.c - Implement __absvsi2 -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements __absvsi2 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15#include <stdlib.h>
16
17// Returns: absolute value
18
19// Effects: aborts if abs(x) < 0
20
21si_int
22__absvsi2(si_int a)
23{
24 const int N = (int)(sizeof(si_int) * CHAR_BIT);
25 if (a == (1 << (N-1)))
26 abort();
27 const si_int t = a >> (N - 1);
28 return (a ^ t) - t;
29}