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

Fix const doubles on macOS #6

Merged
merged 1 commit into from
Dec 31, 2024
Merged

Conversation

cadmic
Copy link
Contributor

@cadmic cadmic commented Dec 31, 2024

Currently the macOS version miscompiles basically anything involving double constants. On 32-bit machines (e.g. Linux builds), for a struct rtx_def *r that represents a const double the value is split into two parts, accessed as

#define CONST_DOUBLE_LOW(r) XWINT (r, 2)  // r->fld[2].rtwint
#define CONST_DOUBLE_HIGH(r) XWINT (r, 3) // r->fld[3].rtwint

and the value is usually copied out like

union real_extract u;
bcopy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof (u));

which assumes that CONST_DOUBLE_LOW and CONST_DOUBLE_HIGH are 4 bytes apart in memory. On macOS we compile as 64-bit though, meaning this bcopy will ignore CONST_DOUBLE_HIGH.

Currently on macOS HOST_BITS_PER_LONG is 32 and HOST_WIDE_INT is int which is kind of a lie. Technically we could fix const doubles by changing HOST_BITS_PER_LONG to 64 (then the code would put entire double values in CONST_DOUBLE_LOW instead of splitting it into two parts) but I'm concerned that this would break matching, since other code uses CONST_DOUBLE_LOW/CONST_DOUBLE_HIGH directly for hashing and such.

Updating all the backends was probably not necessary but it's nice to be consistent I guess.

Copy link
Collaborator

@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.

I agree this solution looks better than papermario's one.

btw, using bcopy and bcmp just for 8 bytes sounds pretty overkill and error prone, I wonder why they went with it.

Also checked drmario does still match 👍

@AngheloAlf AngheloAlf merged commit ac3419e into decompals:master Dec 31, 2024
2 checks passed
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