- backported Vector*::Sum() from Raze.

This commit is contained in:
Christoph Oelckers 2022-11-14 19:49:37 +01:00
parent 31ac1bd414
commit 4994e114c8
3 changed files with 20 additions and 0 deletions

View file

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

View file

@ -202,6 +202,7 @@ std2:
'super' { RET(ParseVersion >= MakeVersion(1, 0, 0)? TK_Super : TK_Identifier); }
'stop' { RET(TK_Stop); }
'null' { RET(TK_Null); }
'nullptr' { RET(ParseVersion >= MakeVersion(4, 9, 0)? TK_Null : TK_Identifier); }
'is' { RET(ParseVersion >= MakeVersion(1, 0, 0)? TK_Is : TK_Identifier); }
'replaces' { RET(ParseVersion >= MakeVersion(1, 0, 0)? TK_Replaces : TK_Identifier); }

View file

@ -9365,6 +9365,7 @@ FxExpression *FxVectorBuiltin::Resolve(FCompileContext &ctx)
assert(Self->IsVector());
case NAME_Length:
case NAME_LengthSquared:
case NAME_Sum:
ValueType = TypeFloat64;
break;
@ -9396,6 +9397,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);