Skip to content

Commit

Permalink
Merge pull request #573 from jengelh/strict-aliasing
Browse files Browse the repository at this point in the history
Resolve UBSAN strict aliasing reports
  • Loading branch information
Lgt2x authored Sep 16, 2024
2 parents 9ac702d + e867977 commit f80fa0b
Show file tree
Hide file tree
Showing 63 changed files with 753 additions and 3,758 deletions.
63 changes: 0 additions & 63 deletions fix/fix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,46 +125,6 @@ float FixCos(angle a) {
return (float)(c0 + ((c1 - c0) * (double)f / 256.0));
}

// Returns the sine of the given angle, but does no interpolation
float FixSinFast(angle a) {
int i;

i = ((a + 0x80) >> 8) & 0xff;

return sincos_table[i];
}

// Returns the cosine of the given angle, but does no interpolation
float FixCosFast(angle a) {
int i;

i = ((a + 0x80) >> 8) & 0xff;

return sincos_table[i + 64];
}

// use this instead of:
// for: (int)floor(x+0.5f) use FloatRound(x)
// (int)ceil(x-0.5f) use FloatRound(x)
// (int)floor(x-0.5f) use FloatRound(x-1.0f)
// (int)floor(x) use FloatRound(x-0.5f)
// for values in the range -2048 to 2048

// Set a vector to {0,0,0}
int FloatRound(float x) {
float nf;
nf = x + 8390656.0f;
return ((*((int *)&nf)) & 0x7FFFFF) - 2048;
}

// A fast way to convert floats to fix
fix FloatToFixFast(float x) {

float nf;
nf = x * 65536.0f + 8390656.0f;
return ((*((int *)&nf)) & 0x7FFFFF) - 2048;
}

// Get rid of the "no return value" warnings in the next three functions
#pragma warning(disable : 4035)

Check warning on line 129 in fix/fix.cpp

View workflow job for this annotation

GitHub Actions / macOS-ARM, Debug

unknown pragma ignored [-Wunknown-pragmas]

Check warning on line 129 in fix/fix.cpp

View workflow job for this annotation

GitHub Actions / macOS-ARM, Release

unknown pragma ignored [-Wunknown-pragmas]

Check warning on line 129 in fix/fix.cpp

View workflow job for this annotation

GitHub Actions / macOS-Intel, Release

unknown pragma ignored [-Wunknown-pragmas]

Check warning on line 129 in fix/fix.cpp

View workflow job for this annotation

GitHub Actions / macOS-Intel, Debug

unknown pragma ignored [-Wunknown-pragmas]

Expand Down Expand Up @@ -245,26 +205,3 @@ angle FixAtan2(float cos, float sin) {
return t;
}
}

// Does a ceiling operation on a fixed number
fix FixCeil(fix num) {
int int_num;
fix new_num;

int_num = FixToInt(num);

if (num & 0xFFFF) {
new_num = IntToFix(int_num + 1);
return new_num;
}

new_num = IntToFix(int_num);
return (new_num);
}

// Floors a fixed number
fix FixFloor(fix num) {
int int_num = FixToInt(num);

return (IntToFix(int_num));
}
23 changes: 0 additions & 23 deletions fix/fix.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,41 +89,18 @@ float FixSin(angle a);
// Returns the cosine of the given angle. Linearly interpolates between two entries in a 256-entry table
float FixCos(angle a);

// Returns the sine of the given angle, but does no interpolation
float FixSinFast(angle a);

// Returns the cosine of the given angle, but does no interpolation
float FixCosFast(angle a);

#define Round(x) ((int)(x + 0.5))

fix FloatToFixFast(float num);

// Conversion macros
//??#define FloatToFix(num) Round((num) * FLOAT_SCALER)
#define FloatToFix(num) ((fix)((num) * FLOAT_SCALER))
#define IntToFix(num) ((num) << FIX_SHIFT)
#define ShortToFix(num) (((int32_t)(num)) << FIX_SHIFT)
#define FixToFloat(num) (((float)(num)) / FLOAT_SCALER)
#define FixToInt(num) ((num) >> FIX_SHIFT)
#define FixToShort(num) ((int16_t)((num) >> FIX_SHIFT))

// use this instead of:
// for: (int)floor(x+0.5f) use FloatRound(x)
// (int)ceil(x-0.5f) use FloatRound(x)
// (int)floor(x-0.5f) use FloatRound(x-1.0f)
// (int)floor(x) use FloatRound(x-0.5f)
// for values in the range -2048 to 2048
int FloatRound(float x);

angle FixAtan2(float cos, float sin);
angle FixAsin(float v);
angle FixAcos(float v);

// Does a ceiling operation on a fixed number
fix FixCeil(fix num);

// Floors a fixed number
fix FixFloor(fix num);

#endif
3 changes: 2 additions & 1 deletion scripts/AIGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

// AIGame.cpp
//
#include <cfloat>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "osiris_import.h"
#include "osiris_common.h"
#include "osiris_vector.h"
#include "DallasFuncs.cpp"
#include "DallasFuncs.h"

#include "module.h"

Expand Down
3 changes: 2 additions & 1 deletion scripts/AIGame3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

// AIGame3.cpp
// 0.1
#include <cfloat>
#include <stdlib.h>
#include <string.h>
#include "osiris_import.h"
#include "osiris_common.h"
#include "osiris_vector.h"
#include "DallasFuncs.cpp"
#include "DallasFuncs.h"

#include "AIGame3_External.h"

Expand Down
2 changes: 1 addition & 1 deletion scripts/BatteriesIncluded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <ctype.h>
#include "osiris_import.h"
#include "osiris_common.h"
#include "DallasFuncs.cpp"
#include "DallasFuncs.h"

#include "module.h"

Expand Down
2 changes: 1 addition & 1 deletion scripts/BossCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <ctype.h>
#include "osiris_import.h"
#include "osiris_common.h"
#include "DallasFuncs.cpp"
#include "DallasFuncs.h"

#include "module.h"

Expand Down
6 changes: 6 additions & 0 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ set(SCRIPTS
# COMMENT "Copy script/data/demohog directory"
#)

add_library(dallas STATIC DallasFuncs.cpp osiris_import.cpp osiris_vector.cpp)
set_target_properties(dallas PROPERTIES PREFIX "")
set_target_properties(dallas PROPERTIES CXX_VISIBILITY_PRESET "hidden")
target_link_libraries(dallas fix misc)

foreach(SCRIPT ${SCRIPTS})
add_library(${SCRIPT} MODULE ${CPPS} ${HEADERS} "${SCRIPT}.cpp")
target_link_libraries(${SCRIPT}
dallas
fix
misc
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/CanyonsCTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <ctype.h>
#include "osiris_import.h"
#include "osiris_common.h"
#include "DallasFuncs.cpp"
#include "DallasFuncs.h"

#include "module.h"

Expand Down
2 changes: 1 addition & 1 deletion scripts/CellTestLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <ctype.h>
#include "osiris_import.h"
#include "osiris_common.h"
#include "DallasFuncs.cpp"
#include "DallasFuncs.h"

#include "module.h"

Expand Down
2 changes: 1 addition & 1 deletion scripts/ChrisTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <ctype.h>
#include "osiris_import.h"
#include "osiris_common.h"
#include "DallasFuncs.cpp"
#include "DallasFuncs.h"

#include "module.h"

Expand Down
Loading

0 comments on commit f80fa0b

Please sign in to comment.