-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Rewrite Cop1.cpp to conform to strict-aliasing rules #214
base: master
Are you sure you want to change the base?
Conversation
330b548
to
cfc25ed
Compare
…ict-aliasing rules
cfc25ed
to
cb956c6
Compare
this is actually slightly broken right now but someone broke the autotests and I can't find the bug
{ | ||
switch(value & 0x7F800000) | ||
uint32_t test; | ||
memcpy(&test, &value, sizeof(float)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also use union
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid in C99 (and above) and C++11 (and above)
{ | ||
gpr[dest].u = gpr[source].u ^ 0x80000000; | ||
gpr[dest] = -gpr[source]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NEG only flips the sign bit, not the whole value, not sure how this would behave, and what if the original value is already negative? surely doing - will keep it the same, which is not a negation
temp.f = sqrt(fabs(convert(gpr[reg2].u))); | ||
gpr[dest].f = convert(gpr[reg1].u) / convert(temp.u); | ||
float temp = sqrtf(fabsf(convert(gpr[reg2]))); | ||
gpr[dest] = convert(gpr[reg1]) / convert(temp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use ureg1/2 ?
control.i = true; | ||
control.si = true; | ||
} | ||
|
||
gpr[dest].f = sqrt(fabs(convert(gpr[source].u))); | ||
gpr[dest] = sqrtf(fabsf(convert(gpr[source]))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use usource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also why only memcpy back the dest on zero and not in normal operation?
} | ||
else | ||
gpr[dest].f = convert(numerator) / convert(denominator); | ||
gpr[dest] = convert(gpr[reg1]) / convert(gpr[reg2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numerator / denominator
…ict-aliasing rules