00001 #include "ssDefs.hpp"
00002
00003 #undef NDEBUG // we need to get the real assertion routines...
00004
00005 #include <cassert>
00006 #include <cstdio>
00007
00008 using namespace SS;
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 void SS::assertFail (const char* expr, const char* file, int line, const char* )
00020 {
00021 #if defined (SS_BUILD_ACC)
00022 __assert((const char*)expr,(const char*)file,line);
00023 #elif defined (SS_BUILD_GCC) && defined (SS_OS_LINUX)
00024 __assert_fail(expr,file,line,"unknown function");
00025 #elif defined (SS_BUILD_GCC) && defined (SS_OS_MAC)
00026 __assert((const char*)expr,file,line);
00027 #elif defined (SS_BUILD_GCC)
00028 __assert((const char*)expr,line,file);
00029 #elif defined (SS_BUILD_CW)
00030 __assertion_failed((char*)expr,(const char*)file,line);
00031 #elif defined (SS_BUILD_BC)
00032 _assert((const char*)expr,(const char*)file,line);
00033 #elif defined (SS_BUILD_IVA)
00034 _assert(expr,file,line);
00035 #else
00036
00037 #endif
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 int SS::intChop (const float& f)
00050 {
00051 INT32 a = *reinterpret_cast<const INT32*>(&f);
00052 INT32 sign = (a>>31);
00053 INT32 mantissa = (a&((1<<23)-1))|(1<<23);
00054 INT32 exponent = ((a&0x7fffffff)>>23)-127;
00055 INT32 r = ((UINT32)(mantissa)<<8)>>(31-exponent);
00056 return ((r ^ (sign)) - sign ) &~ (exponent>>31);
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 int SS::intFloor (const float& f)
00068 {
00069 INT32 a = *reinterpret_cast<const INT32*>(&f);
00070 INT32 sign = (a>>31);
00071 a&=0x7fffffff;
00072 INT32 exponent = (a>>23)-127;
00073 INT32 expsign = ~(exponent>>31);
00074 INT32 imask = ( (1<<(31-(exponent))))-1;
00075 INT32 mantissa = (a&((1<<23)-1));
00076 INT32 r = ((UINT32)(mantissa|(1<<23))<<8)>>(31-exponent);
00077 r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign);
00078 return r;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 int SS::intCeil (const float& f)
00090 {
00091 INT32 a = *reinterpret_cast<const INT32*>(&f) ^ 0x80000000;
00092 INT32 sign = (a>>31);
00093 a&=0x7fffffff;
00094 INT32 exponent = (a>>23)-127;
00095 INT32 expsign = ~(exponent>>31);
00096 INT32 imask = ( (1<<(31-(exponent))))-1;
00097 INT32 mantissa = (a&((1<<23)-1));
00098 INT32 r = ((UINT32)(mantissa|(1<<23))<<8)>>(31-exponent);
00099 r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign);
00100 return -r;
00101 }
00102
00103