Commit 7c9e8032 authored by Mark Dickinson's avatar Mark Dickinson

Issue #11244: Remove outdated peepholer check that was preventing the...

Issue #11244: Remove outdated peepholer check that was preventing the peepholer from folding -0 and -0.0.  Thanks Eugene Toder for the patch.
parent ba7b560c
...@@ -3,6 +3,7 @@ import re ...@@ -3,6 +3,7 @@ import re
import sys import sys
from io import StringIO from io import StringIO
import unittest import unittest
from math import copysign
def disassemble(func): def disassemble(func):
f = StringIO() f = StringIO()
...@@ -207,6 +208,9 @@ class TestTranforms(unittest.TestCase): ...@@ -207,6 +208,9 @@ class TestTranforms(unittest.TestCase):
def test_folding_of_unaryops_on_constants(self): def test_folding_of_unaryops_on_constants(self):
for line, elem in ( for line, elem in (
('-0.5', '(-0.5)'), # unary negative ('-0.5', '(-0.5)'), # unary negative
('-0.0', '(-0.0)'), # -0.0
('-(1.0-1.0)','(-0.0)'), # -0.0 after folding
('-0', '(0)'), # -0
('~-2', '(1)'), # unary invert ('~-2', '(1)'), # unary invert
('+1', '(1)'), # unary positive ('+1', '(1)'), # unary positive
): ):
...@@ -214,6 +218,13 @@ class TestTranforms(unittest.TestCase): ...@@ -214,6 +218,13 @@ class TestTranforms(unittest.TestCase):
self.assertIn(elem, asm, asm) self.assertIn(elem, asm, asm)
self.assertNotIn('UNARY_', asm) self.assertNotIn('UNARY_', asm)
# Check that -0.0 works after marshaling
def negzero():
return -(1.0-1.0)
self.assertNotIn('UNARY_', disassemble(negzero))
self.assertTrue(copysign(1.0, negzero()) < 0)
# Verify that unfoldables are skipped # Verify that unfoldables are skipped
for line, elem in ( for line, elem in (
('-"abc"', "('abc')"), # unary negative ('-"abc"', "('abc')"), # unary negative
......
...@@ -867,6 +867,7 @@ Christian Tismer ...@@ -867,6 +867,7 @@ Christian Tismer
Frank J. Tobin Frank J. Tobin
R Lindsay Todd R Lindsay Todd
Bennett Todd Bennett Todd
Eugene Toder
Matias Torchinsky Matias Torchinsky
Sandro Tosi Sandro Tosi
Richard Townsend Richard Townsend
......
...@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1? ...@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #11244: Remove an unnecessary peepholer check that was preventing
negative zeros from being constant-folded properly.
- Issue #11395: io.FileIO().write() clamps the data length to 32,767 bytes on - Issue #11395: io.FileIO().write() clamps the data length to 32,767 bytes on
Windows if the file is a TTY to workaround a Windows bug. The Windows console Windows if the file is a TTY to workaround a Windows bug. The Windows console
returns an error (12: not enough space error) on writing into stdout if returns an error (12: not enough space error) on writing into stdout if
......
...@@ -238,7 +238,7 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts, PyObject **ob ...@@ -238,7 +238,7 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts, PyObject **ob
static int static int
fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v) fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v)
{ {
PyObject *newconst=NULL/*, *v*/; PyObject *newconst;
Py_ssize_t len_consts; Py_ssize_t len_consts;
int opcode; int opcode;
...@@ -250,9 +250,7 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v ...@@ -250,9 +250,7 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v
opcode = codestr[3]; opcode = codestr[3];
switch (opcode) { switch (opcode) {
case UNARY_NEGATIVE: case UNARY_NEGATIVE:
/* Preserve the sign of -0.0 */ newconst = PyNumber_Negative(v);
if (PyObject_IsTrue(v) == 1)
newconst = PyNumber_Negative(v);
break; break;
case UNARY_INVERT: case UNARY_INVERT:
newconst = PyNumber_Invert(v); newconst = PyNumber_Invert(v);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment