Nikos Nikoleris has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/19129

Change subject: base: Fix ctz32 for systems where unsigned int is not 32bit
......................................................................

base: Fix ctz32 for systems where unsigned int is not 32bit

The implementation of ctz32 uses __builtin_ctz to count the number of
trailing zeros and therefore makes the assumption that an unsigned int
is 32bit. This change checks whether that's the case and if not it
uses __builtin_ctzl instead.

Change-Id: Ic3ed3ada25fd0a93c7eb91d75b954e9924bdbb77
Signed-off-by: Nikos Nikoleris <[email protected]>
---
M src/base/bitfield.hh
1 file changed, 6 insertions(+), 2 deletions(-)



diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh
index 10b1e60..d820295 100644
--- a/src/base/bitfield.hh
+++ b/src/base/bitfield.hh
@@ -286,12 +286,16 @@
 /**
  * Count trailing zeros in a 32-bit value.
  *
- * Returns 32 if the value is zero. Note that the GCC builtin is
- * undefined if the value is zero.
+ * @param An input value
+ * @return The number of trailing zeros or 32 if the value is zero.
  */
 inline int ctz32(uint32_t value)
 {
+#if UINT_MAX == UINT32_MAX
     return value ? __builtin_ctz(value) : 32;
+#else
+    return value ? __builtin_ctzl(value) : 32;
+#endif
 }

 /**

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/19129
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: Ic3ed3ada25fd0a93c7eb91d75b954e9924bdbb77
Gerrit-Change-Number: 19129
Gerrit-PatchSet: 1
Gerrit-Owner: Nikos Nikoleris <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to