Skip to content

Commit

Permalink
Merge pull request #1470 from ltratt/input_output_float_callg
Browse files Browse the repository at this point in the history
Support calls which take and return floats/double.
  • Loading branch information
ptersilie authored Nov 20, 2024
2 parents c9d6466 + 49bd11c commit adea9c2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
57 changes: 57 additions & 0 deletions tests/c/fp_in_out.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Run-time:
// env-var: YKD_SERIALISE_COMPILATION=1
// env-var: YK_LOG=4
// stderr:
// yk-jit-event: start-tracing
// 5.100000
// 5.200000
// yk-jit-event: stop-tracing
// 4.100000
// 4.200000
// yk-jit-event: enter-jit-code
// 3.100000
// 3.200000
// 2.100000
// 2.200000
// yk-jit-event: deoptimise

// Check that passing floats to/from a function works correctly.

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <yk.h>
#include <yk_testing.h>

__attribute__((yk_outline))
float f_f(float x) {
return x + 1.1;
}

__attribute__((yk_outline))
double f_d(double x) {
return x + 1.2;
}

int main(int argc, char **argv) {
YkMT *mt = yk_mt_new(NULL);
yk_mt_hot_threshold_set(mt, 0);
YkLocation loc = yk_location_new();

int res = 9998;
int i = 4;
NOOPT_VAL(loc);
NOOPT_VAL(res);
NOOPT_VAL(i);
while (i > 0) {
yk_mt_control_point(mt, &loc);
fprintf(stderr, "%f\n", f_f((float) i));
fprintf(stderr, "%f\n", f_d((double) i));
i--;
}
NOOPT_VAL(res);
yk_location_drop(loc);
yk_mt_shutdown(mt);
return (EXIT_SUCCESS);
}
20 changes: 7 additions & 13 deletions ykrt/src/compile/jitc_yk/codegen/x64/lsregalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,15 +825,13 @@ impl LSRegAlloc<'_> {
match cnstr {
RegConstraint::InputIntoReg(_, reg)
| RegConstraint::InputIntoRegAndClobber(_, reg)
| RegConstraint::InputOutputIntoReg(_, reg)
| RegConstraint::OutputFromReg(reg)
| RegConstraint::Clobber(reg) => avoid.set(*reg),
RegConstraint::Input(_)
| RegConstraint::InputOutput(_)
| RegConstraint::Output
| RegConstraint::Temporary => {}
RegConstraint::InputOutputIntoReg(_, _) => {
panic!();
}
}
}

Expand Down Expand Up @@ -870,11 +868,11 @@ impl LSRegAlloc<'_> {
},
RegConstraint::InputIntoReg(_, _)
| RegConstraint::InputIntoRegAndClobber(_, _)
| RegConstraint::InputOutputIntoReg(_, _)
| RegConstraint::Clobber(_) => {
// OPT: do the same trick as Input/InputOutput
}
RegConstraint::Output | RegConstraint::OutputFromReg(_) => (),
RegConstraint::InputOutputIntoReg(_op, _reg) => unreachable!(),
RegConstraint::Temporary => (),
}
}
Expand All @@ -888,20 +886,19 @@ impl LSRegAlloc<'_> {
RegConstraint::Input(op)
| RegConstraint::InputIntoReg(op, _)
| RegConstraint::InputIntoRegAndClobber(op, _)
| RegConstraint::InputOutputIntoReg(op, _)
| RegConstraint::InputOutput(op) => {
let reg = match x {
RegConstraint::Input(_) | RegConstraint::InputOutput(_) => {
self.assign_empty_fp_reg(asm, iidx, avoid)
}
RegConstraint::InputIntoReg(_, reg)
| RegConstraint::InputIntoRegAndClobber(_, reg) => {
| RegConstraint::InputIntoRegAndClobber(_, reg)
| RegConstraint::InputOutputIntoReg(_, reg) => {
// OPT: Not everything needs spilling
self.spill_fp_if_not_already(asm, *reg);
*reg
}
RegConstraint::InputOutputIntoReg(_, _) => {
unreachable!()
}
RegConstraint::Output
| RegConstraint::OutputFromReg(_)
| RegConstraint::Temporary
Expand Down Expand Up @@ -934,14 +931,12 @@ impl LSRegAlloc<'_> {
self.fp_regset.unset(reg);
RegState::Empty
}
RegConstraint::InputOutput(_) => {
RegConstraint::InputOutput(_) | RegConstraint::InputOutputIntoReg(_, _) => {
debug_assert!(!found_output);
found_output = true;
RegState::FromInst(iidx)
}
RegConstraint::InputOutputIntoReg(_, _)
| RegConstraint::Output
| RegConstraint::OutputFromReg(_) => {
RegConstraint::Output | RegConstraint::OutputFromReg(_) => {
unreachable!()
}
RegConstraint::Temporary => todo!(),
Expand Down Expand Up @@ -971,7 +966,6 @@ impl LSRegAlloc<'_> {
avoid.set(*reg);
out[i] = Some(*reg);
}
RegConstraint::InputOutputIntoReg(_, _) => unreachable!(),
RegConstraint::Temporary => {
let reg = self.assign_empty_fp_reg(asm, iidx, avoid);
self.fp_regset.unset(reg);
Expand Down

0 comments on commit adea9c2

Please sign in to comment.