summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2000-07-08 04:17:21 (GMT)
committerTim Peters <tim.peters@gmail.com>2000-07-08 04:17:21 (GMT)
commit7d3a511a40a8c90eac66d3d59edbbe3c3d4559b1 (patch)
treeb2a404e6604682d51adf242e1ac51ac225e6a0bc /Objects
parent5639ba4896fa7a4e29f11bf0c42f6e3125785654 (diff)
downloadcpython-7d3a511a40a8c90eac66d3d59edbbe3c3d4559b1.zip
cpython-7d3a511a40a8c90eac66d3d59edbbe3c3d4559b1.tar.gz
cpython-7d3a511a40a8c90eac66d3d59edbbe3c3d4559b1.tar.bz2
Cray J90 fixes for long ints.
This was a convenient excuse to create the pyport.h file recently discussed! Please use new Py_ARITHMETIC_RIGHT_SHIFT when right-shifting a signed int and you *need* sign-extension. This is #define'd in pyport.h, keying off new config symbol SIGNED_RIGHT_SHIFT_ZERO_FILLS. If you're running on a platform that needs that symbol #define'd, the std tests never would have worked for you (in particular, at least test_long would have failed). The autoconfig stuff got added to Python after my Unix days, so I don't know how that works. Would someone please look into doing & testing an auto-config of the SIGNED_RIGHT_SHIFT_ZERO_FILLS symbol? It needs to be defined if & only if, e.g., (-1) >> 3 is not -1.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/intobject.c5
-rw-r--r--Objects/longobject.c13
2 files changed, 9 insertions, 9 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index ba3dde1..a5dc134 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -721,10 +721,7 @@ int_rshift(v, w)
a = 0;
}
else {
- if (a < 0)
- a = ~( ~(unsigned long)a >> b );
- else
- a = (unsigned long)a >> b;
+ a = Py_ARITHMETIC_RIGHT_SHIFT(long, a, b);
}
return PyInt_FromLong(a);
}
diff --git a/Objects/longobject.c b/Objects/longobject.c
index a28dbaf..df3c6a5 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -571,7 +571,8 @@ long_format(PyObject *aa, int base, int addL)
int last = abs(a->ob_size);
int basebits = 1;
i = base;
- while ((i >>= 1) > 1) ++basebits;
+ while ((i >>= 1) > 1)
+ ++basebits;
i = 0;
for (;;) {
@@ -853,7 +854,9 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
carry += v->ob_digit[i+k] - z
+ ((twodigits)zz << SHIFT);
v->ob_digit[i+k] = carry & MASK;
- carry = (carry >> SHIFT) - zz;
+ carry = Py_ARITHMETIC_RIGHT_SHIFT(BASE_TWODIGITS_TYPE,
+ carry, SHIFT);
+ carry -= zz;
}
if (i+k < size_v) {
@@ -870,7 +873,9 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
for (i = 0; i < size_w && i+k < size_v; ++i) {
carry += v->ob_digit[i+k] + w->ob_digit[i];
v->ob_digit[i+k] = carry & MASK;
- carry >>= SHIFT;
+ carry = Py_ARITHMETIC_RIGHT_SHIFT(
+ BASE_TWODIGITS_TYPE,
+ carry, SHIFT);
}
}
} /* for j, k */
@@ -988,8 +993,6 @@ x_add(PyLongObject *a, PyLongObject *b)
for (i = 0; i < size_b; ++i) {
carry += a->ob_digit[i] + b->ob_digit[i];
z->ob_digit[i] = carry & MASK;
- /* The following assumes unsigned shifts don't
- propagate the sign bit. */
carry >>= SHIFT;
}
for (; i < size_a; ++i) {