Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions common/cmake/clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ MACRO(_SET_IF_EMPTY VAR VALUE)
ENDIF()
ENDMACRO()

# Detect ARM64 for Windows
IF(WIN32 AND (CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|aarch64|arm64"))
SET(EMBREE_ARM TRUE)
MESSAGE(STATUS "Detected Windows ARM64 build")
ENDIF()

IF (EMBREE_ARM)
IF ("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
# set ARM an x86 flags for macOS universal binary build
Expand All @@ -16,12 +22,15 @@ IF (EMBREE_ARM)
SET(FLAGS_AVX2 "-D__AVX2__ -D__AVX__ -D__SSE4_2__ -D__SSE4_1__ -D__BMI__ -D__BMI2__ -D__LZCNT__ -mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2")
_SET_IF_EMPTY(FLAGS_AVX512 "-march=skx")
ELSE ()
SET(FLAGS_SSE2 "-D__SSE__ -D__SSE2__")
SET(FLAGS_SSE42 "-D__SSE4_2__ -D__SSE4_1__")
SET(FLAGS_AVX "-D__AVX__ -D__SSE4_2__ -D__SSE4_1__ -D__BMI__ -D__BMI2__ -D__LZCNT__")
SET(FLAGS_AVX2 "-D__AVX2__ -D__AVX__ -D__SSE4_2__ -D__SSE4_1__ -D__BMI__ -D__BMI2__ -D__LZCNT__")
# Pure ARM build - no x86 flags
SET(FLAGS_SSE2 "")
SET(FLAGS_SSE42 "")
SET(FLAGS_AVX "")
SET(FLAGS_AVX2 "")
SET(FLAGS_AVX512 "")
ENDIF ()
ELSE ()
# x86/x64 build - set SSE/AVX flags
# for `thread` keyword
_SET_IF_EMPTY(FLAGS_SSE2 "-msse -msse2 -mno-sse4.2")
_SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2")
Expand All @@ -36,7 +45,12 @@ IF (WIN32)
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /EHsc") # catch C++ exceptions only and extern "C" functions never throw a C++ exception
# SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /MP") # compile source files in parallel
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /GR") # enable runtime type information (on by default)
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -Xclang -fcxx-exceptions") # enable C++ exceptions in Clang

# Only add Clang-specific exception flags if not using MSVC
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -Xclang -fcxx-exceptions") # enable C++ exceptions in Clang
ENDIF()

SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /w") # disable all warnings
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /Gy") # package individual functions
IF (EMBREE_STACK_PROTECTOR)
Expand Down
13 changes: 8 additions & 5 deletions common/cmake/dpcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ MACRO(_SET_IF_EMPTY VAR VALUE)
ENDIF()
ENDMACRO()

_SET_IF_EMPTY(FLAGS_SSE2 "-msse2")
_SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2")
_SET_IF_EMPTY(FLAGS_AVX "-mavx")
_SET_IF_EMPTY(FLAGS_AVX2 "-mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2")
_SET_IF_EMPTY(FLAGS_AVX512 "-march=skx")
# Skip x86-only ISA flags on Windows ARM64
IF(NOT (WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|aarch64|arm64"))
_SET_IF_EMPTY(FLAGS_SSE2 "-msse2")
_SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2")
_SET_IF_EMPTY(FLAGS_AVX "-mavx")
_SET_IF_EMPTY(FLAGS_AVX2 "-mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2")
_SET_IF_EMPTY(FLAGS_AVX512 "-march=skx")
ENDIF()

IF (NOT WIN32)
OPTION(EMBREE_IGNORE_CMAKE_CXX_FLAGS "When enabled Embree ignores default CMAKE_CXX_FLAGS." ON)
Expand Down
10 changes: 8 additions & 2 deletions common/simd/arm/sse2neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
* x86 SSE. (e.g. would solve a hole or NaN pixel in the rendering result)
*/
/* _mm_min|max_ps|ss|pd|sd */
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#endif
#ifndef SSE2NEON_PRECISE_MINMAX
#define SSE2NEON_PRECISE_MINMAX (0)
#endif
Expand Down Expand Up @@ -9038,7 +9044,7 @@ FORCE_INLINE int _sse2neon_sido_negative(int res, int lb, int imm8, int bound)
FORCE_INLINE int _sse2neon_clz(unsigned int x)
{
#if _MSC_VER
unsigned long cnt = 0;
DWORD cnt = 0;
if (_BitScanForward(&cnt, x))
return cnt;
return 32;
Expand All @@ -9050,7 +9056,7 @@ FORCE_INLINE int _sse2neon_clz(unsigned int x)
FORCE_INLINE int _sse2neon_ctz(unsigned int x)
{
#if _MSC_VER
unsigned long cnt = 0;
DWORD cnt = 0;
if (_BitScanReverse(&cnt, x))
return 31 - cnt;
return 32;
Expand Down
7 changes: 7 additions & 0 deletions common/sys/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

#pragma once

// Prevent Windows from defining min/max macros that conflict with std::numeric_limits
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#endif

#if !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
Expand Down
2 changes: 1 addition & 1 deletion common/tasking/taskschedulertbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace embree
#endif

/* now either keep default settings or configure number of threads */
if (numThreads == std::numeric_limits<size_t>::max()) {
if (numThreads == (std::numeric_limits<size_t>::max)()) { // parentheses defeat Windows max() macro
numThreads = threadCount();
}
else {
Expand Down