Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Unified Diff: src/IceUtils.h

Issue 574133002: Add initial integrated assembler w/ some Xmm ops. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: remove duplicate pxor, and use enum Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | src/assembler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceUtils.h
diff --git a/src/IceUtils.h b/src/IceUtils.h
new file mode 100644
index 0000000000000000000000000000000000000000..ffeb792e80617ed7793d4f1d1695b86058fca705
--- /dev/null
+++ b/src/IceUtils.h
@@ -0,0 +1,59 @@
+//===- subzero/src/IceUtils.h - Utility functions ---------------*- C++ -*-===//
+//
+// The Subzero Code Generator
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares some utility functions
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SUBZERO_SRC_ICEUTILS_H
+#define SUBZERO_SRC_ICEUTILS_H
+
+#include <climits>
+
+namespace Ice {
+
+// Similar to bit_cast, but allows copying from types of unrelated
+// sizes. This method was introduced to enable the strict aliasing
+// optimizations of GCC 4.4. Basically, GCC mindlessly relies on
+// obscure details in the C++ standard that make reinterpret_cast
+// virtually useless.
+template <class D, class S> inline D bit_copy(const S &source) {
+ D destination;
+ // This use of memcpy is safe: source and destination cannot overlap.
+ memcpy(&destination, reinterpret_cast<const void *>(&source),
+ sizeof(destination));
+ return destination;
+}
+
+class Utils {
+public:
+ // Check whether an N-bit two's-complement representation can hold value.
+ template <typename T> static inline bool IsInt(int N, T value) {
+ assert((0 < N) &&
+ (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
+ T limit = static_cast<T>(1) << (N - 1);
+ return (-limit <= value) && (value < limit);
+ }
+
+ template <typename T> static inline bool IsUint(int N, T value) {
+ assert((0 < N) &&
+ (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
+ T limit = static_cast<T>(1) << N;
+ return (0 <= value) && (value < limit);
+ }
+
+ template <typename T> static inline bool WouldOverflowAdd(T X, T Y) {
+ return ((X > 0 && Y > 0 && (X > std::numeric_limits<T>::max() - Y)) ||
+ (X < 0 && Y < 0 && (X < std::numeric_limits<T>::min() - Y)));
+ }
+};
+
+} // end of namespace Ice
+
+#endif // SUBZERO_SRC_ICEUTILS_H
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | src/assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698