Compile and test i128 math builtins for Win64

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
This commit is contained in:
Reid Kleckner 2018-11-01 00:00:03 +00:00
parent b61232eacd
commit dffe5a3807
39 changed files with 104 additions and 48 deletions

View File

@ -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)));

View File

@ -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})

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- addvti3_test.c - Test __addvti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ashlti3_test.c - Test __ashlti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ashrti3_test.c - Test __ashrti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- clzti2_test.c - Test __clzti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- cmpti2_test.c - Test __cmpti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ctzti2_test.c - Test __ctzti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- divti3_test.c - Test __divti3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- fixdfti_test.c - Test __fixdfti -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- fixsfti_test.c - Test __fixsfti -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- fixunsdfti_test.c - Test __fixunsdfti -----------------------------===//
//
// The LLVM Compiler Infrastructure
@ -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

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- fixunssfti_test.c - Test __fixunssfti -----------------------------===//
//
// The LLVM Compiler Infrastructure
@ -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;

View File

@ -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.
@ -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;

View File

@ -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.
@ -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;

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- floattidf.c - Test __floattidf ------------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- floattisf_test.c - Test __floattisf -------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -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.
@ -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;

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- floatuntidf.c - Test __floatuntidf --------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -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.
@ -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;

View File

@ -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.
@ -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;

View File

@ -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)
@ -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):

View File

@ -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")

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- lshrti3_test.c - Test __lshrti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- modti3_test.c - Test __modti3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
@ -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))

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- muloti4_test.c - Test __muloti4 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- multi3_test.c - Test __multi3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- mulvti3_test.c - Test __mulvti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
@ -99,13 +100,13 @@ int main()
if (test__mulvti3(-81985529216486895LL, 1, -81985529216486895LL))
return 1;
if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001LL))
if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001ULL))
return 1;
if (test__mulvti3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
return 1;
if (test__mulvti3(3037000499LL, -3037000499LL, -9223372030926249001LL))
return 1;
if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001ULL))
return 1;
if (test__mulvti3(4398046511103LL, 2097152LL, 9223372036852678656LL))
@ -117,7 +118,7 @@ int main()
if (test__mulvti3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
return 1;
if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656LL))
if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656ULL))
return 1;
if (test__mulvti3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
return 1;

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- negti2_test.c - Test __negti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- negvti2_test.c - Test __negvti2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- parityti2_test.c - Test __parityti2 -------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- popcountti2_test.c - Test __popcountti2 ----------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- subvti3_test.c - Test __subvti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ucmpti2_test.c - Test __ucmpti2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- udivmodti4_test.c - Test __udivmodti4 -----------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- udivti3_test.c - Test __udivti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure

View File

@ -1,4 +1,5 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- umodti3_test.c - Test __umodti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure