Finish Vector4 implementation

This commit is contained in:
RaveYard 2022-11-10 15:33:57 +01:00 committed by Christoph Oelckers
commit 31db5847cc
15 changed files with 323 additions and 193 deletions

View file

@ -80,8 +80,9 @@ enum
REGT_KONST = 4,
REGT_MULTIREG2 = 8,
REGT_MULTIREG3 = 16, // (e.g. a vector)
REGT_MULTIREG = 24,
REGT_MULTIREG = 8 | 16 | 64,
REGT_ADDROF = 32, // used with PARAM: pass address of this register
REGT_MULTIREG4 = 64,
REGT_NIL = 128 // parameter was omitted
};
@ -130,6 +131,22 @@ struct VMReturn
assert(RegType == REGT_FLOAT);
*(double *)Location = val;
}
void SetVector4(const double val[4])
{
assert(RegType == (REGT_FLOAT|REGT_MULTIREG4));
((double *)Location)[0] = val[0];
((double *)Location)[1] = val[1];
((double *)Location)[2] = val[2];
((double *)Location)[3] = val[3];
}
void SetVector4(const DVector4 &val)
{
assert(RegType == (REGT_FLOAT | REGT_MULTIREG4));
((double *)Location)[0] = val[0];
((double *)Location)[1] = val[1];
((double *)Location)[2] = val[2];
((double *)Location)[3] = val[3];
}
void SetVector(const double val[3])
{
assert(RegType == (REGT_FLOAT|REGT_MULTIREG3));

View file

@ -512,6 +512,28 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
v[2] = reg.f[B+2];
}
NEXTOP;
OP(SV4):
ASSERTA(a); ASSERTF(B+3); ASSERTKD(C);
GETADDR(PA,KC,X_WRITE_NIL);
{
auto v = (double *)ptr;
v[0] = reg.f[B];
v[1] = reg.f[B+1];
v[2] = reg.f[B+2];
v[3] = reg.f[B+3];
}
NEXTOP;
OP(SV4_R):
ASSERTA(a); ASSERTF(B+3); ASSERTD(C);
GETADDR(PA,RC,X_WRITE_NIL);
{
auto v = (double *)ptr;
v[0] = reg.f[B];
v[1] = reg.f[B+1];
v[2] = reg.f[B+2];
v[3] = reg.f[B+3];
}
NEXTOP;
OP(SFV2):
ASSERTA(a); ASSERTF(B+1); ASSERTKD(C);
GETADDR(PA,KC,X_WRITE_NIL);
@ -550,6 +572,28 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
v[2] = (float)reg.f[B+2];
}
NEXTOP;
OP(SFV4):
ASSERTA(a); ASSERTF(B+3); ASSERTKD(C);
GETADDR(PA,KC,X_WRITE_NIL);
{
auto v = (float *)ptr;
v[0] = (float)reg.f[B];
v[1] = (float)reg.f[B+1];
v[2] = (float)reg.f[B+2];
v[3] = (float)reg.f[B+3];
}
NEXTOP;
OP(SFV4_R):
ASSERTA(a); ASSERTF(B+3); ASSERTD(C);
GETADDR(PA,RC,X_WRITE_NIL);
{
auto v = (float *)ptr;
v[0] = (float)reg.f[B];
v[1] = (float)reg.f[B+1];
v[2] = (float)reg.f[B+2];
v[3] = (float)reg.f[B+3];
}
NEXTOP;
OP(SBIT):
ASSERTA(a); ASSERTD(B);
GETADDR(PA,0,X_WRITE_NIL);
@ -767,6 +811,15 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
::new(param + 2) VMValue(reg.f[b + 2]);
f->NumParam += 2;
break;
case REGT_FLOAT | REGT_MULTIREG4:
assert(b < f->NumRegF - 3);
assert(f->NumParam < sfunc->MaxParam - 2);
::new(param) VMValue(reg.f[b]);
::new(param + 1) VMValue(reg.f[b + 1]);
::new(param + 2) VMValue(reg.f[b + 2]);
::new(param + 3) VMValue(reg.f[b + 3]);
f->NumParam += 3;
break;
case REGT_FLOAT | REGT_ADDROF:
assert(b < f->NumRegF);
::new(param) VMValue(&reg.f[b]);
@ -2173,7 +2226,11 @@ static void SetReturn(const VMRegisters &reg, VMFrame *frame, VMReturn *ret, VM_
assert(regnum < frame->NumRegF);
src = &reg.f[regnum];
}
if (regtype & REGT_MULTIREG3)
if (regtype & REGT_MULTIREG4)
{
ret->SetVector4((double*)src);
}
else if (regtype & REGT_MULTIREG3)
{
ret->SetVector((double *)src);
}

View file

@ -85,8 +85,8 @@ xx(SV2, sv2, RPRVKI, SV2_R, 4, REGT_INT) // store vector2
xx(SV2_R, sv2, RPRVRI, NOP, 0, 0)
xx(SV3, sv3, RPRVKI, SV3_R, 4, REGT_INT) // store vector3
xx(SV3_R, sv3, RPRVRI, NOP, 0, 0)
xx(SV4, sv3, RPRVKI, SV4_R, 4, REGT_INT) // store vector4
xx(SV4_R, sv3, RPRVRI, NOP, 0, 0)
xx(SV4, sv4, RPRVKI, SV4_R, 4, REGT_INT) // store vector4
xx(SV4_R, sv4, RPRVRI, NOP, 0, 0)
xx(SFV2, sfv2, RPRVKI, SFV2_R, 4, REGT_INT) // store fvector2
xx(SFV2_R, sfv2, RPRVRI, NOP, 0, 0)
xx(SFV3, sfv3, RPRVKI, SFV3_R, 4, REGT_INT) // store fvector3
@ -265,7 +265,7 @@ xx(LENV3, lenv3, RFRV, NOP, 0, 0) // fA = vB.Length
xx(EQV3_R, beqv3, CVRR, NOP, 0, 0) // if ((vB == vkC) != A) then pc++ (inexact if A & 33)
xx(EQV3_K, beqv3, CVRK, NOP, 0, 0) // this will never be used.
// Vector math (4D/Quaternion)
// Vector math (4D)
xx(NEGV4, negv4, RVRV, NOP, 0, 0) // vA = -vB
xx(ADDV4_RR, addv4, RVRVRV, NOP, 0, 0) // vA = vB + vkC
xx(SUBV4_RR, subv4, RVRVRV, NOP, 0, 0) // vA = vkB - vkC