157b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe/*
257b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * Copyright (C) 2014 The Android Open Source Project
357b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe *
457b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License");
557b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * you may not use this file except in compliance with the License.
657b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * You may obtain a copy of the License at
757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe *
857b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe *      http://www.apache.org/licenses/LICENSE-2.0
957b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe *
1057b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * Unless required by applicable law or agreed to in writing, software
1157b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS,
1257b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1357b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * See the License for the specific language governing permissions and
1457b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe * limitations under the License.
1557b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe */
1657b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
1757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe#ifndef ART_RUNTIME_ARCH_MIPS64_INSTRUCTION_SET_FEATURES_MIPS64_H_
1857b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe#define ART_RUNTIME_ARCH_MIPS64_INSTRUCTION_SET_FEATURES_MIPS64_H_
1957b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
2057b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe#include "arch/instruction_set_features.h"
2157b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
2257b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampenamespace art {
2357b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
2457b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe// Instruction set features relevant to the MIPS64 architecture.
2557b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampeclass Mips64InstructionSetFeatures FINAL : public InstructionSetFeatures {
2657b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe public:
2757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // Process a CPU variant string like "r4000" and create InstructionSetFeatures.
2857b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  static const Mips64InstructionSetFeatures* FromVariant(const std::string& variant,
2957b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe                                                        std::string* error_msg);
3057b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
3157b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // Parse a bitmap and create an InstructionSetFeatures.
3257b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  static const Mips64InstructionSetFeatures* FromBitmap(uint32_t bitmap);
3357b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
3457b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // Turn C pre-processor #defines into the equivalent instruction set features.
3557b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  static const Mips64InstructionSetFeatures* FromCppDefines();
3657b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
3757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures.
3857b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  static const Mips64InstructionSetFeatures* FromCpuInfo();
3957b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
4057b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce
4157b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // InstructionSetFeatures.
4257b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  static const Mips64InstructionSetFeatures* FromHwcap();
4357b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
4457b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // Use assembly tests of the current runtime (ie kRuntimeISA) to determine the
4557b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // InstructionSetFeatures. This works around kernel bugs in AT_HWCAP and /proc/cpuinfo.
4657b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  static const Mips64InstructionSetFeatures* FromAssembly();
4757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
4857b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  bool Equals(const InstructionSetFeatures* other) const OVERRIDE;
4957b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
5057b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  InstructionSet GetInstructionSet() const OVERRIDE {
5157b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe    return kMips64;
5257b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  }
5357b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
5457b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  uint32_t AsBitmap() const OVERRIDE;
5557b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
5657b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  std::string GetFeatureString() const OVERRIDE;
5757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
5857b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  virtual ~Mips64InstructionSetFeatures() {}
5957b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
6057b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe protected:
6157b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // Parse a vector of the form "fpu32", "mips2" adding these to a new Mips64InstructionSetFeatures.
6257b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  virtual const InstructionSetFeatures*
6357b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe      AddFeaturesFromSplitString(const bool smp, const std::vector<std::string>& features,
6457b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe                                 std::string* error_msg) const OVERRIDE;
6557b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
6657b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe private:
6757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  explicit Mips64InstructionSetFeatures(bool smp) : InstructionSetFeatures(smp) {
6857b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  }
6957b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
7057b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  // Bitmap positions for encoding features as a bitmap.
7157b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  enum {
7257b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe    kSmpBitfield = 1,
7357b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  };
7457b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
7557b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe  DISALLOW_COPY_AND_ASSIGN(Mips64InstructionSetFeatures);
7657b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe};
7757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
7857b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe}  // namespace art
7957b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe
8057b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe#endif  // ART_RUNTIME_ARCH_MIPS64_INSTRUCTION_SET_FEATURES_MIPS64_H_
81