Skip to content

Commit

Permalink
Merge pull request #27 from maniatic0/main
Browse files Browse the repository at this point in the history
Simplified aligned memory functions for Emscripten
  • Loading branch information
jbikker authored Nov 23, 2024
2 parents 478cbf3 + 2227629 commit c4e47db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
25 changes: 2 additions & 23 deletions tiny_bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,9 @@ inline void* malloc64( size_t size, void* = nullptr )
}
inline void free64( void* ptr, void* = nullptr ) { _aligned_free( ptr ); }
}
#elif defined(__EMSCRIPTEN__) // EMSCRIPTEN - needs to be before gcc and clang to avoid misdetection
#else // EMSCRIPTEN / gcc / clang
#define ALIGNED( x ) __attribute__( ( aligned( x ) ) )
#if defined(__wasm_simd128__) || defined(__wasm_relaxed_simd__)
// https://emscripten.org/docs/porting/simd.html
#include <xmmintrin.h>
namespace tinybvh {
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : _mm_malloc( size, 64 );
}
inline void free64( void* ptr, void* = nullptr ) { _mm_free( ptr ); }
}
#else
namespace tinybvh {
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : aligned_alloc( 64, make_multiple_64( size ) );
}
inline void free64( void* ptr, void* = nullptr ) { free( ptr ); }
}
#endif
#else // gcc / clang
#define ALIGNED( x ) __attribute__( ( aligned( x ) ) )
#if defined(__x86_64__) || defined(_M_X64)
#if defined(__x86_64__) || defined(_M_X64) || defined(__wasm_simd128__) || defined(__wasm_relaxed_simd__)
#include <xmmintrin.h>
namespace tinybvh {
inline void* malloc64( size_t size, void* = nullptr )
Expand Down
25 changes: 2 additions & 23 deletions tiny_ocl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,9 @@ inline void* malloc64( size_t size, void* = nullptr )
}
inline void free64( void* ptr, void* = nullptr ) { _aligned_free( ptr ); }
}
#elif defined(__EMSCRIPTEN__) // EMSCRIPTEN - needs to be before gcc and clang to avoid misdetection
#else // EMSCRIPTEN / gcc / clang
#define ALIGNED( x ) __attribute__( ( aligned( x ) ) )
#if defined(__wasm_simd128__) || defined(__wasm_relaxed_simd__)
// https://emscripten.org/docs/porting/simd.html
#include <xmmintrin.h>
namespace tinyocl {
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : _mm_malloc( size, 64 );
}
inline void free64( void* ptr, void* = nullptr ) { _mm_free( ptr ); }
}
#else
namespace tinyocl {
inline void* malloc64( size_t size, void* = nullptr )
{
return size == 0 ? 0 : aligned_alloc( 64, make_multiple_64( size ) );
}
inline void free64( void* ptr, void* = nullptr ) { free( ptr ); }
}
#endif
#else // gcc / clang
#define ALIGNED( x ) __attribute__( ( aligned( x ) ) )
#if defined(__x86_64__) || defined(_M_X64)
#if defined(__x86_64__) || defined(_M_X64) || defined(__wasm_simd128__) || defined(__wasm_relaxed_simd__)
#include <xmmintrin.h>
namespace tinyocl {
inline void* malloc64( size_t size, void* = nullptr )
Expand Down

0 comments on commit c4e47db

Please sign in to comment.