Skip to content

Commit

Permalink
Fix macos compilation
Browse files Browse the repository at this point in the history
 + fix some warnings
  • Loading branch information
sergcpp committed Mar 8, 2023
1 parent f6ee784 commit ccc7aeb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 2 additions & 2 deletions SWalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <assert.h>
#include <stdint.h>

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

Expand All @@ -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]);
}
Expand Down
16 changes: 4 additions & 12 deletions SWcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ inline unsigned long long _xgetbv(unsigned int index) {
// GCC Intrinsics
#include <cpuid.h>
#include <immintrin.h>
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__)
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions SWculling.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion SWculling_Ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/test_framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ void test_framebuffer() {
TEST_END;
}
}
#undef TEST_BEGIN
#undef TEST_END
3 changes: 3 additions & 0 deletions tests/test_pixels.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions tests/test_zbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ void test_zbuffer() {
TEST_END
}
}

#undef TEST_BEGIN
#undef TEST_END

0 comments on commit ccc7aeb

Please sign in to comment.