Add native int64 to quadint struct

This commit is contained in:
Kp 2014-08-16 17:42:34 +00:00
parent 47d0ecee39
commit ceeaadb940
4 changed files with 23 additions and 35 deletions

View file

@ -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<int64_t>(q.low) | (static_cast<int64_t>(q.high) << 32);
*r = static_cast<int32_t>(n / static_cast<int64_t>(c));
*r = static_cast<int32_t>(q.q / static_cast<int64_t>(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);
}

View file

@ -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);

View file

@ -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;

View file

@ -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);