File tree Expand file tree Collapse file tree 4 files changed +37
-22
lines changed
Expand file tree Collapse file tree 4 files changed +37
-22
lines changed Original file line number Diff line number Diff line change @@ -77,5 +77,10 @@ endif()
7777target_link_libraries (benchmark PUBLIC dragonbox::dragonbox_to_chars)
7878target_link_libraries (benchmark PUBLIC dragon_schubfach_lib)
7979target_link_libraries (benchmark PUBLIC dragon4_lib)
80- target_link_libraries (benchmark PUBLIC swift_lib)
80+ if (TARGET swift_lib)
81+ target_link_libraries (benchmark PUBLIC swift_lib)
82+ target_compile_definitions (benchmark PUBLIC SWIFT_LIB_SUPPORTED=1)
83+ else (TARGET swift_lib)
84+ target_compile_definitions (benchmark PUBLIC SWIFT_LIB_SUPPORTED=0)
85+ endif (TARGET swift_lib)
8186target_include_directories (benchmark PUBLIC ${grisu-exact_SOURCE_DIR})
Original file line number Diff line number Diff line change 3232#include " ryu/ryu.h"
3333#include " schubfach_32.h"
3434#include " schubfach_64.h"
35+ #if SWIFT_LIB_SUPPORTED
3536#include " swift/Runtime/SwiftDtoa.h"
37+ #endif
3638#if (__SIZEOF_INT128__ == 16) && (defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER))
3739#include " yy_double.h"
3840#define YY_DOUBLE_SUPPORTED 1
@@ -235,10 +237,15 @@ int double_conversion(T d, std::span<char>& buffer) {
235237
236238template <arithmetic_float T>
237239int swiftDtoa (T d, std::span<char >& buffer) {
240+ #if SWIFT_LIB_SUPPORTED
238241 if constexpr (std::is_same_v<T, float >)
239242 return swift_dtoa_optimal_float (d, buffer.data (), buffer.size ());
240243 else
241244 return swift_dtoa_optimal_double (d, buffer.data (), buffer.size ());
245+ #else
246+ std::cerr << " swift code not supported" << std::endl;
247+ std::abort ();
248+ #endif
242249}
243250
244251template <arithmetic_float T>
Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ int main(int argc, char **argv) {
197197 args[Benchmarks::ABSEIL] = { " abseil" , Benchmarks::abseil<T> , ABSEIL_SUPPORTED };
198198 args[Benchmarks::STD_TO_CHARS] = { " std::to_chars" , Benchmarks::std_to_chars<T> , TO_CHARS_SUPPORTED };
199199 args[Benchmarks::GRISU3] = { " grisu3" , Benchmarks::grisu3<T> , true };
200- args[Benchmarks::SWIFT_DTOA] = { " SwiftDtoa" , Benchmarks::swiftDtoa<T> , true };
200+ args[Benchmarks::SWIFT_DTOA] = { " SwiftDtoa" , Benchmarks::swiftDtoa<T> , SWIFT_LIB_SUPPORTED };
201201 args[Benchmarks::YY_DOUBLE] = { " yy_double" , Benchmarks::yy_double<T> , YY_DOUBLE_SUPPORTED };
202202 return args;
203203 };
Original file line number Diff line number Diff line change @@ -101,26 +101,29 @@ target_include_directories(dragon4_lib PUBLIC
101101 ${dragon4_SOURCE_DIR}
102102)
103103
104- FetchContent_Declare(
105- swift
106- GIT_REPOSITORY https://github.com/swiftlang/swift.git
107- GIT_TAG 6a862d2eb7128ff1f317b07e8ad1a6da939775f3
108- GIT_SHALLOW TRUE
109- )
110- FetchContent_GetProperties(swift)
111- if (NOT swift)
112- FetchContent_Populate(swift) # Downloads code to ${dragon4_SOURCE_DIR}
113- endif ()
114- set (swift_SOURCE_DIR ${swift_SOURCE_DIR} PARENT_SCOPE)
115- add_library (swift_lib STATIC
116- ${swift_SOURCE_DIR} /stdlib/public /runtime/SwiftDtoa.cpp
117- )
118- if (MATH_LIBRARY)
119- target_link_libraries (swift_lib PUBLIC ${MATH_LIBRARY} )
120- endif ()
121- target_include_directories (swift_lib PUBLIC
122- ${swift_SOURCE_DIR} /include
123- )
104+ # Swift code may not build under Windows without extra care.
105+ if (NOT WIN32 )
106+ FetchContent_Declare(
107+ swift
108+ GIT_REPOSITORY https://github.com/swiftlang/swift.git
109+ GIT_TAG 6a862d2eb7128ff1f317b07e8ad1a6da939775f3
110+ GIT_SHALLOW TRUE
111+ )
112+ FetchContent_GetProperties(swift)
113+ if (NOT swift)
114+ FetchContent_Populate(swift) # Downloads code to ${dragon4_SOURCE_DIR}
115+ endif ()
116+ set (swift_SOURCE_DIR ${swift_SOURCE_DIR} PARENT_SCOPE)
117+ add_library (swift_lib STATIC
118+ ${swift_SOURCE_DIR} /stdlib/public /runtime/SwiftDtoa.cpp
119+ )
120+ if (MATH_LIBRARY)
121+ target_link_libraries (swift_lib PUBLIC ${MATH_LIBRARY} )
122+ endif ()
123+ target_include_directories (swift_lib PUBLIC
124+ ${swift_SOURCE_DIR} /include
125+ )
126+ endif (NOT WIN32 )
124127
125128FetchContent_Declare(
126129 drachennest # for schubfach
You can’t perform that action at this time.
0 commit comments