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.


<minor off-topic note>

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.

</off-topic>

Thanks.

--
Andrea Faulds
http://ajf.me/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to