From ccc7aebf2b65907d3e21730e1b3fb44c39c64343 Mon Sep 17 00:00:00 2001 From: Serhii Yablokov Date: Wed, 8 Mar 2023 22:41:24 +0100 Subject: [PATCH] Fix macos compilation + fix some warnings --- CMakeLists.txt | 12 ++++++++---- SWalloc.h | 4 ++-- SWcpu.c | 16 ++++------------ SWculling.c | 8 ++++---- SWculling_Ref.c | 2 +- tests/test_framebuffer.c | 2 ++ tests/test_pixels.c | 3 +++ tests/test_zbuffer.c | 3 +++ 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 861bca1..2df1460 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,12 +58,16 @@ if(MSVC) else() set_source_files_properties(_SW_SSE2.c PROPERTIES COMPILE_FLAGS "/O2 /Ob2") endif() - set_source_files_properties(_SW_AVX2.c PROPERTIES COMPILE_FLAGS "/arch:AVX /O2 /Ob2") + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set_source_files_properties(_SW.c PROPERTIES COMPILE_FLAGS -msse4.1) + set_source_files_properties(_SW_SSE2.c PROPERTIES COMPILE_FLAGS -msse4.1) + endif() + set_source_files_properties(_SW_AVX2.c PROPERTIES COMPILE_FLAGS "/arch:AVX2 /O2 /Ob2") set_source_files_properties(_SW_AVX512.c PROPERTIES COMPILE_FLAGS "/arch:AVX512 /O2 /Ob2") else(MSVC) - set_source_files_properties(_SW_SSE2.c PROPERTIES COMPILE_FLAGS -msse2) - set_source_files_properties(_SW_AVX2.c PROPERTIES COMPILE_FLAGS "-mavx2 -mfma") - set_source_files_properties(_SW_AVX512.c PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq") + set_source_files_properties(_SW_SSE2.c PROPERTIES COMPILE_FLAGS "-msse2 -O2") + set_source_files_properties(_SW_AVX2.c PROPERTIES COMPILE_FLAGS "-mavx2 -mfma -O2") + set_source_files_properties(_SW_AVX512.c PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq -O2") endif(MSVC) add_library(SW STATIC ${ALL_SOURCE_FILES}) diff --git a/SWalloc.h b/SWalloc.h index 68686c9..7a3906c 100644 --- a/SWalloc.h +++ b/SWalloc.h @@ -4,7 +4,7 @@ #include #include -inline void* sw_aligned_malloc(size_t size, size_t alignment) { +static inline void* sw_aligned_malloc(size_t size, size_t alignment) { assert(alignment > sizeof(void *)); size_t space = size + (alignment - 1); @@ -29,7 +29,7 @@ inline void* sw_aligned_malloc(size_t size, size_t alignment) { return ptr; } -inline void sw_aligned_free(void* p) { +static inline void sw_aligned_free(void* p) { if (p) { free(((void **)p)[-1]); } diff --git a/SWcpu.c b/SWcpu.c index 768424f..59abd7c 100644 --- a/SWcpu.c +++ b/SWcpu.c @@ -33,7 +33,7 @@ inline unsigned long long _xgetbv(unsigned int index) { // GCC Intrinsics #include #include -inline void cpuid(int info[4], int InfoType) { +static inline void cpuid(int info[4], int InfoType) { __cpuid_count(InfoType, 0, info[0], info[1], info[2], info[3]); } #if defined(__GNUC__) && (__GNUC__ < 9) && !defined(__APPLE__) @@ -86,10 +86,10 @@ void swCPUInfoInit(SWcpu_info *info) { unsigned nExIds, i = 0; char CPUBrandString[0x40]; // Get the information associated with each extended ID. - __cpuid(CPUInfo, 0x80000000); + cpuid(CPUInfo, 0x80000000); nExIds = CPUInfo[0]; for (i = 0x80000000; i <= nExIds; ++i) { - __cpuid(CPUInfo, i); + cpuid(CPUInfo, i); // Interpret CPU brand string if (i == 0x80000002) memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo)); @@ -113,7 +113,7 @@ void swCPUInfoInit(SWcpu_info *info) { info->physical_memory = ((statex.ullTotalPhys / 1024.0f) / 1024) / 1024; char vendor[13]; - __cpuid(CPUInfo, 0); + cpuid(CPUInfo, 0); memcpy(vendor, &CPUInfo[1], 4); // copy EBX memcpy(vendor + 4, &CPUInfo[2], 4); // copy ECX memcpy(vendor + 8, &CPUInfo[3], 4); // copy EDX @@ -212,14 +212,6 @@ void swCPUInfoInit(SWcpu_info *info) { #endif } -#if !defined(_WIN32) && !defined(__linux) || defined(__ANDROID__) - -void swCInfoInit(SWcpu_info *info) { - memset(info, 0, sizeof(SWcpu_info)); -} - -#endif - void swCPUInfoDestroy(SWcpu_info *info) { free(info->vendor); free(info->model); diff --git a/SWculling.c b/SWculling.c index 32c5048..e2d1751 100644 --- a/SWculling.c +++ b/SWculling.c @@ -10,14 +10,14 @@ SWint _swCullCtxTestRect_Ref(const SWcull_ctx *ctx, const SWfloat p_min[2], cons void _swCullCtxClearBuf_Ref(SWcull_ctx *ctx); void _swCullCtxDebugDepth_Ref(const SWcull_ctx *ctx, SWfloat *out_depth); -#ifdef __aarch64__ +#if defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64) SWint _swProcessTrianglesIndexed_NEON(SWcull_ctx *ctx, const void *attribs, const SWuint *indices, SWuint stride, SWuint index_count, const SWfloat *xform, SWint is_occluder); SWint _swCullCtxTestRect_NEON(const SWcull_ctx *ctx, const SWfloat p_min[2], const SWfloat p_max[3], const SWfloat w_min); void _swCullCtxClearBuf_NEON(SWcull_ctx *ctx); void _swCullCtxDebugDepth_NEON(const SWcull_ctx *ctx, SWfloat *out_depth); -#else // __aarch64__ +#else // defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64) SWint _swProcessTrianglesIndexed_SSE2(SWcull_ctx *ctx, const void *attribs, const SWuint *indices, SWuint stride, SWuint index_count, const SWfloat *xform, SWint is_occluder); SWint _swProcessTrianglesIndexed_AVX2(SWcull_ctx *ctx, const void *attribs, const SWuint *indices, SWuint stride, @@ -42,7 +42,7 @@ SWint _swCullCtxTestRect_AVX512(const SWcull_ctx *ctx, const SWfloat p_min[2], c void _swCullCtxClearBuf_AVX512(SWcull_ctx *ctx); void _swCullCtxDebugDepth_AVX512(const SWcull_ctx *ctx, SWfloat *out_depth); #endif -#endif // __aarch64__ +#endif // defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64) void swCullCtxInit(SWcull_ctx *ctx, const SWint w, const SWint h, SWfloat near_clip) { swCPUInfoInit(&ctx->cpu_info); @@ -70,7 +70,7 @@ void swCullCtxResize(SWcull_ctx *ctx, const SWint w, const SWint h, SWfloat near ctx->half_w = (SWfloat)w / 2; ctx->half_h = (SWfloat)h / 2; -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64) ctx->tile_size_y = 4; ctx->subtile_size_y = 4; ctx->tri_indexed_proc = (SWCullTrianglesIndexedProcType)&_swProcessTrianglesIndexed_NEON; diff --git a/SWculling_Ref.c b/SWculling_Ref.c index 4fe8aa0..bc358d4 100644 --- a/SWculling_Ref.c +++ b/SWculling_Ref.c @@ -353,7 +353,7 @@ SWint _swRasterizeTriangle_Ref(SWcull_ctx *ctx, SWint tile_row_ndx, tri_event[1] = event_start[1]; tri_event[2] = event_start[2]; - SWint start_delta, end_delta, top_delta, start_event = 0, end_event = 0, top_event; + SWint start_delta = 0, end_delta = 0, top_delta = 0, start_event = 0, end_event = 0, top_event = 0; if (use_tight_traversal) { start_delta = slope_tile_delta[2] + LEFT_EDGE_BIAS; end_delta = slope_tile_delta[0] + RIGHT_EDGE_BIAS; diff --git a/tests/test_framebuffer.c b/tests/test_framebuffer.c index 04294c8..4c9fd6d 100644 --- a/tests/test_framebuffer.c +++ b/tests/test_framebuffer.c @@ -98,3 +98,5 @@ void test_framebuffer() { TEST_END; } } +#undef TEST_BEGIN +#undef TEST_END \ No newline at end of file diff --git a/tests/test_pixels.c b/tests/test_pixels.c index 5ec0d7a..58af563 100644 --- a/tests/test_pixels.c +++ b/tests/test_pixels.c @@ -284,3 +284,6 @@ void test_pixels() { REQUIRE_VEC4_EQ(&bgra_buf[4 * (4 * 3 + 3)], 255, 0, 255, 0); } } + +#undef REQUIRE_VEC4_EQ +#undef REQUIRE_FVEC4_EQ diff --git a/tests/test_zbuffer.c b/tests/test_zbuffer.c index 2eb8322..cb58923 100644 --- a/tests/test_zbuffer.c +++ b/tests/test_zbuffer.c @@ -87,3 +87,6 @@ void test_zbuffer() { TEST_END } } + +#undef TEST_BEGIN +#undef TEST_END