Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/40878 )
Change subject: base,arch-sparc: Overhaul the small fenv wrapper in base.
......................................................................
base,arch-sparc: Overhaul the small fenv wrapper in base.
This was written in C, broke the style guide, used macros, used an
obsolete m5_ prefix, and used extern "C" in an odd way.
Change-Id: If38f9a1bca6fd4a4f7f533ddb1e81d6207bc9c44
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40878
Reviewed-by: Gabe Black <[email protected]>
Reviewed-by: Daniel Carvalho <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/arch/sparc/isa/formats/basic.isa
M src/base/SConscript
R src/base/fenv.cc
M src/base/fenv.hh
4 files changed, 54 insertions(+), 35 deletions(-)
Approvals:
Daniel Carvalho: Looks good to me, approved
Gabe Black: Looks good to me, but someone else must approve; Looks good
to me, approved
kokoro: Regressions pass
diff --git a/src/arch/sparc/isa/formats/basic.isa
b/src/arch/sparc/isa/formats/basic.isa
index 8a3f174..901b5df 100644
--- a/src/arch/sparc/isa/formats/basic.isa
+++ b/src/arch/sparc/isa/formats/basic.isa
@@ -156,19 +156,27 @@
exec_code = """
Fsr |= bits(Fsr, 4, 0) << 5;
Fsr = insertBits(Fsr, 4, 0, 0);
- int newrnd = M5_FE_TONEAREST;
+ gem5::RoundingMode newrnd = gem5::RoundingMode::ToNearest;
switch (Fsr<31:30>) {
- case 0: newrnd = M5_FE_TONEAREST; break;
- case 1: newrnd = M5_FE_TOWARDZERO; break;
- case 2: newrnd = M5_FE_UPWARD; break;
- case 3: newrnd = M5_FE_DOWNWARD; break;
+ case 0:
+ newrnd = gem5::RoundingMode::ToNearest;
+ break;
+ case 1:
+ newrnd = gem5::RoundingMode::TowardZero;
+ break;
+ case 2:
+ newrnd = gem5::RoundingMode::Upward;
+ break;
+ case 3:
+ newrnd = gem5::RoundingMode::Downward;
+ break;
}
- int oldrnd = m5_fegetround();
- m5_fesetround(newrnd);
+ gem5::RoundingMode oldrnd = gem5::getFpRound();
+ gem5::setFpRound(newrnd);
__asm__ __volatile__("" ::: "memory");
fault = doFpOp(xc, traceData);
__asm__ __volatile__("" ::: "memory");
- m5_fesetround(oldrnd);
+ gem5::setFpRound(oldrnd);
return fault;
"""
fp_code = filterDoubles(code)
diff --git a/src/base/SConscript b/src/base/SConscript
index 64c2237..4242f9a 100644
--- a/src/base/SConscript
+++ b/src/base/SConscript
@@ -43,7 +43,7 @@
Source('debug.cc')
GTest('debug.test', 'debug.test.cc', 'debug.cc')
if env['USE_FENV']:
- Source('fenv.c')
+ Source('fenv.cc')
else:
warning("No IEEE FP rounding mode control.\n"
"FP results may deviate slightly from other platforms.")
diff --git a/src/base/fenv.c b/src/base/fenv.cc
similarity index 80%
rename from src/base/fenv.c
rename to src/base/fenv.cc
index 2539079..29f5185 100644
--- a/src/base/fenv.c
+++ b/src/base/fenv.cc
@@ -1,4 +1,5 @@
/*
+ * Copyright 2021 Google Inc.
* Copyright (c) 2007 The Regents of The University of Michigan
* All rights reserved.
*
@@ -26,29 +27,28 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <assert.h>
+#include "base/fenv.hh"
+
#include <fenv.h>
-#include <stdlib.h>
-void m5_fesetround(int rm);
-int m5_fegetround();
+#include <cstdlib>
-static const int m5_round_ops[] = {FE_DOWNWARD, FE_TONEAREST,
FE_TOWARDZERO, FE_UPWARD};
-
-void m5_fesetround(int rm)
+namespace gem5
{
- assert(rm >= 0 && rm < 4);
- fesetround(m5_round_ops[rm]);
-}
-int m5_fegetround()
+static const int roundOps[] =
+ { FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD };
+
+void setFpRound(RoundingMode rm) { fesetround(roundOps[(int)rm]); }
+
+RoundingMode
+getFpRound()
{
- int x;
int rm = fegetround();
- for (x = 0; x < 4; x++)
- if (m5_round_ops[x] == rm)
- return x;
+ for (int x = 0; x < 4; x++)
+ if (roundOps[x] == rm)
+ return (RoundingMode)x;
abort();
- return 0;
}
+} // namespace gem5
diff --git a/src/base/fenv.hh b/src/base/fenv.hh
index 406356b..fbd0d5b 100644
--- a/src/base/fenv.hh
+++ b/src/base/fenv.hh
@@ -31,23 +31,34 @@
#include "config/use_fenv.hh"
-#define M5_FE_DOWNWARD 0
-#define M5_FE_TONEAREST 1
-#define M5_FE_TOWARDZERO 2
-#define M5_FE_UPWARD 3
+namespace gem5
+{
+
+enum class RoundingMode
+{
+ Downward = 0,
+ ToNearest = 1,
+ TowardZero = 2,
+ Upward = 3
+};
#if USE_FENV
-extern "C" {
-void m5_fesetround(int rm);
-int m5_fegetround();
-}
+
+void setFpRound(RoundingMode rm);
+RoundingMode getFpRound();
+
#else
// Dummy definitions to allow code to compile w/o a real <fenv.h>.
-inline void m5_fesetround(int rm) { ; }
-inline int m5_fegetround() {return 0; }
+static inline void setFpRound(RoundingMode rm) {}
+static inline
+RoundingMode getFpRound()
+{
+ return RoundingMode::Downward;
+}
#endif // USE_FENV
+} // namespace gem5
#endif // __BASE_FENV_HH__
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40878
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: If38f9a1bca6fd4a4f7f533ddb1e81d6207bc9c44
Gerrit-Change-Number: 40878
Gerrit-PatchSet: 21
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s