Skip to content

Commit

Permalink
Compile and test i128 math builtins for Win64
Browse files Browse the repository at this point in the history
Summary:
Windows has always been LLP64, not LP64, so the macros were incorrect.
Check for _WIN64, since AArch64 sets that too.

The tests have to be fixed up in two main ways:
1. Use 'ULL' suffixes to avoid sign extension when passing hex literals
   with the sign bit set to signed 128 arguments. Clang
   -fms-compatibility makes such hex literals signed, not unsigned.
2. Disable various tests for 80-bit long double interoperation with i128
   values.

Reviewers: joerg, mstorsjo

Subscribers: javed.absar, kristof.beyls, hiraditya, aheejin, llvm-commits

Differential Revision: https://reviews.llvm.org/D53918

llvm-svn: 345796
  • Loading branch information
rnk committed Nov 1, 2018
1 parent b61232e commit dffe5a3
Show file tree
Hide file tree
Showing 39 changed files with 104 additions and 48 deletions.
11 changes: 10 additions & 1 deletion compiler-rt/lib/builtins/int_types.h
Expand Up @@ -60,10 +60,19 @@ typedef union
}s;
} udwords;

#if (defined(__LP64__) || defined(__wasm__) || defined(__mips64)) || defined(__riscv)
#if defined(__LP64__) || defined(__wasm__) || defined(__mips64) || \
defined(__riscv) || defined(_WIN64)
#define CRT_HAS_128BIT
#endif

/* MSVC doesn't have a working 128bit integer type. Users should really compile
* compiler-rt with clang, but if they happen to be doing a standalone build for
* asan or something else, disable the 128 bit parts so things sort of work.
*/
#if defined(_MSC_VER) && !defined(__clang__)
#undef CRT_HAS_128BIT
#endif

#ifdef CRT_HAS_128BIT
typedef int ti_int __attribute__ ((mode (TI)));
typedef unsigned tu_int __attribute__ ((mode (TI)));
Expand Down
10 changes: 10 additions & 0 deletions compiler-rt/test/builtins/CMakeLists.txt
Expand Up @@ -13,8 +13,18 @@ configure_lit_site_cfg(

include(builtin-config-ix)

# Indicate if this is an MSVC environment.
pythonize_bool(MSVC)

# Indicate if the compiler for the builtins library was MSVC. If the builtins
# compiler was clang-cl, we will enable some features that the host compiler
# will not, like C99 _Complex and int128.
set(BUILTINS_IS_MSVC OFF)
if (MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
set(BUILTINS_IS_MSVC ON)
endif()
pythonize_bool(BUILTINS_IS_MSVC)

#TODO: Add support for Apple.
if (NOT APPLE)
foreach(arch ${BUILTIN_SUPPORTED_ARCH})
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/absvti2_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/addvti3_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- addvti3_test.c - Test __addvti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/ashlti3_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ashlti3_test.c - Test __ashlti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/ashrti3_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ashrti3_test.c - Test __ashrti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/clzti2_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- clzti2_test.c - Test __clzti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/cmpti2_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- cmpti2_test.c - Test __cmpti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/ctzti2_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ctzti2_test.c - Test __ctzti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/divti3_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- divti3_test.c - Test __divti3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/ffsti2_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/fixdfti_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- fixdfti_test.c - Test __fixdfti -----------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/fixsfti_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- fixsfti_test.c - Test __fixsfti -----------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
21 changes: 11 additions & 10 deletions compiler-rt/test/builtins/Unit/fixunsdfti_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- fixunsdfti_test.c - Test __fixunsdfti -----------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -99,25 +100,25 @@ int main()
return 1;
#endif

if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800LL))
if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800ULL))
return 1;
if (test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000LL))
if (test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000ULL))
return 1;
if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00ULL))
return 1;
if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800ULL))
return 1;

if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, make_ti(0xFFFFFFFFFFFFF800LL, 0)))
if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, make_ti(0xFFFFFFFFFFFFF800ULL, 0)))
return 1;
if (test__fixunsdfti(0x1.0000000000000p+127, make_ti(0x8000000000000000LL, 0)))
if (test__fixunsdfti(0x1.0000000000000p+127, make_ti(0x8000000000000000ULL, 0)))
return 1;
if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, make_ti(0x7FFFFFFFFFFFFC00LL, 0)))
if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, make_ti(0x7FFFFFFFFFFFFC00ULL, 0)))
return 1;
if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800LL, 0)))
if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800ULL, 0)))
return 1;
if (test__fixunsdfti(0x1.0000000000000p+128, make_ti(0xFFFFFFFFFFFFFFFFLL,
0xFFFFFFFFFFFFFFFFLL)))
if (test__fixunsdfti(0x1.0000000000000p+128, make_ti(0xFFFFFFFFFFFFFFFFULL,
0xFFFFFFFFFFFFFFFFULL)))
return 1;

#if !TARGET_LIBGCC
Expand Down
9 changes: 5 additions & 4 deletions compiler-rt/test/builtins/Unit/fixunssfti_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- fixunssfti_test.c - Test __fixunssfti -----------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -87,18 +88,18 @@ int main()
return 1;
#endif

if (test__fixunssfti(0x1.FFFFFEp+63F, 0xFFFFFF0000000000LL))
if (test__fixunssfti(0x1.FFFFFEp+63F, 0xFFFFFF0000000000ULL))
return 1;
if (test__fixunssfti(0x1.000000p+63F, 0x8000000000000000LL))
if (test__fixunssfti(0x1.000000p+63F, 0x8000000000000000ULL))
return 1;
if (test__fixunssfti(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL))
return 1;
if (test__fixunssfti(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL))
return 1;

if (test__fixunssfti(0x1.FFFFFEp+127F, make_ti(0xFFFFFF0000000000LL, 0)))
if (test__fixunssfti(0x1.FFFFFEp+127F, make_ti(0xFFFFFF0000000000ULL, 0)))
return 1;
if (test__fixunssfti(0x1.000000p+127F, make_ti(0x8000000000000000LL, 0)))
if (test__fixunssfti(0x1.000000p+127F, make_ti(0x8000000000000000ULL, 0)))
return 1;
if (test__fixunssfti(0x1.FFFFFEp+126F, make_ti(0x7FFFFF8000000000LL, 0)))
return 1;
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/test/builtins/Unit/fixunsxfti_test.c
Expand Up @@ -17,7 +17,7 @@
#include "int_lib.h"
#include <stdio.h>

#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE

// Returns: convert a to a unsigned long long, rounding toward zero.
// Negative values all become zero.
Expand Down Expand Up @@ -55,7 +55,7 @@ char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};

int main()
{
#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__fixunsxfti(0.0, 0))
return 1;

Expand Down
10 changes: 5 additions & 5 deletions compiler-rt/test/builtins/Unit/fixxfti_test.c
Expand Up @@ -17,7 +17,7 @@
#include "int_lib.h"
#include <stdio.h>

#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE

// Returns: convert a to a signed long long, rounding toward zero.

Expand Down Expand Up @@ -45,15 +45,15 @@ int test__fixxfti(long double a, ti_int expected)
return x != expected;
}

char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
COMPILE_TIME_ASSERT(sizeof(ti_int) == 2*sizeof(di_int));
COMPILE_TIME_ASSERT(sizeof(su_int)*CHAR_BIT == 32);
COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128);

#endif

int main()
{
#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__fixxfti(0.0, 0))
return 1;

Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/floattidf_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- floattidf.c - Test __floattidf ------------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/floattisf_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- floattisf_test.c - Test __floattisf -------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
10 changes: 5 additions & 5 deletions compiler-rt/test/builtins/Unit/floattixf_test.c
Expand Up @@ -18,7 +18,7 @@
#include <float.h>
#include <stdio.h>

#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE

// Returns: convert a to a long double, rounding toward even.

Expand All @@ -43,15 +43,15 @@ int test__floattixf(ti_int a, long double expected)
return x != expected;
}

char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
char assumption_2[sizeof(ti_int)*CHAR_BIT == 128] = {0};
char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
COMPILE_TIME_ASSERT(sizeof(ti_int) == 2*sizeof(di_int));
COMPILE_TIME_ASSERT(sizeof(ti_int)*CHAR_BIT == 128);
COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128);

#endif

int main()
{
#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__floattixf(0, 0.0))
return 1;

Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/floatuntidf_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- floatuntidf.c - Test __floatuntidf --------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
10 changes: 5 additions & 5 deletions compiler-rt/test/builtins/Unit/floatuntisf_test.c
Expand Up @@ -16,7 +16,7 @@
#include <float.h>
#include <stdio.h>

#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE

// Returns: convert a to a float, rounding toward even.

Expand All @@ -40,15 +40,15 @@ int test__floatuntisf(tu_int a, float expected)
return x != expected;
}

char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
COMPILE_TIME_ASSERT(sizeof(tu_int) == 2*sizeof(du_int));
COMPILE_TIME_ASSERT(sizeof(tu_int)*CHAR_BIT == 128);
COMPILE_TIME_ASSERT(sizeof(float)*CHAR_BIT == 32);

#endif

int main()
{
#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__floatuntisf(0, 0.0F))
return 1;

Expand Down
10 changes: 5 additions & 5 deletions compiler-rt/test/builtins/Unit/floatuntixf_test.c
Expand Up @@ -18,7 +18,7 @@
#include <float.h>
#include <stdio.h>

#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE

// Returns: convert a to a long double, rounding toward even.

Expand All @@ -43,15 +43,15 @@ int test__floatuntixf(tu_int a, long double expected)
return x != expected;
}

char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
COMPILE_TIME_ASSERT(sizeof(tu_int) == 2*sizeof(du_int));
COMPILE_TIME_ASSERT(sizeof(tu_int)*CHAR_BIT == 128);
COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128);

#endif

int main()
{
#ifdef CRT_HAS_128BIT
#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__floatuntixf(0, 0.0))
return 1;

Expand Down
8 changes: 7 additions & 1 deletion compiler-rt/test/builtins/Unit/lit.cfg
Expand Up @@ -24,7 +24,7 @@ default_builtins_opts = ''
config.test_source_root = os.path.dirname(__file__)

# Path to the static library
is_msvc = get_required_attr(config, "builtins_is_msvc")
is_msvc = get_required_attr(config, "is_msvc")
if is_msvc:
base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.builtins%s.lib "
% config.target_suffix)
Expand Down Expand Up @@ -52,9 +52,15 @@ clang_builtins_static_cxxflags = config.cxx_mode_flags + \
clang_builtins_cflags = clang_builtins_static_cflags
clang_builtins_cxxflags = clang_builtins_static_cxxflags

# FIXME: Right now we don't compile the C99 complex builtins when using
# clang-cl. Fix that.
if not is_msvc:
config.available_features.add('c99-complex')

builtins_is_msvc = get_required_attr(config, "builtins_is_msvc")
if not builtins_is_msvc:
config.available_features.add('int128')

clang_wrapper = ""

def build_invocation(compile_flags):
Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/test/builtins/Unit/lit.site.cfg.in
Expand Up @@ -4,7 +4,8 @@ config.name_suffix = "@BUILTINS_TEST_CONFIG_SUFFIX@"
config.builtins_lit_source_dir = "@BUILTINS_LIT_SOURCE_DIR@/Unit"
config.target_cflags = "@BUILTINS_TEST_TARGET_CFLAGS@"
config.target_arch = "@BUILTINS_TEST_TARGET_ARCH@"
config.builtins_is_msvc = @MSVC_PYBOOL@
config.is_msvc = @MSVC_PYBOOL@
config.builtins_is_msvc = @BUILTINS_IS_MSVC_PYBOOL@
# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")

Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/builtins/Unit/lshrti3_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- lshrti3_test.c - Test __lshrti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down
13 changes: 7 additions & 6 deletions compiler-rt/test/builtins/Unit/modti3_test.c
@@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- modti3_test.c - Test __modti3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -63,17 +64,17 @@ int main()
if (test__modti3(-5, -3, -2))
return 1;

if (test__modti3(0x8000000000000000LL, 1, 0x0LL))
if (test__modti3(0x8000000000000000ULL, 1, 0x0LL))
return 1;
if (test__modti3(0x8000000000000000LL, -1, 0x0LL))
if (test__modti3(0x8000000000000000ULL, -1, 0x0LL))
return 1;
if (test__modti3(0x8000000000000000LL, 2, 0x0LL))
if (test__modti3(0x8000000000000000ULL, 2, 0x0LL))
return 1;
if (test__modti3(0x8000000000000000LL, -2, 0x0LL))
if (test__modti3(0x8000000000000000ULL, -2, 0x0LL))
return 1;
if (test__modti3(0x8000000000000000LL, 3, 2))
if (test__modti3(0x8000000000000000ULL, 3, 2))
return 1;
if (test__modti3(0x8000000000000000LL, -3, 2))
if (test__modti3(0x8000000000000000ULL, -3, 2))
return 1;

if (test__modti3(make_ti(0x8000000000000000LL, 0), 1, 0x0LL))
Expand Down

0 comments on commit dffe5a3

Please sign in to comment.