blob: 0c34aa4f1dcad036146afb142f72b0dd71aaa6e0 [file] [log] [blame]
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "jni_macro_assembler.h"
18
19#include <algorithm>
20#include <vector>
21
22#ifdef ART_ENABLE_CODEGEN_arm
Artem Serov6287c232016-11-29 13:31:33 +000023#include "arm/jni_macro_assembler_arm_vixl.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070024#endif
25#ifdef ART_ENABLE_CODEGEN_arm64
Andreas Gampedcf30142016-08-08 16:06:34 -070026#include "arm64/jni_macro_assembler_arm64.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070027#endif
28#ifdef ART_ENABLE_CODEGEN_mips
29#include "mips/assembler_mips.h"
30#endif
31#ifdef ART_ENABLE_CODEGEN_mips64
32#include "mips64/assembler_mips64.h"
33#endif
34#ifdef ART_ENABLE_CODEGEN_x86
Andreas Gampe9954e3b2016-08-05 20:34:39 -070035#include "x86/jni_macro_assembler_x86.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070036#endif
37#ifdef ART_ENABLE_CODEGEN_x86_64
Andreas Gampe1ace16b2016-08-05 09:01:50 -070038#include "x86_64/jni_macro_assembler_x86_64.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070039#endif
40#include "base/casts.h"
David Sehr1ce2b3b2018-04-05 11:02:03 -070041#include "base/memory_region.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070042#include "globals.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070043
44namespace art {
45
46using MacroAsm32UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k32>>;
47
48template <>
49MacroAsm32UniquePtr JNIMacroAssembler<PointerSize::k32>::Create(
Vladimir Markoe764d2e2017-10-05 14:35:55 +010050 ArenaAllocator* allocator,
Andreas Gampe3b165bc2016-08-01 22:07:04 -070051 InstructionSet instruction_set,
52 const InstructionSetFeatures* instruction_set_features) {
53#ifndef ART_ENABLE_CODEGEN_mips
54 UNUSED(instruction_set_features);
55#endif
56
57 switch (instruction_set) {
58#ifdef ART_ENABLE_CODEGEN_arm
Vladimir Marko33bff252017-11-01 14:35:42 +000059 case InstructionSet::kArm:
60 case InstructionSet::kThumb2:
Vladimir Markoe764d2e2017-10-05 14:35:55 +010061 return MacroAsm32UniquePtr(new (allocator) arm::ArmVIXLJNIMacroAssembler(allocator));
Andreas Gampe3b165bc2016-08-01 22:07:04 -070062#endif
63#ifdef ART_ENABLE_CODEGEN_mips
Vladimir Marko33bff252017-11-01 14:35:42 +000064 case InstructionSet::kMips:
Vladimir Markoe764d2e2017-10-05 14:35:55 +010065 return MacroAsm32UniquePtr(new (allocator) mips::MipsAssembler(
66 allocator,
Andreas Gampe3b165bc2016-08-01 22:07:04 -070067 instruction_set_features != nullptr
68 ? instruction_set_features->AsMipsInstructionSetFeatures()
69 : nullptr));
70#endif
71#ifdef ART_ENABLE_CODEGEN_x86
Vladimir Marko33bff252017-11-01 14:35:42 +000072 case InstructionSet::kX86:
Vladimir Markoe764d2e2017-10-05 14:35:55 +010073 return MacroAsm32UniquePtr(new (allocator) x86::X86JNIMacroAssembler(allocator));
Andreas Gampe3b165bc2016-08-01 22:07:04 -070074#endif
75 default:
76 LOG(FATAL) << "Unknown/unsupported 4B InstructionSet: " << instruction_set;
77 UNREACHABLE();
78 }
79}
80
81using MacroAsm64UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k64>>;
82
83template <>
84MacroAsm64UniquePtr JNIMacroAssembler<PointerSize::k64>::Create(
Vladimir Markoe764d2e2017-10-05 14:35:55 +010085 ArenaAllocator* allocator,
Andreas Gampe3b165bc2016-08-01 22:07:04 -070086 InstructionSet instruction_set,
Goran Jakovljevic27af9372017-03-15 15:31:34 +010087 const InstructionSetFeatures* instruction_set_features) {
88#ifndef ART_ENABLE_CODEGEN_mips64
89 UNUSED(instruction_set_features);
90#endif
91
Andreas Gampe3b165bc2016-08-01 22:07:04 -070092 switch (instruction_set) {
93#ifdef ART_ENABLE_CODEGEN_arm64
Vladimir Marko33bff252017-11-01 14:35:42 +000094 case InstructionSet::kArm64:
Vladimir Markoe764d2e2017-10-05 14:35:55 +010095 return MacroAsm64UniquePtr(new (allocator) arm64::Arm64JNIMacroAssembler(allocator));
Andreas Gampe3b165bc2016-08-01 22:07:04 -070096#endif
97#ifdef ART_ENABLE_CODEGEN_mips64
Vladimir Marko33bff252017-11-01 14:35:42 +000098 case InstructionSet::kMips64:
Vladimir Markoe764d2e2017-10-05 14:35:55 +010099 return MacroAsm64UniquePtr(new (allocator) mips64::Mips64Assembler(
100 allocator,
Goran Jakovljevic27af9372017-03-15 15:31:34 +0100101 instruction_set_features != nullptr
102 ? instruction_set_features->AsMips64InstructionSetFeatures()
103 : nullptr));
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700104#endif
105#ifdef ART_ENABLE_CODEGEN_x86_64
Vladimir Marko33bff252017-11-01 14:35:42 +0000106 case InstructionSet::kX86_64:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100107 return MacroAsm64UniquePtr(new (allocator) x86_64::X86_64JNIMacroAssembler(allocator));
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700108#endif
109 default:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100110 UNUSED(allocator);
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700111 LOG(FATAL) << "Unknown/unsupported 8B InstructionSet: " << instruction_set;
112 UNREACHABLE();
113 }
114}
115
116} // namespace art