Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75624 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81296 invoked from network); 17 Jul 2014 01:51:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2014 01:51:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.177 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.220.177 mail-vc0-f177.google.com Received: from [209.85.220.177] ([209.85.220.177:58221] helo=mail-vc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3A/28-37298-D3C27C35 for ; Wed, 16 Jul 2014 21:51:57 -0400 Received: by mail-vc0-f177.google.com with SMTP id hy4so3247441vcb.8 for ; Wed, 16 Jul 2014 18:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=n0ZYDTcol+nIJF/0md2EGjlUztFBvPtj6teDHE5EG8w=; b=h8HJvTkuYkIvEsvJSsKe+03H7f5IOm6b3rg+1IXEAG7vo/xOICyYiqoKmk484gmDZ1 aB5KXF6hNfEmp9TDV8f6+E8Fk5bpMdfyjoQJrLtn4wAlHjojotBgvPuQcsCH28FVL3fX j1sP9yyBRqsKG74WCpeqZGLD1MJtGcG3XeU8R4Weq/I3mqC5KKTQxrs32rMs9t82CqDU IvbCLbJYLslv5oCp26Qs3IDh6JsDpk3L3pNVWbmWGhbgVqBpRjhIr4UlVIPEK2oa+Cfm upOeOAJRM4edC1QPW2ugLGTQPuOj4QgVYHGwPI2StAK9mLRZNv/dNcHpPApHiMutVHv0 +Epg== MIME-Version: 1.0 X-Received: by 10.220.44.20 with SMTP id y20mr13162477vce.60.1405561915020; Wed, 16 Jul 2014 18:51:55 -0700 (PDT) Received: by 10.58.89.170 with HTTP; Wed, 16 Jul 2014 18:51:54 -0700 (PDT) In-Reply-To: References: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> <37F89E54-C5B9-4E81-9D1B-660190BDB1FF@ajf.me> Date: Thu, 17 Jul 2014 09:51:54 +0800 Message-ID: To: Sara Golemon Cc: Andrea Faulds , bishop@php.net, PHP internals Content-Type: multipart/alternative; boundary=047d7b3a98d0a79e7404fe59e206 Subject: Re: [PHP-DEV] [RFC] intdiv() From: tjerk.meesters@gmail.com (Tjerk Meesters) --047d7b3a98d0a79e7404fe59e206 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Sara, On Thu, Jul 17, 2014 at 8:25 AM, Sara Golemon wrote: > On Wed, Jul 16, 2014 at 8:15 AM, Andrea Faulds wrote: > > Nikita Popov doesn=E2=80=99t seem to be a fan of the %% syntax, so it m= ay be > subject to change, though I think it=E2=80=99s the best I=E2=80=99ve hear= d 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 =3D a / b; > long lres =3D 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 > > --=20 -- Tjerk --047d7b3a98d0a79e7404fe59e206--