summaryrefslogtreecommitdiffstats
path: root/newlib/libm/common/fdlibm.h
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libm/common/fdlibm.h')
-rw-r--r--newlib/libm/common/fdlibm.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/newlib/libm/common/fdlibm.h b/newlib/libm/common/fdlibm.h
index 3877ff2dc..ab0ada1a1 100644
--- a/newlib/libm/common/fdlibm.h
+++ b/newlib/libm/common/fdlibm.h
@@ -361,3 +361,13 @@ do { \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
+
+/* Macros to avoid undefined behaviour that can arise if the amount
+ of a shift is exactly equal to the size of the shifted operand. */
+
+#define SAFE_LEFT_SHIFT(op,amt) \
+ (((amt) < 8 * sizeof(op)) ? ((op) << (amt)) : 0)
+
+#define SAFE_RIGHT_SHIFT(op,amt) \
+ (((amt) < 8 * sizeof(op)) ? ((op) >> (amt)) : 0)
+