Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions majit/majit-backend-cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16808,18 +16808,9 @@ impl majit_backend::Backend for CraneliftBackend {

/// llmodel.py:816 bh_call_i: ABI-correct dispatch.
///
/// ARM64/x86-64 C ABI assigns integer and float args to independent register
/// files (x0-x7 + d0-d7 on ARM64; rdi,rsi,… + xmm0-xmm7 on x86-64).
/// We construct `fn(ints…, floats…) -> i64` which places each group in the
/// correct register file regardless of their original interleaving order.
///
/// llmodel.py:816-820 bh_call_i(func, args_i, args_r, args_f, calldescr)
/// calldescr.call_stub_i(func, args_i, args_r, args_f).
///
/// On ARM64/x86-64, the C ABI assigns integer and floating-point args to
/// independent register files (x0-x7 / d0-d7 on ARM64; rdi,rsi,... /
/// xmm0-xmm7 on x86-64). So we can always construct the function pointer
/// as `fn(ints..., floats...) -> i64` and get the correct register layout.
/// Routes through `majit_backend::call_stub::bh_call_i_dispatch`, whose
/// signature is built in `arg_classes` declaration order to match
/// `descr.py:574` / `descr.py:604-605 create_call_stub`.
fn bh_call_i(
&self,
func: i64,
Expand All @@ -16831,15 +16822,13 @@ impl majit_backend::Backend for CraneliftBackend {
if func == 0 {
return 0;
}
let (int_args, float_args) = majit_backend::call_stub::collect_call_args(
let (classes, args) = majit_backend::call_stub::collect_call_args(
&calldescr.arg_classes,
args_i,
args_r,
args_f,
);
unsafe {
majit_backend::call_stub::bh_call_i_dispatch(func as usize, &int_args, &float_args)
}
unsafe { majit_backend::call_stub::bh_call_i_dispatch(func as usize, &classes, &args) }
}

/// llmodel.py:818 bh_call_r: GcRef-returning parallel of `bh_call_i`.
Expand All @@ -16859,19 +16848,18 @@ impl majit_backend::Backend for CraneliftBackend {
if func == 0 {
return majit_ir::GcRef::NULL;
}
let (int_args, float_args) = majit_backend::call_stub::collect_call_args(
let (classes, args) = majit_backend::call_stub::collect_call_args(
&calldescr.arg_classes,
args_i,
args_r,
args_f,
);
let raw = unsafe {
majit_backend::call_stub::bh_call_i_dispatch(func as usize, &int_args, &float_args)
};
let raw =
unsafe { majit_backend::call_stub::bh_call_i_dispatch(func as usize, &classes, &args) };
majit_ir::GcRef(raw as usize)
}

/// llmodel.py:825 bh_call_f / descr.py:590-602 create_call_stub
/// llmodel.py:825 bh_call_f / descr.py:584-605 create_call_stub
/// (`RESULT == lltype.Float`): route through the f64-typed
/// dispatcher so the result lands in xmm0 / d0 rather than rax /
/// x0. Without this override `bhimpl_residual_call_*_f` would
Expand All @@ -16888,18 +16876,16 @@ impl majit_backend::Backend for CraneliftBackend {
if func == 0 {
return 0.0;
}
let (int_args, float_args) = majit_backend::call_stub::collect_call_args(
let (classes, args) = majit_backend::call_stub::collect_call_args(
&calldescr.arg_classes,
args_i,
args_r,
args_f,
);
unsafe {
majit_backend::call_stub::bh_call_f_dispatch(func as usize, &int_args, &float_args)
}
unsafe { majit_backend::call_stub::bh_call_f_dispatch(func as usize, &classes, &args) }
}

/// llmodel.py:834 bh_call_v / descr.py:590-602 create_call_stub
/// llmodel.py:834 bh_call_v / descr.py:590-605 create_call_stub
/// (`RESULT == lltype.Void`): dispatch via the void-typed stub so
/// the funcptr is transmuted to `extern "C" fn(...) -> ()`. Without
/// this override the canonical `residual_call_*_v` walker would
Expand All @@ -16913,22 +16899,22 @@ impl majit_backend::Backend for CraneliftBackend {
args_f: Option<&[i64]>,
calldescr: &majit_translate::jitcode::BhCallDescr,
) {
// llmodel.py:834 bh_call_v / descr.py:590-602 create_call_stub
// llmodel.py:834 bh_call_v / descr.py:590-605 create_call_stub
// (`RESULT == lltype.Void`) parity: route through the void-typed
// dispatcher so genuinely void C callees use the right C-ABI
// signature instead of `extern "C" fn(...) -> i64` (which reads
// garbage from rax/x0).
if func == 0 {
return;
}
let (int_args, float_args) = majit_backend::call_stub::collect_call_args(
let (classes, args) = majit_backend::call_stub::collect_call_args(
&calldescr.arg_classes,
args_i,
args_r,
args_f,
);
unsafe {
majit_backend::call_stub::bh_call_v_dispatch(func as usize, &int_args, &float_args);
majit_backend::call_stub::bh_call_v_dispatch(func as usize, &classes, &args);
}
}

Expand Down
35 changes: 14 additions & 21 deletions majit/majit-backend-dynasm/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3341,11 +3341,9 @@ impl Backend for DynasmBackend {

/// llmodel.py:816 bh_call_i: ABI-correct dispatch via the shared call stub.
///
/// On ARM64/x86-64 the C ABI assigns integer and float args to independent
/// register files, so a typed `extern "C" fn(I × ints, F × floats) -> i64`
/// transmute lands them correctly regardless of original interleaving.
/// Routes through `majit_backend::call_stub::bh_call_i_dispatch` which
/// owns the arity table previously embedded in cranelift's `compiler.rs`.
/// Routes through `majit_backend::call_stub::bh_call_i_dispatch`, whose
/// signature is built in `arg_classes` declaration order to match
/// `descr.py:574` / `descr.py:604-605 create_call_stub`.
fn bh_call_i(
&self,
func: i64,
Expand All @@ -3357,15 +3355,13 @@ impl Backend for DynasmBackend {
if func == 0 {
return 0;
}
let (int_args, float_args) = majit_backend::call_stub::collect_call_args(
let (classes, args) = majit_backend::call_stub::collect_call_args(
&calldescr.arg_classes,
args_i,
args_r,
args_f,
);
unsafe {
majit_backend::call_stub::bh_call_i_dispatch(func as usize, &int_args, &float_args)
}
unsafe { majit_backend::call_stub::bh_call_i_dispatch(func as usize, &classes, &args) }
}

/// llmodel.py:818 bh_call_r: GcRef-returning parallel of `bh_call_i`.
Expand All @@ -3385,19 +3381,18 @@ impl Backend for DynasmBackend {
if func == 0 {
return majit_ir::GcRef::NULL;
}
let (int_args, float_args) = majit_backend::call_stub::collect_call_args(
let (classes, args) = majit_backend::call_stub::collect_call_args(
&calldescr.arg_classes,
args_i,
args_r,
args_f,
);
let raw = unsafe {
majit_backend::call_stub::bh_call_i_dispatch(func as usize, &int_args, &float_args)
};
let raw =
unsafe { majit_backend::call_stub::bh_call_i_dispatch(func as usize, &classes, &args) };
majit_ir::GcRef(raw as usize)
}

/// llmodel.py:825 bh_call_f / descr.py:590-602 create_call_stub
/// llmodel.py:825 bh_call_f / descr.py:584-605 create_call_stub
/// (`RESULT == lltype.Float`) parity: route through the f64-typed
/// dispatcher so an f64-returning C callee delivers via xmm0 / d0
/// instead of rax / x0. Without this override
Expand All @@ -3414,18 +3409,16 @@ impl Backend for DynasmBackend {
if func == 0 {
return 0.0;
}
let (int_args, float_args) = majit_backend::call_stub::collect_call_args(
let (classes, args) = majit_backend::call_stub::collect_call_args(
&calldescr.arg_classes,
args_i,
args_r,
args_f,
);
unsafe {
majit_backend::call_stub::bh_call_f_dispatch(func as usize, &int_args, &float_args)
}
unsafe { majit_backend::call_stub::bh_call_f_dispatch(func as usize, &classes, &args) }
}

/// llmodel.py:834 bh_call_v / descr.py:590-602 create_call_stub
/// llmodel.py:834 bh_call_v / descr.py:590-605 create_call_stub
/// (`RESULT == lltype.Void`) parity: dispatch the funcptr through
/// the void-typed `bh_call_v_dispatch` so a genuinely void C callee
/// is called with the right C-ABI signature. Re-routing through
Expand All @@ -3446,14 +3439,14 @@ impl Backend for DynasmBackend {
if func == 0 {
return;
}
let (int_args, float_args) = majit_backend::call_stub::collect_call_args(
let (classes, args) = majit_backend::call_stub::collect_call_args(
&calldescr.arg_classes,
args_i,
args_r,
args_f,
);
unsafe {
majit_backend::call_stub::bh_call_v_dispatch(func as usize, &int_args, &float_args);
majit_backend::call_stub::bh_call_v_dispatch(func as usize, &classes, &args);
}
}

Expand Down
Loading
Loading