gh-90213: Speed up right shifts of negative integers (GH-30277)

This commit is contained in:
Mark Dickinson 2022-05-02 18:19:03 +01:00 committed by GitHub
parent 4b297a9ffd
commit 0ed91a26fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 30 deletions

View file

@ -985,6 +985,10 @@ class LongTest(unittest.TestCase):
self.assertEqual((-1122) >> 9, -3)
self.assertEqual(2**128 >> 9, 2**119)
self.assertEqual(-2**128 >> 9, -2**119)
# Exercise corner case of the current algorithm, where the result of
# shifting a two-limb int by the limb size still has two limbs.
self.assertEqual((1 - BASE*BASE) >> SHIFT, -BASE)
self.assertEqual((BASE - 1 - BASE*BASE) >> SHIFT, -BASE)
def test_big_rshift(self):
self.assertEqual(42 >> 32, 0)