Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65623 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97726 invoked from network); 4 Feb 2013 10:10:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2013 10:10:40 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-ie0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:58194] helo=mail-ie0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/83-14611-E198F015 for ; Mon, 04 Feb 2013 05:10:39 -0500 Received: by mail-ie0-f174.google.com with SMTP id k10so5413417iea.19 for ; Mon, 04 Feb 2013 02:10:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=/KAuclHXiqF94oct/4tjQsSS1Uw5R8P4I8c6AP6uLxw=; b=HOrQ9efSpfNjPfP92Q/yWwvDBdTdkI1Hvzc4KiU2PqCTBspmHqsvhiEDy7D6Cc5oWE VrPoZ60VpNaFJy2yltj4HBMpoHHqk94h8ulaeu5lQSuJ94kVd0rWFUx0TYsTHQ4M5iuz +NJnEay2RmMiAMm4pMhmrvhLB7JRsY0RLrQ8pOUqbZ3plqtit3WMj+FoEZVV4FC+nxNw CYaJk7ShEp14GgldS4w9+D12e+lg7dkq72cspuy4W3MP4zfwCN8PnAYUyxmMQ1N/A9PN N14QoK7BGej738+MFlcj8Zj3b48O06qhxP6/JBSbXzzyRMHIUKcfEaVCXVBFvgNKP7Tr dnCw== MIME-Version: 1.0 X-Received: by 10.50.88.226 with SMTP id bj2mr5228533igb.105.1359972636035; Mon, 04 Feb 2013 02:10:36 -0800 (PST) Received: by 10.50.106.138 with HTTP; Mon, 4 Feb 2013 02:10:35 -0800 (PST) In-Reply-To: References: Date: Mon, 4 Feb 2013 11:10:35 +0100 Message-ID: To: Ard Biesheuvel , Felipe Pena , Dmitry Stogov , Xinchen Hui Cc: PHP Internals Content-Type: multipart/alternative; boundary=e89a8f3bb01fe00ad504d4e34db9 Subject: Re: [PHP-DEV] more inline assembler noise From: tyra3l@gmail.com (Ferenc Kovacs) --e89a8f3bb01fe00ad504d4e34db9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Jan 18, 2013 at 7:08 PM, Ard Biesheuvel wrote: > Hello, > > Again, apologies for prematurely declaring someone else's code 'crap'. > There are no bugs in the inline x86 assembler in Zend/zend_operators.h, a= s > far as I can tell, only two kinds of issues that I still think should be > addressed. > > First of all, from a maintenance pov, having field offsets (like the > offset of zval.type) and constants (like $0x2 for IS_DOUBLE) hard coded > inside the instructions is a bad idea. > > The other issue is the branching and the floating point instructions. The > inline assembler addresses the common case, but also adds a bunch of > instructions that address the corner case, and some branches to jump over > them. As I indicated in my previous email, branching is relatively costly > on a modern CPU with deep pipelines and having a bunch of FPU instruction= s > in there that hardly ever get executed doesn't help either. > > The primary reason for having inline assembler at all is the ability to > detect overflow. This mainly applies to multiplication, as in that case, > detecting overflow in C code is much harder compared to reading a conditi= on > flag in the CPU (hence the various accelerated implementations in > zend_signed_multiply.h). However, detecting overflow in > addition/subtraction implemented in C is much easier, as the code in > zend_operators.h proves: just a matter of checking the sign bits, or doin= g > a simple compare with LONG_MIN/LONG_MAX. > > Therefore, I would be interested in finding out which benchmark was used > to make the case for having these accelerated implementations in the firs= t > place. The differences in performance between various implementations are > very small in the tests I have done. > > As for the code style/maintainability, I propose to apply the attached > patch. The performance is on par, as far as I can tell, but it is arguabl= y > better code. I will also hook in the ARM versions once I manage to prove > that the performance is affected favourably by them. > > Regards, > Ard. > > > > Before > ------- > > $ time php -r 'for ($i =3D 0; $i < 0x7fffffff; $i++);' > > real 0m56.910s > user 0m56.876s > sys 0m0.008s > > > $ time php -r 'for ($i =3D 0x7fffffff; $i >=3D 0; $i--);' > > real 1m34.576s > user 1m34.518s > sys 0m0.020s > > > $ time php -r 'for ($i =3D 0; $i < 0x7fffffff; $i +=3D 3);' > > real 0m21.494s > user 0m21.473s > sys 0m0.008s > > > $ time php -r 'for ($i =3D 0x7fffffff; $i >=3D 0; $i -=3D 3);' > > real 0m19.879s > user 0m19.865s > sys 0m0.004s > > > After > ----- > > $ time php -r 'for ($i =3D 0; $i < 0x7fffffff; $i++);' > > real 0m56.687s > user 0m56.656s > sys 0m0.004s > > > $ time php -r 'for ($i =3D 0x7fffffff; $i >=3D 0; $i--);' > > real 1m28.124s > user 1m28.082s > sys 0m0.004s > > > $ time php -r 'for ($i =3D 0; $i < 0x7fffffff; $i +=3D 3);' > > real 0m20.561s > user 0m20.545s > sys 0m0.004s > > > $ time php -r 'for ($i =3D 0x7fffffff; $i >=3D 0; $i -=3D 3);' > > real 0m20.524s > user 0m20.509s > sys 0m0.004s > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > hi, any update on this? --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --e89a8f3bb01fe00ad504d4e34db9--