From 719be058e5db54d95325fe029cc800494fb9308c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 2 Dec 2016 00:54:40 +0100 Subject: [PATCH] - use the immediate versions for loading integer constants when possible. --- src/scripting/codegeneration/codegen.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index 2d93dc866..1629c8135 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -2304,14 +2304,29 @@ ExpEmit FxAssign::Emit(VMFunctionBuilder *build) ExpEmit pointer = Base->Emit(build); Address = pointer; - ExpEmit result = Right->Emit(build); + ExpEmit result; + bool intconst = false; + int intconstval; + + if (Right->isConstant() && Right->ValueType->GetRegType() == REGT_INT) + { + intconst = true; + intconstval = static_cast(Right)->GetValue().GetInt(); + result.Konst = true; + result.RegType = REGT_INT; + } + else + { + result = Right->Emit(build); + } assert(result.RegType <= REGT_TYPE); if (pointer.Target) { if (result.Konst) { - build->Emit(loadops[result.RegType], pointer.RegNum, result.RegNum); + if (intconst) build->EmitLoadInt(pointer.RegNum, intconstval); + else build->Emit(loadops[result.RegType], pointer.RegNum, result.RegNum); } else { @@ -2323,7 +2338,8 @@ ExpEmit FxAssign::Emit(VMFunctionBuilder *build) if (result.Konst) { ExpEmit temp(build, result.RegType); - build->Emit(loadops[result.RegType], temp.RegNum, result.RegNum); + if (intconst) build->EmitLoadInt(temp.RegNum, intconstval); + else build->Emit(loadops[result.RegType], temp.RegNum, result.RegNum); result.Free(build); result = temp; }