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

XEmitter: Add enum class Force5Bytes #11834

Conversation

Dentomologist
Copy link
Contributor

@Dentomologist Dentomologist commented May 21, 2023

Replace the bool parameter force5bytes in J, JMP, and J_CC with an enum class. Many callers set that parameter to the literal 'true', which was unclear if you didn't already know what it did.

@AdmiralCurtiss
Copy link
Contributor

I'd prefer if you used an enum class to avoid invalid usage, instead.

@Dentomologist Dentomologist force-pushed the xemitter_use_pseudonamed_parameter_force5bytes branch from e8eb05d to 4bef57c Compare May 21, 2023 23:25
@Dentomologist Dentomologist changed the title XEmitter: Use pseudo-named parameter FORCE_5_BYTES XEmitter: Add enum class Force5Bytes May 21, 2023
Comment on lines 446 to 456
if (test_bit & 8)
pDontBranch = J_CC(condition ? CC_GE : CC_L, true); // Test < 0, so jump over if >= 0.
pDontBranch =
J_CC(condition ? CC_GE : CC_L, Force5Bytes::Yes); // Test < 0, so jump over if >= 0.
else if (test_bit & 4)
pDontBranch = J_CC(condition ? CC_LE : CC_G, true); // Test > 0, so jump over if <= 0.
pDontBranch =
J_CC(condition ? CC_LE : CC_G, Force5Bytes::Yes); // Test > 0, so jump over if <= 0.
else if (test_bit & 2)
pDontBranch = J_CC(condition ? CC_NE : CC_E, true); // Test = 0, so jump over if != 0.
pDontBranch =
J_CC(condition ? CC_NE : CC_E, Force5Bytes::Yes); // Test = 0, so jump over if != 0.
else // SO bit, do not branch (we don't emulate SO for cmp).
pDontBranch = J(true);
pDontBranch = J(Force5Bytes::Yes);
Copy link
Contributor

Choose a reason for hiding this comment

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

These need braces now. Probably a move the comments above the statement, too.

@AdmiralCurtiss
Copy link
Contributor

Looks good otherwise.

@AdmiralCurtiss
Copy link
Contributor

AdmiralCurtiss commented May 23, 2023

(One could argue whether Force5Bytes is a good name at all -- probably something like 'use 4 byte offset' would be more descriptive about what it's actually doing -- but whatever, I'm fine with the name as-is. It was the previous name, after all.)

@Dentomologist Dentomologist force-pushed the xemitter_use_pseudonamed_parameter_force5bytes branch from 4bef57c to a3e3651 Compare May 26, 2023 19:39
@AdmiralCurtiss
Copy link
Contributor

now what did you do here?

@Dentomologist Dentomologist force-pushed the xemitter_use_pseudonamed_parameter_force5bytes branch from a3e3651 to ee108b3 Compare May 26, 2023 19:51
@Dentomologist
Copy link
Contributor Author

Dentomologist commented May 26, 2023

I accidently included a commit with some unrelated changes.

What I actually did was notice these functions each mainly have two separate control flows, and should probably just be separate functions instead. So J is now J_Short and J_Near, etc.

The naming convention of similar variant functions in xemitter is inconsistent, so I picked something that seemed reasonable but let me know if it should be something else.

Notes:

  • I recommend hiding whitespace changes; the diff looks quite a bit cleaner without them.
  • I'll edit the PR description if/when there's agreement this is a better approach.

@AdmiralCurtiss
Copy link
Contributor

I'm not sure whether this is really better, tbqh. @JosJuice, opinions?

Also, why Short and Near? Shouldn't it be Short and Long, or Near and Far or something like that...?

@Dentomologist
Copy link
Contributor Author

Some googling gave me the impression those were the names for those types of jumps (eg https://www.felixcloutier.com/x86/jmp.html), but if that's wrong or I've misunderstood it I can change the names to whatever.

As for the approach itself, I think you can find clearer explanations here or here than I would come up with off the top of my head.

Granted that the Force5Bytes enum is clearer than a literal bool, and if we decide not to do the current approach I'll revert back to it, but it's still acting as an effective boolean that conflates two different actions into one.

@JosJuice
Copy link
Member

I'm not sure whether this is really better, tbqh. @JosJuice, opinions?

I'm not a huge fan. From the perspective of the person writing x86 assembly, the two are the same thing. Even though they're implemented differently, from the perspective of what they actually do, they're identical. That's just my opinion, though.

@Dentomologist
Copy link
Contributor Author

Is it not the case that people writing x86 in Dolphin's JIT already do have to treat Short/Near differently, in order to know whether to pass true/Force5Bytes::Yes or not?

If it is then splitting the functions like this just makes it explicit to the caller what those parameters would be doing, while getting rid of the run-type overhead of handling the parameter.

@JosJuice
Copy link
Member

Yes, that is true, but doing it this way just feels weird to me somehow as an assembly programmer. I don't have a better argument than that.

@Dentomologist
Copy link
Contributor Author

I'll revert back to the enum class. What name should I use: Force5Bytes::Yes/No, OffsetBytes::Four/One, Jump::Near/Short, or something else?

@JosJuice
Copy link
Member

JosJuice commented Jun 6, 2023

I suppose Jump::Near/Short makes sense. I would be fine with Force5Bytes::Yes/No too, though.

Replace the bool parameter force5bytes in J, JMP, and J_CC with an enum
class Jump::Short/Near. Many callers set that parameter to the literal
'true', which was unclear if you didn't already know what it did.
@Dentomologist Dentomologist force-pushed the xemitter_use_pseudonamed_parameter_force5bytes branch from ee108b3 to 4c2759f Compare June 12, 2023 20:06
@Dentomologist
Copy link
Contributor Author

I opted for Jump instead of Force5Bytes because J_CC uses 6 bytes instead.

@AdmiralCurtiss
Copy link
Contributor

I still think that Short/Near is a weird combination, but they are the official terms (probably from back when farcode was a thing...?) so I guess I'm okay with it.

@AdmiralCurtiss AdmiralCurtiss merged commit f5eea4a into dolphin-emu:master Jun 16, 2023
14 checks passed
@Dentomologist Dentomologist deleted the xemitter_use_pseudonamed_parameter_force5bytes branch June 17, 2023 21:43
AdmiralCurtiss added a commit to AdmiralCurtiss/dolphin that referenced this pull request Jun 17, 2023
AdmiralCurtiss added a commit to AdmiralCurtiss/dolphin that referenced this pull request Jun 17, 2023
AdmiralCurtiss added a commit that referenced this pull request Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants