From 04f7b1589ad66db739123f28ee0b14ef2236d156 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Mon, 26 Apr 2010 14:11:48 +0000 Subject: [PATCH] mathlib.h (VectorNormalizeFast): Use a float/int union instead of type punning to avoid strict aliasing violations. the compiler used to emit a warning from rsprite.c:R_DrawSpriteModel() where the macro is used. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@153 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/mathlib.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Quake/mathlib.h b/Quake/mathlib.h index 10f4241b..291d113b 100644 --- a/Quake/mathlib.h +++ b/Quake/mathlib.h @@ -56,15 +56,16 @@ extern int nanmask; #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];} //johnfitz -- courtesy of lordhavoc +// QuakeSpasm: To avoid strict aliasing violations, use a float/int union instead of type punning. #define VectorNormalizeFast(_v)\ {\ - float _y, _number;\ - _number = DotProduct(_v, _v);\ - if (_number != 0.0)\ + union { float f; int i; } _y, _number;\ + _number.f = DotProduct(_v, _v);\ + if (_number.f != 0.0)\ {\ - *((int *)&_y) = 0x5f3759df - ((* (int *) &_number) >> 1);\ - _y = _y * (1.5f - (_number * 0.5f * _y * _y));\ - VectorScale(_v, _y, _v);\ + _y.i = 0x5f3759df - (_number.i >> 1);\ + _y.f = _y.f * (1.5f - (_number.f * 0.5f * _y.f * _y.f));\ + VectorScale(_v, _y.f, _v);\ }\ }