diff options
Diffstat (limited to 'runtime/utils.h')
-rw-r--r-- | runtime/utils.h | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/runtime/utils.h b/runtime/utils.h index 9d04d35e26..9a9f51a7bc 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -173,6 +173,24 @@ static inline uint32_t High32Bits(uint64_t value) { return static_cast<uint32_t>(value >> 32); } +// Traits class providing an unsigned integer type of (byte) size `n`. +template <size_t n> +struct UnsignedIntegerType { + // No defined `type`. +}; + +template <> +struct UnsignedIntegerType<1> { typedef uint8_t type; }; + +template <> +struct UnsignedIntegerType<2> { typedef uint16_t type; }; + +template <> +struct UnsignedIntegerType<4> { typedef uint32_t type; }; + +template <> +struct UnsignedIntegerType<8> { typedef uint64_t type; }; + // Type identity. template <typename T> struct TypeIdentity { @@ -271,6 +289,12 @@ static constexpr int CTZ(T x) { } template<typename T> +static inline int WhichPowerOf2(T x) { + DCHECK((x != 0) && IsPowerOfTwo(x)); + return CTZ(x); +} + +template<typename T> static constexpr int POPCOUNT(T x) { return (sizeof(T) == sizeof(uint32_t)) ? __builtin_popcount(x) @@ -309,7 +333,7 @@ std::string PrintableString(const char* utf8); // Tests whether 's' starts with 'prefix'. bool StartsWith(const std::string& s, const char* prefix); -// Tests whether 's' starts with 'suffix'. +// Tests whether 's' ends with 'suffix'. bool EndsWith(const std::string& s, const char* suffix); // Used to implement PrettyClass, PrettyField, PrettyMethod, and PrettyTypeOf, @@ -516,12 +540,6 @@ std::string GetDalvikCacheFilenameOrDie(const char* file_location, // Returns the system location for an image std::string GetSystemImageFilename(const char* location, InstructionSet isa); -// Returns an .odex file name adjacent to the dex location. -// For example, for "/foo/bar/baz.jar", return "/foo/bar/<isa>/baz.odex". -// The dex location must include a directory component and have an extension. -// Note: does not support multidex location strings. -std::string DexFilenameToOdexFilename(const std::string& location, InstructionSet isa); - // Check whether the given magic matches a known file type. bool IsZipMagic(uint32_t magic); bool IsDexMagic(uint32_t magic); |