1d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers/*
2d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * Copyright (C) 2014 The Android Open Source Project
3d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers *
4d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * Licensed under the Apache License, Version 2.0 (the "License");
5d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * you may not use this file except in compliance with the License.
6d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * You may obtain a copy of the License at
7d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers *
8d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers *      http://www.apache.org/licenses/LICENSE-2.0
9d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers *
10d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * Unless required by applicable law or agreed to in writing, software
11d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * distributed under the License is distributed on an "AS IS" BASIS,
12d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * See the License for the specific language governing permissions and
14d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers * limitations under the License.
15d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers */
16d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
17d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers#ifndef ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_
18d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers#define ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_
19d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
20d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers#include "arch/instruction_set_features.h"
21d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
22d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogersnamespace art {
23d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
24d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers// Instruction set features relevant to the ARM64 architecture.
25d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogersclass Arm64InstructionSetFeatures FINAL : public InstructionSetFeatures {
26d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers public:
27d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Process a CPU variant string like "krait" or "cortex-a15" and create InstructionSetFeatures.
28d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  static const Arm64InstructionSetFeatures* FromVariant(const std::string& variant,
29d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers                                                        std::string* error_msg);
30d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
31d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Parse a bitmap and create an InstructionSetFeatures.
32d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  static const Arm64InstructionSetFeatures* FromBitmap(uint32_t bitmap);
33d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
34d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Turn C pre-processor #defines into the equivalent instruction set features.
35d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  static const Arm64InstructionSetFeatures* FromCppDefines();
36d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
37d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures.
38d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  static const Arm64InstructionSetFeatures* FromCpuInfo();
39d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
40d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce
41d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // InstructionSetFeatures.
42d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  static const Arm64InstructionSetFeatures* FromHwcap();
43d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
44d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Use assembly tests of the current runtime (ie kRuntimeISA) to determine the
45d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // InstructionSetFeatures. This works around kernel bugs in AT_HWCAP and /proc/cpuinfo.
46d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  static const Arm64InstructionSetFeatures* FromAssembly();
47d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
48d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  bool Equals(const InstructionSetFeatures* other) const OVERRIDE;
49d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
50d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  InstructionSet GetInstructionSet() const OVERRIDE {
51d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers    return kArm64;
52d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  }
53d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
54d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  uint32_t AsBitmap() const OVERRIDE;
55d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
56d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Return a string of the form "a53" or "none".
57d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  std::string GetFeatureString() const OVERRIDE;
58d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
59d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Generate code addressing Cortex-A53 erratum 835769?
60d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  bool NeedFixCortexA53_835769() const {
61d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers      return fix_cortex_a53_835769_;
62d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  }
63d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
6420f85597828194c12be10d3a927999def066555eVladimir Marko  // Generate code addressing Cortex-A53 erratum 843419?
6520f85597828194c12be10d3a927999def066555eVladimir Marko  bool NeedFixCortexA53_843419() const {
6620f85597828194c12be10d3a927999def066555eVladimir Marko      return fix_cortex_a53_843419_;
6720f85597828194c12be10d3a927999def066555eVladimir Marko  }
6820f85597828194c12be10d3a927999def066555eVladimir Marko
69760d8efd535764e54500bf65a944ed3f2a54c123Serban Constantinescu  // NOTE: This flag can be tunned on a CPU basis. In general all ARMv8 CPUs
70760d8efd535764e54500bf65a944ed3f2a54c123Serban Constantinescu  // should prefer the Acquire-Release semantics over the explicit DMBs when
71760d8efd535764e54500bf65a944ed3f2a54c123Serban Constantinescu  // handling load/store-volatile. For a specific use case see the ARM64
72760d8efd535764e54500bf65a944ed3f2a54c123Serban Constantinescu  // Optimizing backend.
73579885a26d761f5ba9550f2a1cd7f0f598c2e1e3Serban Constantinescu  bool PreferAcquireRelease() const {
74760d8efd535764e54500bf65a944ed3f2a54c123Serban Constantinescu    return true;
75579885a26d761f5ba9550f2a1cd7f0f598c2e1e3Serban Constantinescu  }
76579885a26d761f5ba9550f2a1cd7f0f598c2e1e3Serban Constantinescu
77d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  virtual ~Arm64InstructionSetFeatures() {}
78d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
79d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers protected:
80d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Parse a vector of the form "a53" adding these to a new ArmInstructionSetFeatures.
81d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  const InstructionSetFeatures*
82d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers      AddFeaturesFromSplitString(const bool smp, const std::vector<std::string>& features,
83d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers                                 std::string* error_msg) const OVERRIDE;
84d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
85d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers private:
8620f85597828194c12be10d3a927999def066555eVladimir Marko  explicit Arm64InstructionSetFeatures(bool smp,
8720f85597828194c12be10d3a927999def066555eVladimir Marko                                       bool needs_a53_835769_fix,
8820f85597828194c12be10d3a927999def066555eVladimir Marko                                       bool needs_a53_843419_fix)
8920f85597828194c12be10d3a927999def066555eVladimir Marko      : InstructionSetFeatures(smp),
9020f85597828194c12be10d3a927999def066555eVladimir Marko        fix_cortex_a53_835769_(needs_a53_835769_fix),
9120f85597828194c12be10d3a927999def066555eVladimir Marko        fix_cortex_a53_843419_(needs_a53_843419_fix) {
92d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  }
93d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
94d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  // Bitmap positions for encoding features as a bitmap.
95d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  enum {
96d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers    kSmpBitfield = 1,
97d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers    kA53Bitfield = 2,
98d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  };
99d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
100d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  const bool fix_cortex_a53_835769_;
10120f85597828194c12be10d3a927999def066555eVladimir Marko  const bool fix_cortex_a53_843419_;
102d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
103d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers  DISALLOW_COPY_AND_ASSIGN(Arm64InstructionSetFeatures);
104d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers};
105d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
106d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers}  // namespace art
107d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers
108d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers#endif  // ART_RUNTIME_ARCH_ARM64_INSTRUCTION_SET_FEATURES_ARM64_H_
109