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

Unified Diff: src/IceAPInt.h

Issue 797323002: Simplify LLVM's APInt and APFloat for use in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix misspelling. Created 6 years 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/IceAPFloat.h ('k') | src/PNaClTranslator.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceAPInt.h
diff --git a/src/IceAPInt.h b/src/IceAPInt.h
new file mode 100644
index 0000000000000000000000000000000000000000..1789dd5751aa88d30d373579c19341884385ab44
--- /dev/null
+++ b/src/IceAPInt.h
@@ -0,0 +1,62 @@
+//===-- subzero/src/IceAPInt.h - Constant integer conversions --*- C++ -*--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file implements a class to represent 64 bit integer constant
+/// values, and thier conversion to variable bit sized integers.
+///
+/// Note: This is a simplified version of llvm/include/llvm/ADT/APInt.h for use
+/// with Subzero.
+//===----------------------------------------------------------------------===//
+
+#ifndef SUBZERO_SRC_ICEAPINT_H
+#define SUBZERO_SRC_ICEAPINT_H
+
+#include "IceDefs.h"
+
+namespace Ice {
+
+class APInt {
+public:
+ /// Bits in an (internal) value.
+ static const SizeT APINT_BITS_PER_WORD = sizeof(uint64_t) * CHAR_BIT;
+
+ APInt(SizeT Bits, uint64_t Val) : BitWidth(Bits), Val(Val) {
+ assert(Bits && "bitwidth too small");
+ assert(Bits <= APINT_BITS_PER_WORD && "bitwidth too big");
+ clearUnusedBits();
+ }
+
+ uint32_t getBitWidth() const { return BitWidth; }
+
+ int64_t getSExtValue() const {
+ return static_cast<int64_t>(Val << (APINT_BITS_PER_WORD - BitWidth)) >>
+ (APINT_BITS_PER_WORD - BitWidth);
+ }
+
+ uint64_t getRawData() const { return Val; }
+
+private:
+ uint32_t BitWidth; // The number of bits in this APInt.
+ uint64_t Val; // The (64-bit) equivalent integer value.
+
+ /// Clear unused high order bits.
+ void clearUnusedBits() {
+ // If all bits are used, we want to leave the value alone.
+ if (BitWidth == APINT_BITS_PER_WORD)
+ return;
+
+ // Mask out the high bits.
+ Val &= ~static_cast<uint64_t>(0) >> (APINT_BITS_PER_WORD - BitWidth);
+ }
+};
+
+} // end of namespace Ice
+
+#endif // SUBZERO_SRC_ICEAPINT_H
« no previous file with comments | « src/IceAPFloat.h ('k') | src/PNaClTranslator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698