ID_MAYBE_INLINE for not-forced inlining

On Windows, ID_INLINE does __forceinline, which is bad if the function
calls alloca() and is called in a loop..
So use just __inline there so the compiler can choose not to inline
(if called in a loop).
This didn't cause actual stack overflows as far as I know, but it could
(and MSVC warns about it).
This commit is contained in:
Daniel Gibson 2020-01-11 15:48:02 +01:00
parent aca8c24c3a
commit b756276b54
4 changed files with 8 additions and 4 deletions

View file

@ -204,7 +204,7 @@ idCurve::RombergIntegral
====================
*/
template< class type >
ID_INLINE float idCurve<type>::RombergIntegral( const float t0, const float t1, const int order ) const {
ID_MAYBE_INLINE float idCurve<type>::RombergIntegral(const float t0, const float t1, const int order) const {
int i, j, k, m, n;
float sum, delta;
float *temp[2];
@ -242,7 +242,7 @@ idCurve::GetLengthBetweenKnots
====================
*/
template< class type >
ID_INLINE float idCurve<type>::GetLengthBetweenKnots( const int i0, const int i1 ) const {
ID_MAYBE_INLINE float idCurve<type>::GetLengthBetweenKnots(const int i0, const int i1) const {
float length = 0.0f;
for ( int i = i0; i < i1; i++ ) {
length += RombergIntegral( times[i], times[i+1], 5 );

View file

@ -340,7 +340,7 @@ idLCP_Square::CalcForceDelta
modifies this->delta_f
============
*/
ID_INLINE void idLCP_Square::CalcForceDelta( int d, float dir ) {
ID_MAYBE_INLINE void idLCP_Square::CalcForceDelta(int d, float dir) {
int i;
float *ptr;

View file

@ -2389,7 +2389,7 @@ ID_INLINE void idMatX::Clamp( float min, float max ) {
}
}
ID_INLINE idMatX &idMatX::SwapRows( int r1, int r2 ) {
ID_MAYBE_INLINE idMatX &idMatX::SwapRows(int r1, int r2) {
float *ptr;
ptr = (float *) _alloca16( numColumns * sizeof( float ) );

View file

@ -85,6 +85,9 @@ If you have questions concerning this license or the applicable additional terms
#define ALIGN16( x ) __declspec(align(16)) x
#define PACKED
#define ID_INLINE __forceinline
// DG: alternative to forced inlining of ID_INLINE for functions that do alloca()
// and are called in a loop so inlining them might cause stack overflow
#define ID_MAYBE_INLINE __inline
#define ID_STATIC_TEMPLATE static
#define assertmem( x, y ) assert( _CrtIsValidPointer( x, y, true ) )
#else
@ -96,6 +99,7 @@ If you have questions concerning this license or the applicable additional terms
#define ALIGN16( x ) x __attribute__ ((aligned (16)))
#define PACKED __attribute__((packed))
#define ID_INLINE inline
#define ID_MAYBE_INLINE inline
#define ID_STATIC_TEMPLATE
#define assertmem( x, y )
#endif