Skip to content

Unify type juggling in math.c #12286

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

Merged
merged 1 commit into from
Sep 24, 2023
Merged

Conversation

TimWolla
Copy link
Member

As privately suggested by @Girgias.

- Consistently use a `switch()` with `EMPTY_SWITCH_DEFAULT_CASE();`
- Consistently use `zval_get_double()` for multi-type / non-double zvals
  instead of casting manually.
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

LGTM thank you!

ZEND_ASSERT(0 && "Unexpected type");
switch (Z_TYPE_P(value)) {
case IS_LONG:
if (Z_LVAL_P(value) == ZEND_LONG_MIN) {
Copy link
Member

Choose a reason for hiding this comment

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

Possibly as a follow-up wrapping this unlikely condition in UNEXPECTED() might make sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

This case is a little odd anyway. For 32 bit versions it made sense, because doubles would be able to accurately represent 2147483648, but for 64 bit versions they are not capable of accurately representing 9223372036854775808. I wonder if this should throw instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now wrapped in UNEXPECTED, this actually results in slightly better assembly.

@TimWolla TimWolla merged commit 82aad0b into php:master Sep 24, 2023
@TimWolla TimWolla deleted the math-type-handling branch September 24, 2023 14:15
TimWolla added a commit that referenced this pull request Sep 24, 2023
As suggested in GH-12286. This results in slightly better assembly in clang,
because the expected case will be handled by a forward jump that is not taken.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants