1 #ifndef __MDFN_MATH_OPS_H 2 #define __MDFN_MATH_OPS_H 3 4 // Some compilers' optimizers and some platforms might fubar the generated code from these macros, 5 // so some tests are run in...tests.cpp 6 #define sign_8_to_s16(_value) ((int16)(int8)(_value)) 7 #define sign_9_to_s16(_value) (((int16)((unsigned int)(_value) << 7)) >> 7) 8 #define sign_10_to_s16(_value) (((int16)((uint32)(_value) << 6)) >> 6) 9 #define sign_11_to_s16(_value) (((int16)((uint32)(_value) << 5)) >> 5) 10 #define sign_12_to_s16(_value) (((int16)((uint32)(_value) << 4)) >> 4) 11 #define sign_13_to_s16(_value) (((int16)((uint32)(_value) << 3)) >> 3) 12 #define sign_14_to_s16(_value) (((int16)((uint32)(_value) << 2)) >> 2) 13 #define sign_15_to_s16(_value) (((int16)((uint32)(_value) << 1)) >> 1) 14 15 // This obviously won't convert higher-than-32 bit numbers to signed 32-bit ;) 16 // Also, this shouldn't be used for 8-bit and 16-bit signed numbers, since you can 17 // convert those faster with typecasts... 18 #define sign_x_to_s32(_bits, _value) (((int32)((uint32)(_value) << (32 - _bits))) >> (32 - _bits)) 19 20 #endif 21