Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88066 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21499 invoked from network); 6 Sep 2015 18:05:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Sep 2015 18:05:34 -0000 X-Host-Fingerprint: 2.122.81.212 unknown Received: from [2.122.81.212] ([2.122.81.212:13543] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E1/06-59944-D608CE55 for ; Sun, 06 Sep 2015 14:05:34 -0400 Message-ID: To: internals@lists.php.net References: <02a601d0dbed$2c828df0$8587a9d0$@belski.net> <02ae01d0dbf5$01c17330$05445990$@belski.net> <02b001d0dbf5$607ab7b0$21702710$@belski.net> <02ba01d0dbfb$3de2c390$b9a84ab0$@belski.net> Date: Sun, 6 Sep 2015 19:05:29 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0 SeaMonkey/2.35 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 2.122.81.212 Subject: Re: [PHP-DEV] Overflow checks and integral vars comparison From: ajf@ajf.me (Andrea Faulds) Hi Sherif, Sherif Ramadan wrote: > > Of course, but the ASM can also be ported to other architectures and > wrapped in #ifdef for non x86 and MSVC or other compilers, for example. > It's not impossible to achieve some sane degree of portability there. I see > Andrea already worked on some of this in zend_operators.h for example > https://github.com/php/php-src/blob/ee2e1691080dad2a3110107dd8bd02ee23b41fa0/Zend/zend_operators.h#L437 > > Of course, making integer overflow checks safe and efficient is by no means > easy on every given architecture, but surely we could aim to support at > least the broadest current architectures at first and fall back to C > overflow checks if necessary. > The email I'm replying to here is more than a month old now. Just to set the record straight, though, PHP's assembly and pure C overflow checks on arithmetic operations aren't my work, they've been there for a long time. If you were to `git blame` them you might find the original author eventually. The only overflow checks I added to PHP were for float-to-int conversions, and that doesn't require inline asm. One thing I *did* do, however, was rip out that inline assembly in my bigint branch (which wasn't merged in the end, alas), since it was out-of-date (didn't handle bigints) and I wouldn't dare mess with it. Instead, I replaced it it with clang and GCC-compatible intrinsics, which require no assembly knowledge to understand: https://github.com/php/php-src/commit/bdcd9bbd29fac886192fbc410ccb96bd4cb93375 At some point, I might make a pull request to add this to PHP master, if it provides a performance boost. Thanks. -- Andrea Faulds http://ajf.me/