From 8c535748eeb5d88e5f55964b821f52bfec239455 Mon Sep 17 00:00:00 2001 From: Erin Catto Date: Wed, 27 Dec 2023 21:21:40 -0800 Subject: [PATCH] Trim SIMDE and more cmake cleanup (#90) Could not remove float16 stuff without major modification --- CMakeLists.txt | 2 +- extern/simde/CMakeLists.txt | 1 - extern/simde/simde-bf16.h | 131 ------------------------------------ samples/CMakeLists.txt | 7 +- src/CMakeLists.txt | 16 ++--- test/CMakeLists.txt | 4 +- 6 files changed, 8 insertions(+), 153 deletions(-) delete mode 100644 extern/simde/simde-bf16.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c45ae6fc..0ec41887 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,7 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) FetchContent_MakeAvailable(enkits) # Tests need static linkage because they test internal Box2D functions - if (NOT ${BUILD_SHARED_LIBS}) + if (NOT BUILD_SHARED_LIBS) message(STATUS "Adding Box2D unit tests") add_subdirectory(test) else() diff --git a/extern/simde/CMakeLists.txt b/extern/simde/CMakeLists.txt index a664b540..e773d7f1 100644 --- a/extern/simde/CMakeLists.txt +++ b/extern/simde/CMakeLists.txt @@ -8,7 +8,6 @@ add_library( simde-aes.h simde-align.h simde-arch.h - simde-bf16.h simde-common.h simde-complex.h simde-constify.h diff --git a/extern/simde/simde-bf16.h b/extern/simde/simde-bf16.h deleted file mode 100644 index 7e073685..00000000 --- a/extern/simde/simde-bf16.h +++ /dev/null @@ -1,131 +0,0 @@ -/* SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Copyright: - * 2023 Yi-Yen Chung (Copyright owned by Andes Technology) - */ - -#include "hedley.h" -#include "simde-common.h" -#include "simde-detect-clang.h" - -#if !defined(SIMDE_BFLOAT16_H) -#define SIMDE_BFLOAT16_H - -HEDLEY_DIAGNOSTIC_PUSH -SIMDE_DISABLE_UNWANTED_DIAGNOSTICS -SIMDE_BEGIN_DECLS_ - -/* This implementations is based upon simde-f16.h */ - -/* Portable version which should work on pretty much any compiler. - * Obviously you can't rely on compiler support for things like - * conversion to/from 32-bit floats, so make sure you always use the - * functions and macros in this file! - */ -#define SIMDE_BFLOAT16_API_PORTABLE 1 - -#define SIMDE_BFLOAT16_API_BF16 2 - -#if !defined(SIMDE_BFLOAT16_API) - #if defined(SIMDE_ARM_NEON_BF16) - #define SIMDE_BFLOAT16_API SIMDE_BFLOAT16_API_BF16 - #else - #define SIMDE_BFLOAT16_API SIMDE_BFLOAT16_API_PORTABLE - #endif -#endif - -#if SIMDE_BFLOAT16_API == SIMDE_BFLOAT16_API_BF16 - #include - typedef __bf16 simde_bfloat16; -#elif SIMDE_BFLOAT16_API == SIMDE_BFLOAT16_API_PORTABLE - typedef struct { uint16_t value; } simde_bfloat16; -#else - #error No 16-bit floating point API. -#endif - -/* Conversion -- convert between single-precision and brain half-precision - * floats. */ -static HEDLEY_ALWAYS_INLINE HEDLEY_CONST -simde_bfloat16 -simde_bfloat16_from_float32 (simde_float32 value) { -#if defined(SIMDE_ARM_NEON_A32V8_NATIVE) && defined(SIMDE_ARM_NEON_BF16) - return vcvth_bf16_f32(value); -#else - simde_bfloat16 res; - char* src = HEDLEY_REINTERPRET_CAST(char*, &value); - // rounding to nearest bfloat16 - // If the 17th bit of value is 1, set the rounding to 1. - uint8_t rounding = 0; - - #if SIMDE_ENDIAN_ORDER == SIMDE_ENDIAN_LITTLE - if (src[1] & UINT8_C(0x80)) rounding = 1; - src[2] = HEDLEY_STATIC_CAST(char, (HEDLEY_STATIC_CAST(uint8_t, src[2]) + rounding)); - simde_memcpy(&res, src+2, sizeof(res)); - #else - if (src[2] & UINT8_C(0x80)) rounding = 1; - src[1] = HEDLEY_STATIC_CAST(char, (HEDLEY_STATIC_CAST(uint8_t, src[1]) + rounding)); - simde_memcpy(&res, src, sizeof(res)); - #endif - - return res; -#endif -} - -static HEDLEY_ALWAYS_INLINE HEDLEY_CONST -simde_float32 -simde_bfloat16_to_float32 (simde_bfloat16 value) { -#if defined(SIMDE_ARM_NEON_A32V8_NATIVE) && defined(SIMDE_ARM_NEON_BF16) - return vcvtah_f32_bf16(value); -#else - simde_float32 res = 0.0; - char* _res = HEDLEY_REINTERPRET_CAST(char*, &res); - - #if SIMDE_ENDIAN_ORDER == SIMDE_ENDIAN_LITTLE - simde_memcpy(_res+2, &value, sizeof(value)); - #else - simde_memcpy(_res, &value, sizeof(value)); - #endif - - return res; -#endif -} - -SIMDE_DEFINE_CONVERSION_FUNCTION_(simde_uint16_as_bfloat16, simde_bfloat16, uint16_t) - -#define SIMDE_NANBF simde_uint16_as_bfloat16(0xFFC1) // a quiet Not-a-Number -#define SIMDE_INFINITYBF simde_uint16_as_bfloat16(0x7F80) -#define SIMDE_NINFINITYBF simde_uint16_as_bfloat16(0xFF80) - -#define SIMDE_BFLOAT16_VALUE(value) simde_bfloat16_from_float32(SIMDE_FLOAT32_C(value)) - -#if !defined(simde_isinfbf) && defined(simde_math_isinff) - #define simde_isinfbf(a) simde_math_isinff(simde_bfloat16_to_float32(a)) -#endif -#if !defined(simde_isnanbf) && defined(simde_math_isnanf) - #define simde_isnanbf(a) simde_math_isnanf(simde_bfloat16_to_float32(a)) -#endif - -SIMDE_END_DECLS_ -HEDLEY_DIAGNOSTIC_POP - -#endif /* !defined(SIMDE_BFLOAT16_H) */ diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 2b97a169..1fe15d06 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -55,7 +55,7 @@ set(JSMN_DIR ${CMAKE_SOURCE_DIR}/extern/jsmn) add_library(jsmn INTERFACE ${JSMN_DIR}/jsmn.h) target_include_directories(jsmn INTERFACE ${JSMN_DIR}) -set(BOX2D_SAMPLES +add_executable(samples draw.cpp draw.h main.cpp @@ -63,7 +63,6 @@ set(BOX2D_SAMPLES sample.h settings.h settings.cpp - collection/benchmark.cpp collection/human.cpp collection/human.h @@ -85,8 +84,6 @@ set(BOX2D_SAMPLES collection/sample_vertical_stack.cpp ) -add_executable(samples ${BOX2D_SAMPLES}) - set_target_properties(samples PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES @@ -107,4 +104,4 @@ add_custom_command( ${CMAKE_CURRENT_SOURCE_DIR}/data/ ${CMAKE_CURRENT_BINARY_DIR}/data/) -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${BOX2D_SAMPLES}) +# source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${BOX2D_SAMPLES}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd87858c..eba33982 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -85,12 +85,7 @@ set(BOX2D_API_FILES set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) -if (MSVC) - # Visual Studio won't load the natvis unless it is in the project - add_library(box2d ${BOX2D_SOURCE_FILES} ${BOX2D_API_FILES} box2d.natvis) -else() - add_library(box2d ${BOX2D_SOURCE_FILES} ${BOX2D_API_FILES}) -endif() +add_library(box2d ${BOX2D_SOURCE_FILES} ${BOX2D_API_FILES}) # Generate box2d_export.h to handles shared library builds include(GenerateExportHeader) @@ -118,6 +113,9 @@ set_target_properties(box2d PROPERTIES ) if (MSVC) + # Visual Studio won't load the natvis unless it is in the project + target_sources(box2d PRIVATE box2d.natvis) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # Atomics are still considered experimental in Visual Studio 17.8 target_compile_options(box2d PRIVATE /experimental:c11atomics /arch:AVX2) @@ -138,12 +136,6 @@ elseif (APPLE) # target_compile_options(box2d PRIVATE) endif() -# todo needed? -find_library(MATH_LIBRARY m) -if (MATH_LIBRARY) - target_link_libraries(box2d PUBLIC ${MATH_LIBRARY}) -endif() - if (BOX2D_PROFILE) target_compile_definitions(box2d PRIVATE BOX2D_PROFILE) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9a1f386c..93261ddc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,6 @@ # Box2D unit test app -set(BOX2D_TESTS +add_executable(test main.c test_bitset.c test_collision.c @@ -13,8 +13,6 @@ set(BOX2D_TESTS test_world.c ) -add_executable(test ${BOX2D_TESTS}) - set_target_properties(test PROPERTIES C_STANDARD 17 C_STANDARD_REQUIRED YES