medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 56db176eadfa05b60f3eaaaa9cac38ac226498f2
parent 2c0ebd1fe78568d3deb3ab4fdfa46086cfc20b44
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Mon Oct 24 20:25:06 +0300

Remove check_*, INLINE -> forceinline

Diffstat:
int_conversions.h | 118++++++++++---------------------------------------------------------------------
1 file changed, 14 insertions(+), 104 deletions(-)
diff --git a/int_conversions.h b/int_conversions.h @@ -2,84 +2,12 @@ #define _INT_CONVERSIONS_H_ #include "intrinsics.h" +#include "platform_inline.h" /* - * check_T( x ) asserts that x is within T's min/max values and returns ( T ) x - * clamp_T( x ) returns ( T ) x clamped to T's min/max values + * clamping casts */ -#define IS_SIGNED( T ) ( ( T ) -1 < 0 ) - -template< typename T > -s64 check_s64( T x ) { - if( IS_SIGNED( T ) ) ASSERT( x >= S64_MIN ); - ASSERT( x <= S64_MAX ); - return ( s64 ) x; -} - -template< typename T > -s64 check_s64( T x ) { -#pragma GCC diagnostic push // GCC warns even though the optimiser removes the branch -#pragma GCC diagnostic ignored "-Wsign-compare" - if( IS_SIGNED( T ) ) ASSERT( x >= S64_MIN ); -#pragma GCC diagnostic pop - ASSERT( x <= S64_MAX ); - return ( s64 ) x; -} -template< typename T > -s32 check_s32( T x ) { - if( IS_SIGNED( T ) ) ASSERT( x >= S32_MIN ); - ASSERT( x <= S32_MAX ); - return ( s32 ) x; -} - -template< typename T > -s32 check_s32( T x ) { -#pragma GCC diagnostic push // GCC warns even though the optimiser removes the branch -#pragma GCC diagnostic ignored "-Wsign-compare" - if( IS_SIGNED( T ) ) ASSERT( x >= S32_MIN ); -#pragma GCC diagnostic pop - ASSERT( x <= S32_MAX ); - return ( s32 ) x; -} -template< typename T > -s16 check_s16( T x ) { - if( IS_SIGNED( T ) ) ASSERT( x >= S16_MIN ); - ASSERT( x <= S16_MAX ); - return ( s16 ) x; -} - -template< typename T > -s16 check_s16( T x ) { -#pragma GCC diagnostic push // GCC warns even though the optimiser removes the branch -#pragma GCC diagnostic ignored "-Wsign-compare" - if( IS_SIGNED( T ) ) ASSERT( x >= S16_MIN ); -#pragma GCC diagnostic pop - ASSERT( x <= S16_MAX ); - return ( s16 ) x; -} -template< typename T > -s8 check_s8( T x ) { - if( IS_SIGNED( T ) ) ASSERT( x >= S8_MIN ); - ASSERT( x <= S8_MAX ); - return ( s8 ) x; -} - -template< typename T > -s8 check_s8( T x ) { -#pragma GCC diagnostic push // GCC warns even though the optimiser removes the branch -#pragma GCC diagnostic ignored "-Wsign-compare" - if( IS_SIGNED( T ) ) ASSERT( x >= S8_MIN ); -#pragma GCC diagnostic pop - ASSERT( x <= S8_MAX ); - return ( s8 ) x; -} -template< typename T > -u64 check_u64( T x ) { - ASSERT( x >= 0 && x <= U64_MAX ); - return ( u64 ) x; -} - template< typename T > u64 clamp_u64( T x ) { if( x < 0 ) return 0; @@ -88,12 +16,6 @@ u64 clamp_u64( T x ) { } template< typename T > -u32 check_u32( T x ) { - ASSERT( x >= 0 && x <= U32_MAX ); - return ( u32 ) x; -} - -template< typename T > u32 clamp_u32( T x ) { if( x < 0 ) return 0; if( x > U32_MAX ) return U32_MAX; @@ -101,12 +23,6 @@ u32 clamp_u32( T x ) { } template< typename T > -u16 check_u16( T x ) { - ASSERT( x >= 0 && x <= U16_MAX ); - return ( u16 ) x; -} - -template< typename T > u16 clamp_u16( T x ) { if( x < 0 ) return 0; if( x > U16_MAX ) return U16_MAX; @@ -114,12 +30,6 @@ u16 clamp_u16( T x ) { } template< typename T > -u8 check_u8( T x ) { - ASSERT( x >= 0 && x <= U8_MAX ); - return ( u8 ) x; -} - -template< typename T > u8 clamp_u8( T x ) { if( x < 0 ) return 0; if( x > U8_MAX ) return U8_MAX; @@ -130,32 +40,32 @@ u8 clamp_u8( T x ) { * size preserving signed/unsigned conversions */ -INLINE s8 to_signed( u8 x ) { return ( s8 ) x; } -INLINE s16 to_signed( u16 x ) { return ( s16 ) x; } -INLINE s32 to_signed( u32 x ) { return ( s32 ) x; } -INLINE s64 to_signed( u64 x ) { return ( s64 ) x; } +forceinline s8 to_signed( u8 x ) { return ( s8 ) x; } +forceinline s16 to_signed( u16 x ) { return ( s16 ) x; } +forceinline s32 to_signed( u32 x ) { return ( s32 ) x; } +forceinline s64 to_signed( u64 x ) { return ( s64 ) x; } -INLINE u8 to_unsigned( s8 x ) { return ( u8 ) x; } -INLINE u16 to_unsigned( s16 x ) { return ( u16 ) x; } -INLINE u32 to_unsigned( s32 x ) { return ( u32 ) x; } -INLINE u64 to_unsigned( s64 x ) { return ( u64 ) x; } +forceinline u8 to_unsigned( s8 x ) { return ( u8 ) x; } +forceinline u16 to_unsigned( s16 x ) { return ( u16 ) x; } +forceinline u32 to_unsigned( s32 x ) { return ( u32 ) x; } +forceinline u64 to_unsigned( s64 x ) { return ( u64 ) x; } /* * quantization */ -INLINE u32 quantize01( float x, u32 num_bits ) { +forceinline u32 quantize01( float x, u32 num_bits ) { ASSERT( x >= 0.0f && x <= 1.0f ); return u32( x * checked_cast< float >( ( 1 << num_bits ) - 1 ) + 0.5f ); } -INLINE float dequantize01( u32 q, u32 num_bits ) { +forceinline float dequantize01( u32 q, u32 num_bits ) { float result = float( q ) / float( ( 1 << num_bits ) - 1 ); ASSERT( result >= 0.0f && result <= 1.0f ); return result; } -INLINE s32 quantize11( float x, u32 num_bits ) { +forceinline s32 quantize11s( float x, u32 num_bits ) { ASSERT( x >= -1.0f && x <= 1.0f ); num_bits--; if( x >= 0 ) { @@ -165,7 +75,7 @@ INLINE s32 quantize11( float x, u32 num_bits ) { return s32( x * checked_cast< float >( 1 << num_bits ) - 0.5f ); } -INLINE float dequantize11( s32 q, u32 num_bits ) { +forceinline float dequantize11s( s32 q, u32 num_bits ) { num_bits--; if( q >= 0 ) { float result = dequantize01( checked_cast< u32 >( q ), num_bits );