From d829db1da59687684ace41d0bfa00405f19010a0 Mon Sep 17 00:00:00 2001 From: water Date: Thu, 12 Aug 2021 20:09:25 -0400 Subject: [PATCH 1/2] set u64 from float --- goalc/compiler/compilation/Define.cpp | 9 +++++++++ .../with_game/test-set-u64-from-float.gc | 8 ++++++++ test/goalc/test_with_game.cpp | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 test/goalc/source_templates/with_game/test-set-u64-from-float.gc diff --git a/goalc/compiler/compilation/Define.cpp b/goalc/compiler/compilation/Define.cpp index c09f4748cd..b7aee7f071 100644 --- a/goalc/compiler/compilation/Define.cpp +++ b/goalc/compiler/compilation/Define.cpp @@ -226,6 +226,7 @@ Val* Compiler::do_set(const goos::Object& form, Val* dest, RegVal* src_in_reg, V src_in_reg = src_128; } + // we want to allow setting a smaller thing from a 128-bit variable if (as_mem_deref->info.size != 16 && (src_in_reg->ireg().reg_class == RegClass::VECTOR_FLOAT || src_in_reg->ireg().reg_class == RegClass::INT_128)) { auto fe = get_parent_env_of_type(env); @@ -234,6 +235,14 @@ Val* Compiler::do_set(const goos::Object& form, Val* dest, RegVal* src_in_reg, V src_in_reg = src_gpr; } + // we want to allow setting a 64-bit place to a float + if (as_mem_deref->info.size == 8 && src_in_reg->ireg().reg_class == RegClass::FLOAT) { + auto fe = get_parent_env_of_type(env); + auto src_gpr = fe->make_ireg(src_in_reg->type(), RegClass::GPR_64); + env->emit_ir(src_gpr, src_in_reg); + src_in_reg = src_gpr; + } + // setting somewhere in memory auto base = as_mem_deref->base; auto base_as_mco = dynamic_cast(base); diff --git a/test/goalc/source_templates/with_game/test-set-u64-from-float.gc b/test/goalc/source_templates/with_game/test-set-u64-from-float.gc new file mode 100644 index 0000000000..bc7b7887c1 --- /dev/null +++ b/test/goalc/source_templates/with_game/test-set-u64-from-float.gc @@ -0,0 +1,8 @@ +(let ((a (new 'stack-no-clear 'array 'float 4)) + (b (new 'stack-no-clear 'array 'uint64 2)) + ) + (set! (-> b 0) #xbbbbbbbbbbbbbbbb) + (set! (-> a 0) 12.0) + (set! (-> b 0) (the-as uint (- (-> a 0)))) + (format #t "~f #x~X #x~X #x~X~%" (-> b 0) (-> b 0) (-> (the-as (pointer uint32) b) 0) (-> (the-as (pointer uint32) b) 1)) + ) diff --git a/test/goalc/test_with_game.cpp b/test/goalc/test_with_game.cpp index 60d5a0770d..996fb68ebc 100644 --- a/test/goalc/test_with_game.cpp +++ b/test/goalc/test_with_game.cpp @@ -830,6 +830,11 @@ TEST_F(WithGameTests, GetEnumVals) { "(thing5 . #))\n0\n"}); } +TEST_F(WithGameTests, SetU64FromFloat) { + runner.run_static_test(env, testCategory, "test-set-u64-from-float.gc", + {"-12.0000 #xc1400000 #xc1400000 #x0\n0\n"}); +} + TEST(TypeConsistency, TypeConsistency) { Compiler compiler; compiler.enable_throw_on_redefines(); From b5f53bba3fa074b1728adfa7d5240e7904a228ed Mon Sep 17 00:00:00 2001 From: water Date: Thu, 12 Aug 2021 20:12:27 -0400 Subject: [PATCH 2/2] changelog --- docs/markdown/progress-notes/changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/markdown/progress-notes/changelog.md b/docs/markdown/progress-notes/changelog.md index 399e6cf023..3d07971fca 100644 --- a/docs/markdown/progress-notes/changelog.md +++ b/docs/markdown/progress-notes/changelog.md @@ -187,4 +187,5 @@ - Creating arrays on the stack now must be done with `stack-no-clear` as they are not memset to 0 or constructed in any way. - The register allocator has been dramatically improved and generates ~5x fewer spill instructions and is able to eliminate more moves. - Added a `(print-debug-compiler-stats)` form to print out statistics related to register allocation and move elimination -- Added `get-enum-vals` which returns a list of pairs. Each pair is the name (symbol) and value (int) for each value in the enum \ No newline at end of file +- Added `get-enum-vals` which returns a list of pairs. Each pair is the name (symbol) and value (int) for each value in the enum +- It is now possible to set a 64-bit memory location from a float, if you insert a cast. It will zero-extend the float, just like any other float -> 64-bit conversion. \ No newline at end of file