Use abs.s instruction where possible

This commit is contained in:
Ryan Dwyer 2023-05-12 21:46:45 +10:00
parent 4c99495ccb
commit cba20b1e2f
12 changed files with 73 additions and 80 deletions

View File

@ -959,7 +959,7 @@ void eyespyProcessInput(bool allowbuttons)
// Update bob
if (spc4 == 0.0f) {
if (g_Vars.currentplayer->eyespy->bobactive || ABS(g_Vars.currentplayer->eyespy->vel.y) < 0.1f) {
if (g_Vars.currentplayer->eyespy->bobactive || absf(g_Vars.currentplayer->eyespy->vel.y) < 0.1f) {
g_Vars.currentplayer->eyespy->bobactive = true;
g_Vars.currentplayer->eyespy->bobtimer += g_Vars.lvupdate60;
g_Vars.currentplayer->eyespy->vel.y += 0.025f * g_Vars.currentplayer->eyespy->bobdir;

View File

@ -1487,7 +1487,7 @@ static void chrHandleJointPositioned(s32 joint, Mtxf *mtx)
&& g_CurModelChr->actiontype != ACT_DEAD
&& g_CurModelChr->actiontype != ACT_DIE) {
zrot = g_CurModelChr->drugheadsway / 360.0f * M_BADTAU;
xrot -= (28.0f - ABS(g_CurModelChr->drugheadsway)) / 250.0f * M_BADTAU;
xrot -= (28.0f - absf(g_CurModelChr->drugheadsway)) / 250.0f * M_BADTAU;
}
}
@ -2355,7 +2355,7 @@ s32 chrTick(struct prop *prop)
sp130 = bike->w * 1000;
sp17c.x = cosf(sp178) * sp130;
sp17c.y = ABS(bike->w) * 200 + 25;
sp17c.y = absf(bike->w) * 200 + 25;
sp17c.z = sinf(-sp178) * sp130;
mtx4LoadTranslation(&sp17c, &sp1a8);

View File

@ -9987,10 +9987,10 @@ static void chrTickRobotAttack(struct chrdata *chr)
if (act->numshots[0] <= 0 && act->numshots[1] <= 0) {
empty = true;
if (ABS(chr->gunroty[0]) < 0.03f
&& ABS(chr->gunrotx[0]) < 0.03f
&& ABS(chr->gunroty[1]) < 0.03f
&& ABS(chr->gunrotx[1]) < 0.03f) {
if (absf(chr->gunroty[0]) < 0.03f
&& absf(chr->gunrotx[0]) < 0.03f
&& absf(chr->gunroty[1]) < 0.03f
&& absf(chr->gunrotx[1]) < 0.03f) {
act->finished = true;
}
}
@ -10485,7 +10485,7 @@ static bool func0f043f2c(struct chrdata *chr, struct coord *runpos, u32 arg2, f3
applyRotation(&finalangle, angle1, turnspeed, accel, accel + accel, maxspeed);
if (ABS(finalangle - angle1) < 0.01f) {
if (absf(finalangle - angle1) < 0.01f) {
*turnspeed = 0;
result = true;
}

View File

@ -1751,15 +1751,15 @@ static f32 func0f0053d0(s32 roomnum1, struct coord *pos1, s32 portalnum1, s32 ro
sp64 = *sp68;
xdiff = pos1->x - pos2->x;
xdiff = xdiff > 0.0f ? xdiff : -xdiff;
xdiff = absf(xdiff);
if (xdiff < sp64) {
zdiff = pos1->z - pos2->z;
zdiff = zdiff > 0.0f ? zdiff : -zdiff;
zdiff = absf(zdiff);
if (zdiff < sp64) {
ydiff = pos1->y - pos2->y;
ydiff = ydiff > 0.0f ? ydiff : -ydiff;
ydiff = absf(ydiff);
if (ydiff < sp64) {
f32 dist = sqrtf(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
@ -1781,11 +1781,11 @@ static f32 func0f0053d0(s32 roomnum1, struct coord *pos1, s32 portalnum1, s32 ro
sp64 -= sp50;
xdiff2 = sp44.x - pos1->x;
xdiff2 = xdiff2 > 0.0f ? xdiff2 : -xdiff2;
xdiff2 = absf(xdiff2);
if (xdiff2 < sp64) {
zdiff2 = sp44.z - pos1->z;
zdiff2 = zdiff2 > 0.0f ? zdiff2 : -zdiff2;
zdiff2 = absf(zdiff2);
if (zdiff2 < sp64) {
f32 sp38 = sqrtf(xdiff2 * xdiff2 + zdiff2 * zdiff2);
@ -1799,11 +1799,11 @@ static f32 func0f0053d0(s32 roomnum1, struct coord *pos1, s32 portalnum1, s32 ro
sp64 -= sp38;
xdiff3 = sp2c.x - pos2->x;
xdiff3 = xdiff3 > 0.0f ? xdiff3 : -xdiff3;
xdiff3 = absf(xdiff3);
if (xdiff3 < sp64) {
zdiff3 = sp2c.z - pos2->z;
zdiff3 = zdiff3 > 0.0f ? zdiff3 : -zdiff3;
zdiff3 = absf(zdiff3);
if (zdiff3 < sp64) {
f32 dist3 = sqrtf(xdiff3 * xdiff3 + zdiff3 * zdiff3);

View File

@ -462,7 +462,7 @@ static void htmTickChr(struct chrdata *chr)
rangexz = sqrtf(dist.x * dist.x + dist.z * dist.z);
rangey = ABS(dist.y);
rangey = absf(dist.y);
relangle = atan2f(dist.x, dist.z) * 57.295776367188f + angle;

View File

@ -253,12 +253,12 @@ static void propsndTickChannel(s32 channelnum)
f32 f12 = channel->unk04 - channel->unk06;
f32 f14 = g_Vars.lvupdate60 * (1.0f / 6000.0f) * channel->unk18;
if (ABS(f12) > 1.0f) {
if (absf(f12) > 1.0f) {
if (f14 > 1.0f) {
f14 = 1.0f;
}
if (ABS(f14 * f12) > 1.0f) {
if (absf(f14 * f12) > 1.0f) {
sp48 = channel->unk06 + (s32) (f14 * f12);
}
}
@ -305,7 +305,7 @@ static void propsndTickChannel(s32 channelnum)
sp40 = -1;
}
if (sp3c > 0.0f && ABS(sp3c - channel->unk48) > 0.01f) {
if (sp3c > 0.0f && absf(sp3c - channel->unk48) > 0.01f) {
channel->unk48 = sp3c;
} else {
sp3c = -1.0f;
@ -961,7 +961,7 @@ static s32 propsnd0f094b1c(struct coord *pos, s32 arg1, f32 arg2, struct audioch
sp3c *= arg2;
f2 = atan2f(ABSF(sp3c), ABSF(sp38));
f2 = atan2f(absf(sp3c), absf(sp38));
if (!(sp3c >= 0.0f) || !(sp38 >= 0.0f)) {
if (sp3c >= 0.0f) {

View File

@ -15,8 +15,6 @@
#include "data.h"
#include "types.h"
#define SKYABS(val) (val >= 0.0f ? (val) : -(val))
bool g_SkyLightningActive;
Mtxf var800a33a8;
struct coord g_SunPositions[3]; // relative to centre screen, with a huge scale
@ -1629,23 +1627,23 @@ static Gfx *sky0f122d4c(Gfx *gdl, struct skything38 *arg1, struct skything38 *ar
sp354[0] = sp364[0] * sp47c->unk24;
sp358[0] = sp364[0] * 32767.0f;
sp330[0] = SKYABS(sp338[0]);
sp334[0] = SKYABS(sp33c[0]);
sp330[0] = absf(sp338[0]);
sp334[0] = absf(sp33c[0]);
if (sp330[0] < SKYABS(sp344[0])) {
sp330[0] = SKYABS(sp344[0]);
if (sp330[0] < absf(sp344[0])) {
sp330[0] = absf(sp344[0]);
}
if (sp334[0] < SKYABS(sp348[0])) {
sp334[0] = SKYABS(sp348[0]);
if (sp334[0] < absf(sp348[0])) {
sp334[0] = absf(sp348[0]);
}
if (sp330[0] < SKYABS(sp350[0])) {
sp330[0] = SKYABS(sp350[0]);
if (sp330[0] < absf(sp350[0])) {
sp330[0] = absf(sp350[0]);
}
if (sp334[0] < SKYABS(sp354[0])) {
sp334[0] = SKYABS(sp354[0]);
if (sp334[0] < absf(sp354[0])) {
sp334[0] = absf(sp354[0]);
}
sp310[0] = sp484->r + 0.5f;
@ -1753,8 +1751,8 @@ static Gfx *sky0f122d4c(Gfx *gdl, struct skything38 *arg1, struct skything38 *ar
sp208[0] = sp368 * (1.0f / 32.0f);
for (i = 0; i < 8; i++) {
sp1d0[i] = SKYABS(sp290[i]) * (1.0f / 32.0f);
sp1b0[i] = SKYABS(sp2b0[i]) * (1.0f / 32.0f);
sp1d0[i] = absf(sp290[i]) * (1.0f / 32.0f);
sp1b0[i] = absf(sp2b0[i]) * (1.0f / 32.0f);
}
sp1a0[0] = sp200[0] + (2.0f * sp1d0[4]) + sp1b0[4];
@ -2168,31 +2166,31 @@ static Gfx *sky0f123fd4(Gfx *gdl, struct skything38 *arg1, struct skything38 *ar
sp394[0] = sp3a8[0] * arg4->unk24;
sp398[0] = sp3a8[0] * 32767.0f;
sp364[0] = SKYABS(sp36c[0]);
sp368[0] = SKYABS(sp370[0]);
sp364[0] = absf(sp36c[0]);
sp368[0] = absf(sp370[0]);
if (sp364[0] < SKYABS(sp378[0])) {
sp364[0] = SKYABS(sp378[0]);
if (sp364[0] < absf(sp378[0])) {
sp364[0] = absf(sp378[0]);
}
if (sp368[0] < SKYABS(sp37c[0])) {
sp368[0] = SKYABS(sp37c[0]);
if (sp368[0] < absf(sp37c[0])) {
sp368[0] = absf(sp37c[0]);
}
if (sp364[0] < SKYABS(sp384[0])) {
sp364[0] = SKYABS(sp384[0]);
if (sp364[0] < absf(sp384[0])) {
sp364[0] = absf(sp384[0]);
}
if (sp368[0] < SKYABS(sp388[0])) {
sp368[0] = SKYABS(sp388[0]);
if (sp368[0] < absf(sp388[0])) {
sp368[0] = absf(sp388[0]);
}
if (sp364[0] < SKYABS(sp390[0])) {
sp364[0] = SKYABS(sp390[0]);
if (sp364[0] < absf(sp390[0])) {
sp364[0] = absf(sp390[0]);
}
if (sp368[0] < SKYABS(sp394[0])) {
sp368[0] = SKYABS(sp394[0]);
if (sp368[0] < absf(sp394[0])) {
sp368[0] = absf(sp394[0]);
}
sp354[0] = sp36c[0]; sp354[1] = sp370[0]; sp354[2] = sp374[0];
@ -2279,8 +2277,8 @@ static Gfx *sky0f123fd4(Gfx *gdl, struct skything38 *arg1, struct skything38 *ar
sp23c[0] = sp3ac * (1.0f / 32.0f);
for (i = 0; i < 4; i++) {
sp214[i] = SKYABS(sp2d4[i]) * (1.0f / 32.0f);
sp1f4[i] = SKYABS(sp2f4[i]) * (1.0f / 32.0f);
sp214[i] = absf(sp2d4[i]) * (1.0f / 32.0f);
sp1f4[i] = absf(sp2f4[i]) * (1.0f / 32.0f);
}
sp1d4[0] = sp234[0] + (2.0f * sp214[0]) + sp1f4[0];

View File

@ -315,10 +315,10 @@ Gfx *sparksRender(Gfx *gdl)
Mtxf spd4;
if (g_SparksAreActive) {
if (ABS(g_Vars.currentplayer->cam_look.y) > ABS(g_Vars.currentplayer->cam_look.x)) {
axis = ABS(g_Vars.currentplayer->cam_look.z) > ABS(g_Vars.currentplayer->cam_look.y) ? 2 : 1;
if (absf(g_Vars.currentplayer->cam_look.y) > absf(g_Vars.currentplayer->cam_look.x)) {
axis = absf(g_Vars.currentplayer->cam_look.z) > absf(g_Vars.currentplayer->cam_look.y) ? 2 : 1;
} else {
axis = ABS(g_Vars.currentplayer->cam_look.z) > ABS(g_Vars.currentplayer->cam_look.x) ? 2 : 0;
axis = absf(g_Vars.currentplayer->cam_look.z) > absf(g_Vars.currentplayer->cam_look.x) ? 2 : 0;
}
texSelect(&gdl, &g_TexSparkConfigs[0], 4, 0, 2, 1, NULL);
@ -472,7 +472,7 @@ Gfx *sparksRender(Gfx *gdl)
switch (axis) {
case 0:
if (ABS(spark->speed.z) > ABS(spark->speed.y)) {
if (absf(spark->speed.z) > absf(spark->speed.y)) {
vertices[1].y = vertices[1].y - type->unk06 - group->age * type->unk0a - (s32)sp120;
vertices[2].y = vertices[2].y + type->unk06 + group->age * type->unk0a + (s32)sp120;
} else {
@ -481,7 +481,7 @@ Gfx *sparksRender(Gfx *gdl)
}
break;
case 1:
if (ABS(spark->speed.x) > ABS(spark->speed.z)) {
if (absf(spark->speed.x) > absf(spark->speed.z)) {
vertices[1].z = vertices[1].z - type->unk06 - group->age * type->unk0a - (s32)sp120;
vertices[2].z = vertices[2].z + type->unk06 + group->age * type->unk0a + (s32)sp120;
} else {
@ -490,7 +490,7 @@ Gfx *sparksRender(Gfx *gdl)
}
break;
case 2:
if (ABS(spark->speed.x) > ABS(spark->speed.y)) {
if (absf(spark->speed.x) > absf(spark->speed.y)) {
vertices[1].y = vertices[1].y - type->unk06 - group->age * type->unk0a - (s32)sp120;
vertices[2].y = vertices[2].y + type->unk06 + group->age * type->unk0a + (s32)sp120;
} else {

View File

@ -93,8 +93,6 @@ static void starInsert(s32 index, struct coord *arg1)
}
}
#define ABS2(value) ((value) < 0 ? -(value) : (value))
void starsReset(void)
{
s32 v0;
@ -164,7 +162,7 @@ void starsReset(void)
guNormalize(&spd4.f[0], &spd4.f[1], &spd4.f[2]);
f0 = (ABS2(spd4.f[0]) > ABS2(spd4.f[1])) ? (ABS2(spd4.f[0]) > ABS2(spd4.f[2]) ? ABS2(spd4.f[0]) : ABS2(spd4.f[2])) : (ABS2(spd4.f[1]) > ABS2(spd4.f[2]) ? ABS2(spd4.f[1]) : ABS2(spd4.f[2]));
f0 = (absf(spd4.f[0]) > absf(spd4.f[1])) ? (absf(spd4.f[0]) > absf(spd4.f[2]) ? absf(spd4.f[0]) : absf(spd4.f[2])) : (absf(spd4.f[1]) > absf(spd4.f[2]) ? absf(spd4.f[1]) : absf(spd4.f[2]));
spc8.f[0] = spd4.f[0] / f0;
spc8.f[1] = spd4.f[1] / f0;

View File

@ -792,9 +792,9 @@ void wallhitCreateWith20Args(struct coord *relpos, struct coord *arg1, struct co
sp1ac.f[1] = relpos->y;
sp1ac.f[2] = relpos->z;
xiszero = ABS(arg1->x) < 0.00001f ? true : false;
yiszero = ABS(arg1->y) < 0.00001f ? true : false;
ziszero = ABS(arg1->z) < 0.00001f ? true : false;
xiszero = absf(arg1->x) < 0.00001f ? true : false;
yiszero = absf(arg1->y) < 0.00001f ? true : false;
ziszero = absf(arg1->z) < 0.00001f ? true : false;
if (xiszero && ziszero) {
sp1f4.x = -1.0f;

View File

@ -19,8 +19,6 @@
#include "data.h"
#include "types.h"
#define ABSF(val) ((val) > 0.0f ? (val) : -(val))
static Gfx *weatherRenderRain(Gfx *gdl, struct weatherdata *weather, s32 arg2);
static Gfx *weatherRenderSnow(Gfx *gdl, struct weatherdata *weather, s32 arg2);
@ -384,8 +382,8 @@ void weatherTickRain(struct weatherdata *weather)
lVar6 = 2;
// Reset particle
particle->pos.x = data->boundarymin.x + RANDOMFRAC() * (ABS(data->boundarymin.x) + ABS(data->boundarymax.x));
particle->pos.z = data->boundarymin.z + RANDOMFRAC() * (ABS(data->boundarymin.z) + ABS(data->boundarymax.z));
particle->pos.x = data->boundarymin.x + RANDOMFRAC() * (absf(data->boundarymin.x) + absf(data->boundarymax.x));
particle->pos.z = data->boundarymin.z + RANDOMFRAC() * (absf(data->boundarymin.z) + absf(data->boundarymax.z));
particle->unk1c = RANDOMFRAC() + 0.7f;
@ -560,8 +558,8 @@ void weatherTickSnow(struct weatherdata *weather)
if (particle->pos.y < data->boundarymin.y) {
lVar7 = 2;
particle->pos.x = data->boundarymin.f[0] + RANDOMFRAC() * (ABS(data->boundarymin.f[0]) + ABS(data->boundarymax.f[0]));
particle->pos.z = data->boundarymin.f[2] + RANDOMFRAC() * (ABS(data->boundarymin.f[2]) + ABS(data->boundarymax.f[2]));
particle->pos.x = data->boundarymin.f[0] + RANDOMFRAC() * (absf(data->boundarymin.f[0]) + absf(data->boundarymax.f[0]));
particle->pos.z = data->boundarymin.f[2] + RANDOMFRAC() * (absf(data->boundarymin.f[2]) + absf(data->boundarymax.f[2]));
particle->unk1c = RANDOMFRAC() + 0.7f;
@ -863,9 +861,9 @@ static Gfx *weatherRenderRain(Gfx *gdl, struct weatherdata *weather, s32 arg2)
sp224.f[1] = sp230.f[1] - particledata->unk3e80.f[1];
sp224.f[2] = sp230.f[2] - particledata->unk3e80.f[2];
if (ABSF(sp224.f[0]) > ABSF(particledata->boundarymin.f[0]) + ABSF(particledata->boundarymax.f[0])
|| ABSF(sp224.f[1]) > ABSF(particledata->boundarymin.f[1]) + ABSF(particledata->boundarymax.f[1])
|| ABSF(sp224.f[2]) > ABSF(particledata->boundarymin.f[2]) + ABSF(particledata->boundarymax.f[2])) {
if (absf(sp224.f[0]) > absf(particledata->boundarymin.f[0]) + absf(particledata->boundarymax.f[0])
|| absf(sp224.f[1]) > absf(particledata->boundarymin.f[1]) + absf(particledata->boundarymax.f[1])
|| absf(sp224.f[2]) > absf(particledata->boundarymin.f[2]) + absf(particledata->boundarymax.f[2])) {
sp224.f[0] = particledata->boundaryrange.f[0] * 0.5f;
sp224.f[1] = particledata->boundaryrange.f[1] * 0.5f;
sp224.f[2] = particledata->boundaryrange.f[2] * 0.5f;
@ -1420,9 +1418,9 @@ static Gfx *weatherRenderSnow(Gfx *gdl, struct weatherdata *weather, s32 arg2)
sp228.f[1] = sp234.f[1] - particledata->unk3e80.f[1];
sp228.f[2] = sp234.f[2] - particledata->unk3e80.f[2];
if (ABSF(sp228.f[0]) > ABSF(particledata->boundarymin.f[0]) + ABSF(particledata->boundarymax.f[0])
|| ABSF(sp228.f[1]) > ABSF(particledata->boundarymin.f[1]) + ABSF(particledata->boundarymax.f[1])
|| ABSF(sp228.f[2]) > ABSF(particledata->boundarymin.f[2]) + ABSF(particledata->boundarymax.f[2])) {
if (absf(sp228.f[0]) > absf(particledata->boundarymin.f[0]) + absf(particledata->boundarymax.f[0])
|| absf(sp228.f[1]) > absf(particledata->boundarymin.f[1]) + absf(particledata->boundarymax.f[1])
|| absf(sp228.f[2]) > absf(particledata->boundarymin.f[2]) + absf(particledata->boundarymax.f[2])) {
sp228.f[0] = particledata->boundaryrange.f[0] * 0.5f;
sp228.f[1] = particledata->boundaryrange.f[1] * 0.5f;
sp228.f[2] = particledata->boundaryrange.f[2] * 0.5f;
@ -1665,7 +1663,7 @@ static Gfx *weatherRenderSnow(Gfx *gdl, struct weatherdata *weather, s32 arg2)
}
// 5500
tmp = ABSF(f2) / var8007f100;
tmp = absf(f2) / var8007f100;
f2 = tmp;
// 5524
@ -1681,7 +1679,7 @@ static Gfx *weatherRenderSnow(Gfx *gdl, struct weatherdata *weather, s32 arg2)
f2 = sp118.f[2] - sp264[j][11];
}
f2 = ABSF(f2) / var8007f100;
f2 = absf(f2) / var8007f100;
if (f2 > sp260) {
sp260 = f2;
@ -1747,7 +1745,7 @@ static Gfx *weatherRenderSnow(Gfx *gdl, struct weatherdata *weather, s32 arg2)
f16 = particledata->particles[s8].pos.f[0] - particledata->boundarymax.f[0] + 150.0f;
}
f16 = ABSF(f16) / 150.0f;
f16 = absf(f16) / 150.0f;
if (f16 > sp260) {
sp260 = f16;
@ -1765,7 +1763,7 @@ static Gfx *weatherRenderSnow(Gfx *gdl, struct weatherdata *weather, s32 arg2)
f16 = particledata->particles[s8].pos.f[1] - particledata->boundarymax.f[1] + 150.0f;
}
f16 = ABSF(f16) / 150.0f;
f16 = absf(f16) / 150.0f;
if (f16 > sp260) {
sp260 = f16;
@ -1783,7 +1781,7 @@ static Gfx *weatherRenderSnow(Gfx *gdl, struct weatherdata *weather, s32 arg2)
f16 = particledata->particles[s8].pos.f[2] - particledata->boundarymax.f[2] + 150.0f;
}
f16 = ABSF(f16) / 150.0f;
f16 = absf(f16) / 150.0f;
if (f16 > sp260) {
sp260 = f16;

View File

@ -21,7 +21,6 @@
#define MAXFLOAT ((float)3.40282346638528860e+38)
#define ABS(val) ((val) > 0 ? (val) : -(val))
#define ABSF(val) ((val) > 0.0f ? (val) : -(val))
#define ALIGN2(val) (((val) | 1) ^ 0x1)
#define ALIGN4(val) ((((val) + 0x3) | 0x3) ^ 0x3)
#define ALIGN8(val) ((((val) + 0x7) | 0x7) ^ 0x7)