diff --git a/common/3d/points.cpp b/common/3d/points.cpp index d3f01a991..14c5c04ec 100644 --- a/common/3d/points.cpp +++ b/common/3d/points.cpp @@ -59,8 +59,7 @@ ubyte g3_rotate_point(g3s_point *dest,const vms_vector *src) int checkmuldiv(fix *r,fix a,fix b,fix c) { quadint q,qt; - - q.low=q.high=0; + q.q = 0; fixmulaccum(&q,a,b); qt = q; @@ -74,8 +73,7 @@ int checkmuldiv(fix *r,fix a,fix b,fix c) if (qt.high >= c) return 0; else { - int64_t n = static_cast(q.low) | (static_cast(q.high) << 32); - *r = static_cast(n / static_cast(c)); + *r = static_cast(q.q / static_cast(c)); return 1; } } @@ -178,14 +176,9 @@ ubyte g3_add_delta_vec(g3s_point *dest,const g3s_point *src,const vms_vector *de fix g3_calc_point_depth(const vms_vector *pnt) { quadint q; - - q.low=q.high=0; + q.q = 0; fixmulaccum(&q,(pnt->x - View_position.x),View_matrix.fvec.x); fixmulaccum(&q,(pnt->y - View_position.y),View_matrix.fvec.y); fixmulaccum(&q,(pnt->z - View_position.z),View_matrix.fvec.z); - return fixquadadjust(&q); } - - - diff --git a/common/include/maths.h b/common/include/maths.h index 649970a13..399215853 100644 --- a/common/include/maths.h +++ b/common/include/maths.h @@ -30,8 +30,13 @@ typedef int16_t fixang; //angles typedef struct quadint // integer 64 bit, previously called "quad" { + union { + struct { u_int32_t low; int32_t high; + }; + int64_t q; + }; } quadint; @@ -81,10 +86,16 @@ fix fixmuldiv (fix a, fix b, fix c); void fixmulaccum (quadint * q, fix a, fix b); //extract a fix from a quadint product -fix fixquadadjust (quadint * q); +static inline fix fixquadadjust (quadint * q) +{ + return q->q >> 16; +} //negate a quadint -void fixquadnegate (quadint * q); +static inline void fixquadnegate (quadint * q) +{ + q->q = -q->q; +} //computes the square root of a long, returning a short ushort long_sqrt (int32_t a); diff --git a/common/maths/fixc.cpp b/common/maths/fixc.cpp index 44ebe0f66..480fe26a7 100644 --- a/common/maths/fixc.cpp +++ b/common/maths/fixc.cpp @@ -17,13 +17,6 @@ #include "dxxerror.h" #include "maths.h" -//negate a quad -void fixquadnegate(quadint *q) -{ - q->low = 0 - q->low; - q->high = 0 - q->high - (q->low != 0); -} - //multiply two ints & add 64-bit result to 64-bit sum void fixmulaccum(quadint *q,fix a,fix b) { @@ -59,13 +52,6 @@ void fixmulaccum(quadint *q,fix a,fix b) } -//extract a fix from a quad product -fix fixquadadjust(quadint *q) -{ - return (q->high<<16) + (q->low>>16); -} - - #define EPSILON (F1_0/100) fix fixmul(fix a, fix b) @@ -136,7 +122,6 @@ u_int32_t quad_sqrt(const quadint iq) const int32_t high = iq.high; int i, cnt; u_int32_t r,old_r,t; - quadint tq; if (high<0) return 0; @@ -175,11 +160,12 @@ u_int32_t quad_sqrt(const quadint iq) } while (!(r==t || r==old_r)); t = fixdivquadlongu(low,high,r); + quadint tq; //edited 05/17/99 Matt Mueller - tq.high is undefined here.. so set them to = 0 - tq.low=tq.high=0; + tq.q = 0; //end edit -MM fixmulaccum(&tq,r,t); - if (tq.low!=low || tq.high!=high) + if (tq.q != iq.q) r++; return r; diff --git a/common/maths/vecmat.cpp b/common/maths/vecmat.cpp index e1a85d975..607d4c686 100644 --- a/common/maths/vecmat.cpp +++ b/common/maths/vecmat.cpp @@ -207,9 +207,7 @@ static fix vm_vec_dot3(fix x,fix y,fix z,const vms_vector *v) fix vm_vec_mag(const vms_vector *v) { quadint q; - - q.low = q.high = 0; - + q.q = 0; fixmulaccum(&q,v->x,v->x); fixmulaccum(&q,v->y,v->y); fixmulaccum(&q,v->z,v->z); @@ -431,17 +429,17 @@ vms_vector *vm_vec_crossprod(vms_vector *dest,const vms_vector *src0,const vms_v Assert(dest!=src0 && dest!=src1); - q.low = q.high = 0; + q.q = 0; fixmulaccum(&q,src0->y,src1->z); fixmulaccum(&q,-src0->z,src1->y); dest->x = fixquadadjust(&q); - q.low = q.high = 0; + q.q = 0; fixmulaccum(&q,src0->z,src1->x); fixmulaccum(&q,-src0->x,src1->z); dest->y = fixquadadjust(&q); - q.low = q.high = 0; + q.q = 0; fixmulaccum(&q,src0->x,src1->y); fixmulaccum(&q,-src0->y,src1->x); dest->z = fixquadadjust(&q);