Re: [RFC] intdiv()

From: Date: Thu, 17 Jul 2014 00:25:38 +0000
Subject: Re: [RFC] intdiv()
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-75621@lists.php.net to get a copy of this message
On Wed, Jul 16, 2014 at 8:15 AM, Andrea Faulds <ajf@ajf.me> wrote:
> Nikita Popov doesn’t seem to be a fan of the %% syntax, so it may be subject to change,
> though I think it’s the best I’ve heard so far. ;)
>
Nor am I.  Here's a thought though: How about just making / return int
when there's no remainder.

Looking at this code, you might think it's inefficent:

double dres = a / b;
long lres = a / b;
if (a % b) {
  return dres;
} else {
  return lres;
}

But in fact at -O1, gcc will optimize this (probably clang and others
as well) to a single idivq instruction and only do the cvtsi2sdq in
the dres case.

My point being, we can just make division with an integral result
return a result of integer division without altering the syntax or
adding a perf hit.

-Sara


Thread (49 messages)

« previous php.internals (#75621) next »