Skip to content

Commit 574e91a

Browse files
committed
Re-implement SlopeDiv with approximate division
1 parent 1ffaad0 commit 574e91a

File tree

6 files changed

+18
-39
lines changed

6 files changed

+18
-39
lines changed

src/doomtype.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ typedef unsigned char byte;
5656

5757
#if defined(__GNUC__) || defined(__clang__)
5858
#define CONSTFUNC __attribute__((const))
59+
#define PUREFUNC __attribute__((pure))
5960
#else
6061
#define CONSTFUNC
62+
#define PUREFUNC
6163
#endif
6264

6365
#endif

src/m_fixed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ inline static int CONSTFUNC D_abs(fixed_t x)
6363
* Fixed Point Multiplication
6464
*/
6565

66-
inline fixed_t CONSTFUNC FixedMul(fixed_t a, fixed_t b)
66+
inline static fixed_t CONSTFUNC FixedMul(fixed_t a, fixed_t b)
6767
{
6868
return (fixed_t)((int64_t) a * b >> FRACBITS);
6969
}

src/r_main.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ R_AddPointToBox
150150
// check point against partition plane.
151151
// Returns side 0 (front) or 1 (back).
152152
//
153-
int
153+
PUREFUNC int
154154
R_PointOnSide
155155
( fixed_t x,
156156
fixed_t y,
157-
node_t* node )
157+
const node_t* node )
158158
{
159159
fixed_t dx;
160160
fixed_t dy;
@@ -265,6 +265,17 @@ R_PointOnSegSide
265265
return 1;
266266
}
267267

268+
static CONSTFUNC int SlopeDiv(unsigned num, unsigned den)
269+
{
270+
den = den >> 8;
271+
272+
if (den == 0)
273+
return SLOPERANGE;
274+
275+
const unsigned int ans = FixedApproxDiv(num << 3, den) >> FRACBITS;
276+
277+
return (ans <= SLOPERANGE) ? ans : SLOPERANGE;
278+
}
268279

269280
//
270281
// R_PointToAngle
@@ -275,11 +286,6 @@ R_PointOnSegSide
275286
// tangent (slope) value which is looked up in the
276287
// tantoangle[] table.
277288

278-
//
279-
280-
281-
282-
283289
angle_t
284290
R_PointToAngle
285291
( fixed_t x,

src/r_main.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ extern void (*colfunc) (void);
9898

9999
//
100100
// Utility functions.
101-
int
101+
PUREFUNC int
102102
R_PointOnSide
103103
( fixed_t x,
104104
fixed_t y,
105-
node_t* node );
105+
const node_t* node );
106106

107107
int
108108
R_PointOnSegSide

src/tables.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,6 @@ rcsid[] = "$Id: tables.c,v 1.4 1997/02/03 16:47:57 b1 Exp $";
4343
#include "tables.h"
4444

4545

46-
47-
48-
int
49-
SlopeDiv
50-
( unsigned num,
51-
unsigned den)
52-
{
53-
unsigned ans;
54-
55-
if (den < 512)
56-
return SLOPERANGE;
57-
58-
ans = (num<<3)/(den>>8);
59-
60-
return ans <= SLOPERANGE ? ans : SLOPERANGE;
61-
}
62-
63-
64-
65-
6646
int finetangent[4096] =
6747
{
6848
-170910304,-56965752,-34178904,-24413316,-18988036,-15535599,-13145455,-11392683,

src/tables.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ typedef unsigned angle_t;
7676
// without additional checking.
7777
extern angle_t tantoangle[SLOPERANGE+1];
7878

79-
80-
// Utility function,
81-
// called by R_PointToAngle.
82-
int
83-
SlopeDiv
84-
( unsigned num,
85-
unsigned den);
86-
87-
8879
#endif
8980
//-----------------------------------------------------------------------------
9081
//

0 commit comments

Comments
 (0)