[gem5-dev] Change in gem5/gem5[master]: base: Fix enums checkpointing

2019-02-18 Thread Giacomo Travaglini (Gerrit)
Giacomo Travaglini has submitted this change and it was merged. (  
https://gem5-review.googlesource.com/c/public/gem5/+/16382 )


Change subject: base: Fix enums checkpointing
..

base: Fix enums checkpointing

Creating an extra version of string to number converters (__to_number)
in base/str.hh; it will be used by enums only when unserializing
them.  The reason not to have a single helper for both enums and
integers is that std::numeric_limits trait is not specialized for enums.
We fix this by using the std::underlying_type trait.

Change-Id: I819e35c0df8c094de7b7a6390152964fa47d513d
Signed-off-by: Giacomo Travaglini 
Reviewed-by: Ciro Santilli 
Signed-off-by: Giacomo Travaglini 
Reviewed-on: https://gem5-review.googlesource.com/c/16382
Reviewed-by: Daniel Carvalho 
Reviewed-by: Andreas Sandberg 
Maintainer: Jason Lowe-Power 
---
M src/base/str.hh
1 file changed, 11 insertions(+), 4 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved
  Daniel Carvalho: Looks good to me, approved
  Jason Lowe-Power: Looks good to me, approved



diff --git a/src/base/str.hh b/src/base/str.hh
index 61022bd..1ea18b7 100644
--- a/src/base/str.hh
+++ b/src/base/str.hh
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 

 #include "base/logging.hh"
@@ -108,8 +109,7 @@
  *   integeral type, as well as enums and floating-point types.
  */
 template 
-typename std::enable_if<(std::is_integral::value ||
-std::is_enum::value) &&
+typename std::enable_if::value &&
 std::is_signed::value, T>::type
 __to_number(const std::string )
 {
@@ -121,8 +121,7 @@
 }

 template 
-typename std::enable_if<(std::is_integral::value ||
-std::is_enum::value) &&
+typename std::enable_if::value &&
 !std::is_signed::value, T>::type
 __to_number(const std::string )
 {
@@ -134,6 +133,14 @@
 }

 template 
+typename std::enable_if::value, T>::type
+__to_number(const std::string )
+{
+auto r = __to_number::type>(value);
+return static_cast(r);
+}
+
+template 
 typename std::enable_if::value, T>::type
 __to_number(const std::string )
 {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/16382
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: I819e35c0df8c094de7b7a6390152964fa47d513d
Gerrit-Change-Number: 16382
Gerrit-PatchSet: 3
Gerrit-Owner: Giacomo Travaglini 
Gerrit-Reviewer: Andreas Sandberg 
Gerrit-Reviewer: Ciro Santilli 
Gerrit-Reviewer: Daniel Carvalho 
Gerrit-Reviewer: Gabe Black 
Gerrit-Reviewer: Giacomo Travaglini 
Gerrit-Reviewer: Jason Lowe-Power 
Gerrit-MessageType: merged
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

[gem5-dev] Change in gem5/gem5[master]: base: Fix enums checkpointing

2019-02-15 Thread Giacomo Travaglini (Gerrit)
Hello Gabe Black, Jason Lowe-Power, Daniel Carvalho, Andreas Sandberg, Ciro  
Santilli,


I'd like you to reexamine a change. Please visit

https://gem5-review.googlesource.com/c/public/gem5/+/16382

to look at the new patch set (#2).

Change subject: base: Fix enums checkpointing
..

base: Fix enums checkpointing

Creating an extra version of string to number converters (__to_number)
in base/str.hh; it will be used by enums only when unserializing
them.  The reason not to have a single helper for both enums and
integers is that std::numeric_limits trait is not specialized for enums.
We fix this by using the std::underlying_type trait.

Change-Id: I819e35c0df8c094de7b7a6390152964fa47d513d
Signed-off-by: Giacomo Travaglini 
Reviewed-by: Ciro Santilli 
Signed-off-by: Giacomo Travaglini 
---
M src/base/str.hh
1 file changed, 11 insertions(+), 4 deletions(-)


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/16382
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: I819e35c0df8c094de7b7a6390152964fa47d513d
Gerrit-Change-Number: 16382
Gerrit-PatchSet: 2
Gerrit-Owner: Giacomo Travaglini 
Gerrit-Reviewer: Andreas Sandberg 
Gerrit-Reviewer: Ciro Santilli 
Gerrit-Reviewer: Daniel Carvalho 
Gerrit-Reviewer: Gabe Black 
Gerrit-Reviewer: Giacomo Travaglini 
Gerrit-Reviewer: Jason Lowe-Power 
Gerrit-MessageType: newpatchset
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

[gem5-dev] Change in gem5/gem5[master]: base: Fix enums checkpointing

2019-02-12 Thread Giacomo Travaglini (Gerrit)

Hello Ciro Santilli,

I'd like you to do a code review. Please visit

https://gem5-review.googlesource.com/c/public/gem5/+/16382

to review the following change.


Change subject: base: Fix enums checkpointing
..

base: Fix enums checkpointing

Creating an extra version of string to number converters (__to_number)
in base/str.hh; it will be used by enums only when unserializing
them.  The reason not to have a single helper for both enums and
integers is that std::numeric_limits trait is not specialized for enums.
We fix this by using the std::underlying_type trait.

Change-Id: I819e35c0df8c094de7b7a6390152964fa47d513d
Signed-off-by: Giacomo Travaglini 
Reviewed-by: Ciro Santilli 
---
M src/base/str.hh
1 file changed, 27 insertions(+), 4 deletions(-)



diff --git a/src/base/str.hh b/src/base/str.hh
index 61022bd..1d7c780 100644
--- a/src/base/str.hh
+++ b/src/base/str.hh
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 

 #include "base/logging.hh"
@@ -108,8 +109,7 @@
  *   integeral type, as well as enums and floating-point types.
  */
 template 
-typename std::enable_if<(std::is_integral::value ||
-std::is_enum::value) &&
+typename std::enable_if::value &&
 std::is_signed::value, T>::type
 __to_number(const std::string )
 {
@@ -121,8 +121,7 @@
 }

 template 
-typename std::enable_if<(std::is_integral::value ||
-std::is_enum::value) &&
+typename std::enable_if::value &&
 !std::is_signed::value, T>::type
 __to_number(const std::string )
 {
@@ -134,6 +133,30 @@
 }

 template 
+typename std::enable_if::value, T>::type
+__to_number(const std::string )
+{
+// start big and narrow it down if needed, determine the base  
dynamically

+long long r = std::stoll(value, nullptr, 0);
+
+// Check if value is out of range. The check is different depending on
+// whether it is a signed or unsigned enum
+if (std::is_signed::type>::value) {
+if (r < std::numeric_limits<
+typename std::underlying_type::type>::min() ||
+r > std::numeric_limits<
+typename std::underlying_type::type>::max())
+throw std::out_of_range("Out of range");
+} else {
+if (r > std::numeric_limits<
+typename std::underlying_type::type>::max())
+throw std::out_of_range("Out of range");
+}
+
+return static_cast(r);
+}
+
+template 
 typename std::enable_if::value, T>::type
 __to_number(const std::string )
 {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/16382
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: I819e35c0df8c094de7b7a6390152964fa47d513d
Gerrit-Change-Number: 16382
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini 
Gerrit-Reviewer: Ciro Santilli 
Gerrit-MessageType: newchange
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev