Linux fixes (#3)

This commit is contained in:
Erin Catto 2026-05-12 22:24:23 -07:00 • committed by GitHub
commit 9b4aa025ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 24 deletions

View file

@ -2,10 +2,7 @@
name: CI Build
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
env:
BUILD_TYPE: Debug

View file

@ -22,6 +22,7 @@
#include <algorithm>
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <vector>

View file

@ -59,22 +59,13 @@ static inline b3V32 b3NegV( b3V32 a )
return _mm_sub_ps( _mm_setzero_ps(), a );
}
// Unaligned loads are much faster on recent hardware with little to no penalty
// Note: This may read one extra float beyond a b3Vec3 for performance. Address sanitizer
// is disabled for this function as the extra read is intentional and safe.
#if defined( __linux__ ) || defined( __APPLE__ ) || defined( __clang__ )
__attribute__( ( no_sanitize_address ) )
#elif defined( _MSC_VER )
__declspec( no_sanitize_address )
#endif
static inline b3V32
b3LoadV( const float* src )
static inline b3V32 b3LoadV( const float* src )
{
const __m128i masK3 = _mm_setr_epi32( 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0 );
// Read an extra float which gets zeroed (to avoid NaN or Inf)
b3V32 a = _mm_loadu_ps( src );
return _mm_and_ps( a, _mm_castsi128_ps( masK3 ) );
// Loads exactly 12 bytes: 8 via movsd, 4 via movss.
// Result lane 3 is implicitly zero from the partial loads.
__m128 xy = _mm_castpd_ps( _mm_load_sd( (const double*)( src ) ) );
__m128 z = _mm_load_ss( src + 2 );
return _mm_movelh_ps( xy, z ); // { src[0], src[1], src[2], 0.0f }
}
static inline b3V32 b3ZeroV( void )

View file

@ -15,6 +15,8 @@
#include <stdio.h>
#include <string.h>
#define NAME_LENGTH 16
#if defined( _WIN32 )
#ifndef WIN32_LEAN_AND_MEAN
@ -139,7 +141,7 @@ typedef struct b3Thread
HANDLE thread;
b3ThreadFunction* function;
void* context;
char name[32];
char name[NAME_LENGTH];
} b3Thread;
typedef HRESULT( WINAPI* b3SetThreadDescriptionFn )( HANDLE, PCWSTR );
@ -176,7 +178,7 @@ static void b3SetCurrentThreadName( const char* name )
return;
}
wchar_t wide[32];
wchar_t wide[NAME_LENGTH];
int n = MultiByteToWideChar( CP_UTF8, 0, name, -1, wide, (int)( sizeof( wide ) / sizeof( wide[0] ) ) );
if ( n > 0 )
{
@ -314,7 +316,7 @@ typedef struct b3Thread
pthread_t thread;
b3ThreadFunction* function;
void* context;
char name[32];
char name[NAME_LENGTH];
} b3Thread;
static void b3SetCurrentThreadName( const char* name )
@ -326,7 +328,7 @@ static void b3SetCurrentThreadName( const char* name )
#if defined( __linux__ )
// Linux caps thread names at 15 chars + null terminator.
char truncated[16];
char truncated[NAME_LENGTH];
snprintf( truncated, sizeof( truncated ), "%s", name );
pthread_setname_np( pthread_self(), truncated );
#else
@ -490,7 +492,7 @@ typedef struct b3Thread
pthread_t thread;
b3ThreadFunction* function;
void* context;
char name[32];
char name[NAME_LENGTH];
} b3Thread;
// macOS pthread_setname_np takes only the name — it always names the calling thread.