Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75661 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58991 invoked from network); 17 Jul 2014 09:24:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2014 09:24:46 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.175 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.213.175 mail-ig0-f175.google.com Received: from [209.85.213.175] ([209.85.213.175:41578] helo=mail-ig0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 21/A9-09067-D5697C35 for ; Thu, 17 Jul 2014 05:24:45 -0400 Received: by mail-ig0-f175.google.com with SMTP id uq10so5708292igb.8 for ; Thu, 17 Jul 2014 02:24:42 -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=tiO4QpSeiWQOBXN3vxWbGtpCDs4cbweqg5ef3yRrDRU=; b=jhph0nQMiaZaS3w4GR+qbfEI7BugFT7QA+JI/+LsK075MFc5o5KDCSLPisNZ956HHK HDH8QNwzaIGyLJ/Wb/J3lhad8+cFmJck3iFs4pwghWA9CJn+aESAAYGBjWbXN8/XRQx6 ppBhiu32H7jk7ZoQldwMxQlbFIS2/tdjaLk6KtTVYG5AsQdCa7J084rwgXPR7hRTurEd PaGSh6nenZVTKrp/+c/lv7PYtozaljUAi2FUAMYwJ6tDNTWj5ts5MS6cKXwgzEOqbgTq 5xfXS6SAd1JxpnuTEZtSbcVq2lpj2TfhTRnm3/m4/KYmhq+lhEmFJ/LdWQ051HocPxhf 9hIQ== MIME-Version: 1.0 X-Received: by 10.60.103.173 with SMTP id fx13mr42874731oeb.25.1405589082168; Thu, 17 Jul 2014 02:24:42 -0700 (PDT) Received: by 10.182.132.2 with HTTP; Thu, 17 Jul 2014 02:24:42 -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 11:24:42 +0200 Message-ID: To: Sara Golemon Cc: Andrea Faulds , bishop@php.net, PHP internals Content-Type: multipart/alternative; boundary=089e010d8c7af1627f04fe60355e Subject: Re: [PHP-DEV] [RFC] intdiv() From: nikita.ppv@gmail.com (Nikita Popov) --089e010d8c7af1627f04fe60355e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Jul 17, 2014 at 2: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. > > 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. > This is already what is currently happening, see http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.c#1067. Andreas proposal is only useful in the case that the numbers don't divide exactly and you need round-down/truncation behavior and your numbers are in a range where the indirection through double arithmetic results in precision loss. Nikita --089e010d8c7af1627f04fe60355e--