Skip to content
Closed
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ in both state modes, updating twelve more expectation rows. The scanner probes
retain failures caused by unsupported `final` constructs or internal data types;
no scanner expectation is changed.

The `string` implementation updates forty-two reviewed expectation rows: both
state modes for `5.13-builtin-methods-strings`, `6.16--string`, the sixteen
`6.16.*` method cases, `6.20.4--localparam_string`,
`11.4.12.2--string_concat_op` and `11.4.12.2--string_repl_op` change from fail
to pass. Each was simulated and its values checked, not only elaborated. Full
official runs at the pinned revision report 507 passing cases in 2state and 509
in 4state. No passing case regresses. The `12.7.3--foreach`, `12.7.4--while` and
`12.7.5--dowhile` cases keep failing: they use an unpacked array of strings,
which is rejected because its element and character selects are not yet told
apart.

The report contains each case’s state mode, verdict, selected execution mode,
tags, tool return code and path to the official log. The output directory retains
both the official log and runner diagnostics for each case and state mode.
Expand Down
84 changes: 42 additions & 42 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ chapter-11/11.4.12.1--repl_op-sim.sv 2state pass
chapter-11/11.4.12.1--repl_op-sim.sv 4state pass
chapter-11/11.4.12.1--repl_op.sv 2state pass
chapter-11/11.4.12.1--repl_op.sv 4state pass
chapter-11/11.4.12.2--string_concat_op.sv 2state fail
chapter-11/11.4.12.2--string_concat_op.sv 4state fail
chapter-11/11.4.12.2--string_repl_op.sv 2state fail
chapter-11/11.4.12.2--string_repl_op.sv 4state fail
chapter-11/11.4.12.2--string_concat_op.sv 2state pass
chapter-11/11.4.12.2--string_concat_op.sv 4state pass
chapter-11/11.4.12.2--string_repl_op.sv 2state pass
chapter-11/11.4.12.2--string_repl_op.sv 4state pass
chapter-11/11.4.13--set_member-sim.sv 2state pass
chapter-11/11.4.13--set_member-sim.sv 4state pass
chapter-11/11.4.13--set_member.sv 2state pass
Expand Down Expand Up @@ -1011,8 +1011,8 @@ chapter-5/5.12-attributes-operator.sv 2state pass
chapter-5/5.12-attributes-operator.sv 4state pass
chapter-5/5.12-attributes-variable.sv 2state pass
chapter-5/5.12-attributes-variable.sv 4state pass
chapter-5/5.13-builtin-methods-strings.sv 2state fail
chapter-5/5.13-builtin-methods-strings.sv 4state fail
chapter-5/5.13-builtin-methods-strings.sv 2state pass
chapter-5/5.13-builtin-methods-strings.sv 4state pass
chapter-5/5.4--coments.sv 2state pass
chapter-5/5.4--coments.sv 4state pass
chapter-5/5.6--identifiers.sv 2state pass
Expand Down Expand Up @@ -1109,44 +1109,44 @@ chapter-6/6.13--void.sv 2state pass
chapter-6/6.13--void.sv 4state pass
chapter-6/6.14--chandle.sv 2state fail
chapter-6/6.14--chandle.sv 4state fail
chapter-6/6.16--string.sv 2state fail
chapter-6/6.16--string.sv 4state fail
chapter-6/6.16.1--string_len.sv 2state fail
chapter-6/6.16.1--string_len.sv 4state fail
chapter-6/6.16--string.sv 2state pass
chapter-6/6.16--string.sv 4state pass
chapter-6/6.16.1--string_len.sv 2state pass
chapter-6/6.16.1--string_len.sv 4state pass
chapter-6/6.16.10--string_atoreal.sv 2state fail
chapter-6/6.16.10--string_atoreal.sv 4state fail
chapter-6/6.16.11--string_itoa.sv 2state fail
chapter-6/6.16.11--string_itoa.sv 4state fail
chapter-6/6.16.12--string_hextoa.sv 2state fail
chapter-6/6.16.12--string_hextoa.sv 4state fail
chapter-6/6.16.13--string_octtoa.sv 2state fail
chapter-6/6.16.13--string_octtoa.sv 4state fail
chapter-6/6.16.14--string_bintoa.sv 2state fail
chapter-6/6.16.14--string_bintoa.sv 4state fail
chapter-6/6.16.11--string_itoa.sv 2state pass
chapter-6/6.16.11--string_itoa.sv 4state pass
chapter-6/6.16.12--string_hextoa.sv 2state pass
chapter-6/6.16.12--string_hextoa.sv 4state pass
chapter-6/6.16.13--string_octtoa.sv 2state pass
chapter-6/6.16.13--string_octtoa.sv 4state pass
chapter-6/6.16.14--string_bintoa.sv 2state pass
chapter-6/6.16.14--string_bintoa.sv 4state pass
chapter-6/6.16.15--string_realtoa.sv 2state fail
chapter-6/6.16.15--string_realtoa.sv 4state fail
chapter-6/6.16.2--string_putc.sv 2state fail
chapter-6/6.16.2--string_putc.sv 4state fail
chapter-6/6.16.3--string_getc.sv 2state fail
chapter-6/6.16.3--string_getc.sv 4state fail
chapter-6/6.16.4--string_toupper.sv 2state fail
chapter-6/6.16.4--string_toupper.sv 4state fail
chapter-6/6.16.5--string_tolower.sv 2state fail
chapter-6/6.16.5--string_tolower.sv 4state fail
chapter-6/6.16.6--string_compare.sv 2state fail
chapter-6/6.16.6--string_compare.sv 4state fail
chapter-6/6.16.7--string_icompare.sv 2state fail
chapter-6/6.16.7--string_icompare.sv 4state fail
chapter-6/6.16.8--string_substr.sv 2state fail
chapter-6/6.16.8--string_substr.sv 4state fail
chapter-6/6.16.9--string_atobin.sv 2state fail
chapter-6/6.16.9--string_atobin.sv 4state fail
chapter-6/6.16.9--string_atohex.sv 2state fail
chapter-6/6.16.9--string_atohex.sv 4state fail
chapter-6/6.16.9--string_atoi.sv 2state fail
chapter-6/6.16.9--string_atoi.sv 4state fail
chapter-6/6.16.9--string_atooct.sv 2state fail
chapter-6/6.16.9--string_atooct.sv 4state fail
chapter-6/6.16.2--string_putc.sv 2state pass
chapter-6/6.16.2--string_putc.sv 4state pass
chapter-6/6.16.3--string_getc.sv 2state pass
chapter-6/6.16.3--string_getc.sv 4state pass
chapter-6/6.16.4--string_toupper.sv 2state pass
chapter-6/6.16.4--string_toupper.sv 4state pass
chapter-6/6.16.5--string_tolower.sv 2state pass
chapter-6/6.16.5--string_tolower.sv 4state pass
chapter-6/6.16.6--string_compare.sv 2state pass
chapter-6/6.16.6--string_compare.sv 4state pass
chapter-6/6.16.7--string_icompare.sv 2state pass
chapter-6/6.16.7--string_icompare.sv 4state pass
chapter-6/6.16.8--string_substr.sv 2state pass
chapter-6/6.16.8--string_substr.sv 4state pass
chapter-6/6.16.9--string_atobin.sv 2state pass
chapter-6/6.16.9--string_atobin.sv 4state pass
chapter-6/6.16.9--string_atohex.sv 2state pass
chapter-6/6.16.9--string_atohex.sv 4state pass
chapter-6/6.16.9--string_atoi.sv 2state pass
chapter-6/6.16.9--string_atoi.sv 4state pass
chapter-6/6.16.9--string_atooct.sv 2state pass
chapter-6/6.16.9--string_atooct.sv 4state pass
chapter-6/6.17--event.sv 2state fail
chapter-6/6.17--event.sv 4state fail
chapter-6/6.18--typedef.sv 2state pass
Expand Down Expand Up @@ -1209,8 +1209,8 @@ chapter-6/6.20.4--localparam_int.sv 2state pass
chapter-6/6.20.4--localparam_int.sv 4state pass
chapter-6/6.20.4--localparam_logic.sv 2state pass
chapter-6/6.20.4--localparam_logic.sv 4state pass
chapter-6/6.20.4--localparam_string.sv 2state fail
chapter-6/6.20.4--localparam_string.sv 4state fail
chapter-6/6.20.4--localparam_string.sv 2state pass
chapter-6/6.20.4--localparam_string.sv 4state pass
chapter-6/6.20.4--localparam_unsigned_int.sv 2state pass
chapter-6/6.20.4--localparam_unsigned_int.sv 4state pass
chapter-6/6.20.5--specparam.sv 2state pass
Expand Down
24 changes: 18 additions & 6 deletions crates/celox-backend-arm64/src/scalar/extern_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ pub(super) fn emit_call_extern(
saved: &[u8],
pinned_fp: &[u8],
) -> Result<(), EmitError> {
let register_args = args.len().min(REGISTER_ARGS);
// The heap helper takes the state pointer before the arguments, so C
// argument `position` is `args[position - leading]`.
let heap = func == celox_sir::extern_abi::HEAP_HELPER_ID;
let leading = usize::from(heap);
let positions = args.len() + leading;
let register_args = positions.min(REGISTER_ARGS);
// Outgoing stack arguments sit at SP, followed by the staged register
// arguments and the save areas.
let staging = args.len().saturating_sub(REGISTER_ARGS) * 8;
let staging = positions.saturating_sub(REGISTER_ARGS) * 8;
let gpr_save = staging + register_args * 8;
let fp_save = gpr_save + saved.len() * 8;
let frame = (fp_save + pinned_fp.len() * 8 + 15) & !15;
Expand All @@ -80,10 +85,11 @@ pub(super) fn emit_call_extern(
// Write every argument before overwriting any argument register, so
// the moves into x0-x7 cannot clobber a source.
for (index, &value) in args.iter().enumerate() {
let offset = if index < REGISTER_ARGS {
staging + index * 8
let position = index + leading;
let offset = if position < REGISTER_ARGS {
staging + position * 8
} else {
(index - REGISTER_ARGS) * 8
(position - REGISTER_ARGS) * 8
};
emit_store_at(
ops,
Expand All @@ -93,7 +99,7 @@ pub(super) fn emit_call_extern(
OpSize::S64,
);
}
for index in 0..register_args {
for index in leading..register_args {
emit_load_at(
ops,
index as u8,
Expand All @@ -102,6 +108,10 @@ pub(super) fn emit_call_extern(
OpSize::S64,
);
}
if heap {
// The state pointer is the saved x0.
emit_load_at(ops, 0, 31, gpr_save as i64, OpSize::S64);
}

// The state pointer is the saved x0.
emit_load_at(ops, SCRATCH1, 31, gpr_save as i64, OpSize::S64);
Expand All @@ -114,6 +124,8 @@ pub(super) fn emit_call_extern(
);
let offset = if func == celox_sir::float::FLOAT_HELPER_ID {
-8
} else if heap {
-16
} else {
i64::from(func) * 8
};
Expand Down
22 changes: 17 additions & 5 deletions crates/celox-backend-cranelift/src/translator/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,23 +489,35 @@ impl SIRTranslator {
state.mem_ptr,
celox_state_layout::STATE_HEADER_EXTERN_FUNCTIONS_ADDR_OFFSET as i32,
);
// The heap helper sits two slots before the user table and takes the
// state pointer before its arguments.
let heap = func == celox_sir::extern_abi::HEAP_HELPER_ID;
let function = state.builder.ins().load(
types::I64,
MemFlags::trusted(),
table,
i32::try_from(func as u64 * 8).expect("extern function index fits the table"),
if heap {
-16
} else {
i32::try_from(func as u64 * 8).expect("extern function index fits the table")
},
);

let mut signature = Signature::new(self.target_config.default_call_conv);
signature
.params
.extend(args.iter().map(|_| AbiParam::new(types::I64)));
.extend((0..args.len() + usize::from(heap)).map(|_| AbiParam::new(types::I64)));
signature.returns.push(AbiParam::new(types::I64));
let signature = state.builder.import_signature(signature);

let arguments = args
.iter()
.map(|arg| self.extern_call_argument(state, *arg))
let arguments = heap
.then_some(state.mem_ptr)
.into_iter()
.chain(
args.iter()
.map(|arg| self.extern_call_argument(state, *arg))
.collect::<Vec<_>>(),
)
.collect::<Vec<_>>();
let call = state
.builder
Expand Down
23 changes: 17 additions & 6 deletions crates/celox-backend-x86/src/backend/native/emit/extern_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,39 @@ pub(super) fn emit_call_extern(
} else {
(&[rdi, rsi, rdx, rcx, r8, r9], 0)
};
let arg_count = usize::from(arg_count);
// The heap helper takes the state pointer before the staged arguments.
let heap = func == celox_sir::extern_abi::HEAP_HELPER_ID;
let leading = usize::from(heap);
let arg_count = usize::from(arg_count) + leading;
let stack_args = arg_count.saturating_sub(registers.len()) as i32;
// Generated code is entered with RSP = 8 (mod 16) and never moves it.
let frame = ((shadow + 8 * stack_args + 15) & !15) + 8;
asm.sub(rsp, frame)?;
for slot in registers.len()..arg_count {
let slot = slot as i32;
// C argument `position` comes from call-area slot `position - leading`.
for position in registers.len()..arg_count {
let slot = (position - leading) as i32;
asm.mov(rax, qword_ptr(rbx + (area + 8 * slot)))?;
asm.mov(
qword_ptr(rsp + (shadow + 8 * (slot - registers.len() as i32))),
qword_ptr(rsp + (shadow + 8 * (position - registers.len()) as i32)),
rax,
)?;
}
for (slot, &register) in registers.iter().enumerate().take(arg_count) {
asm.mov(register, qword_ptr(rbx + (area + 8 * slot as i32)))?;
for (position, &register) in registers.iter().enumerate().take(arg_count) {
if position < leading {
asm.mov(register, rbx)?;
} else {
let slot = (position - leading) as i32;
asm.mov(register, qword_ptr(rbx + (area + 8 * slot)))?;
}
}
asm.mov(
rax,
qword_ptr(rbx + celox_state_layout::STATE_HEADER_EXTERN_FUNCTIONS_ADDR_OFFSET as i32),
)?;
let offset = if func == celox_sir::float::FLOAT_HELPER_ID {
-8
} else if heap {
-16
} else {
i32::try_from(u64::from(func) * 8).expect("extern function index")
};
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-backend-x86/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ const _: () = {
);
assert!(
celox_state_layout::STATE_HEADER_EXTERN_FUNCTIONS_ADDR_OFFSET + 8
<= celox_state_layout::STATE_HEADER_HEAP_ADDR_OFFSET
);
assert!(
celox_state_layout::STATE_HEADER_HEAP_ADDR_OFFSET + 8
<= celox_state_layout::STATE_HEADER_SIZE
);
};
Expand Down
5 changes: 5 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ pub struct RuntimeEventSite {
pub arg_is_string: Vec<bool>,
#[serde(default)]
pub arg_float_precision: Vec<Option<FloatPrecision>>,
/// Arguments that are heap handles of strings, formatted as their
/// contents. Missing entries are not handles.
#[serde(default)]
pub arg_is_handle: Vec<bool>,
}

/// A function in the host's C ABI that the design calls, such as a
Expand Down Expand Up @@ -1599,6 +1603,7 @@ mod tests {
arg_signed: Vec::new(),
arg_is_string: Vec::new(),
arg_float_precision: Vec::new(),
arg_is_handle: Vec::new(),
});
runtime.comb_observers.push(RuntimeCombObserver {
site_id: 0,
Expand Down
Loading
Loading