Hey people.
Still I'm working on my Descent ports and I have 2 CPU "eater" functions here I would like to optimize.
I think the best I would get with ASM but I really have no clue about it. But probably rewriting could help as well.
Here is the code:
AND
Any idead about this?
Probably I could do some things with inline asm but as said.. no clue how
Still I'm working on my Descent ports and I have 2 CPU "eater" functions here I would like to optimize.
I think the best I would get with ASM but I really have no clue about it. But probably rewriting could help as well.
Here is the code:
Code:
int32_t fixdivquadlong(u_int32_t nl,u_int32_t nh,u_int32_t d)
{
int i;
u_int32_t tmp0;
ubyte tmp1;
u_int32_t r;
ubyte T,Q,M;
r = 0;
Q = ((nh&0x80000000)!=0);
M = ((d&0x80000000)!=0);
T = (M!=Q);
if (M == 0)
{
for (i=0; i<32; i++ ) {
r <<= 1;
r |= T;
T = ((nl&0x80000000L)!=0);
nl <<= 1;
switch( Q ) {
case 0:
Q = (unsigned char)((0x80000000L & nh) != 0 );
nh = (nh << 1) | (u_int32_t)T;
tmp0 = nh;
nh -= d;
tmp1 = (nh>tmp0);
if (Q == 0)
Q = tmp1;
else
Q = (unsigned char)(tmp1 == 0);
break;
case 1:
Q = (unsigned char)((0x80000000L & nh) != 0 );
nh = (nh << 1) | (u_int32_t)T;
tmp0 = nh;
nh += d;
tmp1 = (nh<tmp0);
if (Q == 0)
Q = tmp1;
else
Q = (unsigned char)(tmp1 == 0);
break;
}
T = (Q==M);
}
}
else
{
for (i=0; i<32; i++ ) {
r <<= 1;
r |= T;
T = ((nl&0x80000000L)!=0);
nl <<= 1;
switch( Q ) {
case 0:
Q = (unsigned char)((0x80000000L & nh) != 0 );
nh = (nh << 1) | (u_int32_t)T;
tmp0 = nh;
nh += d;
tmp1 = (nh<tmp0);
if (Q == 1)
Q = tmp1;
else
Q = (unsigned char)(tmp1 == 0);
break;
case 1:
Q = (unsigned char)((0x80000000L & nh) != 0 );
nh = (nh << 1) | (u_int32_t)T;
tmp0 = nh;
nh = nh - d;
tmp1 = (nh>tmp0);
if (Q == 1)
Q = tmp1;
else
Q = (unsigned char)(tmp1 == 0);
break;
}
T = (Q==M);
}
}
r = (r << 1) | T;
return r;
}
AND
Code:
void fixmulaccum(quad *q,fix a,fix b)
{
u_int32_t aa,bb;
u_int32_t ah,al,bh,bl;
u_int32_t t,c=0,old;
int neg;
neg = ((a^b) < 0);
aa = labs(a); bb = labs(b);
ah = aa>>16; al = aa&0xffff;
bh = bb>>16; bl = bb&0xffff;
t = ah*bl + bh*al;
if (neg)
fixquadnegate(q);
old = q->low;
q->low += al*bl;
if (q->low < old) q->high++;
old = q->low;
q->low += (t<<16);
if (q->low < old) q->high++;
q->high += ah*bh + (t>>16) + c;
if (neg)
fixquadnegate(q);
}
Any idead about this?
Probably I could do some things with inline asm but as said.. no clue how