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

Implement a set of new QC opcodes for bit shifts and unsigned integer math. #237

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

divVerent
Copy link
Contributor

Suggested by Spoike.

Fixes #236

Also fixing existing bugs in OP_DIV_* (no division by zero check, and inaccuracy in OP_DIV_IF).

Previously 5 / 1.25 returned 5 due to rounding the 1.25 to int and
performing an integer division.

Now 5 / 1.25 will return 4 due to converting the 5 to floating point and
performing a floating division.

Same applied to +, - and * for int and float types in this order.

Which is a lot more what one would expect based on what C does, and
also matches FTEQW.
- OP_RSHIFT_I
- OP_LSHIFT_I
- OP_LE_U
- OP_LT_U
- OP_DIV_U
- OP_RSHIFT_U

For all other ops FTEQCC emits the _I operations; this is technically
broken but meh. Compile DP with `-fwrapv` if you care.
Now all the OP_DIV operations emit a warning and proceed on division by
zero, instead of potentially crashing the program.

This also handles the special case of -2147483648 / -1, which also traps on
x86 and thus must be handled.
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.

More QC opcodes
1 participant