Bug #68064 [Opn->Csd]: Bitwise shift tests failed because of unspecified operation

[email protected]
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=68064&edit=1

 ID:                 68064
 Updated by:         [email protected]
 Reported by:        ogatak at jp dot ibm dot com
 Summary:            Bitwise shift tests failed because of unspecified
                     operation
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            PHP Language Specification
 Operating System:   Linux PPC64
 PHP Version:        5.6.0
-Assigned To:        
+Assigned To:        ajf
 Block user comment: N
 Private report:     N

 New Comment:

The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------
[2014-09-20 14:38:29] [email protected]

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.

------------------------------------------------------------------------
[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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.