2009-08-07 20:30:09 +00:00
|
|
|
//===-- absvdi2.c - Implement __absvdi2 -----------------------------------===//
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
// This file implements __absvdi2 for the compiler_rt library.
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-26 16:47:03 +00:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
// Returns: absolute value
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
// Effects: aborts if abs(x) < 0
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2011-04-19 17:52:09 +00:00
|
|
|
COMPILER_RT_ABI di_int __absvdi2(di_int a) {
|
2009-06-26 16:47:03 +00:00
|
|
|
const int N = (int)(sizeof(di_int) * CHAR_BIT);
|
2023-04-14 07:44:44 +02:00
|
|
|
if (a == ((di_int)((du_int)1 << (N - 1))))
|
2010-03-31 17:00:45 +00:00
|
|
|
compilerrt_abort();
|
2009-06-26 16:47:03 +00:00
|
|
|
const di_int t = a >> (N - 1);
|
|
|
|
return (a ^ t) - t;
|
|
|
|
}
|