blob: c0869719d3f3e3b4ee53a3cc5e8af7e6dc812984 [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- absvti2.c - Implement __absvdi2 -----------------------------------===//
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 __absvti2 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#if __x86_64
15
16#include "int_lib.h"
17#include <stdlib.h>
18
19// Returns: absolute value
20
21// Effects: aborts if abs(x) < 0
22
23ti_int
24__absvti2(ti_int a)
25{
26 const int N = (int)(sizeof(ti_int) * CHAR_BIT);
27 if (a == ((ti_int)1 << (N-1)))
28 abort();
29 const ti_int s = a >> (N - 1);
30 return (a ^ s) - s;
31}
32
33#endif