set u64 from float

This commit is contained in:
water
2021-08-12 20:09:25 -04:00
parent 69aad00760
commit d829db1da5
3 changed files with 22 additions and 0 deletions
+9
View File
@@ -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<FunctionEnv>(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<FunctionEnv>(env);
auto src_gpr = fe->make_ireg(src_in_reg->type(), RegClass::GPR_64);
env->emit_ir<IR_RegSet>(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<MemoryOffsetConstantVal*>(base);
@@ -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))
)
+5
View File
@@ -830,6 +830,11 @@ TEST_F(WithGameTests, GetEnumVals) {
"(thing5 . #<invalid object #x5>))\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();