Code style and Readability fixes. Credit to Craig van Vliet.

llvm-svn: 78403
This commit is contained in:
Edward O'Callaghan 2009-08-07 20:30:09 +00:00
parent 40134e71be
commit 5583632adf
55 changed files with 1248 additions and 1137 deletions

View File

@ -8,6 +8,11 @@ beautification by scripts. The fields are: name (N), email (E), web-address
(W), PGP key ID and fingerprint (P), description (D), and snail-mail address
(S).
N: Craig van Vliet
E: cvanvliet@auroraux.org
W: http://www.auroraux.org
D: Code style and Readability fixes.
N: Edward O'Callaghan
E: eocallaghan@auroraux.org
W: http://www.auroraux.org

View File

@ -1,22 +1,23 @@
//===-- absvdi2.c - Implement __absvdi2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __absvdi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- absvdi2.c - Implement __absvdi2 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
*===----------------------------------------------------------------------===
*
* This file implements __absvdi2 for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <stdlib.h>
// Returns: absolute value
/* Returns: absolute value */
// Effects: aborts if abs(x) < 0
/* Effects: aborts if abs(x) < 0 */
di_int
__absvdi2(di_int a)

View File

@ -1,22 +1,23 @@
//===-- absvsi2.c - Implement __absvsi2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __absvsi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- absvsi2.c - Implement __absvsi2 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __absvsi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <stdlib.h>
// Returns: absolute value
/* Returns: absolute value */
// Effects: aborts if abs(x) < 0
/* Effects: aborts if abs(x) < 0 */
si_int
__absvsi2(si_int a)

View File

@ -1,24 +1,25 @@
//===-- absvti2.c - Implement __absvdi2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __absvti2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- absvti2.c - Implement __absvdi2 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __absvti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
#include <stdlib.h>
// Returns: absolute value
/* Returns: absolute value */
// Effects: aborts if abs(x) < 0
/* Effects: aborts if abs(x) < 0 */
ti_int
__absvti2(ti_int a)

View File

@ -1,22 +1,23 @@
//===-- addvdi3.c - Implement __addvdi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __addvdi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- addvdi3.c - Implement __addvdi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __addvdi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <stdlib.h>
// Returns: a + b
/* Returns: a + b */
// Effects: aborts if a + b overflows
/* Effects: aborts if a + b overflows */
di_int
__addvdi3(di_int a, di_int b)

View File

@ -1,22 +1,23 @@
//===-- addvsi3.c - Implement __addvsi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __addvsi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- addvsi3.c - Implement __addvsi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __addvsi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <stdlib.h>
// Returns: a + b
/* Returns: a + b */
// Effects: aborts if a + b overflows
/* Effects: aborts if a + b overflows */
si_int
__addvsi3(si_int a, si_int b)

View File

@ -1,12 +1,12 @@
//===-- apple_versioning.c - Adds versioning symbols for ld ---------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/* ===-- apple_versioning.c - Adds versioning symbols for ld ---------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
@ -28,10 +28,9 @@
#endif
//
// Symbols in libSystem.dylib in 10.6 and later,
// but are in libgcc_s.dylib in earlier versions
//
/* Symbols in libSystem.dylib in 10.6 and later,
* but are in libgcc_s.dylib in earlier versions
*/
NOT_HERE_BEFORE_10_6(__absvdi2)
NOT_HERE_BEFORE_10_6(__absvsi2)
NOT_HERE_BEFORE_10_6(__absvti2)
@ -142,5 +141,5 @@ NOT_HERE_BEFORE_10_6(__trampoline_setup)
#endif
#endif // __APPLE__
#endif /* __APPLE__*/

View File

@ -1,21 +1,22 @@
//===-- ashldi3.c - Implement __ashldi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __ashldi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ====-- ashldi3.c - Implement __ashldi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ashldi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: a << b
/* Returns: a << b */
// Precondition: 0 <= b < bits_in_dword
/* Precondition: 0 <= b < bits_in_dword */
di_int
__ashldi3(di_int a, si_int b)
@ -24,12 +25,12 @@ __ashldi3(di_int a, si_int b)
dwords input;
dwords result;
input.all = a;
if (b & bits_in_word) // bits_in_word <= b < bits_in_dword
if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
{
result.low = 0;
result.high = input.low << (b - bits_in_word);
}
else // 0 <= b < bits_in_word
else /* 0 <= b < bits_in_word */
{
if (b == 0)
return a;

View File

@ -1,23 +1,24 @@
//===-- ashlti3.c - Implement __ashlti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __ashlti3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- ashlti3.c - Implement __ashlti3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ashlti3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
// Returns: a << b
/* Returns: a << b */
// Precondition: 0 <= b < bits_in_tword
/* Precondition: 0 <= b < bits_in_tword */
ti_int
__ashlti3(ti_int a, si_int b)
@ -26,12 +27,12 @@ __ashlti3(ti_int a, si_int b)
twords input;
twords result;
input.all = a;
if (b & bits_in_dword) // bits_in_dword <= b < bits_in_tword
if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */
{
result.low = 0;
result.high = input.low << (b - bits_in_dword);
}
else // 0 <= b < bits_in_dword
else /* 0 <= b < bits_in_dword */
{
if (b == 0)
return a;
@ -41,4 +42,4 @@ __ashlti3(ti_int a, si_int b)
return result.all;
}
#endif
#endif /* __x86_64 */

View File

@ -1,21 +1,22 @@
//===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __ashrdi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ashrdi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: arithmetic a >> b
/* Returns: arithmetic a >> b */
// Precondition: 0 <= b < bits_in_dword
/* Precondition: 0 <= b < bits_in_dword */
di_int
__ashrdi3(di_int a, si_int b)
@ -24,13 +25,13 @@ __ashrdi3(di_int a, si_int b)
dwords input;
dwords result;
input.all = a;
if (b & bits_in_word) // bits_in_word <= b < bits_in_dword
if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
{
// result.high = input.high < 0 ? -1 : 0
/* result.high = input.high < 0 ? -1 : 0 */
result.high = input.high >> (bits_in_word - 1);
result.low = input.high >> (b - bits_in_word);
}
else // 0 <= b < bits_in_word
else /* 0 <= b < bits_in_word */
{
if (b == 0)
return a;

View File

@ -1,21 +1,23 @@
//===-- cmpdi2.c - Implement __cmpdi2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __cmpdi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- cmpdi2.c - Implement __cmpdi2 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __cmpdi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: if (a < b) returns 0
// if (a == b) returns 1
// if (a > b) returns 2
/* Returns: if (a < b) returns 0
* if (a == b) returns 1
* if (a > b) returns 2
*/
si_int
__cmpdi2(di_int a, di_int b)

View File

@ -1,23 +1,25 @@
//===-- cmpti2.c - Implement __cmpti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __cmpti2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- cmpti2.c - Implement __cmpti2 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __cmpti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
// Returns: if (a < b) returns 0
// if (a == b) returns 1
// if (a > b) returns 2
/* Returns: if (a < b) returns 0
* if (a == b) returns 1
* if (a > b) returns 2
*/
si_int
__cmpti2(ti_int a, ti_int b)

View File

@ -1,21 +1,22 @@
//===-- ctzdi2.c - Implement __ctzdi2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __ctzdi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- ctzdi2.c - Implement __ctzdi2 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ctzdi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: the number of trailing 0-bits
/* Returns: the number of trailing 0-bits */
// Precondition: a != 0
/* Precondition: a != 0 */
si_int
__ctzdi2(di_int a)

View File

@ -1,54 +1,57 @@
//===-- ctzsi2.c - Implement __ctzsi2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __ctzsi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- ctzsi2.c - Implement __ctzsi2 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ctzsi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: the number of trailing 0-bits
/* Returns: the number of trailing 0-bits */
// Precondition: a != 0
/* Precondition: a != 0 */
si_int
__ctzsi2(si_int a)
{
su_int x = (su_int)a;
si_int t = ((x & 0x0000FFFF) == 0) << 4; // if (x has no small bits) t = 16 else 0
x >>= t; // x = [0 - 0xFFFF] + higher garbage bits
su_int r = t; // r = [0, 16]
// return r + ctz(x)
si_int t = ((x & 0x0000FFFF) == 0) << 4; /* if (x has no small bits) t = 16 else 0 */
x >>= t; /* x = [0 - 0xFFFF] + higher garbage bits */
su_int r = t; /* r = [0, 16] */
/* return r + ctz(x) */
t = ((x & 0x00FF) == 0) << 3;
x >>= t; // x = [0 - 0xFF] + higher garbage bits
r += t; // r = [0, 8, 16, 24]
// return r + ctz(x)
x >>= t; /* x = [0 - 0xFF] + higher garbage bits */
r += t; /* r = [0, 8, 16, 24] */
/* return r + ctz(x) */
t = ((x & 0x0F) == 0) << 2;
x >>= t; // x = [0 - 0xF] + higher garbage bits
r += t; // r = [0, 4, 8, 12, 16, 20, 24, 28]
// return r + ctz(x)
x >>= t; /* x = [0 - 0xF] + higher garbage bits */
r += t; /* r = [0, 4, 8, 12, 16, 20, 24, 28] */
/* return r + ctz(x) */
t = ((x & 0x3) == 0) << 1;
x >>= t;
x &= 3; // x = [0 - 3]
r += t; // r = [0 - 30] and is even
// return r + ctz(x)
// The branch-less return statement below is equivalent
// to the following switch statement:
// switch (x)
// {
// case 0:
// return r + 2;
// case 2:
// return r + 1;
// case 1:
// case 3:
// return r;
// }
x &= 3; /* x = [0 - 3] */
r += t; /* r = [0 - 30] and is even */
/* return r + ctz(x) */
/* The branch-less return statement below is equivalent
* to the following switch statement:
* switch (x)
* {
* case 0:
* return r + 2;
* case 2:
* return r + 1;
* case 1:
* case 3:
* return r;
* }
*/
return r + ((2 - (x >> 1)) & -((x & 1) == 0));
}

View File

@ -1,21 +1,22 @@
//===-- divdc3.c - Implement __divdc3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __divdc3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- divdc3.c - Implement __divdc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divdc3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <math.h>
#include <complex.h>
// Returns: the quotient of (a + ib) / (c + id)
/* Returns: the quotient of (a + ib) / (c + id) */
double _Complex
__divdc3(double __a, double __b, double __c, double __d)

View File

@ -1,30 +1,31 @@
//===-- divdi3.c - Implement __divdi3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __divdi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- divdi3.c - Implement __divdi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divdi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
// Returns: a / b
/* Returns: a / b */
di_int
__divdi3(di_int a, di_int b)
{
const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;
di_int s_a = a >> bits_in_dword_m1; // s_a = a < 0 ? -1 : 0
di_int s_b = b >> bits_in_dword_m1; // s_b = b < 0 ? -1 : 0
a = (a ^ s_a) - s_a; // negate if s_a == -1
b = (b ^ s_b) - s_b; // negate if s_b == -1
s_a ^= s_b; // sign of quotient
return (__udivmoddi4(a, b, (du_int*)0) ^ s_a) - s_a; // negate if s_a == -1
di_int s_a = a >> bits_in_dword_m1; /* s_a = a < 0 ? -1 : 0 */
di_int s_b = b >> bits_in_dword_m1; /* s_b = b < 0 ? -1 : 0 */
a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
s_a ^= s_b; /*sign of quotient */
return (__udivmoddi4(a, b, (du_int*)0) ^ s_a) - s_a; /* negate if s_a == -1 */
}

View File

@ -1,21 +1,22 @@
//===-- divsc3.c - Implement __divsc3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __divsc3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- divsc3.c - Implement __divsc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divsc3 for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <math.h>
#include <complex.h>
// Returns: the quotient of (a + ib) / (c + id)
/* Returns: the quotient of (a + ib) / (c + id) */
float _Complex
__divsc3(float __a, float __b, float __c, float __d)

View File

@ -1,30 +1,31 @@
//===-- divsi3.c - Implement __divsi3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __divsi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- divsi3.c - Implement __divsi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divsi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
su_int __udivsi3(su_int n, su_int d);
// Returns: a / b
/* Returns: a / b */
si_int
__divsi3(si_int a, si_int b)
{
const int bits_in_word_m1 = (int)(sizeof(si_int) * CHAR_BIT) - 1;
si_int s_a = a >> bits_in_word_m1; // s_a = a < 0 ? -1 : 0
si_int s_b = b >> bits_in_word_m1; // s_b = b < 0 ? -1 : 0
a = (a ^ s_a) - s_a; // negate if s_a == -1
b = (b ^ s_b) - s_b; // negate if s_b == -1
s_a ^= s_b; // sign of quotient
return (__udivsi3(a, b) ^ s_a) - s_a; // negate if s_a == -1
si_int s_a = a >> bits_in_word_m1; /* s_a = a < 0 ? -1 : 0 */
si_int s_b = b >> bits_in_word_m1; /* s_b = b < 0 ? -1 : 0 */
a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
s_a ^= s_b; /* sign of quotient */
return (__udivsi3(a, b) ^ s_a) - s_a; /* negate if s_a == -1 */
}

View File

@ -1,15 +1,15 @@
//===-- divxc3.c - Implement __divxc3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __divxc3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- divxc3.c - Implement __divxc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divxc3 for the compiler_rt library.
*
*/
#if !_ARCH_PPC
@ -17,7 +17,7 @@
#include <math.h>
#include <complex.h>
// Returns: the quotient of (a + ib) / (c + id)
/* Returns: the quotient of (a + ib) / (c + id) */
long double _Complex
__divxc3(long double __a, long double __b, long double __c, long double __d)

View File

@ -1,25 +1,27 @@
//===-- fixdfdi.c - Implement __fixdfdi -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __fixdfdi for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- fixdfdi.c - Implement __fixdfdi -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __fixdfdi for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: convert a to a signed long long, rounding toward zero.
/* Returns: convert a to a signed long long, rounding toward zero. */
// Assumption: double is a IEEE 64 bit floating point type
// su_int is a 32 bit integral type
// value in double is representable in di_int (no range checking performed)
/* Assumption: double is a IEEE 64 bit floating point type
* su_int is a 32 bit integral type
* value in double is representable in di_int (no range checking performed)
*/
// seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
di_int
__fixdfdi(double a)
@ -38,4 +40,4 @@ __fixdfdi(double a)
else
r.all >>= (52 - e);
return (r.all ^ s) - s;
}
}

View File

@ -1,27 +1,29 @@
//===-- fixdfti.c - Implement __fixdfti -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __fixdfti for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- fixdfti.c - Implement __fixdfti -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __fixdfti for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
// Returns: convert a to a signed long long, rounding toward zero.
/* Returns: convert a to a signed long long, rounding toward zero. */
// Assumption: double is a IEEE 64 bit floating point type
// su_int is a 32 bit integral type
// value in double is representable in ti_int (no range checking performed)
/* Assumption: double is a IEEE 64 bit floating point type
* su_int is a 32 bit integral type
* value in double is representable in ti_int (no range checking performed)
*/
// seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
ti_int
__fixdfti(double a)

View File

@ -1,25 +1,27 @@
//===-- fixsfdi.c - Implement __fixsfdi -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __fixsfdi for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- fixsfdi.c - Implement __fixsfdi -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __fixsfdi for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: convert a to a signed long long, rounding toward zero.
/* Returns: convert a to a signed long long, rounding toward zero. */
// Assumption: float is a IEEE 32 bit floating point type
// su_int is a 32 bit integral type
// value in float is representable in di_int (no range checking performed)
/* Assumption: float is a IEEE 32 bit floating point type
* su_int is a 32 bit integral type
* value in float is representable in di_int (no range checking performed)
*/
// seee eeee emmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
di_int
__fixsfdi(float a)

View File

@ -26,7 +26,7 @@
* (no range checking performed)
*/
// seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
tu_int
__fixunssfti(float a)

View File

@ -1,29 +1,32 @@
//===-- floatdidf.c - Implement __floatdidf -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floatdidf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- floatdidf.c - Implement __floatdidf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
*===----------------------------------------------------------------------===
*
* This file implements __floatdidf for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <float.h>
// Returns: convert a to a double, rounding toward even.
/* Returns: convert a to a double, rounding toward even. */
// Assumption: double is a IEEE 64 bit floating point type
// di_int is a 64 bit integral type
/* Assumption: double is a IEEE 64 bit floating point type
* di_int is a 64 bit integral type
*/
// seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
#ifndef __SOFT_FP__
// Support for systems that have hardware floating-point; we'll set the inexact flag
// as a side-effect of this computation.
/* Support for systems that have hardware floating-point; we'll set the inexact flag
* as a side-effect of this computation.
*/
#include <stdint.h>
double
@ -42,8 +45,9 @@ __floatdidf(di_int a)
}
#else
// Support for systems that don't have hardware floating-point; there are no flags to
// set, and we don't want to code-gen to an unknown soft-float implementation.
/* Support for systems that don't have hardware floating-point; there are no flags to
* set, and we don't want to code-gen to an unknown soft-float implementation.
*/
double
__floatdidf(di_int a)
@ -53,17 +57,18 @@ __floatdidf(di_int a)
const unsigned N = sizeof(di_int) * CHAR_BIT;
const di_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __builtin_clzll(a); // number of significant digits
int e = sd - 1; // exponent
int sd = N - __builtin_clzll(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > DBL_MANT_DIG)
{
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
// 12345678901234567890123456
// 1 = msb 1 bit
// P = bit DBL_MANT_DIG-1 bits to the right of 1
// Q = bit DBL_MANT_DIG bits to the right of 1
// R = "or" of all bits to the right of Q
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit DBL_MANT_DIG-1 bits to the right of 1
* Q = bit DBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case DBL_MANT_DIG + 1:
@ -75,28 +80,28 @@ __floatdidf(di_int a)
a = ((du_int)a >> (sd - (DBL_MANT_DIG+2))) |
((a & ((du_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
};
// finish:
a |= (a & 4) != 0; // Or P into R
++a; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
if (a & ((du_int)1 << DBL_MANT_DIG))
{
a >>= 1;
++e;
}
// a is now rounded to DBL_MANT_DIG bits
/* a is now rounded to DBL_MANT_DIG bits */
}
else
{
a <<= (DBL_MANT_DIG - sd);
// a is now rounded to DBL_MANT_DIG bits
/* a is now rounded to DBL_MANT_DIG bits */
}
double_bits fb;
fb.u.high = ((su_int)s & 0x80000000) | // sign
((e + 1023) << 20) | // exponent
((su_int)(a >> 32) & 0x000FFFFF); // mantissa-high
fb.u.low = (su_int)a; // mantissa-low
fb.u.high = ((su_int)s & 0x80000000) | /* sign */
((e + 1023) << 20) | /* exponent */
((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
fb.u.low = (su_int)a; /* mantissa-low */
return fb.f;
}
#endif

View File

@ -1,25 +1,27 @@
//===-- floatdisf.c - Implement __floatdisf -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floatdisf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- floatdisf.c - Implement __floatdisf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
*===----------------------------------------------------------------------===
*
* This file implements __floatdisf for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <float.h>
// Returns: convert a to a float, rounding toward even.
/* Returns: convert a to a float, rounding toward even.*/
// Assumption: float is a IEEE 32 bit floating point type
// di_int is a 64 bit integral type
/* Assumption: float is a IEEE 32 bit floating point type
* di_int is a 64 bit integral type
*/
// seee eeee emmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
float
__floatdisf(di_int a)
@ -29,17 +31,18 @@ __floatdisf(di_int a)
const unsigned N = sizeof(di_int) * CHAR_BIT;
const di_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __builtin_clzll(a); // number of significant digits
int e = sd - 1; // exponent
int sd = N - __builtin_clzll(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > FLT_MANT_DIG)
{
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
// 12345678901234567890123456
// 1 = msb 1 bit
// P = bit FLT_MANT_DIG-1 bits to the right of 1
// Q = bit FLT_MANT_DIG bits to the right of 1
// R = "or" of all bits to the right of Q
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit FLT_MANT_DIG-1 bits to the right of 1
* Q = bit FLT_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case FLT_MANT_DIG + 1:
@ -51,26 +54,26 @@ __floatdisf(di_int a)
a = ((du_int)a >> (sd - (FLT_MANT_DIG+2))) |
((a & ((du_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
};
// finish:
a |= (a & 4) != 0; // Or P into R
++a; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
if (a & ((du_int)1 << FLT_MANT_DIG))
{
a >>= 1;
++e;
}
// a is now rounded to FLT_MANT_DIG bits
/* a is now rounded to FLT_MANT_DIG bits */
}
else
{
a <<= (FLT_MANT_DIG - sd);
// a is now rounded to FLT_MANT_DIG bits
/* a is now rounded to FLT_MANT_DIG bits */
}
float_bits fb;
fb.u = ((su_int)s & 0x80000000) | // sign
((e + 127) << 23) | // exponent
((su_int)a & 0x007FFFFF); // mantissa
fb.u = ((su_int)s & 0x80000000) | /* sign */
((e + 127) << 23) | /* exponent */
((su_int)a & 0x007FFFFF); /* mantissa */
return fb.f;
}

View File

@ -1,27 +1,30 @@
//===-- floatdixf.c - Implement __floatdixf -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floatdixf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- floatdixf.c - Implement __floatdixf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatdixf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if !_ARCH_PPC
#include "int_lib.h"
// Returns: convert a to a long double, rounding toward even.
/* Returns: convert a to a long double, rounding toward even. */
// Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
// di_int is a 64 bit integral type
/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
* di_int is a 64 bit integral type
*/
// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
*/
long double
__floatdixf(di_int a)
@ -32,11 +35,11 @@ __floatdixf(di_int a)
const di_int s = a >> (N-1);
a = (a ^ s) - s;
int clz = __builtin_clzll(a);
int e = (N - 1) - clz ; // exponent
int e = (N - 1) - clz ; /* exponent */
long_double_bits fb;
fb.u.high.low = ((su_int)s & 0x00008000) | // sign
(e + 16383); // exponent
fb.u.low.all = a << clz; // mantissa
fb.u.high.low = ((su_int)s & 0x00008000) | /* sign */
(e + 16383); /* exponent */
fb.u.low.all = a << clz; /* mantissa */
return fb.f;
}

View File

@ -1,27 +1,29 @@
//===-- floattidf.c - Implement __floattidf -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floattidf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- floattidf.c - Implement __floattidf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floattidf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
#include <float.h>
// Returns: convert a to a double, rounding toward even.
/* Returns: convert a to a double, rounding toward even.*/
// Assumption: double is a IEEE 64 bit floating point type
// ti_int is a 128 bit integral type
/* Assumption: double is a IEEE 64 bit floating point type
* ti_int is a 128 bit integral type
*/
// seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
si_int __clzti2(ti_int a);
@ -33,17 +35,18 @@ __floattidf(ti_int a)
const unsigned N = sizeof(ti_int) * CHAR_BIT;
const ti_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __clzti2(a); // number of significant digits
int e = sd - 1; // exponent
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > DBL_MANT_DIG)
{
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
// 12345678901234567890123456
// 1 = msb 1 bit
// P = bit DBL_MANT_DIG-1 bits to the right of 1
// Q = bit DBL_MANT_DIG bits to the right of 1
// R = "or" of all bits to the right of Q
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit DBL_MANT_DIG-1 bits to the right of 1
* Q = bit DBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case DBL_MANT_DIG + 1:
@ -55,28 +58,28 @@ __floattidf(ti_int a)
a = ((tu_int)a >> (sd - (DBL_MANT_DIG+2))) |
((a & ((tu_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
};
// finish:
a |= (a & 4) != 0; // Or P into R
++a; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
if (a & ((tu_int)1 << DBL_MANT_DIG))
{
a >>= 1;
++e;
}
// a is now rounded to DBL_MANT_DIG bits
/* a is now rounded to DBL_MANT_DIG bits */
}
else
{
a <<= (DBL_MANT_DIG - sd);
// a is now rounded to DBL_MANT_DIG bits
/* a is now rounded to DBL_MANT_DIG bits */
}
double_bits fb;
fb.u.high = ((su_int)s & 0x80000000) | // sign
((e + 1023) << 20) | // exponent
((su_int)(a >> 32) & 0x000FFFFF); // mantissa-high
fb.u.low = (su_int)a; // mantissa-low
fb.u.high = ((su_int)s & 0x80000000) | /* sign */
((e + 1023) << 20) | /* exponent */
((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
fb.u.low = (su_int)a; /* mantissa-low */
return fb.f;
}

View File

@ -1,27 +1,29 @@
//===-- floattisf.c - Implement __floattisf -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floattisf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- floattisf.c - Implement __floattisf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floattisf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
#include <float.h>
// Returns: convert a to a float, rounding toward even.
/* Returns: convert a to a float, rounding toward even. */
// Assumption: float is a IEEE 32 bit floating point type
// ti_int is a 128 bit integral type
/* Assumption: float is a IEEE 32 bit floating point type
* ti_int is a 128 bit integral type
*/
// seee eeee emmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
si_int __clzti2(ti_int a);
@ -33,17 +35,18 @@ __floattisf(ti_int a)
const unsigned N = sizeof(ti_int) * CHAR_BIT;
const ti_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __clzti2(a); // number of significant digits
int e = sd - 1; // exponent
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > FLT_MANT_DIG)
{
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
// 12345678901234567890123456
// 1 = msb 1 bit
// P = bit FLT_MANT_DIG-1 bits to the right of 1
// Q = bit FLT_MANT_DIG bits to the right of 1
// R = "or" of all bits to the right of Q
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit FLT_MANT_DIG-1 bits to the right of 1
* Q = bit FLT_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case FLT_MANT_DIG + 1:
@ -55,27 +58,27 @@ __floattisf(ti_int a)
a = ((tu_int)a >> (sd - (FLT_MANT_DIG+2))) |
((a & ((tu_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
};
// finish:
a |= (a & 4) != 0; // Or P into R
++a; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
if (a & ((tu_int)1 << FLT_MANT_DIG))
{
a >>= 1;
++e;
}
// a is now rounded to FLT_MANT_DIG bits
/* a is now rounded to FLT_MANT_DIG bits */
}
else
{
a <<= (FLT_MANT_DIG - sd);
// a is now rounded to FLT_MANT_DIG bits
/* a is now rounded to FLT_MANT_DIG bits */
}
float_bits fb;
fb.u = ((su_int)s & 0x80000000) | // sign
((e + 127) << 23) | // exponent
((su_int)a & 0x007FFFFF); // mantissa
fb.u = ((su_int)s & 0x80000000) | /* sign */
((e + 127) << 23) | /* exponent */
((su_int)a & 0x007FFFFF); /* mantissa */
return fb.f;
}

View File

@ -37,8 +37,8 @@ __floattixf(ti_int a)
const unsigned N = sizeof(ti_int) * CHAR_BIT;
const ti_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __clzti2(a); // number of significant digits
int e = sd - 1; // exponent
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > LDBL_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
@ -48,7 +48,7 @@ __floattixf(ti_int a)
* P = bit LDBL_MANT_DIG-1 bits to the right of 1
* Q = bit LDBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
*/
switch (sd)
{
case LDBL_MANT_DIG + 1:

View File

@ -1,29 +1,33 @@
//===-- floatundidf.c - Implement __floatundidf ---------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floatundidf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- floatundidf.c - Implement __floatundidf ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatundidf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <float.h>
// Returns: convert a to a double, rounding toward even.
/* Returns: convert a to a double, rounding toward even. */
// Assumption: double is a IEEE 64 bit floating point type
// du_int is a 64 bit integral type
/* Assumption: double is a IEEE 64 bit floating point type
* du_int is a 64 bit integral type
*/
// seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
#ifndef __SOFT_FP__
// Support for systems that have hardware floating-point; we'll set the inexact flag
// as a side-effect of this computation.
/* Support for systems that have hardware floating-point; we'll set the inexact flag
* as a side-effect of this computation.
*/
#include <stdint.h>
double
@ -44,8 +48,9 @@ __floatundidf(du_int a)
}
#else
// Support for systems that don't have hardware floating-point; there are no flags to
// set, and we don't want to code-gen to an unknown soft-float implementation.
/* Support for systems that don't have hardware floating-point; there are no flags to
* set, and we don't want to code-gen to an unknown soft-float implementation.
*/
double
__floatundidf(du_int a)
@ -53,17 +58,18 @@ __floatundidf(du_int a)
if (a == 0)
return 0.0;
const unsigned N = sizeof(du_int) * CHAR_BIT;
int sd = N - __builtin_clzll(a); // number of significant digits
int e = sd - 1; // exponent
int sd = N - __builtin_clzll(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > DBL_MANT_DIG)
{
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
// 12345678901234567890123456
// 1 = msb 1 bit
// P = bit DBL_MANT_DIG-1 bits to the right of 1
// Q = bit DBL_MANT_DIG bits to the right of 1
// R = "or" of all bits to the right of Q
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit DBL_MANT_DIG-1 bits to the right of 1
* Q = bit DBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case DBL_MANT_DIG + 1:
@ -75,27 +81,27 @@ __floatundidf(du_int a)
a = (a >> (sd - (DBL_MANT_DIG+2))) |
((a & ((du_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
};
// finish:
a |= (a & 4) != 0; // Or P into R
++a; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
if (a & ((du_int)1 << DBL_MANT_DIG))
{
a >>= 1;
++e;
}
// a is now rounded to DBL_MANT_DIG bits
/* a is now rounded to DBL_MANT_DIG bits */
}
else
{
a <<= (DBL_MANT_DIG - sd);
// a is now rounded to DBL_MANT_DIG bits
/* a is now rounded to DBL_MANT_DIG bits */
}
double_bits fb;
fb.u.high = ((e + 1023) << 20) | // exponent
((su_int)(a >> 32) & 0x000FFFFF); // mantissa-high
fb.u.low = (su_int)a; // mantissa-low
fb.u.high = ((e + 1023) << 20) | /* exponent */
((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
fb.u.low = (su_int)a; /* mantissa-low */
return fb.f;
}
#endif

View File

@ -1,25 +1,27 @@
//===-- floatundisf.c - Implement __floatundisf ---------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floatundisf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- floatundisf.c - Implement __floatundisf ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatundisf for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <float.h>
// Returns: convert a to a float, rounding toward even.
/* Returns: convert a to a float, rounding toward even. */
// Assumption: float is a IEEE 32 bit floating point type
// du_int is a 64 bit integral type
/* Assumption: float is a IEEE 32 bit floating point type
* du_int is a 64 bit integral type
*/
// seee eeee emmm mmmm mmmm mmmm mmmm mmmm
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
float
__floatundisf(du_int a)
@ -27,17 +29,18 @@ __floatundisf(du_int a)
if (a == 0)
return 0.0F;
const unsigned N = sizeof(du_int) * CHAR_BIT;
int sd = N - __builtin_clzll(a); // number of significant digits
int e = sd - 1; // exponent
int sd = N - __builtin_clzll(a); /* number of significant digits */
int e = sd - 1; /* 8 exponent */
if (sd > FLT_MANT_DIG)
{
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
// 12345678901234567890123456
// 1 = msb 1 bit
// P = bit FLT_MANT_DIG-1 bits to the right of 1
// Q = bit FLT_MANT_DIG bits to the right of 1
// R = "or" of all bits to the right of Q
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit FLT_MANT_DIG-1 bits to the right of 1
* Q = bit FLT_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case FLT_MANT_DIG + 1:
@ -49,25 +52,25 @@ __floatundisf(du_int a)
a = (a >> (sd - (FLT_MANT_DIG+2))) |
((a & ((du_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
};
// finish:
a |= (a & 4) != 0; // Or P into R
++a; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
if (a & ((du_int)1 << FLT_MANT_DIG))
{
a >>= 1;
++e;
}
// a is now rounded to FLT_MANT_DIG bits
/* a is now rounded to FLT_MANT_DIG bits */
}
else
{
a <<= (FLT_MANT_DIG - sd);
// a is now rounded to FLT_MANT_DIG bits
/* a is now rounded to FLT_MANT_DIG bits */
}
float_bits fb;
fb.u = ((e + 127) << 23) | // exponent
((su_int)a & 0x007FFFFF); // mantissa
fb.u = ((e + 127) << 23) | /* exponent */
((su_int)a & 0x007FFFFF); /* mantissa */
return fb.f;
}

View File

@ -1,28 +1,30 @@
//===-- floatundixf.c - Implement __floatundixf ---------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floatundixf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- floatundixf.c - Implement __floatundixf ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatundixf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if !_ARCH_PPC
#include "int_lib.h"
// Returns: convert a to a long double, rounding toward even.
/* Returns: convert a to a long double, rounding toward even. */
// Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
// du_int is a 64 bit integral type
// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
* du_int is a 64 bit integral type
*/
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
*/
long double
__floatundixf(du_int a)
{
@ -30,11 +32,11 @@ __floatundixf(du_int a)
return 0.0;
const unsigned N = sizeof(du_int) * CHAR_BIT;
int clz = __builtin_clzll(a);
int e = (N - 1) - clz ; // exponent
int e = (N - 1) - clz ; /* exponent */
long_double_bits fb;
fb.u.high.low = (e + 16383); // exponent
fb.u.low.all = a << clz; // mantissa
fb.u.high.low = (e + 16383); /* exponent */
fb.u.low.all = a << clz; /* mantissa */
return fb.f;
}
#endif
#endif /* _ARCH_PPC */

View File

@ -1,31 +1,32 @@
//===-- moddi3.c - Implement __moddi3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __moddi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- moddi3.c - Implement __moddi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __moddi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
// Returns: a % b
/* Returns: a % b */
di_int
__moddi3(di_int a, di_int b)
{
const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;
di_int s = b >> bits_in_dword_m1; // s = b < 0 ? -1 : 0
b = (b ^ s) - s; // negate if s == -1
s = a >> bits_in_dword_m1; // s = a < 0 ? -1 : 0
a = (a ^ s) - s; // negate if s == -1
di_int s = b >> bits_in_dword_m1; /* s = b < 0 ? -1 : 0 */
b = (b ^ s) - s; /* negate if s == -1 */
s = a >> bits_in_dword_m1; /* s = a < 0 ? -1 : 0 */
a = (a ^ s) - s; /* negate if s == -1 */
di_int r;
__udivmoddi4(a, b, (du_int*)&r);
return (r ^ s) - s; // negate if s == -1
return (r ^ s) - s; /* negate if s == -1 */
}

View File

@ -1,19 +1,20 @@
//===-- modsi3.c - Implement __modsi3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __modsi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- modsi3.c - Implement __modsi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __modsi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: a % b
/* Returns: a % b */
si_int
__modsi3(si_int a, si_int b)

View File

@ -1,15 +1,16 @@
//===-- modti3.c - Implement __modti3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __modti3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- modti3.c - Implement __modti3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __modti3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
@ -17,19 +18,19 @@
tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
// Returns: a % b
/*Returns: a % b */
ti_int
__modti3(ti_int a, ti_int b)
{
const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
ti_int s = b >> bits_in_tword_m1; // s = b < 0 ? -1 : 0
b = (b ^ s) - s; // negate if s == -1
s = a >> bits_in_tword_m1; // s = a < 0 ? -1 : 0
a = (a ^ s) - s; // negate if s == -1
ti_int s = b >> bits_in_tword_m1; /* s = b < 0 ? -1 : 0 */
b = (b ^ s) - s; /* negate if s == -1 */
s = a >> bits_in_tword_m1; /* s = a < 0 ? -1 : 0 */
a = (a ^ s) - s; /* negate if s == -1 */
ti_int r;
__udivmodti4(a, b, (tu_int*)&r);
return (r ^ s) - s; // negate if s == -1
return (r ^ s) - s; /* negate if s == -1 */
}
#endif

View File

@ -1,21 +1,22 @@
//===-- muldc3.c - Implement __muldc3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __muldc3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- muldc3.c - Implement __muldc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __muldc3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <math.h>
#include <complex.h>
// Returns: the product of a + ib and c + id
/* Returns: the product of a + ib and c + id */
double _Complex
__muldc3(double __a, double __b, double __c, double __d)

View File

@ -1,19 +1,20 @@
//===-- muldi3.c - Implement __muldi3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __muldi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- muldi3.c - Implement __muldi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __muldi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: a * b
/* Returns: a * b */
static
di_int
@ -37,7 +38,7 @@ __muldsi3(su_int a, su_int b)
return r.all;
}
// Returns: a * b
/* Returns: a * b */
di_int
__muldi3(di_int a, di_int b)

View File

@ -1,21 +1,22 @@
//===-- mulsc3.c - Implement __mulsc3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __mulsc3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __mulsc3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <math.h>
#include <complex.h>
// Returns: the product of a + ib and c + id
/* Returns: the product of a + ib and c + id */
float _Complex
__mulsc3(float __a, float __b, float __c, float __d)

View File

@ -1,21 +1,22 @@
//===-- multi3.c - Implement __multi3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __multi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- multi3.c - Implement __multi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
* This file implements __multi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
// Returns: a * b
/* Returns: a * b */
static
ti_int
@ -39,7 +40,7 @@ __mulddi3(du_int a, du_int b)
return r.all;
}
// Returns: a * b
/* Returns: a * b */
ti_int
__multi3(ti_int a, ti_int b)

View File

@ -1,22 +1,23 @@
//===-- mulvdi3.c - Implement __mulvdi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __mulvdi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- mulvdi3.c - Implement __mulvdi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __mulvdi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
#include <stdlib.h>
// Returns: a * b
/* Returns: a * b */
// Effects: aborts if a * b overflows
/* Effects: aborts if a * b overflows */
di_int
__mulvdi3(di_int a, di_int b)

View File

@ -1,24 +1,25 @@
//===-- negvti2.c - Implement __negvti2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __negvti2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- negvti2.c - Implement __negvti2 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
*===----------------------------------------------------------------------===
*
*This file implements __negvti2 for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
#include <stdlib.h>
// Returns: -a
/* Returns: -a */
// Effects: aborts if -a overflows
/* Effects: aborts if -a overflows */
ti_int
__negvti2(ti_int a)

View File

@ -1,19 +1,20 @@
//===-- paritydi2.c - Implement __paritydi2 -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __paritydi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- paritydi2.c - Implement __paritydi2 -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __paritydi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: 1 if number of bits is odd else returns 0
/* Returns: 1 if number of bits is odd else returns 0 */
si_int __paritysi2(si_int a);

View File

@ -1,19 +1,20 @@
//===-- paritysi2.c - Implement __paritysi2 -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __paritysi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- paritysi2.c - Implement __paritysi2 -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __paritysi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: 1 if number of bits is odd else returns 0
/* Returns: 1 if number of bits is odd else returns 0 */
si_int
__paritysi2(si_int a)

View File

@ -1,21 +1,22 @@
//===-- parityti2.c - Implement __parityti2 -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __parityti2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- parityti2.c - Implement __parityti2 -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __parityti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
// Returns: 1 if number of bits is odd else returns 0
/* Returns: 1 if number of bits is odd else returns 0 */
si_int __paritydi2(di_int a);

View File

@ -1,32 +1,33 @@
//===-- popcountsi2.c - Implement __popcountsi2 ---------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __popcountsi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- popcountsi2.c - Implement __popcountsi2 ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __popcountsi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: count of 1 bits
/* Returns: count of 1 bits */
si_int
__popcountsi2(si_int a)
{
su_int x = (su_int)a;
x = x - ((x >> 1) & 0x55555555);
// Every 2 bits holds the sum of every pair of bits
/* Every 2 bits holds the sum of every pair of bits */
x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
// Every 4 bits holds the sum of every 4-set of bits (3 significant bits)
/* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) */
x = (x + (x >> 4)) & 0x0F0F0F0F;
// Every 8 bits holds the sum of every 8-set of bits (4 significant bits)
/* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) */
x = (x + (x >> 16));
// The lower 16 bits hold two 8 bit sums (5 significant bits).
// Upper 16 bits are garbage
return (x + (x >> 8)) & 0x0000003F; // (6 significant bits)
/* The lower 16 bits hold two 8 bit sums (5 significant bits).*/
/* Upper 16 bits are garbage */
return (x + (x >> 8)) & 0x0000003F; /* (6 significant bits) */
}

View File

@ -1,21 +1,22 @@
//===-- popcountti2.c - Implement __popcountti2 ----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __popcountti2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- popcountti2.c - Implement __popcountti2 ----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __popcountti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
// Returns: count of 1 bits
/* Returns: count of 1 bits */
si_int
__popcountti2(ti_int a)
@ -23,21 +24,21 @@ __popcountti2(ti_int a)
tu_int x3 = (tu_int)a;
x3 = x3 - ((x3 >> 1) & (((tu_int)0x5555555555555555uLL << 64) |
0x5555555555555555uLL));
// Every 2 bits holds the sum of every pair of bits (64)
/* Every 2 bits holds the sum of every pair of bits (64) */
x3 = ((x3 >> 2) & (((tu_int)0x3333333333333333uLL << 64) | 0x3333333333333333uLL))
+ (x3 & (((tu_int)0x3333333333333333uLL << 64) | 0x3333333333333333uLL));
// Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (32)
/* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (32) */
x3 = (x3 + (x3 >> 4))
& (((tu_int)0x0F0F0F0F0F0F0F0FuLL << 64) | 0x0F0F0F0F0F0F0F0FuLL);
// Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (16)
/* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (16) */
du_int x2 = (du_int)(x3 + (x3 >> 64));
// Every 8 bits holds the sum of every 8-set of bits (5 significant bits) (8)
/* Every 8 bits holds the sum of every 8-set of bits (5 significant bits) (8) */
su_int x = (su_int)(x2 + (x2 >> 32));
// Every 8 bits holds the sum of every 8-set of bits (6 significant bits) (4)
/* Every 8 bits holds the sum of every 8-set of bits (6 significant bits) (4) */
x = x + (x >> 16);
// Every 8 bits holds the sum of every 8-set of bits (7 significant bits) (2)
// Upper 16 bits are garbage
return (x + (x >> 8)) & 0xFF; // (8 significant bits)
/* Every 8 bits holds the sum of every 8-set of bits (7 significant bits) (2) */
/* Upper 16 bits are garbage */
return (x + (x >> 8)) & 0xFF; /* (8 significant bits) */
}
#endif

View File

@ -1,19 +1,20 @@
//===-- powisf2.cpp - Implement __powisf2 ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __powisf2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/*===-- powisf2.cpp - Implement __powisf2 ---------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __powisf2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: a ^ b
/* Returns: a ^ b */
float
__powisf2(float a, si_int b)

View File

@ -1,21 +1,23 @@
//===-- ucmpdi2.c - Implement __ucmpdi2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __ucmpdi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- ucmpdi2.c - Implement __ucmpdi2 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ucmpdi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: if (a < b) returns 0
// if (a == b) returns 1
// if (a > b) returns 2
/* Returns: if (a < b) returns 0
* if (a == b) returns 1
* if (a > b) returns 2
*/
si_int
__ucmpdi2(du_int a, du_int b)

View File

@ -1,21 +1,22 @@
//===-- udivdi3.c - Implement __udivdi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __udivdi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- udivdi3.c - Implement __udivdi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __udivdi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
// Returns: a / b
/* Returns: a / b */
du_int
__udivdi3(du_int a, du_int b)

View File

@ -1,22 +1,24 @@
//===-- udivmoddi4.c - Implement __udivmoddi4 -----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __udivmoddi4 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- udivmoddi4.c - Implement __udivmoddi4 -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __udivmoddi4 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Effects: if rem != 0, *rem = a % b
// Returns: a / b
/* Effects: if rem != 0, *rem = a % b
* Returns: a / b
*/
// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide
/* Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide */
du_int
__udivmoddi4(du_int a, du_int b, du_int* rem)
@ -30,43 +32,47 @@ __udivmoddi4(du_int a, du_int b, du_int* rem)
udwords q;
udwords r;
unsigned sr;
// special cases, X is unknown, K != 0
/* special cases, X is unknown, K != 0 */
if (n.high == 0)
{
if (d.high == 0)
{
// 0 X
// ---
// 0 X
/* 0 X
* ---
* 0 X
*/
if (rem)
*rem = n.low % d.low;
return n.low / d.low;
}
// 0 X
// ---
// K X
/* 0 X
* ---
* K X
*/
if (rem)
*rem = n.low;
return 0;
}
// n.high != 0
/* n.high != 0 */
if (d.low == 0)
{
if (d.high == 0)
{
// K X
// ---
// 0 0
/* K X
* ---
* 0 0
*/
if (rem)
*rem = n.high % d.low;
return n.high / d.low;
}
// d.high != 0
/* d.high != 0 */
if (n.low == 0)
{
// K 0
// ---
// K 0
/* K 0
* ---
* K 0
*/
if (rem)
{
r.high = n.high % d.high;
@ -75,10 +81,11 @@ __udivmoddi4(du_int a, du_int b, du_int* rem)
}
return n.high / d.high;
}
// K K
// ---
// K 0
if ((d.high & (d.high - 1)) == 0) // if d is a power of 2
/* K K
* ---
* K 0
*/
if ((d.high & (d.high - 1)) == 0) /* if d is a power of 2 */
{
if (rem)
{
@ -88,11 +95,12 @@ __udivmoddi4(du_int a, du_int b, du_int* rem)
}
return n.high >> __builtin_ctz(d.high);
}
// K K
// ---
// K 0
/* K K
* ---
* K 0
*/
sr = __builtin_clz(d.high) - __builtin_clz(n.high);
// 0 <= sr <= n_uword_bits - 2 or sr large
/* 0 <= sr <= n_uword_bits - 2 or sr large */
if (sr > n_uword_bits - 2)
{
if (rem)
@ -100,22 +108,23 @@ __udivmoddi4(du_int a, du_int b, du_int* rem)
return 0;
}
++sr;
// 1 <= sr <= n_uword_bits - 1
// q.all = n.all << (n_udword_bits - sr);
/* 1 <= sr <= n_uword_bits - 1 */
/* q.all = n.all << (n_udword_bits - sr); */
q.low = 0;
q.high = n.low << (n_uword_bits - sr);
// r.all = n.all >> sr;
/* r.all = n.all >> sr; */
r.high = n.high >> sr;
r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
}
else // d.low != 0
else /* d.low != 0 */
{
if (d.high == 0)
{
// K X
// ---
// 0 K
if ((d.low & (d.low - 1)) == 0) // if d is a power of 2
/* K X
* ---
* 0 K
*/
if ((d.low & (d.low - 1)) == 0) /* if d is a power of 2 */
{
if (rem)
*rem = n.low & (d.low - 1);
@ -126,35 +135,37 @@ __udivmoddi4(du_int a, du_int b, du_int* rem)
q.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
return q.all;
}
// K X
// ---
// 0 K
/* K X
* ---
*0 K
*/
sr = 1 + n_uword_bits + __builtin_clz(d.low) - __builtin_clz(n.high);
// 2 <= sr <= n_udword_bits - 1
// q.all = n.all << (n_udword_bits - sr);
// r.all = n.all >> sr;
// if (sr == n_uword_bits)
// {
// q.low = 0;
// q.high = n.low;
// r.high = 0;
// r.low = n.high;
// }
// else if (sr < n_uword_bits) // 2 <= sr <= n_uword_bits - 1
// {
// q.low = 0;
// q.high = n.low << (n_uword_bits - sr);
// r.high = n.high >> sr;
// r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
// }
// else // n_uword_bits + 1 <= sr <= n_udword_bits - 1
// {
// q.low = n.low << (n_udword_bits - sr);
// q.high = (n.high << (n_udword_bits - sr)) |
// (n.low >> (sr - n_uword_bits));
// r.high = 0;
// r.low = n.high >> (sr - n_uword_bits);
// }
/* 2 <= sr <= n_udword_bits - 1
* q.all = n.all << (n_udword_bits - sr);
* r.all = n.all >> sr;
* if (sr == n_uword_bits)
* {
* q.low = 0;
* q.high = n.low;
* r.high = 0;
* r.low = n.high;
* }
* else if (sr < n_uword_bits) // 2 <= sr <= n_uword_bits - 1
* {
* q.low = 0;
* q.high = n.low << (n_uword_bits - sr);
* r.high = n.high >> sr;
* r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
* }
* else // n_uword_bits + 1 <= sr <= n_udword_bits - 1
* {
* q.low = n.low << (n_udword_bits - sr);
* q.high = (n.high << (n_udword_bits - sr)) |
* (n.low >> (sr - n_uword_bits));
* r.high = 0;
* r.low = n.high >> (sr - n_uword_bits);
* }
*/
q.low = (n.low << (n_udword_bits - sr)) &
((si_int)(n_uword_bits - sr) >> (n_uword_bits-1));
q.high = ((n.low << ( n_uword_bits - sr)) &
@ -172,11 +183,12 @@ __udivmoddi4(du_int a, du_int b, du_int* rem)
}
else
{
// K X
// ---
// K K
/* K X
* ---
* K K
*/
sr = __builtin_clz(d.high) - __builtin_clz(n.high);
// 0 <= sr <= n_uword_bits - 1 or sr large
/* 0 <= sr <= n_uword_bits - 1 or sr large */
if (sr > n_uword_bits - 1)
{
if (rem)
@ -184,21 +196,22 @@ __udivmoddi4(du_int a, du_int b, du_int* rem)
return 0;
}
++sr;
// 1 <= sr <= n_uword_bits
// q.all = n.all << (n_udword_bits - sr);
/* 1 <= sr <= n_uword_bits */
/* q.all = n.all << (n_udword_bits - sr); */
q.low = 0;
q.high = n.low << (n_uword_bits - sr);
// r.all = n.all >> sr;
// if (sr < n_uword_bits)
// {
// r.high = n.high >> sr;
// r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
// }
// else
// {
// r.high = 0;
// r.low = n.high;
// }
/* r.all = n.all >> sr;
* if (sr < n_uword_bits)
* {
* r.high = n.high >> sr;
* r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
* }
* else
* {
* r.high = 0;
* r.low = n.high;
* }
*/
r.high = (n.high >> sr) &
((si_int)(sr - n_uword_bits) >> (n_uword_bits-1));
r.low = (n.high << (n_uword_bits - sr)) |
@ -206,25 +219,27 @@ __udivmoddi4(du_int a, du_int b, du_int* rem)
((si_int)(sr - n_uword_bits) >> (n_uword_bits-1)));
}
}
// Not a special case
// q and r are initialized with:
// q.all = n.all << (n_udword_bits - sr);
// r.all = n.all >> sr;
// 1 <= sr <= n_udword_bits - 1
/* Not a special case
* q and r are initialized with:
* q.all = n.all << (n_udword_bits - sr);
* r.all = n.all >> sr;
* 1 <= sr <= n_udword_bits - 1
*/
su_int carry = 0;
for (; sr > 0; --sr)
{
// r:q = ((r:q) << 1) | carry
/* r:q = ((r:q) << 1) | carry */
r.high = (r.high << 1) | (r.low >> (n_uword_bits - 1));
r.low = (r.low << 1) | (q.high >> (n_uword_bits - 1));
q.high = (q.high << 1) | (q.low >> (n_uword_bits - 1));
q.low = (q.low << 1) | carry;
// carry = 0;
// if (r.all >= d.all)
// {
// r.all -= d.all;
// carry = 1;
// }
/* carry = 0;
* if (r.all >= d.all)
* {
* r.all -= d.all;
* carry = 1;
* }
*/
const di_int s = (di_int)(d.all - r.all - 1) >> (n_udword_bits - 1);
carry = s & 1;
r.all -= d.all & s;

View File

@ -1,24 +1,26 @@
//===-- udivmodti4.c - Implement __udivmodti4 -----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __udivmodti4 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- udivmodti4.c - Implement __udivmodti4 -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __udivmodti4 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
#include "int_lib.h"
// Effects: if rem != 0, *rem = a % b
// Returns: a / b
/* Effects: if rem != 0, *rem = a % b
* Returns: a / b
*/
// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide
/* Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide */
tu_int
__udivmodti4(tu_int a, tu_int b, tu_int* rem)
@ -32,43 +34,47 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem)
utwords q;
utwords r;
unsigned sr;
// special cases, X is unknown, K != 0
/* special cases, X is unknown, K != 0 */
if (n.high == 0)
{
if (d.high == 0)
{
// 0 X
// ---
// 0 X
/* 0 X
* ---
* 0 X
*/
if (rem)
*rem = n.low % d.low;
return n.low / d.low;
}
// 0 X
// ---
// K X
/* 0 X
* ---
* K X
*/
if (rem)
*rem = n.low;
return 0;
}
// n.high != 0
/* n.high != 0 */
if (d.low == 0)
{
if (d.high == 0)
{
// K X
// ---
// 0 0
/* K X
* ---
* 0 0
*/
if (rem)
*rem = n.high % d.low;
return n.high / d.low;
}
// d.high != 0
/* d.high != 0 */
if (n.low == 0)
{
// K 0
// ---
// K 0
/* K 0
* ---
* K 0
*/
if (rem)
{
r.high = n.high % d.high;
@ -77,10 +83,11 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem)
}
return n.high / d.high;
}
// K K
// ---
// K 0
if ((d.high & (d.high - 1)) == 0) // if d is a power of 2
/* K K
* ---
* K 0
*/
if ((d.high & (d.high - 1)) == 0) /* if d is a power of 2 */
{
if (rem)
{
@ -90,11 +97,12 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem)
}
return n.high >> __builtin_ctzll(d.high);
}
// K K
// ---
// K 0
/* K K
* ---
* K 0
*/
sr = __builtin_clzll(d.high) - __builtin_clzll(n.high);
// 0 <= sr <= n_udword_bits - 2 or sr large
/* 0 <= sr <= n_udword_bits - 2 or sr large */
if (sr > n_udword_bits - 2)
{
if (rem)
@ -102,22 +110,23 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem)
return 0;
}
++sr;
// 1 <= sr <= n_udword_bits - 1
// q.all = n.all << (n_utword_bits - sr);
/* 1 <= sr <= n_udword_bits - 1 */
/* q.all = n.all << (n_utword_bits - sr); */
q.low = 0;
q.high = n.low << (n_udword_bits - sr);
// r.all = n.all >> sr;
/* r.all = n.all >> sr; */
r.high = n.high >> sr;
r.low = (n.high << (n_udword_bits - sr)) | (n.low >> sr);
}
else // d.low != 0
else /* d.low != 0 */
{
if (d.high == 0)
{
// K X
// ---
// 0 K
if ((d.low & (d.low - 1)) == 0) // if d is a power of 2
/* K X
* ---
* 0 K
*/
if ((d.low & (d.low - 1)) == 0) /* if d is a power of 2 */
{
if (rem)
*rem = n.low & (d.low - 1);
@ -128,36 +137,38 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem)
q.low = (n.high << (n_udword_bits - sr)) | (n.low >> sr);
return q.all;
}
// K X
// ---
// 0 K
/* K X
* ---
* 0 K
*/
sr = 1 + n_udword_bits + __builtin_clzll(d.low)
- __builtin_clzll(n.high);
// 2 <= sr <= n_utword_bits - 1
// q.all = n.all << (n_utword_bits - sr);
// r.all = n.all >> sr;
// if (sr == n_udword_bits)
// {
// q.low = 0;
// q.high = n.low;
// r.high = 0;
// r.low = n.high;
// }
// else if (sr < n_udword_bits) // 2 <= sr <= n_udword_bits - 1
// {
// q.low = 0;
// q.high = n.low << (n_udword_bits - sr);
// r.high = n.high >> sr;
// r.low = (n.high << (n_udword_bits - sr)) | (n.low >> sr);
// }
// else // n_udword_bits + 1 <= sr <= n_utword_bits - 1
// {
// q.low = n.low << (n_utword_bits - sr);
// q.high = (n.high << (n_utword_bits - sr)) |
// (n.low >> (sr - n_udword_bits));
// r.high = 0;
// r.low = n.high >> (sr - n_udword_bits);
// }
/* 2 <= sr <= n_utword_bits - 1
* q.all = n.all << (n_utword_bits - sr);
* r.all = n.all >> sr;
* if (sr == n_udword_bits)
* {
* q.low = 0;
* q.high = n.low;
* r.high = 0;
* r.low = n.high;
* }
* else if (sr < n_udword_bits) // 2 <= sr <= n_udword_bits - 1
* {
* q.low = 0;
* q.high = n.low << (n_udword_bits - sr);
* r.high = n.high >> sr;
* r.low = (n.high << (n_udword_bits - sr)) | (n.low >> sr);
* }
* else // n_udword_bits + 1 <= sr <= n_utword_bits - 1
* {
* q.low = n.low << (n_utword_bits - sr);
* q.high = (n.high << (n_utword_bits - sr)) |
* (n.low >> (sr - n_udword_bits));
* r.high = 0;
* r.low = n.high >> (sr - n_udword_bits);
* }
*/
q.low = (n.low << (n_utword_bits - sr)) &
((di_int)(int)(n_udword_bits - sr) >> (n_udword_bits-1));
q.high = ((n.low << ( n_udword_bits - sr)) &
@ -175,11 +186,12 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem)
}
else
{
// K X
// ---
// K K
/* K X
* ---
* K K
*/
sr = __builtin_clzll(d.high) - __builtin_clzll(n.high);
// 0 <= sr <= n_udword_bits - 1 or sr large
/*0 <= sr <= n_udword_bits - 1 or sr large */
if (sr > n_udword_bits - 1)
{
if (rem)
@ -187,21 +199,22 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem)
return 0;
}
++sr;
// 1 <= sr <= n_udword_bits
// q.all = n.all << (n_utword_bits - sr);
/* 1 <= sr <= n_udword_bits */
/* q.all = n.all << (n_utword_bits - sr); */
q.low = 0;
q.high = n.low << (n_udword_bits - sr);
// r.all = n.all >> sr;
// if (sr < n_udword_bits)
// {
// r.high = n.high >> sr;
// r.low = (n.high << (n_udword_bits - sr)) | (n.low >> sr);
// }
// else
// {
// r.high = 0;
// r.low = n.high;
// }
/* r.all = n.all >> sr;
* if (sr < n_udword_bits)
* {
* r.high = n.high >> sr;
* r.low = (n.high << (n_udword_bits - sr)) | (n.low >> sr);
* }
* else
* {
* r.high = 0;
* r.low = n.high;
* }
*/
r.high = (n.high >> sr) &
((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1));
r.low = (n.high << (n_udword_bits - sr)) |
@ -209,25 +222,27 @@ __udivmodti4(tu_int a, tu_int b, tu_int* rem)
((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1)));
}
}
// Not a special case
// q and r are initialized with:
// q.all = n.all << (n_utword_bits - sr);
// r.all = n.all >> sr;
// 1 <= sr <= n_utword_bits - 1
/* Not a special case
* q and r are initialized with:
* q.all = n.all << (n_utword_bits - sr);
* r.all = n.all >> sr;
* 1 <= sr <= n_utword_bits - 1
*/
su_int carry = 0;
for (; sr > 0; --sr)
{
// r:q = ((r:q) << 1) | carry
/* r:q = ((r:q) << 1) | carry */
r.high = (r.high << 1) | (r.low >> (n_udword_bits - 1));
r.low = (r.low << 1) | (q.high >> (n_udword_bits - 1));
q.high = (q.high << 1) | (q.low >> (n_udword_bits - 1));
q.low = (q.low << 1) | carry;
// carry = 0;
// if (r.all >= d.all)
// {
// r.all -= d.all;
// carry = 1;
// }
/* carry = 0;
* if (r.all >= d.all)
* {
* r.all -= d.all;
* carry = 1;
* }
*/
const ti_int s = (ti_int)(d.all - r.all - 1) >> (n_utword_bits - 1);
carry = s & 1;
r.all -= d.all & s;

View File

@ -1,21 +1,22 @@
//===-- udivsi3.c - Implement __udivsi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __udivsi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- udivsi3.c - Implement __udivsi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __udivsi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: a / b
/* Returns: a / b */
// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide
/* Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide */
su_int
__udivsi3(su_int n, su_int d)
@ -24,34 +25,35 @@ __udivsi3(su_int n, su_int d)
su_int q;
su_int r;
unsigned sr;
// special cases
/* special cases */
if (d == 0)
return 0; // ?!
return 0; /* ?! */
if (n == 0)
return 0;
sr = __builtin_clz(d) - __builtin_clz(n);
// 0 <= sr <= n_uword_bits - 1 or sr large
if (sr > n_uword_bits - 1) // d > r
/* 0 <= sr <= n_uword_bits - 1 or sr large */
if (sr > n_uword_bits - 1) /* d > r */
return 0;
if (sr == n_uword_bits - 1) // d == 1
if (sr == n_uword_bits - 1) /* d == 1 */
return n;
++sr;
// 1 <= sr <= n_uword_bits - 1
// Not a special case
/* 1 <= sr <= n_uword_bits - 1 */
/* Not a special case */
q = n << (n_uword_bits - sr);
r = n >> sr;
su_int carry = 0;
for (; sr > 0; --sr)
{
// r:q = ((r:q) << 1) | carry
/* r:q = ((r:q) << 1) | carry */
r = (r << 1) | (q >> (n_uword_bits - 1));
q = (q << 1) | carry;
// carry = 0;
// if (r.all >= d.all)
// {
// r.all -= d.all;
// carry = 1;
// }
/* carry = 0;
* if (r.all >= d.all)
* {
* r.all -= d.all;
* carry = 1;
* }
*/
const si_int s = (si_int)(d - r - 1) >> (n_uword_bits - 1);
carry = s & 1;
r -= d & s;

View File

@ -1,15 +1,16 @@
//===-- udivti3.c - Implement __udivti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __udivti3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- udivti3.c - Implement __udivti3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __udivti3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#if __x86_64
@ -17,7 +18,7 @@
tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
// Returns: a / b
/* Returns: a / b */
tu_int
__udivti3(tu_int a, tu_int b)
@ -25,4 +26,4 @@ __udivti3(tu_int a, tu_int b)
return __udivmodti4(a, b, 0);
}
#endif
#endif /* __x86_64 */

View File

@ -1,21 +1,22 @@
//===-- umoddi3.c - Implement __umoddi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __umoddi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- umoddi3.c - Implement __umoddi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __umoddi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
// Returns: a % b
/* Returns: a % b */
du_int
__umoddi3(du_int a, du_int b)

View File

@ -1,19 +1,20 @@
//===-- umodsi3.c - Implement __umodsi3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __umodsi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
/* ===-- umodsi3.c - Implement __umodsi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __umodsi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "int_lib.h"
// Returns: a % b
/* Returns: a % b */
su_int __udivsi3(su_int a, su_int b);