Skip to content

Commit

Permalink
- backported Vector*::Sum() from Raze.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Nov 14, 2022
1 parent 31ac1bd commit 4994e11
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common/engine/namedef.h
Expand Up @@ -154,6 +154,7 @@ xx(stateinfo)
xx(DamageFunction)
xx(Length)
xx(LengthSquared)
xx(Sum)
xx(Unit)
xx(Angle)
xx(PlusZ)
Expand Down
1 change: 1 addition & 0 deletions src/common/engine/sc_man_scanner.re
Expand Up @@ -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); }
Expand Down
18 changes: 18 additions & 0 deletions src/common/scripting/backend/codegen.cpp
Expand Up @@ -9365,6 +9365,7 @@ FxExpression *FxVectorBuiltin::Resolve(FCompileContext &ctx)
assert(Self->IsVector());
case NAME_Length:
case NAME_LengthSquared:
case NAME_Sum:
ValueType = TypeFloat64;
break;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4994e11

Please sign in to comment.