Andreas Sandberg has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/16001

Change subject: python: Add missing operators to NumericParamValue
......................................................................

python: Add missing operators to NumericParamValue

Add missing operators to NumericParamValue and ensure that they are
able to work on the underlying value if the right hand side is a
param.

Change-Id: I2bd86662aee9891bbd89aed7ebe20b827b5528bd
Signed-off-by: Andreas Sandberg <andreas.sandb...@arm.com>
---
M src/python/m5/params.py
1 file changed, 45 insertions(+), 4 deletions(-)



diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index 9613994..0899890 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -464,6 +464,10 @@
 # operations in a type-safe way.  e.g., a Latency times an int returns
 # a new Latency object.
 class NumericParamValue(ParamValue):
+    @staticmethod
+    def unwrap(v):
+        return v.value if isinstance(v, NumericParamValue) else v
+
     def __str__(self):
         return str(self.value)

@@ -482,7 +486,7 @@

     def __mul__(self, other):
         newobj = self.__class__(self)
-        newobj.value *= other
+        newobj.value *= NumericParamValue.unwrap(other)
         newobj._check()
         return newobj

@@ -490,16 +494,53 @@

     def __div__(self, other):
         newobj = self.__class__(self)
-        newobj.value /= other
+        newobj.value /= NumericParamValue.unwrap(other)
         newobj._check()
         return newobj

-    def __sub__(self, other):
+    __truediv__ = __div__
+
+    def __floordiv__(self, other):
         newobj = self.__class__(self)
-        newobj.value -= other
+        newobj.value //= NumericParamValue.unwrap(other)
         newobj._check()
         return newobj

+
+    def __sub__(self, other):
+        newobj = self.__class__(self)
+        newobj.value -= NumericParamValue.unwrap(other)
+        newobj._check()
+        return newobj
+
+    def __iadd__(self, other):
+        self.value += NumericParamValue.unwrap(other)
+        self._check()
+        return self
+
+    def __isub__(self, other):
+        self.value += NumericParamValue.unwrap(other)
+        self._check()
+        return self
+
+    def __imul__(self, other):
+        self.value *= NumericParamValue.unwrap(other)
+        self._check()
+        return self
+
+    def __itruediv__(self, other):
+        self.value /= NumericParamValue.unwrap(other)
+        self._check()
+        return self
+
+    def __ifloordiv__(self, other):
+        self.value //= NumericParamValue.unwrap(other)
+        self._check()
+        return self
+
+    def __lt__(self, other):
+        return self.value < NumericParamValue.unwrap(other)
+
     def config_value(self):
         return self.value


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/16001
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I2bd86662aee9891bbd89aed7ebe20b827b5528bd
Gerrit-Change-Number: 16001
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to