From 651e5a49246a3945e996bdc699aaf865ec697e0d Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 8 Oct 2024 04:17:58 +0200 Subject: [PATCH] proper inline this --- src/tables.c | 20 -------------------- src/tables.h | 27 ++++++++++++++++++++++----- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/tables.c b/src/tables.c index 9b904ed78..43200e75e 100644 --- a/src/tables.c +++ b/src/tables.c @@ -26,26 +26,6 @@ #include "tables.h" -FUNCINLINE ATTRINLINE unsigned SlopeDiv(unsigned num, unsigned den) -{ - unsigned ans; - num <<= (FINE_FRACBITS-FRACBITS); - den <<= (FINE_FRACBITS-FRACBITS); - if (den < 512) - return SLOPERANGE; - ans = (num<<3) / (den>>8); - return ans <= SLOPERANGE ? ans : SLOPERANGE; -} - -FUNCINLINE ATTRINLINE UINT64 SlopeDivEx(unsigned int num, unsigned int den) -{ - UINT64 ans; - if (den < 512) - return SLOPERANGE; - ans = ((UINT64)num<<3)/(den>>8); - return ans <= SLOPERANGE ? ans : SLOPERANGE; -} - fixed_t AngleFixed(angle_t af) { angle_t wa = ANGLE_180; diff --git a/src/tables.h b/src/tables.h index 4856c90ea..0e58e41f9 100644 --- a/src/tables.h +++ b/src/tables.h @@ -73,6 +73,9 @@ extern fixed_t finetangent[FINEANGLES/2]; typedef UINT32 angle_t; +// The table values in tables.c are calculated with this many fractional bits. +#define FINE_FRACBITS 16 + // To get a global angle from Cartesian coordinates, the coordinates are // flipped until they are in the first octant of the coordinate system, then // the y (<=x) is scaled and divided by x to get a tangent (slope) value @@ -85,9 +88,26 @@ typedef UINT32 angle_t; extern angle_t tantoangle[SLOPERANGE+1]; // Utility function, called by R_PointToAngle. -FUNCMATH unsigned SlopeDiv(unsigned num, unsigned den); +FUNCINLINE static ATTRINLINE unsigned SlopeDiv(unsigned num, unsigned den) +{ + unsigned ans; + num <<= (FINE_FRACBITS-FRACBITS); + den <<= (FINE_FRACBITS-FRACBITS); + if (den < 512) + return SLOPERANGE; + ans = (num<<3) / (den>>8); + return ans <= SLOPERANGE ? ans : SLOPERANGE; +} + // Only called by R_PointToAngle64 -FUNCMATH UINT64 SlopeDivEx(unsigned int num, unsigned int den); +FUNCINLINE static ATTRINLINE UINT64 SlopeDivEx(unsigned int num, unsigned int den) +{ + UINT64 ans; + if (den < 512) + return SLOPERANGE; + ans = ((UINT64)num<<3)/(den>>8); + return ans <= SLOPERANGE ? ans : SLOPERANGE; +} // 360 - angle_t(ANGLE_45) = ANGLE_315 FUNCMATH FUNCINLINE static ATTRINLINE angle_t InvAngle(angle_t a) @@ -122,9 +142,6 @@ void FV3_Rotate(vector3_t *rotVec, const vector3_t *axisVec, const angle_t angle /// Fixed Point Matrix functions void FM_Rotate(matrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z); -// The table values in tables.c are calculated with this many fractional bits. -#define FINE_FRACBITS 16 - // These macros should be used in case FRACBITS < FINE_FRACBITS. #define FINESINE(n) (finesine[n]>>(FINE_FRACBITS-FRACBITS)) #define FINECOSINE(n) (finecosine[n]>>(FINE_FRACBITS-FRACBITS))