Skip to content

add jp, jnp, jo, jno - #19

Merged
evmar merged 1 commit into
evmar:mainfrom
LinusU:lu-jcc-parity-overflow
Sep 9, 2026
Merged

add jp, jnp, jo, jno#19
evmar merged 1 commit into
evmar:mainfrom
LinusU:lu-jcc-parity-overflow

Conversation

@LinusU

@LinusU LinusU commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Hey again @evmar, long time no see! 👋

I've been setting loose a number of different models to go nuts on my childhood games to see what comes of it. And I saw that they did a lot of overlapping work, and I would also love to contribute things upstream to you!

If you want this, my plan is to continue sending bite sized, hopefully somewhat easy for you to review, PRs. But I do 100% understand if this is not something that you would appreciate.

Anyhow, if you want it, here is the first one. I just adds some jump instructions that were missing.

Clauds description of the changes:

Adds the parity and overflow conditional jumps, mirroring the existing js/jns
pattern. The flags are already computed by the arithmetic and shift ops and
restored by sahf, so these just read them.

jp/jnp show up in every MSVC floating-point compare sequence (fnstsw / sahf /
jp), so this unblocks running most programs that touch the x87.

Verified with cargo fmt, cargo test, and the winapi-exe smoke build.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@evmar

evmar commented Sep 9, 2026

Copy link
Copy Markdown
Owner

I love this, and would love to help you however I can! Thanks for the patch!

@evmar
evmar merged commit 2294324 into evmar:main Sep 9, 2026
}

pub fn jp(&mut self, from: Cont, x: Cont) -> Cont {
if self.cpu.flags.contains(Flags::PF) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, note that none of the operations that affect parity currently set this flag, so these instructions won't do the right thing 😬

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it!

@evmar evmar Sep 10, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parity is really annoying because in principle all the arithmetic operations compute it, and then it's almost never actually needed.

Originally what I did in retrowin32 was a hack where if the decoder saw a jp/jnp, it would panic if the previous instruction wasn't some specific thing, so then when it hit the jnp it could retroactively compute parity. (In both links I'm talking about the deleted code)

In my ideal world in theseus we could statically analyze the code enough that we would know when we actually need parity computation or not, similar to this hack but principled and covering all the cases. But I think until we hit that world, just computing parity always (like the added code in the above diff) is probably fine, and I can think of the static analysis thing as an optimization. (Lately I've been working on the static analysis bit of things, which is why I haven't committed to Theseus in a bit!)

@LinusU
LinusU deleted the lu-jcc-parity-overflow branch September 10, 2026 08:01
@LinusU

LinusU commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

That's so fun to hear! I just got sound working in Moto Racer and got to complete an entire race, so fun to see it working on modern hardware 🤩

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