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

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 nits. 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
Index: src/IceAPInt.h
diff --git a/src/IceAPInt.h b/src/IceAPInt.h
new file mode 100644
index 0000000000000000000000000000000000000000..d117f0a49e5d82b6d7902564bbdb2c6221917899
--- /dev/null
+++ b/src/IceAPInt.h
@@ -0,0 +1,63 @@
+//===-- 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.
+ SizeT APINT_BITS_PER_WORD =
Jim Stichnoth 2014/12/12 21:54:16 This should be static const, or an enum value.
Karl 2014/12/12 22:46:12 Done.
+ static_cast<uint32_t>(sizeof(uint64_t)) * CHAR_BIT;
Jim Stichnoth 2014/12/12 21:54:16 I'm not sure the static_cast is actually needed, b
Karl 2014/12/12 22:46:12 Simplified.
+
+ APInt(SizeT Bits, uint64_t Val) : BitWidth(Bits), Val(Val) {
+ assert(BitWidth && "bitwidth too small");
+ assert(Bits <= APINT_BITS_PER_WORD && "bitwidth too big");
Jim Stichnoth 2014/12/12 21:54:16 Use Bits in both asserts, or BitWidth in both asse
Karl 2014/12/12 22:46:12 Done.
+ clearUnusedBits();
+ }
+
+ uint32_t getBitWidth() const { return BitWidth; }
+
+ uint64_t getSExtValue() const {
Jim Stichnoth 2014/12/12 21:54:16 Should this return int64_t like the llvm::Constant
Karl 2014/12/12 22:46:12 Done.
+ return static_cast<int64_t>((Val << (APINT_BITS_PER_WORD - BitWidth)) >>
Karl 2014/12/12 22:46:13 Bug was missing parenthesis before last ">>" on li
+ (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

Powered by Google App Engine
This is Rietveld 408576698