Re: Weird bitset shift offset in zend_alloc
| From: | Stanislav Malyshev | Date: | Wed, 06 Mar 2019 08:47:01 +0000 |
| Subject: | Re: Weird bitset shift offset in zend_alloc | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104597@lists.php.net to get a copy of this message | ||
Hi!
> This is intended x86 specific optimization. The behavior of SHR is
> documented.
>
> See https://c9x.me/x86/html/file_module_x86_id_285.html
>
> "The count is masked to 5 bits, which limits the count range to 0 to 31"
> on 32-bit systems.
I see. But I wonder whether the compiler will always compile it as SHR,
is it guarnateed? Looking at optimization behavior for clang, for me
ZEND_BIT_TEST( bits, 65 ) - where bits is an array of 0xFF - produces 1
under -O0 but 0 under -O1 (I guess it figures out it's a constant and
optimizes the shift away). So I wonder whether this construct isn't
dangerous...
--
Stas Malyshev
smalyshev@wikimedia.org