Re: [RFC] intdiv()

From: Date: Thu, 17 Jul 2014 01:51:54 +0000
Subject: Re: [RFC] intdiv()
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-75624@lists.php.net to get a copy of this message
Hi Sara, On Thu, Jul 17, 2014 at 8:25 AM, Sara Golemon <pollita@php.net> wrote: > 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. > Just out of curiosity, does the compiler optimise it into something like this? if (a % b) { return a / b; } else { return (double)a / b; } Or, would writing it like that skip the optimisation of being able to fetch the division result from %rax? > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- -- Tjerk

« previous php.internals (#75624) next »