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

Ignore hex/decimal differences in 'li' on MIPS #134

Closed

Conversation

mkst
Copy link
Contributor

@mkst mkst commented Dec 17, 2023

Is this the best way to tackle this? I put it behind a guard so we aren't trying to do a regex match for every line...

With this change:
image
Without:
image

[edit] Just seen the issue here #121, which is pretty much what this PR is trying to address - outside of pseudo operations, its just trying to ignore 0x6 vs 6...

Copy link
Contributor

@AngheloAlf AngheloAlf left a comment

Choose a reason for hiding this comment

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

Could you change this so this feature can be turned on and off, since this can be a very real diff on N64 (at least on IDO).

See the convo at #134

diff.py Outdated
Comment on lines 1580 to 1584
return re.sub(
f"(-?0x[0-9a-fA-F]+)", lambda m: str(int(m.group(1), 16)), row
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a compiled regex with re.compile (https://docs.python.org/3/library/re.html#re.compile) would be better

@mkst
Copy link
Contributor Author

mkst commented Dec 17, 2023

I've been playing around with this and only 1 thru 9 appear as 1 thru 9 (rather than 0x1 thru 0x9). Negative values are decimal, and values above 10 are hexidecimal. Does this still need to go behind an option - I know that -1 and 0xFF are different values under IDO, but this PR won't treat them as equivalent (after my latest changes)

@AngheloAlf
Copy link
Contributor

AngheloAlf commented Dec 17, 2023

Here's a scratch where the difference between the two matters
https://decomp.me/scratch/xv8L5

This doesn't match when linked, so asm-differ showing no diffs would be misleading.

@AngheloAlf
Copy link
Contributor

btw, for some reason when turning off pseudo instructions asm-differ shows dli $t1, 0x1 instead of ori $t1, $zero, 0x1. This seems to be some weird bug on asm-differ, since this doesn't happen on objdump

@mkst
Copy link
Contributor Author

mkst commented Dec 17, 2023

Wow, I had no idea IDO was this awful 😅 I'll stick it behind an option, one for tomorrow

@simonlindholm
Copy link
Owner

Have you looked into patching compiler/assembler to avoid this diff instead? Would be nice to avoid option bloat. (Though I'm not really opposed to adding one, either.)

@simonlindholm
Copy link
Owner

btw, for some reason when turning off pseudo instructions asm-differ shows dli $t1, 0x1 instead of ori $t1, $zero, 0x1. This seems to be some weird bug on asm-differ, since this doesn't happen on objdump

Guessing this is due to objdump flags. I don't know which ones decomp.me passes

@mkst
Copy link
Contributor Author

mkst commented Dec 17, 2023

Could be a mips1 vs mips2 thing. The assembler is gnu as here... I'll see whether it makes any difference to change the value in maspsx before it goes to as... But that won't help the N64 SN stuff.

[edit]: The instruction being assembled is li $v0,0x00000002, so I really don't understand where the 0x2 vs 2 is coming from.

@mkst
Copy link
Contributor Author

mkst commented Dec 17, 2023

Setting the arch for mipsel turns the dli into ori:

MIPSEL_SETTINGS = replace(MIPS_SETTINGS, name="mipsel", big_endian=False, arch_flags=["-m", "mips:3000"])

image

@mkst
Copy link
Contributor Author

mkst commented Dec 17, 2023

Very open to opinions on the name of the config option, ignore_equivalent_immediates was the best my tired brain could come up with.

@AngheloAlf
Copy link
Contributor

btw, for some reason when turning off pseudo instructions asm-differ shows dli $t1, 0x1 instead of ori $t1, $zero, 0x1. This seems to be some weird bug on asm-differ, since this doesn't happen on objdump

Guessing this is due to objdump flags. I don't know which ones decomp.me passes

It doesn't seem to be a decomp.me issue since it happens locally too

diff.py Outdated
@@ -1575,6 +1576,12 @@ def __init__(self, config: Config) -> None:
super().__init__(config)
self.seen_jr_ra = False

def _normalize_arch_specific(self, mnemonic: str, row: str) -> str:
if self.config.ignore_equivalent_immediates and mnemonic == "li":
regex = re.compile(f",0x([1-9])$") # only 1 thru 9
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea of compiling a regex is to compile it only once, not every time the function is called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was googling and read:

Is it worth using Python’s re.compile()?
As you know, Python always internally compiles and caches regexes whenever you use them anyway (including calls to search() or match()), so using compile() method, you’re only changing when the regex gets compiled.

But sure, I'll stick it outside the function

@mkst mkst force-pushed the ignore-hex-dec-differences-in-li branch from e585446 to acb381c Compare December 18, 2023 07:45
@mkst
Copy link
Contributor Author

mkst commented Dec 18, 2023

I'll need to add this to create_config() to be able to use it in decomp.me...

@mkst
Copy link
Contributor Author

mkst commented Dec 19, 2023

OK chaps, please re-review now that I've made some changes; again, if you can think of a better (shorter) name for this option please shout!

@mkst
Copy link
Contributor Author

mkst commented Dec 20, 2023

This PR will become less important for anyone using maspsx because I've just pushed a commit to expand the li instruction.

@simonlindholm
Copy link
Owner

You didn't add a cmdline flag, so this doesn't work as is. Actually, I think it should probably be a project setting, since it feels assembler-/project-specific.

Given the commit to maspsx though, is there still a use-case for this? Or should we close it and reopen if the need comes up again?

@mkst
Copy link
Contributor Author

mkst commented Dec 21, 2023

I'm happy to just close this one, glædelige jul 🎅

@mkst mkst closed this Dec 21, 2023
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.

3 participants