Repository navigation
Performance optimizations from LLMs #156
lukevalenty
started this conversation in
General
Replies: 2 comments
|
Here's a simple one, the horizontal minimum NEON instruction was gated by On my MacBook Pro M5 Max: In @@ -524,31 +524,17 @@ static inline b3FloatW b3EqualsW( b3FloatW a, b3FloatW b )
return vreinterpretq_f32_u32( vceqq_f32( a, b ) );
}
+// B3_SIMD_NEON is only defined for AArch64, which has the horizontal reductions vminvq and vmaxvq.
static inline bool b3AllZeroW( b3FloatW a )
{
- // Create a zero vector for comparison
- b3FloatW zero = vdupq_n_f32( 0.0f );
-
- // Compare the input vector with zero
- uint32x4_t cmp_result = vceqq_f32( a, zero );
-
-// Check if all comparison results are non-zero using vminvq
-#ifdef __ARM_FEATURE_SVE
- // ARM v8.2+ has horizontal minimum instruction
- return vminvq_u32( cmp_result ) != 0;
-#else
- // For older ARM architectures, we need to manually check all lanes
- return vgetq_lane_u32( cmp_result, 0 ) != 0 && vgetq_lane_u32( cmp_result, 1 ) != 0 && vgetq_lane_u32( cmp_result, 2 ) != 0 &&
- vgetq_lane_u32( cmp_result, 3 ) != 0;
-#endif
+ uint32x4_t equalsZero = vceqq_f32( a, vdupq_n_f32( 0.0f ) );
+ return vminvq_u32( equalsZero ) != 0;
}
-// _mm_movemask_ps equivalent, compatible with ARM v7.
+// _mm_movemask_ps equivalent
static inline bool b3AnyTrueW( b3FloatW mask )
{
- uint32x4_t m = vreinterpretq_u32_f32( mask );
- uint32x2_t p = vorr_u32( vget_low_u32( m ), vget_high_u32( m ) );
- return ( vget_lane_u32( p, 0 ) | vget_lane_u32( p, 1 ) ) != 0;
+ return vmaxvq_u32( vreinterpretq_u32_f32( mask ) ) != 0;
}
// component-wise returns mask ? b : a |
0 replies
|
I'm happy to receive any performance optimization ideas. Thanks for humanizing them. :) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi @erincatto, pretty awesome library. I'm using it for an AI robot training gym and may have some performance optimizations for it. However, I'm using Fable 5.1 and GPT-6 Astra for the code and it looks like you prefer to write the production code yourself (or by another human).
I'm going to let the agents cook for a little bit and then I will post a summary of the optimizations in my own words here.
All reactions