Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80244 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4921 invoked from network); 6 Jan 2015 23:54:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2015 23:54:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.207 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.207 imap2-2.ox.privateemail.com Received: from [192.64.116.207] ([192.64.116.207:38182] helo=imap2-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/26-61664-BB57CA45 for ; Tue, 06 Jan 2015 18:54:35 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id AE9BF8C007D; Tue, 6 Jan 2015 18:54:32 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id jFPOnOEeno4b; Tue, 6 Jan 2015 18:54:32 -0500 (EST) Received: from oa-res-26-240.wireless.abdn.ac.uk (oa-res-26-240.wireless.abdn.ac.uk [137.50.26.240]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id B86BE8C0009; Tue, 6 Jan 2015 18:54:31 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: Date: Tue, 6 Jan 2015 23:54:29 +0000 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <93376D88-A704-4F89-AB90-82EEDAE82081@ajf.me> References: <8C47FA53-0964-49C0-963C-332A936348A5@ajf.me> <68229C26-4EEC-49DC-BA05-D5AC9728D1E8@ajf.me> To: Dmitry Stogov X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [RFC] Big Integer Support From: ajf@ajf.me (Andrea Faulds) Hey Dmitry, > On 23 Oct 2014, at 16:22, Dmitry Stogov wrote: >=20 >> 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 = complex. 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 = asm 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 = VMs, and >> possibly others (don=E2=80=99t we have PowerPC in the source just = now?). >>=20 >=20 > 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 least 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 = merge 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 = GMP backend, not the LibTomMath one. I=E2=80=99m doing this since = there=E2=80=99s still one or two small things I haven=E2=80=99t finished = implementing for LibTomMath, e.g. the binary bitwise ops have the wrong = behaviour just now. For master, I used ./configure --enable-debug --enable-phpdbg = =E2=80=94-disable-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=09 6.453 6.64525 DIFFERENCE=09 -0.19225 0.19225 RATIO=09 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 = just be because I got rid of fast_increment_function in favour of just = checking of 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=09 6.34325 6.592 DIFFERENCE=09 -0.24875 0.24875 RATIO=09 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=09 6.398125 6.618625 DIFFERENCE=09 -0.2205 0.2205 RATIO=09 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=99= s still a good sign. :) Thanks! -- Andrea Faulds http://ajf.me/