Bug #68064 [Opn]: Bitwise shift tests failed because of unspecified operation
| From: | ajf@php.net | Date: | Sat, 20 Sep 2014 14:38:29 +0000 |
| Subject: | Bug #68064 [Opn]: Bitwise shift tests failed because of unspecified operation | ||
| References: | 1 | Groups: | php.standards |
| Request: | Send a blank email to standards-+get-456@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68064&edit=1
ID: 68064
Updated by: ajf@php.net
Reported by: ogatak at jp dot ibm dot com
Summary: Bitwise shift tests failed because of unspecified
operation
Status: Open
Type: Bug
Package: PHP Language Specification
Operating System: Linux PPC64
PHP Version: 5.6.0
Block user comment: N
Private report: N
New Comment:
As it happens, my Integer Semantics RFC would fix this:
https://wiki.php.net/rfc/integer_semantics
I am currently in need of votes for it.
Previous Comments:
------------------------------------------------------------------------
[2014-09-20 14:26:23] ogatak at jp dot ibm dot com
Description:
------------
Hello,
I noticed that bitwise shit test cases (of "make test") failed when the shift count is
larger than 64 or is a negative number because the test cases rely on the behavior of x86 CPU.
I ran "make test" on Linux PPC64 (RHEL 6.4) machine, and three out of twelve failed tests
were those for shift right/left operators.
As far as I checked the handlers of shift right/left operators in Zend/zend_operators.c, they just
execute ">>" or "<<" operator of C. Since C language does not
define the behavior when the shift count exceeds the bit width of the operand, the result depends on
how CPU's shift instruction performs.
x86 CPU masks the shift count with 0x3f before shifting the operand, but many other processors,
including POWER architecture, do not mask the shift count. Those processors simply sweep all bits
away. This difference caused the test failure.
I checked the PHP manual on the site, but I couldn't find the definition of the behavior when
the shift count exceeds the bit width.
I think the language specification should define the behavior of such case. If masking with 0x3F is
the specification, the handler of PHP shift operators should mask the shift count with 0x3F. If
"undefined" is the specification, it should be described in the language manual and toled
PHP programmers about this potential portability issue. The failed tests should also need to be
excluded from "make test" list in the latter case.
Following is the list of failed test cases:
tests/lang/operators/bitwiseShiftLeft_basiclong_64bit
tests/lang/operators/bitwiseShiftLeft_variationStr_64bit
tests/lang/operators/bitwiseShiftRight_basiclong_64bit
(tests/lang/operators/bitwiseShiftRight_variationStr_64bit was skipped)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68064&edit=1