Created
February 14, 2014 14:45
-
-
Save squeaky-pl/9002219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r e5565168e86f rpython/jit/backend/llsupport/descr.py | |
--- a/rpython/jit/backend/llsupport/descr.py Fri Feb 14 14:34:24 2014 +0100 | |
+++ b/rpython/jit/backend/llsupport/descr.py Fri Feb 14 15:44:56 2014 +0100 | |
@@ -103,6 +103,26 @@ | |
def is_field_signed(self): | |
return self.flag == FLAG_SIGNED | |
+ def is_integer_bounded(self): | |
+ return self.flag in (FLAG_SIGNED, FLAG_UNSIGNED) \ | |
+ and self.field_size < symbolic.WORD | |
+ | |
+ def get_integer_min(self): | |
+ if self.flag == FLAG_UNSIGNED: | |
+ return 0 | |
+ elif self.flag == FLAG_SIGNED: | |
+ return -(1 << ((self.field_size << 3) - 1)) | |
+ | |
+ assert False | |
+ | |
+ def get_integer_max(self): | |
+ if self.flag == FLAG_UNSIGNED: | |
+ return (1 << (self.field_size << 3)) - 1 | |
+ elif self.flag == FLAG_SIGNED: | |
+ return (1 << ((self.field_size << 3) - 1)) - 1 | |
+ | |
+ assert False | |
+ | |
def sort_key(self): | |
return self.offset | |
diff -r e5565168e86f rpython/jit/backend/llsupport/test/test_descr.py | |
--- a/rpython/jit/backend/llsupport/test/test_descr.py Fri Feb 14 14:34:24 2014 +0100 | |
+++ b/rpython/jit/backend/llsupport/test/test_descr.py Fri Feb 14 15:44:56 2014 +0100 | |
@@ -432,3 +432,21 @@ | |
assert descr.basesize == struct.calcsize("PP") # hash, length | |
assert descr.lendescr.offset == struct.calcsize("P") # hash | |
assert not descr.is_array_of_pointers() | |
+ | |
+ | |
+def test_descr_integer_bounded(): | |
+ descr = FieldDescr('descr', 0, 1, FLAG_SIGNED) | |
+ assert descr.is_integer_bounded() | |
+ | |
+ descr = FieldDescr('descr', 0, symbolic.WORD, FLAG_UNSIGNED) | |
+ assert not descr.is_integer_bounded() | |
+ | |
+ | |
+def test_descr_get_integer_bounds(): | |
+ descr = FieldDescr('decr', 0, 1, FLAG_UNSIGNED) | |
+ assert descr.get_integer_min() == 0 | |
+ assert descr.get_integer_max() == 255 | |
+ | |
+ descr = FieldDescr('descr', 0, 1, FLAG_SIGNED) | |
+ assert descr.get_integer_min() == -128 | |
+ assert descr.get_integer_max() == 127 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment