forked from madmann91/bvh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor platform-specific intrinsics to avoid the use of
__
and us…
…e functions instead of macros whenever possible
- Loading branch information
Showing
14 changed files
with
113 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,46 @@ | ||
#ifndef BVH_PLATFORM_HPP | ||
#define BVH_PLATFORM_HPP | ||
|
||
#include <cstddef> | ||
#include <cassert> | ||
|
||
#ifdef _OPENMP | ||
#include <omp.h> | ||
#include <cassert> | ||
#define bvh__get_num_threads() omp_get_num_threads() | ||
#define bvh__get_thread_num() omp_get_thread_num() | ||
#define bvh__assert_not_in_parallel() assert(omp_get_level() == 0); | ||
#define bvh__assert_in_parallel() assert(omp_get_level() > 0); | ||
#else | ||
#define bvh__get_num_threads() 1 | ||
#define bvh__get_thread_num() 0 | ||
#define bvh__assert_not_in_parallel() (void)0 | ||
#define bvh__assert_in_parallel() (void)0 | ||
#endif | ||
|
||
#if defined(__GNUC__) || defined(__clang__) | ||
#define bvh__restrict__ __restrict | ||
#define bvh__always_inline__ __attribute__((always_inline)) | ||
#define bvh__likely(x) __builtin_expect(x, true) | ||
#define bvh__unlikely(x) __builtin_expect(x, false) | ||
#define bvh_restrict __restrict | ||
#define bvh_always_inline __attribute__((always_inline)) | ||
#elif defined(_MSC_VER) | ||
#define bvh__restrict__ __restrict | ||
#define bvh__always_inline__ __forceinline | ||
#define bvh__likely(x) x | ||
#define bvh__unlikely(x) x | ||
#define bvh_restrict __restrict | ||
#define bvh_always_inline __forceinline | ||
#else | ||
#define bvh_restrict | ||
#define bvh_always_inline | ||
#endif | ||
|
||
#if defined(__GNUC__) || defined(__clang__) | ||
#define bvh_likely(x) __builtin_expect(x, true) | ||
#define bvh_unlikely(x) __builtin_expect(x, false) | ||
#else | ||
#define bvh__restrict__ | ||
#define bvh__always_inline__ | ||
#define bvh__likely(x) x | ||
#define bvh__unlikely(x) x | ||
#define bvh_likely(x) x | ||
#define bvh_unlikely(x) x | ||
#endif | ||
|
||
namespace bvh { | ||
|
||
#ifdef _OPENMP | ||
inline size_t get_thread_count() { return omp_get_num_threads(); } | ||
inline size_t get_thread_id() { return omp_get_thread_num(); } | ||
inline void assert_not_in_parallel() { assert(omp_get_level() == 0); } | ||
inline void assert_in_parallel() { assert(omp_get_level() > 0); } | ||
#else | ||
inline constexpr size_t get_thread_count() { return 1; } | ||
inline constexpr size_t get_thread_id() { return 0; } | ||
inline void assert_not_in_parallel() {} | ||
inline void assert_in_parallel() {} | ||
#endif | ||
|
||
} // namespace bvh | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.