Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export cycle_internal for single stepping #1255

Closed
wants to merge 1 commit into from

Conversation

donno2048
Copy link
Contributor

Using a cycles function approach was suggested in #103 as a single-stepping solution.

The exported cycle was removed however.

I think it could be useful to export such a function, maybe the cycle_internal should be having some wrapping before it can be shipped, but I think it'd beneficial overall.

@copy
Copy link
Owner

copy commented Feb 18, 2025

I think exposing cycle_internal is sub-optimal for two reasons:

  • It doesn't really single step, e.g. the jitted code will usually execute more than one instruction
  • It's a big function that is called often, so exporting it may negatively affect inlining decisions and/or code size

What you really want is probably something like this:

#[no_mangle]
unsafe fn single_step() {
    *previous_ip = *instruction_pointer;
    let opcode = match read_imm8() {
        Ok(x) => x,
        Err(()) => return,
    };
    run_instruction(opcode | (*is_32 as i32) << 8);
    *instruction_counter += 1;
}

Note that this may still execute more than one instruction in a few cases, e.g. after STI or REP prefixes (I wouldn't mind a flag to disable that, if you really need it).

@donno2048
Copy link
Contributor Author

I think exposing cycle_internal is sub-optimal for two reasons:

  • It doesn't really single step, e.g. the jitted code will usually execute more than one instruction

I guess, my use-case was more "clocking" over single-stepping so it didn't matter, but in general, it may not be a good decision...

@copy
Copy link
Owner

copy commented Feb 20, 2025

I guess, my use-case was more "clocking" over single-stepping so it didn't matter, but in general, it may not be a good decision...

What is the goal here? Clocking may be interesting to have directly in v86.

@donno2048
Copy link
Contributor Author

Just to adjust the clock speed of the "cpu" to fit better the clock speed required by the program

@copy
Copy link
Owner

copy commented Feb 20, 2025

Just to adjust the clock speed of the "cpu" to fit better the clock speed required by the program

That sounds useful to other people, I'd suggest to upstream that feature directly rather than exposing cycle_internal. Let's close this PR.

@copy copy closed this Feb 20, 2025
@donno2048 donno2048 deleted the patch-1 branch February 20, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants