- added a 'Sum()' intrinsic to the vectors.

This commit is contained in:
Christoph Oelckers 2022-11-14 12:04:56 +01:00
parent 306db376d9
commit cbf47b4dee
2 changed files with 20 additions and 1 deletions

View file

@ -152,6 +152,7 @@ xx(stateinfo)
xx(DamageFunction)
xx(Length)
xx(LengthSquared)
xx(Sum)
xx(Unit)
xx(Angle)
xx(PlusZ)

View file

@ -8273,7 +8273,7 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
else if (Self->IsVector())
{
// handle builtins: Vectors got 5.
if (MethodName == NAME_Length || MethodName == NAME_LengthSquared || MethodName == NAME_Unit || MethodName == NAME_Angle)
if (MethodName == NAME_Length || MethodName == NAME_LengthSquared || MethodName == NAME_Sum || MethodName == NAME_Unit || MethodName == NAME_Angle)
{
if (ArgList.Size() > 0)
{
@ -9280,6 +9280,7 @@ FxExpression *FxVectorBuiltin::Resolve(FCompileContext &ctx)
{
case NAME_Length:
case NAME_LengthSquared:
case NAME_Sum:
case NAME_Angle:
ValueType = TypeFloat64;
break;
@ -9312,6 +9313,23 @@ ExpEmit FxVectorBuiltin::Emit(VMFunctionBuilder *build)
{
build->Emit(vecSize == 2 ? OP_DOTV2_RR : vecSize == 3 ? OP_DOTV3_RR : OP_DOTV4_RR, to.RegNum, op.RegNum, op.RegNum);
}
else if (Function == NAME_Sum)
{
ExpEmit temp(build, ValueType->GetRegType(), 1);
build->Emit(OP_FLOP, to.RegNum, op.RegNum, FLOP_ABS);
build->Emit(OP_FLOP, temp.RegNum, op.RegNum + 1, FLOP_ABS);
build->Emit(OP_ADDF_RR, to.RegNum, to.RegNum, temp.RegNum);
if (vecSize > 2)
{
build->Emit(OP_FLOP, temp.RegNum, op.RegNum + 2, FLOP_ABS);
build->Emit(OP_ADDF_RR, to.RegNum, to.RegNum, temp.RegNum);
}
if (vecSize > 3)
{
build->Emit(OP_FLOP, temp.RegNum, op.RegNum + 3, FLOP_ABS);
build->Emit(OP_ADDF_RR, to.RegNum, to.RegNum, temp.RegNum);
}
}
else if (Function == NAME_Unit)
{
ExpEmit len(build, REGT_FLOAT);