From 3f9cdd9b56c1978a73d23e5c56abd34bb1ef4443 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 4 May 2022 01:10:59 +0200 Subject: [PATCH] vm: fix mul and div instructions --- .../src/prog8/codegen/virtual/CodeGen.kt | 2 ++ docs/source/todo.rst | 1 - examples/test.p8 | 31 +++++-------------- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt b/codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt index 32ce1ce82..73bc80218 100644 --- a/codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt +++ b/codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt @@ -388,6 +388,7 @@ class CodeGen(internal val program: PtProgram, code += VmCodeInstruction(Opcode.LOAD, VmDataType.FLOAT, fpReg1 = fpReg, fpValue = 0f) } else { val factorReg = vmRegisters.nextFreeFloat() + code += VmCodeInstruction(Opcode.LOAD, VmDataType.FLOAT, fpReg1=factorReg, fpValue = factor) code += VmCodeInstruction(Opcode.MUL, VmDataType.FLOAT, fpReg1 = fpReg, fpReg2 = fpReg, fpReg3 = factorReg) } return code @@ -430,6 +431,7 @@ class CodeGen(internal val program: PtProgram, code += VmCodeInstruction(Opcode.LOAD, VmDataType.FLOAT, fpReg1 = fpReg, fpValue = Float.MAX_VALUE) } else { val factorReg = vmRegisters.nextFreeFloat() + code += VmCodeInstruction(Opcode.LOAD, VmDataType.FLOAT, fpReg1=factorReg, fpValue = factor) code += VmCodeInstruction(Opcode.DIV, VmDataType.FLOAT, fpReg1 = fpReg, fpReg2 = fpReg, fpReg3 = factorReg) } return code diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 788137c65..d70856430 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -4,7 +4,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ - vm: implement float any, all, reverse, sort -- vm: fix test fp calc result being 0 - vm: get rid of intermediate floats.xxx() functions somehow, instead generate the float instructions directly? - pipe operator: allow non-unary function calls in the pipe that specify the other argument(s) in the calls. - allow "xxx" * constexpr (where constexpr is not a number literal), now gives expression error not same type diff --git a/examples/test.p8 b/examples/test.p8 index 071ba076e..918b10dd4 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -10,29 +10,14 @@ main { sub start() { float fl = 42.123 float fl2 = fl / 1.0 - txt.print_ub(fl2 as ubyte) - txt.nl() - txt.print_uw(fl2 as uword) - txt.nl() - byte bb = fl2 as byte - txt.print_b(bb) - txt.nl() - txt.print_b(fl2 as byte) - txt.nl() - txt.print_w(fl2 as word) - txt.nl() - word ww = fl2 as word - txt.print_w(ww) - txt.nl() - -; txt.print("rad 180 = ") -; floats.print_f(floats.rad(180.0)) -; txt.print("rad 360 = ") -; floats.print_f(floats.rad(360.0)) -; txt.print("deg 2 = ") -; floats.print_f(floats.deg(2.0)) -; txt.print("deg pi = ") -; floats.print_f(floats.deg(floats.PI)) + txt.print("rad 180 = ") + floats.print_f(floats.rad(180.0)) + txt.print("\nrad 360 = ") + floats.print_f(floats.rad(360.0)) + txt.print("\ndeg 2 = ") + floats.print_f(floats.deg(2.0)) + txt.print("\ndeg pi = ") + floats.print_f(floats.deg(floats.PI)) sys.exit(42) ; floats.print_f(-42.42) ; float f1 = 1.2345