On Wed, Jul 16, 2014 at 6:51 PM, Tjerk Meesters
<tjerk.meest...@gmail.com> wrote:
> Just out of curiosity, does the compiler optimise it into something like
> this?
>
> if (a % b) {
>   return a / b;
> } else {
>   return (double)a / b;
> }
>
Ya know what? I feel dumb.  FP division is a whole separate
instruction.  I forgot that (int/int) is always int, even if you're
storing in a double.  Derp.

So yeah, In that code you pasted, you get a single idivq in the int
args with no remainder case, but you do have to do a divsd in the
remainder exists case.  So not as perf neutral as I was thinking.
Beneficial in the int case since idivq is less costly than divsd, but
the common case may well be ((a%b)!=0), so it's probably harmful more
often than not.

All that said, *I* think the tradeoff of an extra idivq in the
(probably more common) remainder case is worth it in the interest of
keeping PHP's syntax simple.

If we're really set on adding a new operator, I'd vote for something
which provides dividend *and* remainder in some way. (Useful for time
arithmetic, for example)

-Sara

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to