version 1.2 | | version 1.3 |
---|
| | |
* C version of fixed point library | | * C version of fixed point library |
* | | * |
* $Log$ | | * $Log$ |
| | * Revision 1.3 1999/10/18 00:31:01 donut |
| | * more alpha fixes from Falk Hueffner |
| | * |
* Revision 1.2 1999/08/05 22:53:41 sekmu | | * Revision 1.2 1999/08/05 22:53:41 sekmu |
* | | * |
* D3D patch(es) from ADB | | * D3D patch(es) from ADB |
| | |
//multiply two ints & add 64-bit result to 64-bit sum | | //multiply two ints & add 64-bit result to 64-bit sum |
void fixmulaccum(quad *q,fix a,fix b) | | void fixmulaccum(quad *q,fix a,fix b) |
{ | | { |
ulong aa,bb; | | u_int32_t aa,bb; |
ulong ah,al,bh,bl; | | u_int32_t ah,al,bh,bl; |
ulong t,c=0,old; | | u_int32_t t,c=0,old; |
int neg; | | int neg; |
| | |
neg = ((a^b) < 0); | | neg = ((a^b) < 0); |
| | |
| | |
#ifdef NO_FIX_INLINE | | #ifdef NO_FIX_INLINE |
//divide a quad by a fix, returning a fix | | //divide a quad by a fix, returning a fix |
long fixdivquadlong(ulong nl,ulong nh,ulong d) | | int32_t fixdivquadlong(u_int32_t nl,u_int32_t nh,u_int32_t d) |
{ | | { |
int i; | | int i; |
ulong tmp0; | | u_int32_t tmp0; |
ubyte tmp1; | | ubyte tmp1; |
ulong r; | | u_int32_t r; |
ubyte T,Q,M; | | ubyte T,Q,M; |
| | |
r = 0; | | r = 0; |
| | |
| | |
case 0: | | case 0: |
Q = (unsigned char)((0x80000000L & nh) != 0 ); | | Q = (unsigned char)((0x80000000L & nh) != 0 ); |
nh = (nh << 1) | (unsigned long)T; | | nh = (nh << 1) | (u_int32_t)T; |
| | |
tmp0 = nh; | | tmp0 = nh; |
nh -= d; | | nh -= d; |
| | |
break; | | break; |
case 1: | | case 1: |
Q = (unsigned char)((0x80000000L & nh) != 0 ); | | Q = (unsigned char)((0x80000000L & nh) != 0 ); |
nh = (nh << 1) | (unsigned long)T; | | nh = (nh << 1) | (u_int32_t)T; |
| | |
tmp0 = nh; | | tmp0 = nh; |
nh += d; | | nh += d; |
| | |
| | |
case 0: | | case 0: |
Q = (unsigned char)((0x80000000L & nh) != 0 ); | | Q = (unsigned char)((0x80000000L & nh) != 0 ); |
nh = (nh << 1) | (unsigned long)T; | | nh = (nh << 1) | (u_int32_t)T; |
| | |
tmp0 = nh; | | tmp0 = nh; |
nh += d; | | nh += d; |
| | |
break; | | break; |
case 1: | | case 1: |
Q = (unsigned char)((0x80000000L & nh) != 0 ); | | Q = (unsigned char)((0x80000000L & nh) != 0 ); |
nh = (nh << 1) | (unsigned long)T; | | nh = (nh << 1) | (u_int32_t)T; |
| | |
tmp0 = nh; | | tmp0 = nh; |
nh = nh - d; | | nh = nh - d; |
| | |
| | |
unsigned int fixdivquadlongu(uint nl, uint nh, uint d) | | unsigned int fixdivquadlongu(uint nl, uint nh, uint d) |
{ | | { |
return fixdivquadlong((ulong) nl,(ulong) nh,(ulong) d); | | return fixdivquadlong((u_int32_t) nl,(u_int32_t) nh,(u_int32_t) d); |
} | | } |
#else | | #else |
long fixdivquadlong(ulong nl,ulong nh,ulong d) { | | int32_t fixdivquadlong(u_int32_t nl,u_int32_t nh,u_int32_t d) { |
long a; | | int32_t a; |
__asm__("idivl %3" | | __asm__("idivl %3" |
:"=a" (a) | | :"=a" (a) |
:"a" (nl), "d" (nh), "r" (d) | | :"a" (nl), "d" (nh), "r" (d) |
| | |
); | | ); |
return (a); | | return (a); |
} | | } |
static inline ulong fixdivquadlongu(ulong nl,ulong nh,ulong d) { | | static inline u_int32_t fixdivquadlongu(u_int32_t nl,u_int32_t nh,u_int32_t d) { |
ulong a; | | u_int32_t a; |
__asm__("divl %3" | | __asm__("divl %3" |
:"=a" (a) | | :"=a" (a) |
:"a" (nl), "d" (nh), "r" (d) | | :"a" (nl), "d" (nh), "r" (d) |
| | |
} | | } |
#endif | | #endif |
| | |
ulong quad_sqrt(ulong low,long high) | | u_int32_t quad_sqrt(u_int32_t low,int32_t high) |
{ | | { |
int i, cnt; | | int i, cnt; |
ulong r,old_r,t; | | u_int32_t r,old_r,t; |
quad tq; | | quad tq; |
| | |
if (high<0) | | if (high<0) |
return 0; | | return 0; |
| | |
if (high==0 && (long)low>=0) | | if (high==0 && (int32_t)low>=0) |
return long_sqrt((long)low); | | return long_sqrt((int32_t)low); |
| | |
if (high & 0xff000000) { | | if (high & 0xff000000) { |
cnt=12+16; i = high >> 24; | | cnt=12+16; i = high >> 24; |
| | |
} | | } |
| | |
//computes the square root of a long, returning a short | | //computes the square root of a long, returning a short |
ushort long_sqrt(long a) | | ushort long_sqrt(int32_t a) |
{ | | { |
int cnt,r,old_r,t; | | int cnt,r,old_r,t; |
| | |