Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80278 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57187 invoked from network); 8 Jan 2015 16:02:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jan 2015 16:02:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.169 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.169 mail-vc0-f169.google.com Received: from [209.85.220.169] ([209.85.220.169:40104] helo=mail-vc0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/05-21915-71AAEA45 for ; Thu, 08 Jan 2015 11:02:32 -0500 Received: by mail-vc0-f169.google.com with SMTP id hy10so1392884vcb.0 for ; Thu, 08 Jan 2015 08:02:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=e/zxyGxt+eDqN3ezOI8htPzQXfwCP8VMkkN9b028yyQ=; b=AbkF2qlRcja/ZUMcRXQesK4C+EmvHQ/FOITOaaW0Cb49tGw1mam7iJgdiIZk1FD1tT ZnkldxxL1piHo7AKuOMhQeL5qDgBD4PYQssV578wWHO8enq4CicqdlpPteVk+KNefr/K /ysKWt/5V4qHksLlfR+4z5wFu0zs563HWFY9cbAmsnhjPzJHkJNvsYB8vGilx6JqWB0c IvTmHZb/juq2MH72/cshQS+mC0suH06udHSj+5ZE71f+iIzZZJ2XpptnFxQUs1DQqnOH 6PeI4+PVmo2dr4Ue9kd1OvTMvB5j3Cpk/fwibkmzxL31hVP7Dadmx/5L7i03AyFyOnzu ifCQ== X-Gm-Message-State: ALoCoQnprfWjEI2890OGyLqo4427Y+uBhEOn9LQCNwz7jBKedVO/6qcuSU+9t2V65fiUj2i1JPZ5SkynV7aggqmBqJHje0GbkOJ4V4OM7MTojeCnJOrUZdWE6H9WIOIseF0bAKKMaK/uBZiAgVDhqfpPkbcllRb1/w== MIME-Version: 1.0 X-Received: by 10.220.185.193 with SMTP id cp1mr6855991vcb.80.1420732948765; Thu, 08 Jan 2015 08:02:28 -0800 (PST) Received: by 10.52.26.40 with HTTP; Thu, 8 Jan 2015 08:02:28 -0800 (PST) In-Reply-To: <93376D88-A704-4F89-AB90-82EEDAE82081@ajf.me> References: <8C47FA53-0964-49C0-963C-332A936348A5@ajf.me> <68229C26-4EEC-49DC-BA05-D5AC9728D1E8@ajf.me> <93376D88-A704-4F89-AB90-82EEDAE82081@ajf.me> Date: Thu, 8 Jan 2015 20:02:28 +0400 Message-ID: To: Andrea Faulds Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e01538610bb76ee050c262aa7 Subject: Re: [PHP-DEV] [RFC] Big Integer Support From: dmitry@zend.com (Dmitry Stogov) --089e01538610bb76ee050c262aa7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I'm really surprised by the results :) I'll try to find time for bigint on next week and play with it a bit. Thanks. Dmitry. On Wed, Jan 7, 2015 at 2:54 AM, Andrea Faulds wrote: > Hey Dmitry, > > > On 23 Oct 2014, at 16:22, Dmitry Stogov wrote: > > > >> I=E2=80=99ve so far been scared to touch the asm=E2=80=A6 but actually= , I don=E2=80=99t think it > >> could be *that* hard. It=E2=80=99s not doing something especially comp= lex. The > >> bigint API looks fairly stable now and I=E2=80=99m unlikely to change = it much > >> further, so there=E2=80=99s little worry about having to change the as= m a second > >> time. The main problem with asm, I suppose, is testing it. I do have a > >> 32-bit Ubuntu VM set up, but I=E2=80=99d also need to set up Windows V= Ms, and > >> possibly others (don=E2=80=99t we have PowerPC in the source just now?= ). > >> > > > > change asm for 32-bit Linux and add TODO marks for others. I don't test > PHP > > on PPC as well. > > After procrastinating about this for a long time, I finally went and > updated the overflow checks today and ran bench.php. > > I still haven=E2=80=99t touched the inline asm, I=E2=80=99ve just removed= it, since clang > and GCC (only in GCC 5.0, sadly) have checked arithmetic intrinsics. If > someone wants to, they can rewrite the inline asm for compilers that have > no overflow-checking intrinsics, but this is good enough for now, at leas= t > for the purposes of performance checking on my machine. I=E2=80=99m using= clang, by > the way. If you want to replicate these results, you=E2=80=99ll probably = also need > it, since GCC 5.0 isn=E2=80=99t out yet, unfortunately. > > I compiled the bigint-libtommath branch (theoretically this was just a > branch, but actually all the new changes have gone there, I=E2=80=99ll me= rge it > into the bigint branch once LibTomMath port is done), and the current > master branch. > > For bigint-libtommath, I used ./configure --enable-debug --enable-phpdbg > =E2=80=94-disable-all =E2=80=94-enable-bigint-gmp > > Because of the =E2=80=94-enable-bigint-gmp flag, it=E2=80=99s using the G= MP backend, not > the LibTomMath one. I=E2=80=99m doing this since there=E2=80=99s still on= e or two small > things I haven=E2=80=99t finished implementing for LibTomMath, e.g. the b= inary > bitwise ops have the wrong behaviour just now. > > For master, I used ./configure --enable-debug --enable-phpdbg =E2=80=94-d= isable-all > > Then, I ran bench.php four times, and each time I ran it first on > ./php-bigint-gmp, then on ./php-bigint-master. > > On each run, the bigint branch turned out faster, as well as overall: > > bigint master > 6.593 6.659 > 6.424 6.661 > 6.414 6.588 > 6.381 6.673 > AVERAGE > 6.453 6.64525 > DIFFERENCE > -0.19225 0.19225 > RATIO > 0.971069561 1.0297923446 > > So master is 2.9% slower! Full output here: > https://gist.github.com/TazeTSchnitzel/759c1513b442571f5e26 > > I can=E2=80=99t actually explain why bigints would be faster. It might ju= st be > because I got rid of fast_increment_function in favour of just checking o= f > op1 =3D=3D ZEND_LONG_MAX in zend_vm_execute.h, ditto for > fast_decrement_function. Maybe using overflow intrinsics is faster than > inline asm. Maybe it=E2=80=99s something completely different. I honestly= don=E2=80=99t > know. > > The result surprised me as I expect bigints would be slower, so I redid > it. Again, bigints came out on top: > > bigint master > 6.55 6.779 > 6.353 6.738 > 6.326 6.674 > 6.144 6.177 > AVERAGE > 6.34325 6.592 > DIFFERENCE > -0.24875 0.24875 > RATIO > 0.9622648665 1.0392149135 > > This time master was around 3.9% slower. Full log here: > https://gist.github.com/TazeTSchnitzel/59c190b86c9dd5b20570 > > If we combine the two runs: > > bigint master > 6.593 6.659 > 6.424 6.661 > 6.414 6.588 > 6.381 6.673 > 6.55 6.779 > 6.353 6.738 > 6.326 6.674 > 6.144 6.177 > AVERAGE > 6.398125 6.618625 > DIFFERENCE > -0.2205 0.2205 > RATIO > 0.9666849232 1.0344632216 > > master=E2=80=99s 3.4% slower. > > Just to check I named the files correctly: > > oa-res-26-240:php-src ajf$ ./php-master -r 'var_dump(PHP_INT_MAX * 2);' > float(1.844674407371E+19) > oa-res-26-240:php-src ajf$ ./php-bigint-gmp -r 'var_dump(PHP_INT_MAX * 2)= ;' > int(18446744073709551614) > > Yes, it=E2=80=99s definitely the bigint branch. > > So, at least by these preliminary results, the bigint branch would appear > to be faster than master. This is merely bench.php, but it=E2=80=99s stil= l a good > sign. :) > > Thanks! > -- > Andrea Faulds > http://ajf.me/ > > > > > --089e01538610bb76ee050c262aa7--