Skip to content

Commit

Permalink
fixed some _Float16 detection issues
Browse files Browse the repository at this point in the history
also:
- fixed a few minor issues with tests
- removed `__fp16` support (it was always broken)
  • Loading branch information
marzer committed Oct 17, 2022
1 parent 12f9c67 commit c8780a5
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
steps:
- name: Install dependencies
run: |
python3 -m pip install -U pip==21.3.1
python3 -m pip install -U pip
pip3 install meson ninja
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: |
apt -y update
apt -y install --no-install-recommends git python3 python3-pip doxygen
pip3 install --upgrade --requirement tools/requirements.txt
pip3 install --upgrade poxy
- name: Generate docs
run: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ template:
#### Fixes:

- fixed null pointer dereference in parser when exceptions are disabled (#169) (@ncaklovic)
- fixed spurious warnings in MSVC 19.34
- fixed some `_Float16` detection issues

<br><br>

Expand Down
2 changes: 2 additions & 0 deletions docs/poxy.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# this is a config file for Poxy - a Doxygen + m.css front-end written in Python.
# https://github.com/marzer/poxy
#
# config reference: https://github.com/marzer/poxy/wiki/Configuration-options

name = 'toml++'
author = 'Mark Gillard'
Expand Down
10 changes: 0 additions & 10 deletions include/toml++/impl/forward_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,6 @@ TOML_IMPL_NAMESPACE_START
template <typename T>
struct float_traits : float_traits_base<T, std::numeric_limits<T>::digits, std::numeric_limits<T>::digits10>
{};
#ifdef TOML_FP16
template <>
struct float_traits<TOML_FP16> : float_traits_base<TOML_FP16, __FLT16_MANT_DIG__, __FLT16_DIG__>
{};
#endif
#ifdef TOML_FLOAT16
template <>
struct float_traits<TOML_FLOAT16> : float_traits_base<TOML_FLOAT16, __FLT16_MANT_DIG__, __FLT16_DIG__>
Expand All @@ -651,11 +646,6 @@ TOML_IMPL_NAMESPACE_START
template <>
struct value_traits<long double> : float_traits<long double>
{};
#ifdef TOML_FP16
template <>
struct value_traits<TOML_FP16> : float_traits<TOML_FP16>
{};
#endif
#ifdef TOML_FLOAT16
template <>
struct value_traits<TOML_FLOAT16> : float_traits<TOML_FLOAT16>
Expand Down
113 changes: 85 additions & 28 deletions include/toml++/impl/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#endif

//#=====================================================================================================================
//# COMPILER/OS/ARCH DETECTION
//# COMPILER / OS
//#=====================================================================================================================

#ifdef __clang__
Expand Down Expand Up @@ -75,11 +75,46 @@
#else
#define TOML_INTELLISENSE 0
#endif

//#=====================================================================================================================
//# ARCHITECTURE
//#=====================================================================================================================

// IA64
#if defined(__ia64__) || defined(__ia64) || defined(_IA64) || defined(__IA64__) || defined(_M_IA64)
#define TOML_ARCH_ITANIUM 1
#else
#define TOML_ARCH_ITANIUM 0
#endif

// AMD64
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
#define TOML_ARCH_AMD64 1
#else
#define TOML_ARCH_AMD64 0
#endif

// 32-bit x86
#if defined(__i386__) || defined(_M_IX86)
#define TOML_ARCH_X86 1
#else
#define TOML_ARCH_X86 0
#endif

// ARM
#if defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64) || defined(_M_ARM64) || defined(__ARM_64BIT_STATE) \
|| defined(__arm__) || defined(_M_ARM) || defined(__ARM_32BIT_STATE)
#define TOML_ARM 1
|| defined(_M_ARM64EC)
#define TOML_ARCH_ARM32 0
#define TOML_ARCH_ARM64 1
#define TOML_ARCH_ARM 1
#elif defined(__arm__) || defined(_M_ARM) || defined(__ARM_32BIT_STATE)
#define TOML_ARCH_ARM32 1
#define TOML_ARCH_ARM64 0
#define TOML_ARCH_ARM 1
#else
#define TOML_ARM 0
#define TOML_ARCH_ARM32 0
#define TOML_ARCH_ARM64 0
#define TOML_ARCH_ARM 0
#endif

//#=====================================================================================================================
Expand Down Expand Up @@ -1016,40 +1051,62 @@ TOML_ENABLE_WARNINGS;
//# }}

//#=====================================================================================================================
//# EXTENDED INT AND FLOAT TYPES
//# FLOAT16
//#=====================================================================================================================
// clang-format off

#ifdef __FLT16_MANT_DIG__
#if __FLT_RADIX__ == 2 \
&& __FLT16_MANT_DIG__ == 11 \
&& __FLT16_DIG__ == 3 \
&& __FLT16_MIN_EXP__ == -13 \
&& __FLT16_MIN_10_EXP__ == -4 \
&& __FLT16_MAX_EXP__ == 16 \
&& __FLT16_MAX_10_EXP__ == 4
#if TOML_ARM && (TOML_GCC || TOML_CLANG)
#define TOML_FP16 __fp16
#endif
#if TOML_ARM && TOML_CLANG // not present in g++
#define TOML_FLOAT16 _Float16
#endif
#endif
#if TOML_CLANG
//# {{
// Excerpt from https://clang.llvm.org/docs/LanguageExtensions.html:
//
// _Float16 is currently only supported on the following targets,
// with further targets pending ABI standardization:
//
// 32-bit ARM
// 64-bit ARM (AArch64)
// AMDGPU
// SPIR
// X86 as long as SSE2 is available
//
//# }}
#if (TOML_ARCH_ARM || TOML_ARCH_X86 || TOML_ARCH_AMD64) && defined(__FLT16_MANT_DIG__)
#define TOML_FLOAT16 _Float16
#endif
#elif TOML_GCC
//# {{
// Excerpt from https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html:
//
// The _Float16 type is supported on AArch64 systems by default, on ARM systems when the IEEE format for
// 16-bit floating-point types is selected with -mfp16-format=ieee and,
// for both C and C++, on x86 systems with SSE2 enabled.
//
// *** except: the bit about x86 seems incorrect?? ***
//# }}
/*
*/
#if (TOML_ARCH_ARM /*|| TOML_ARCH_X86 || TOML_ARCH_AMD64*/) && defined(__FLT16_MANT_DIG__)
#define TOML_FLOAT16 _Float16
#endif
#endif

#if defined(__SIZEOF_FLOAT128__) \
&& defined(__FLT128_MANT_DIG__) \
&& defined(__LDBL_MANT_DIG__) \
//#=====================================================================================================================
//# FLOAT128
//#=====================================================================================================================

#if defined(__SIZEOF_FLOAT128__) && defined(__FLT128_MANT_DIG__) && defined(__LDBL_MANT_DIG__) \
&& __FLT128_MANT_DIG__ > __LDBL_MANT_DIG__
#define TOML_FLOAT128 __float128
#define TOML_FLOAT128 __float128
#endif

//#=====================================================================================================================
//# INT128
//#=====================================================================================================================

#ifdef __SIZEOF_INT128__
#define TOML_INT128 __int128_t
#define TOML_UINT128 __uint128_t
#define TOML_INT128 __int128_t
#define TOML_UINT128 __uint128_t
#endif

// clang-format on
//#====================================================================================================================
//# VERSIONS AND NAMESPACES
//#====================================================================================================================
Expand Down
8 changes: 6 additions & 2 deletions include/toml++/toml.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ TOML_POP_WARNINGS;
#undef TOML_ANON_NAMESPACE
#undef TOML_ANON_NAMESPACE_END
#undef TOML_ANON_NAMESPACE_START
#undef TOML_ARM
#undef TOML_ARCH_ARM
#undef TOML_ARCH_AMD64
#undef TOML_ARCH_ARM32
#undef TOML_ARCH_ARM64
#undef TOML_ARCH_ITANIUM
#undef TOML_ARCH_X86
#undef TOML_ASSERT
#undef TOML_ASSERT_ASSUME
#undef TOML_ASSUME
Expand Down Expand Up @@ -127,7 +132,6 @@ TOML_POP_WARNINGS;
#undef TOML_FLOAT_CHARCONV
#undef TOML_FLOAT128
#undef TOML_FLOAT16
#undef TOML_FP16
#undef TOML_GCC
#undef TOML_HAS_ATTR
#undef TOML_HAS_BUILTIN
Expand Down
30 changes: 2 additions & 28 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ compiler_supports_char8_args = []
if is_gcc or is_clang
compiler_supports_char8_args += '-fchar8_t'
endif
compiler_supports_char8_args_private = []
compiler_supports_char8_args_private += compiler_supports_cpp20_args
compiler_supports_char8_args_private += compiler_supports_char8_args
compiler_supports_char8 = compiler_supports_cpp20 and compiler.links('''
#include <version>
#include <string_view>
Expand All @@ -278,7 +275,7 @@ compiler_supports_char8 = compiler_supports_cpp20 and compiler.links('''
}
''',
name: 'supports char8_t',
args: compiler_supports_char8_args_private
args: [ compiler_supports_cpp20_args, compiler_supports_char8_args ]
)

#######################################################################################################################
Expand Down Expand Up @@ -325,27 +322,6 @@ compiler_supports_consteval_properly = compiler_supports_consteval and not compi
# __fp16 and _Float16 checks
#######################################################################################################################

float_16_preprocessor_single_check_template = '''
#ifndef @0@
#error @0@ wasn't defined!
#else
#pragma message("@0@: " MAKE_STRING(@0@))
#endif
#if @0@ != @1@
#error @0@ was not @1@!
#endif
'''
float_16_preprocessor_checks = '''
#define MAKE_STRING(s) MAKE_STRING_1(s)
#define MAKE_STRING_1(s) #s
''' + float_16_preprocessor_single_check_template.format('__FLT_RADIX__', '2') \
+ float_16_preprocessor_single_check_template.format('__FLT16_MANT_DIG__', '11') \
+ float_16_preprocessor_single_check_template.format('__FLT16_DIG__', '3') \
+ float_16_preprocessor_single_check_template.format('__FLT16_MIN_EXP__', '-13') \
+ float_16_preprocessor_single_check_template.format('__FLT16_MIN_10_EXP__', '-4') \
+ float_16_preprocessor_single_check_template.format('__FLT16_MAX_EXP__', '16') \
+ float_16_preprocessor_single_check_template.format('__FLT16_MAX_10_EXP__', '4')

compiler_supports_float16_args = []
if is_gcc
compiler_supports_float16_args += '-mfp16-format=ieee'
Expand All @@ -364,8 +340,6 @@ compiler_supports_fp16 = compiler.links('''
args: compiler_supports_float16_args
)
compiler_supports_float16 = compiler.links('''
@0@
int main()
{
static_assert(sizeof(_Float16) == 2);
Expand All @@ -374,7 +348,7 @@ compiler_supports_float16 = compiler.links('''
const auto f3 = static_cast<_Float16>(0.2L);
return 0;
}
'''.format(float_16_preprocessor_checks),
''',
name: 'supports _Float16',
args: compiler_supports_float16_args
)
Expand Down
10 changes: 5 additions & 5 deletions tests/conformance_burntsushi_invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,16 @@ zyx = 42)"sv;
zyx = 42)"sv;
static constexpr auto table_quoted_no_close = R"(["where will it end]
name = value)"sv;
static constexpr auto table_redefine = R"(# Define b as int, and try to use it as a table: error
static constexpr auto table_redefine = R"(# Define b as int, and try to use it as a table: error
[a]
b = 1
[a.b]
c = 2)"sv;
static constexpr auto table_rrbrace = R"([[table] ])"sv;
static constexpr auto table_text_after_table = R"([error] this shouldn't be here)"sv;
static constexpr auto table_whitespace = R"([invalid key])"sv;
static constexpr auto table_with_pound = R"([key#group]
static constexpr auto table_rrbrace = R"([[table] ])"sv;
static constexpr auto table_text_after_table = R"([error] this shouldn't be here)"sv;
static constexpr auto table_whitespace = R"([invalid key])"sv;
static constexpr auto table_with_pound = R"([key#group]
answer = 42)"sv;
}

Expand Down
6 changes: 0 additions & 6 deletions tests/impl_toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ namespace toml
CHECK_CAN_REPRESENT_NATIVE(TOML_INT128, true);
CHECK_CAN_REPRESENT_NATIVE(TOML_UINT128, false);
#endif
#ifdef TOML_FP16
CHECK_CAN_REPRESENT_NATIVE(TOML_FP16, false);
#endif
#ifdef TOML_FLOAT16
CHECK_CAN_REPRESENT_NATIVE(TOML_FLOAT16, false);
#endif
Expand Down Expand Up @@ -292,9 +289,6 @@ namespace toml
CHECK_INSERTED_AS(uint32_t, value<int64_t>);
CHECK_INSERTED_AS(float, value<double>);
CHECK_INSERTED_AS(double, value<double>);
#ifdef TOML_FP16
CHECK_INSERTED_AS(TOML_FP16, value<double>);
#endif
#ifdef TOML_FLOAT16
CHECK_INSERTED_AS(TOML_FLOAT16, value<double>);
#endif
Expand Down
13 changes: 4 additions & 9 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ endif
#######################################################################################################################

compiler_supports_fast_math_args = []
if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang'
if is_gcc or is_clang
compiler_supports_fast_math_args += '-ffast-math'
compiler_supports_fast_math_args += '-ffp-contract=fast'
elif compiler.get_id() == 'msvc' or compiler.get_id() == 'intel-cl'
elif is_msvc or is_icc_cl
compiler_supports_fast_math_args += '/fp:fast'
endif
compiler_supports_fast_math = compiler.links('''
Expand Down Expand Up @@ -186,13 +186,8 @@ foreach cpp20 : cpp20_modes
test_args += compiler_supports_fast_math_args
endif

if compiler_supports_float16 or compiler_supports_fp16
if compiler_supports_fp16
test_args += '-DSHOULD_HAVE_FP16=1'
endif
if compiler_supports_float16
test_args += '-DSHOULD_HAVE_FLOAT16=1'
endif
if compiler_supports_float16
test_args += '-DSHOULD_HAVE_FLOAT16=1'
endif
if compiler_supports_int128
test_args += '-DSHOULD_HAVE_INT128=1'
Expand Down
20 changes: 17 additions & 3 deletions tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#else
#include "../include/toml++/toml.h"
#endif
#if defined(TOML_FP16) ^ SHOULD_HAVE_FP16
#error TOML_FP16 was not deduced correctly
#endif
#if defined(TOML_FLOAT16) ^ SHOULD_HAVE_FLOAT16
#error TOML_FLOAT16 was not deduced correctly
#endif
Expand Down Expand Up @@ -410,3 +407,20 @@ namespace Catch
extern template std::string stringify(const node_view<const node>&);
}
}

#if TOML_CPP >= 20 && TOML_CLANG && TOML_CLANG <= 14 // https://github.com/llvm/llvm-project/issues/55560

TOML_PUSH_WARNINGS;
TOML_DISABLE_WARNINGS;

namespace
{
[[maybe_unused]] static std::u8string clang_string_workaround(const char8_t* a, const char8_t* b)
{
return { a, b };
}
}

TOML_POP_WARNINGS;

#endif
Loading

0 comments on commit c8780a5

Please sign in to comment.