diff options
author | 2017-05-24 13:20:49 -0700 | |
---|---|---|
committer | 2017-05-24 21:45:50 -0700 | |
commit | 705543e43d1e7df753c64cd048a933f7b9681226 (patch) | |
tree | c69dccee07cf2cf64f66a03d222d1f66271f42f1 | |
parent | 1dfa89847acf85fe68ac5dbef43993ecec07948d (diff) |
ART: Clean up instruction_set.h
Move functions to constexpr where possible and make them more
readable (we're C++14 now).
Test: m
Test: m test-art-host
Change-Id: I4b697e8ff74edec972bf6fa652df82aa58a04934
-rw-r--r-- | runtime/arch/instruction_set.cc | 24 | ||||
-rw-r--r-- | runtime/arch/instruction_set.h | 72 |
2 files changed, 56 insertions, 40 deletions
diff --git a/runtime/arch/instruction_set.cc b/runtime/arch/instruction_set.cc index 8f64dcd306..64af7eccd4 100644 --- a/runtime/arch/instruction_set.cc +++ b/runtime/arch/instruction_set.cc @@ -18,8 +18,8 @@ // Explicitly include our own elf.h to avoid Linux and other dependencies. #include "../elf.h" +#include "android-base/logging.h" #include "base/bit_utils.h" -#include "base/logging.h" #include "globals.h" namespace art { @@ -36,11 +36,9 @@ void InstructionSetAbort(InstructionSet isa) { case kNone: LOG(FATAL) << "Unsupported instruction set " << isa; UNREACHABLE(); - - default: - LOG(FATAL) << "Unknown ISA " << isa; - UNREACHABLE(); } + LOG(FATAL) << "Unknown ISA " << isa; + UNREACHABLE(); } const char* GetInstructionSetString(InstructionSet isa) { @@ -60,10 +58,9 @@ const char* GetInstructionSetString(InstructionSet isa) { return "mips64"; case kNone: return "none"; - default: - LOG(FATAL) << "Unknown ISA " << isa; - UNREACHABLE(); } + LOG(FATAL) << "Unknown ISA " << isa; + UNREACHABLE(); } InstructionSet GetInstructionSetFromString(const char* isa_str) { @@ -128,10 +125,9 @@ size_t GetInstructionSetAlignment(InstructionSet isa) { case kNone: LOG(FATAL) << "ISA kNone does not have alignment."; UNREACHABLE(); - default: - LOG(FATAL) << "Unknown ISA " << isa; - UNREACHABLE(); } + LOG(FATAL) << "Unknown ISA " << isa; + UNREACHABLE(); } #if !defined(ART_STACK_OVERFLOW_GAP_arm) || !defined(ART_STACK_OVERFLOW_GAP_arm64) || \ @@ -197,11 +193,9 @@ size_t GetStackOverflowReservedBytes(InstructionSet isa) { case kNone: LOG(FATAL) << "kNone has no stack overflow size"; UNREACHABLE(); - - default: - LOG(FATAL) << "Unknown instruction set" << isa; - UNREACHABLE(); } + LOG(FATAL) << "Unknown instruction set" << isa; + UNREACHABLE(); } } // namespace art diff --git a/runtime/arch/instruction_set.h b/runtime/arch/instruction_set.h index 7ef9a7abb5..7203b188c1 100644 --- a/runtime/arch/instruction_set.h +++ b/runtime/arch/instruction_set.h @@ -93,7 +93,7 @@ InstructionSet GetInstructionSetFromELF(uint16_t e_machine, uint32_t e_flags); // Fatal logging out of line to keep the header clean of logging.h. NO_RETURN void InstructionSetAbort(InstructionSet isa); -static inline PointerSize GetInstructionSetPointerSize(InstructionSet isa) { +constexpr PointerSize GetInstructionSetPointerSize(InstructionSet isa) { switch (isa) { case kArm: // Fall-through. @@ -109,23 +109,37 @@ static inline PointerSize GetInstructionSetPointerSize(InstructionSet isa) { return kMipsPointerSize; case kMips64: return kMips64PointerSize; - default: - InstructionSetAbort(isa); + + case kNone: + break; } + InstructionSetAbort(isa); } -ALWAYS_INLINE static inline constexpr size_t GetInstructionSetInstructionAlignment( - InstructionSet isa) { - return (isa == kThumb2 || isa == kArm) ? kThumb2InstructionAlignment : - (isa == kArm64) ? kArm64InstructionAlignment : - (isa == kX86) ? kX86InstructionAlignment : - (isa == kX86_64) ? kX86_64InstructionAlignment : - (isa == kMips) ? kMipsInstructionAlignment : - (isa == kMips64) ? kMips64InstructionAlignment : - 0; // Invalid case, but constexpr doesn't support asserts. +constexpr size_t GetInstructionSetInstructionAlignment(InstructionSet isa) { + switch (isa) { + case kArm: + // Fall-through. + case kThumb2: + return kThumb2InstructionAlignment; + case kArm64: + return kArm64InstructionAlignment; + case kX86: + return kX86InstructionAlignment; + case kX86_64: + return kX86_64InstructionAlignment; + case kMips: + return kMipsInstructionAlignment; + case kMips64: + return kMips64InstructionAlignment; + + case kNone: + break; + } + InstructionSetAbort(isa); } -static inline bool IsValidInstructionSet(InstructionSet isa) { +constexpr bool IsValidInstructionSet(InstructionSet isa) { switch (isa) { case kArm: case kThumb2: @@ -135,15 +149,16 @@ static inline bool IsValidInstructionSet(InstructionSet isa) { case kMips: case kMips64: return true; + case kNone: - default: return false; } + return false; } size_t GetInstructionSetAlignment(InstructionSet isa); -static inline bool Is64BitInstructionSet(InstructionSet isa) { +constexpr bool Is64BitInstructionSet(InstructionSet isa) { switch (isa) { case kArm: case kThumb2: @@ -156,16 +171,17 @@ static inline bool Is64BitInstructionSet(InstructionSet isa) { case kMips64: return true; - default: - InstructionSetAbort(isa); + case kNone: + break; } + InstructionSetAbort(isa); } -static inline PointerSize InstructionSetPointerSize(InstructionSet isa) { +constexpr PointerSize InstructionSetPointerSize(InstructionSet isa) { return Is64BitInstructionSet(isa) ? PointerSize::k64 : PointerSize::k32; } -static inline size_t GetBytesPerGprSpillLocation(InstructionSet isa) { +constexpr size_t GetBytesPerGprSpillLocation(InstructionSet isa) { switch (isa) { case kArm: // Fall-through. @@ -182,12 +198,13 @@ static inline size_t GetBytesPerGprSpillLocation(InstructionSet isa) { case kMips64: return 8; - default: - InstructionSetAbort(isa); + case kNone: + break; } + InstructionSetAbort(isa); } -static inline size_t GetBytesPerFprSpillLocation(InstructionSet isa) { +constexpr size_t GetBytesPerFprSpillLocation(InstructionSet isa) { switch (isa) { case kArm: // Fall-through. @@ -204,9 +221,10 @@ static inline size_t GetBytesPerFprSpillLocation(InstructionSet isa) { case kMips64: return 8; - default: - InstructionSetAbort(isa); + case kNone: + break; } + InstructionSetAbort(isa); } size_t GetStackOverflowReservedBytes(InstructionSet isa); @@ -243,7 +261,7 @@ static inline constexpr TwoWordReturn GetTwoWordFailureValue() { } // Use the lower 32b for the method pointer and the upper 32b for the code pointer. -static inline TwoWordReturn GetTwoWordSuccessValue(uintptr_t hi, uintptr_t lo) { +static inline constexpr TwoWordReturn GetTwoWordSuccessValue(uintptr_t hi, uintptr_t lo) { static_assert(sizeof(uint32_t) == sizeof(uintptr_t), "Unexpected size difference"); uint32_t lo32 = lo; uint64_t hi64 = static_cast<uint64_t>(hi); @@ -251,6 +269,10 @@ static inline TwoWordReturn GetTwoWordSuccessValue(uintptr_t hi, uintptr_t lo) { } #elif defined(__x86_64__) || defined(__aarch64__) || (defined(__mips__) && defined(__LP64__)) + +// Note: TwoWordReturn can't be constexpr for 64-bit targets. We'd need a constexpr constructor, +// which would violate C-linkage in the entrypoint functions. + struct TwoWordReturn { uintptr_t lo; uintptr_t hi; |