Skip to content

Unify type juggling in math.c#12286

Merged
TimWolla merged 1 commit into
php:masterfrom
TimWolla:math-type-handling
Sep 24, 2023
Merged

Unify type juggling in math.c#12286
TimWolla merged 1 commit into
php:masterfrom
TimWolla:math-type-handling

Conversation

@TimWolla

Copy link
Copy Markdown
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.

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM thank you!

Comment thread ext/standard/math.c
ZEND_ASSERT(0 && "Unexpected type");
switch (Z_TYPE_P(value)) {
case IS_LONG:
if (Z_LVAL_P(value) == ZEND_LONG_MIN) {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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