fast_floor.diff

kervala, 07/26/2009 10:58 pm

Download (1.7 kB)

D:/code/nel/include/nel/misc/fast_floor.h (working copy)
33 33
// fastFloor function.
34 34
// Actually, it seems to be bugged on VC7 (functions returns bad values)
35 35
// TODO: fix that
36
#if defined(NL_OS_WINDOWS) && !defined(NL_NO_ASM)
37
	// && defined(NL_COMP_VC6)
36
#if defined(NL_OS_WINDOWS)
38 37

39 38
#include <cfloat>
39
#ifdef NL_NO_ASM
40
	#include <smmintrin.h>
41
#endif
40 42

41 43
// The magic constant value. support both positive and negative numbers.
42 44
extern double	OptFastFloorMagicConst ;
......
74 76
// Force __stdcall to not pass parameters in registers.
75 77
inline sint32 __stdcall OptFastFloor(float x)
76 78
{
77
	static __int64	res;
79
#ifdef NL_NO_ASM
80
	__m128 a;
81
	a.m128_f32[0] = x;
82
	return _mm_cvtss_si32(a);
83
#else
84
	 static __int64	res;
78 85
	__asm
79 86
	{
80 87
		fld		x
......
83 90
	}
84 91

85 92
	return (sint32) (res&0xFFFFFFFF);
93
#endif
86 94
}
87 95

88 96

89 97
// Force __stdcall to not pass parameters in registers.
90 98
inline float __stdcall OptFastFractionnalPart(float x)
91 99
{
100
#ifdef NL_NO_ASM
101
	return x - OptFastFloor(x);
102
#else
92 103
	static double res;
93 104
	__asm
94 105
	{
......
101 112
	}
102 113

103 114
	return * (float *) &res;
115
#endif
104 116
}
105 117

106 118

......
122 134
/// Same method as OptFastFloor, but result are always positive and should never be bigger than 2^23-1
123 135
inline uint32 __stdcall OptFastFloor24(float x)
124 136
{
137
#ifdef NL_NO_ASM
138
	__m128 a;
139
	a.m128_f32[0] = x;
140
	return (uint32)_mm_cvtss_si32(a);
141
#else
125 142
	static uint32	res;
126 143
	__asm
127 144
	{
......
131 148
	}
132 149

133 150
	return res;
151
#endif
134 152
}
135 153

136 154