11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_CODEGEN_RISCV64_CONSTANTS_RISCV64_H_ 61cb0ef41Sopenharmony_ci#define V8_CODEGEN_RISCV64_CONSTANTS_RISCV64_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/base/logging.h" 91cb0ef41Sopenharmony_ci#include "src/base/macros.h" 101cb0ef41Sopenharmony_ci#include "src/common/globals.h" 111cb0ef41Sopenharmony_ci#include "src/flags/flags.h" 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// UNIMPLEMENTED_ macro for RISCV. 141cb0ef41Sopenharmony_ci#ifdef DEBUG 151cb0ef41Sopenharmony_ci#define UNIMPLEMENTED_RISCV() \ 161cb0ef41Sopenharmony_ci v8::internal::PrintF("%s, \tline %d: \tfunction %s not implemented. \n", \ 171cb0ef41Sopenharmony_ci __FILE__, __LINE__, __func__); 181cb0ef41Sopenharmony_ci#else 191cb0ef41Sopenharmony_ci#define UNIMPLEMENTED_RISCV() 201cb0ef41Sopenharmony_ci#endif 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci#define UNSUPPORTED_RISCV() \ 231cb0ef41Sopenharmony_ci v8::internal::PrintF("Unsupported instruction %d.\n", __LINE__) 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cienum Endianness { kLittle, kBig }; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci#if defined(V8_TARGET_LITTLE_ENDIAN) 281cb0ef41Sopenharmony_cistatic const Endianness kArchEndian = kLittle; 291cb0ef41Sopenharmony_ci#elif defined(V8_TARGET_BIG_ENDIAN) 301cb0ef41Sopenharmony_cistatic const Endianness kArchEndian = kBig; 311cb0ef41Sopenharmony_ci#else 321cb0ef41Sopenharmony_ci#error Unknown endianness 331cb0ef41Sopenharmony_ci#endif 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci#if defined(V8_TARGET_LITTLE_ENDIAN) 361cb0ef41Sopenharmony_ciconst uint32_t kLeastSignificantByteInInt32Offset = 0; 371cb0ef41Sopenharmony_ciconst uint32_t kLessSignificantWordInDoublewordOffset = 0; 381cb0ef41Sopenharmony_ci#elif defined(V8_TARGET_BIG_ENDIAN) 391cb0ef41Sopenharmony_ciconst uint32_t kLeastSignificantByteInInt32Offset = 3; 401cb0ef41Sopenharmony_ciconst uint32_t kLessSignificantWordInDoublewordOffset = 4; 411cb0ef41Sopenharmony_ci#else 421cb0ef41Sopenharmony_ci#error Unknown endianness 431cb0ef41Sopenharmony_ci#endif 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci#ifndef __STDC_FORMAT_MACROS 461cb0ef41Sopenharmony_ci#define __STDC_FORMAT_MACROS 471cb0ef41Sopenharmony_ci#endif 481cb0ef41Sopenharmony_ci#include <inttypes.h> 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci// Defines constants and accessor classes to assemble, disassemble and 511cb0ef41Sopenharmony_ci// simulate RISC-V instructions. 521cb0ef41Sopenharmony_ci// 531cb0ef41Sopenharmony_ci// See: The RISC-V Instruction Set Manual 541cb0ef41Sopenharmony_ci// Volume I: User-Level ISA 551cb0ef41Sopenharmony_ci// Try https://content.riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf. 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_cinamespace v8 { 581cb0ef41Sopenharmony_cinamespace internal { 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ciconstexpr size_t kMaxPCRelativeCodeRangeInMB = 4094; 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 631cb0ef41Sopenharmony_ci// Registers and FPURegisters. 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci// Number of general purpose registers. 661cb0ef41Sopenharmony_ciconst int kNumRegisters = 32; 671cb0ef41Sopenharmony_ciconst int kInvalidRegister = -1; 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci// Number of registers with pc. 701cb0ef41Sopenharmony_ciconst int kNumSimuRegisters = 33; 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci// In the simulator, the PC register is simulated as the 34th register. 731cb0ef41Sopenharmony_ciconst int kPCRegister = 34; 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci// Number coprocessor registers. 761cb0ef41Sopenharmony_ciconst int kNumFPURegisters = 32; 771cb0ef41Sopenharmony_ciconst int kInvalidFPURegister = -1; 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci// Number vectotr registers 801cb0ef41Sopenharmony_ciconst int kNumVRegisters = 32; 811cb0ef41Sopenharmony_ciconst int kInvalidVRegister = -1; 821cb0ef41Sopenharmony_ci// 'pref' instruction hints 831cb0ef41Sopenharmony_ciconst int32_t kPrefHintLoad = 0; 841cb0ef41Sopenharmony_ciconst int32_t kPrefHintStore = 1; 851cb0ef41Sopenharmony_ciconst int32_t kPrefHintLoadStreamed = 4; 861cb0ef41Sopenharmony_ciconst int32_t kPrefHintStoreStreamed = 5; 871cb0ef41Sopenharmony_ciconst int32_t kPrefHintLoadRetained = 6; 881cb0ef41Sopenharmony_ciconst int32_t kPrefHintStoreRetained = 7; 891cb0ef41Sopenharmony_ciconst int32_t kPrefHintWritebackInvalidate = 25; 901cb0ef41Sopenharmony_ciconst int32_t kPrefHintPrepareForStore = 30; 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci// Actual value of root register is offset from the root array's start 931cb0ef41Sopenharmony_ci// to take advantage of negative displacement values. 941cb0ef41Sopenharmony_ci// TODO(sigurds): Choose best value. 951cb0ef41Sopenharmony_ciconstexpr int kRootRegisterBias = 256; 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci// Helper functions for converting between register numbers and names. 981cb0ef41Sopenharmony_ciclass Registers { 991cb0ef41Sopenharmony_ci public: 1001cb0ef41Sopenharmony_ci // Return the name of the register. 1011cb0ef41Sopenharmony_ci static const char* Name(int reg); 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci // Lookup the register number for the name provided. 1041cb0ef41Sopenharmony_ci static int Number(const char* name); 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ci struct RegisterAlias { 1071cb0ef41Sopenharmony_ci int reg; 1081cb0ef41Sopenharmony_ci const char* name; 1091cb0ef41Sopenharmony_ci }; 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci static const int64_t kMaxValue = 0x7fffffffffffffffl; 1121cb0ef41Sopenharmony_ci static const int64_t kMinValue = 0x8000000000000000l; 1131cb0ef41Sopenharmony_ci 1141cb0ef41Sopenharmony_ci private: 1151cb0ef41Sopenharmony_ci static const char* names_[kNumSimuRegisters]; 1161cb0ef41Sopenharmony_ci static const RegisterAlias aliases_[]; 1171cb0ef41Sopenharmony_ci}; 1181cb0ef41Sopenharmony_ci 1191cb0ef41Sopenharmony_ci// Helper functions for converting between register numbers and names. 1201cb0ef41Sopenharmony_ciclass FPURegisters { 1211cb0ef41Sopenharmony_ci public: 1221cb0ef41Sopenharmony_ci // Return the name of the register. 1231cb0ef41Sopenharmony_ci static const char* Name(int reg); 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ci // Lookup the register number for the name provided. 1261cb0ef41Sopenharmony_ci static int Number(const char* name); 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ci struct RegisterAlias { 1291cb0ef41Sopenharmony_ci int creg; 1301cb0ef41Sopenharmony_ci const char* name; 1311cb0ef41Sopenharmony_ci }; 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci private: 1341cb0ef41Sopenharmony_ci static const char* names_[kNumFPURegisters]; 1351cb0ef41Sopenharmony_ci static const RegisterAlias aliases_[]; 1361cb0ef41Sopenharmony_ci}; 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_ciclass VRegisters { 1391cb0ef41Sopenharmony_ci public: 1401cb0ef41Sopenharmony_ci // Return the name of the register. 1411cb0ef41Sopenharmony_ci static const char* Name(int reg); 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ci // Lookup the register number for the name provided. 1441cb0ef41Sopenharmony_ci static int Number(const char* name); 1451cb0ef41Sopenharmony_ci 1461cb0ef41Sopenharmony_ci struct RegisterAlias { 1471cb0ef41Sopenharmony_ci int creg; 1481cb0ef41Sopenharmony_ci const char* name; 1491cb0ef41Sopenharmony_ci }; 1501cb0ef41Sopenharmony_ci 1511cb0ef41Sopenharmony_ci private: 1521cb0ef41Sopenharmony_ci static const char* names_[kNumVRegisters]; 1531cb0ef41Sopenharmony_ci static const RegisterAlias aliases_[]; 1541cb0ef41Sopenharmony_ci}; 1551cb0ef41Sopenharmony_ci 1561cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 1571cb0ef41Sopenharmony_ci// Instructions encoding constants. 1581cb0ef41Sopenharmony_ci 1591cb0ef41Sopenharmony_ci// On RISCV all instructions are 32 bits, except for RVC. 1601cb0ef41Sopenharmony_ciusing Instr = int32_t; 1611cb0ef41Sopenharmony_ciusing ShortInstr = int16_t; 1621cb0ef41Sopenharmony_ci 1631cb0ef41Sopenharmony_ci// Special Software Interrupt codes when used in the presence of the RISC-V 1641cb0ef41Sopenharmony_ci// simulator. 1651cb0ef41Sopenharmony_cienum SoftwareInterruptCodes { 1661cb0ef41Sopenharmony_ci // Transition to C code. 1671cb0ef41Sopenharmony_ci call_rt_redirected = 0xfffff 1681cb0ef41Sopenharmony_ci}; 1691cb0ef41Sopenharmony_ci 1701cb0ef41Sopenharmony_ci// On RISC-V Simulator breakpoints can have different codes: 1711cb0ef41Sopenharmony_ci// - Breaks between 0 and kMaxWatchpointCode are treated as simple watchpoints, 1721cb0ef41Sopenharmony_ci// the simulator will run through them and print the registers. 1731cb0ef41Sopenharmony_ci// - Breaks between kMaxWatchpointCode and kMaxStopCode are treated as stop() 1741cb0ef41Sopenharmony_ci// instructions (see Assembler::stop()). 1751cb0ef41Sopenharmony_ci// - Breaks larger than kMaxStopCode are simple breaks, dropping you into the 1761cb0ef41Sopenharmony_ci// debugger. 1771cb0ef41Sopenharmony_ciconst uint32_t kMaxWatchpointCode = 31; 1781cb0ef41Sopenharmony_ciconst uint32_t kMaxStopCode = 127; 1791cb0ef41Sopenharmony_ciSTATIC_ASSERT(kMaxWatchpointCode < kMaxStopCode); 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_ci// ----- Fields offset and length. 1821cb0ef41Sopenharmony_ci// RISCV constants 1831cb0ef41Sopenharmony_ciconst int kBaseOpcodeShift = 0; 1841cb0ef41Sopenharmony_ciconst int kBaseOpcodeBits = 7; 1851cb0ef41Sopenharmony_ciconst int kFunct7Shift = 25; 1861cb0ef41Sopenharmony_ciconst int kFunct7Bits = 7; 1871cb0ef41Sopenharmony_ciconst int kFunct5Shift = 27; 1881cb0ef41Sopenharmony_ciconst int kFunct5Bits = 5; 1891cb0ef41Sopenharmony_ciconst int kFunct3Shift = 12; 1901cb0ef41Sopenharmony_ciconst int kFunct3Bits = 3; 1911cb0ef41Sopenharmony_ciconst int kFunct2Shift = 25; 1921cb0ef41Sopenharmony_ciconst int kFunct2Bits = 2; 1931cb0ef41Sopenharmony_ciconst int kRs1Shift = 15; 1941cb0ef41Sopenharmony_ciconst int kRs1Bits = 5; 1951cb0ef41Sopenharmony_ciconst int kVs1Shift = 15; 1961cb0ef41Sopenharmony_ciconst int kVs1Bits = 5; 1971cb0ef41Sopenharmony_ciconst int kVs2Shift = 20; 1981cb0ef41Sopenharmony_ciconst int kVs2Bits = 5; 1991cb0ef41Sopenharmony_ciconst int kVdShift = 7; 2001cb0ef41Sopenharmony_ciconst int kVdBits = 5; 2011cb0ef41Sopenharmony_ciconst int kRs2Shift = 20; 2021cb0ef41Sopenharmony_ciconst int kRs2Bits = 5; 2031cb0ef41Sopenharmony_ciconst int kRs3Shift = 27; 2041cb0ef41Sopenharmony_ciconst int kRs3Bits = 5; 2051cb0ef41Sopenharmony_ciconst int kRdShift = 7; 2061cb0ef41Sopenharmony_ciconst int kRdBits = 5; 2071cb0ef41Sopenharmony_ciconst int kRlShift = 25; 2081cb0ef41Sopenharmony_ciconst int kAqShift = 26; 2091cb0ef41Sopenharmony_ciconst int kImm12Shift = 20; 2101cb0ef41Sopenharmony_ciconst int kImm12Bits = 12; 2111cb0ef41Sopenharmony_ciconst int kImm11Shift = 2; 2121cb0ef41Sopenharmony_ciconst int kImm11Bits = 11; 2131cb0ef41Sopenharmony_ciconst int kShamtShift = 20; 2141cb0ef41Sopenharmony_ciconst int kShamtBits = 5; 2151cb0ef41Sopenharmony_ciconst int kShamtWShift = 20; 2161cb0ef41Sopenharmony_ciconst int kShamtWBits = 6; 2171cb0ef41Sopenharmony_ciconst int kArithShiftShift = 30; 2181cb0ef41Sopenharmony_ciconst int kImm20Shift = 12; 2191cb0ef41Sopenharmony_ciconst int kImm20Bits = 20; 2201cb0ef41Sopenharmony_ciconst int kCsrShift = 20; 2211cb0ef41Sopenharmony_ciconst int kCsrBits = 12; 2221cb0ef41Sopenharmony_ciconst int kMemOrderBits = 4; 2231cb0ef41Sopenharmony_ciconst int kPredOrderShift = 24; 2241cb0ef41Sopenharmony_ciconst int kSuccOrderShift = 20; 2251cb0ef41Sopenharmony_ci// for C extension 2261cb0ef41Sopenharmony_ciconst int kRvcFunct4Shift = 12; 2271cb0ef41Sopenharmony_ciconst int kRvcFunct4Bits = 4; 2281cb0ef41Sopenharmony_ciconst int kRvcFunct3Shift = 13; 2291cb0ef41Sopenharmony_ciconst int kRvcFunct3Bits = 3; 2301cb0ef41Sopenharmony_ciconst int kRvcRs1Shift = 7; 2311cb0ef41Sopenharmony_ciconst int kRvcRs1Bits = 5; 2321cb0ef41Sopenharmony_ciconst int kRvcRs2Shift = 2; 2331cb0ef41Sopenharmony_ciconst int kRvcRs2Bits = 5; 2341cb0ef41Sopenharmony_ciconst int kRvcRdShift = 7; 2351cb0ef41Sopenharmony_ciconst int kRvcRdBits = 5; 2361cb0ef41Sopenharmony_ciconst int kRvcRs1sShift = 7; 2371cb0ef41Sopenharmony_ciconst int kRvcRs1sBits = 3; 2381cb0ef41Sopenharmony_ciconst int kRvcRs2sShift = 2; 2391cb0ef41Sopenharmony_ciconst int kRvcRs2sBits = 3; 2401cb0ef41Sopenharmony_ciconst int kRvcFunct2Shift = 5; 2411cb0ef41Sopenharmony_ciconst int kRvcFunct2BShift = 10; 2421cb0ef41Sopenharmony_ciconst int kRvcFunct2Bits = 2; 2431cb0ef41Sopenharmony_ciconst int kRvcFunct6Shift = 10; 2441cb0ef41Sopenharmony_ciconst int kRvcFunct6Bits = 6; 2451cb0ef41Sopenharmony_ci 2461cb0ef41Sopenharmony_ci// for RVV extension 2471cb0ef41Sopenharmony_ciconstexpr int kRvvELEN = 64; 2481cb0ef41Sopenharmony_ciconstexpr int kRvvVLEN = 128; 2491cb0ef41Sopenharmony_ciconstexpr int kRvvSLEN = kRvvVLEN; 2501cb0ef41Sopenharmony_ciconst int kRvvFunct6Shift = 26; 2511cb0ef41Sopenharmony_ciconst int kRvvFunct6Bits = 6; 2521cb0ef41Sopenharmony_ciconst uint32_t kRvvFunct6Mask = 2531cb0ef41Sopenharmony_ci (((1 << kRvvFunct6Bits) - 1) << kRvvFunct6Shift); 2541cb0ef41Sopenharmony_ci 2551cb0ef41Sopenharmony_ciconst int kRvvVmBits = 1; 2561cb0ef41Sopenharmony_ciconst int kRvvVmShift = 25; 2571cb0ef41Sopenharmony_ciconst uint32_t kRvvVmMask = (((1 << kRvvVmBits) - 1) << kRvvVmShift); 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ciconst int kRvvVs2Bits = 5; 2601cb0ef41Sopenharmony_ciconst int kRvvVs2Shift = 20; 2611cb0ef41Sopenharmony_ciconst uint32_t kRvvVs2Mask = (((1 << kRvvVs2Bits) - 1) << kRvvVs2Shift); 2621cb0ef41Sopenharmony_ci 2631cb0ef41Sopenharmony_ciconst int kRvvVs1Bits = 5; 2641cb0ef41Sopenharmony_ciconst int kRvvVs1Shift = 15; 2651cb0ef41Sopenharmony_ciconst uint32_t kRvvVs1Mask = (((1 << kRvvVs1Bits) - 1) << kRvvVs1Shift); 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ciconst int kRvvRs1Bits = kRvvVs1Bits; 2681cb0ef41Sopenharmony_ciconst int kRvvRs1Shift = kRvvVs1Shift; 2691cb0ef41Sopenharmony_ciconst uint32_t kRvvRs1Mask = (((1 << kRvvRs1Bits) - 1) << kRvvRs1Shift); 2701cb0ef41Sopenharmony_ci 2711cb0ef41Sopenharmony_ciconst int kRvvRs2Bits = 5; 2721cb0ef41Sopenharmony_ciconst int kRvvRs2Shift = 20; 2731cb0ef41Sopenharmony_ciconst uint32_t kRvvRs2Mask = (((1 << kRvvRs2Bits) - 1) << kRvvRs2Shift); 2741cb0ef41Sopenharmony_ci 2751cb0ef41Sopenharmony_ciconst int kRvvImm5Bits = kRvvVs1Bits; 2761cb0ef41Sopenharmony_ciconst int kRvvImm5Shift = kRvvVs1Shift; 2771cb0ef41Sopenharmony_ciconst uint32_t kRvvImm5Mask = (((1 << kRvvImm5Bits) - 1) << kRvvImm5Shift); 2781cb0ef41Sopenharmony_ci 2791cb0ef41Sopenharmony_ciconst int kRvvVdBits = 5; 2801cb0ef41Sopenharmony_ciconst int kRvvVdShift = 7; 2811cb0ef41Sopenharmony_ciconst uint32_t kRvvVdMask = (((1 << kRvvVdBits) - 1) << kRvvVdShift); 2821cb0ef41Sopenharmony_ci 2831cb0ef41Sopenharmony_ciconst int kRvvRdBits = kRvvVdBits; 2841cb0ef41Sopenharmony_ciconst int kRvvRdShift = kRvvVdShift; 2851cb0ef41Sopenharmony_ciconst uint32_t kRvvRdMask = (((1 << kRvvRdBits) - 1) << kRvvRdShift); 2861cb0ef41Sopenharmony_ci 2871cb0ef41Sopenharmony_ciconst int kRvvZimmBits = 11; 2881cb0ef41Sopenharmony_ciconst int kRvvZimmShift = 20; 2891cb0ef41Sopenharmony_ciconst uint32_t kRvvZimmMask = (((1 << kRvvZimmBits) - 1) << kRvvZimmShift); 2901cb0ef41Sopenharmony_ci 2911cb0ef41Sopenharmony_ciconst int kRvvUimmShift = kRvvRs1Shift; 2921cb0ef41Sopenharmony_ciconst int kRvvUimmBits = kRvvRs1Bits; 2931cb0ef41Sopenharmony_ciconst uint32_t kRvvUimmMask = (((1 << kRvvUimmBits) - 1) << kRvvUimmShift); 2941cb0ef41Sopenharmony_ci 2951cb0ef41Sopenharmony_ciconst int kRvvWidthBits = 3; 2961cb0ef41Sopenharmony_ciconst int kRvvWidthShift = 12; 2971cb0ef41Sopenharmony_ciconst uint32_t kRvvWidthMask = (((1 << kRvvWidthBits) - 1) << kRvvWidthShift); 2981cb0ef41Sopenharmony_ci 2991cb0ef41Sopenharmony_ciconst int kRvvMopBits = 2; 3001cb0ef41Sopenharmony_ciconst int kRvvMopShift = 26; 3011cb0ef41Sopenharmony_ciconst uint32_t kRvvMopMask = (((1 << kRvvMopBits) - 1) << kRvvMopShift); 3021cb0ef41Sopenharmony_ci 3031cb0ef41Sopenharmony_ciconst int kRvvMewBits = 1; 3041cb0ef41Sopenharmony_ciconst int kRvvMewShift = 28; 3051cb0ef41Sopenharmony_ciconst uint32_t kRvvMewMask = (((1 << kRvvMewBits) - 1) << kRvvMewShift); 3061cb0ef41Sopenharmony_ci 3071cb0ef41Sopenharmony_ciconst int kRvvNfBits = 3; 3081cb0ef41Sopenharmony_ciconst int kRvvNfShift = 29; 3091cb0ef41Sopenharmony_ciconst uint32_t kRvvNfMask = (((1 << kRvvNfBits) - 1) << kRvvNfShift); 3101cb0ef41Sopenharmony_ci 3111cb0ef41Sopenharmony_ci// RISCV Instruction bit masks 3121cb0ef41Sopenharmony_ciconst uint32_t kBaseOpcodeMask = ((1 << kBaseOpcodeBits) - 1) 3131cb0ef41Sopenharmony_ci << kBaseOpcodeShift; 3141cb0ef41Sopenharmony_ciconst uint32_t kFunct3Mask = ((1 << kFunct3Bits) - 1) << kFunct3Shift; 3151cb0ef41Sopenharmony_ciconst uint32_t kFunct5Mask = ((1 << kFunct5Bits) - 1) << kFunct5Shift; 3161cb0ef41Sopenharmony_ciconst uint32_t kFunct7Mask = ((1 << kFunct7Bits) - 1) << kFunct7Shift; 3171cb0ef41Sopenharmony_ciconst uint32_t kFunct2Mask = 0b11 << kFunct7Shift; 3181cb0ef41Sopenharmony_ciconst uint32_t kRTypeMask = kBaseOpcodeMask | kFunct3Mask | kFunct7Mask; 3191cb0ef41Sopenharmony_ciconst uint32_t kRATypeMask = kBaseOpcodeMask | kFunct3Mask | kFunct5Mask; 3201cb0ef41Sopenharmony_ciconst uint32_t kRFPTypeMask = kBaseOpcodeMask | kFunct7Mask; 3211cb0ef41Sopenharmony_ciconst uint32_t kR4TypeMask = kBaseOpcodeMask | kFunct3Mask | kFunct2Mask; 3221cb0ef41Sopenharmony_ciconst uint32_t kITypeMask = kBaseOpcodeMask | kFunct3Mask; 3231cb0ef41Sopenharmony_ciconst uint32_t kSTypeMask = kBaseOpcodeMask | kFunct3Mask; 3241cb0ef41Sopenharmony_ciconst uint32_t kBTypeMask = kBaseOpcodeMask | kFunct3Mask; 3251cb0ef41Sopenharmony_ciconst uint32_t kUTypeMask = kBaseOpcodeMask; 3261cb0ef41Sopenharmony_ciconst uint32_t kJTypeMask = kBaseOpcodeMask; 3271cb0ef41Sopenharmony_ciconst uint32_t kVTypeMask = kRvvFunct6Mask | kFunct3Mask | kBaseOpcodeMask; 3281cb0ef41Sopenharmony_ciconst uint32_t kRs1FieldMask = ((1 << kRs1Bits) - 1) << kRs1Shift; 3291cb0ef41Sopenharmony_ciconst uint32_t kRs2FieldMask = ((1 << kRs2Bits) - 1) << kRs2Shift; 3301cb0ef41Sopenharmony_ciconst uint32_t kRs3FieldMask = ((1 << kRs3Bits) - 1) << kRs3Shift; 3311cb0ef41Sopenharmony_ciconst uint32_t kRdFieldMask = ((1 << kRdBits) - 1) << kRdShift; 3321cb0ef41Sopenharmony_ciconst uint32_t kBImm12Mask = kFunct7Mask | kRdFieldMask; 3331cb0ef41Sopenharmony_ciconst uint32_t kImm20Mask = ((1 << kImm20Bits) - 1) << kImm20Shift; 3341cb0ef41Sopenharmony_ciconst uint32_t kImm12Mask = ((1 << kImm12Bits) - 1) << kImm12Shift; 3351cb0ef41Sopenharmony_ciconst uint32_t kImm11Mask = ((1 << kImm11Bits) - 1) << kImm11Shift; 3361cb0ef41Sopenharmony_ciconst uint32_t kImm31_12Mask = ((1 << 20) - 1) << 12; 3371cb0ef41Sopenharmony_ciconst uint32_t kImm19_0Mask = ((1 << 20) - 1); 3381cb0ef41Sopenharmony_ciconst uint32_t kRvcOpcodeMask = 3391cb0ef41Sopenharmony_ci 0b11 | (((1 << kRvcFunct3Bits) - 1) << kRvcFunct3Shift); 3401cb0ef41Sopenharmony_ciconst uint32_t kRvcFunct3Mask = 3411cb0ef41Sopenharmony_ci (((1 << kRvcFunct3Bits) - 1) << kRvcFunct3Shift); 3421cb0ef41Sopenharmony_ciconst uint32_t kRvcFunct4Mask = 3431cb0ef41Sopenharmony_ci (((1 << kRvcFunct4Bits) - 1) << kRvcFunct4Shift); 3441cb0ef41Sopenharmony_ciconst uint32_t kRvcFunct6Mask = 3451cb0ef41Sopenharmony_ci (((1 << kRvcFunct6Bits) - 1) << kRvcFunct6Shift); 3461cb0ef41Sopenharmony_ciconst uint32_t kRvcFunct2Mask = 3471cb0ef41Sopenharmony_ci (((1 << kRvcFunct2Bits) - 1) << kRvcFunct2Shift); 3481cb0ef41Sopenharmony_ciconst uint32_t kRvcFunct2BMask = 3491cb0ef41Sopenharmony_ci (((1 << kRvcFunct2Bits) - 1) << kRvcFunct2BShift); 3501cb0ef41Sopenharmony_ciconst uint32_t kCRTypeMask = kRvcOpcodeMask | kRvcFunct4Mask; 3511cb0ef41Sopenharmony_ciconst uint32_t kCSTypeMask = kRvcOpcodeMask | kRvcFunct6Mask; 3521cb0ef41Sopenharmony_ciconst uint32_t kCATypeMask = kRvcOpcodeMask | kRvcFunct6Mask | kRvcFunct2Mask; 3531cb0ef41Sopenharmony_ciconst uint32_t kRvcBImm8Mask = (((1 << 5) - 1) << 2) | (((1 << 3) - 1) << 10); 3541cb0ef41Sopenharmony_ci 3551cb0ef41Sopenharmony_ci// RISCV CSR related bit mask and shift 3561cb0ef41Sopenharmony_ciconst int kFcsrFlagsBits = 5; 3571cb0ef41Sopenharmony_ciconst uint32_t kFcsrFlagsMask = (1 << kFcsrFlagsBits) - 1; 3581cb0ef41Sopenharmony_ciconst int kFcsrFrmBits = 3; 3591cb0ef41Sopenharmony_ciconst int kFcsrFrmShift = kFcsrFlagsBits; 3601cb0ef41Sopenharmony_ciconst uint32_t kFcsrFrmMask = ((1 << kFcsrFrmBits) - 1) << kFcsrFrmShift; 3611cb0ef41Sopenharmony_ciconst int kFcsrBits = kFcsrFlagsBits + kFcsrFrmBits; 3621cb0ef41Sopenharmony_ciconst uint32_t kFcsrMask = kFcsrFlagsMask | kFcsrFrmMask; 3631cb0ef41Sopenharmony_ci 3641cb0ef41Sopenharmony_ciconst int kNopByte = 0x00000013; 3651cb0ef41Sopenharmony_ci// Original MIPS constants 3661cb0ef41Sopenharmony_ci// TODO(RISCV): to be cleaned up 3671cb0ef41Sopenharmony_ciconst int kImm16Shift = 0; 3681cb0ef41Sopenharmony_ciconst int kImm16Bits = 16; 3691cb0ef41Sopenharmony_ciconst uint32_t kImm16Mask = ((1 << kImm16Bits) - 1) << kImm16Shift; 3701cb0ef41Sopenharmony_ci// end of TODO(RISCV): to be cleaned up 3711cb0ef41Sopenharmony_ci 3721cb0ef41Sopenharmony_ci// ----- RISCV Base Opcodes 3731cb0ef41Sopenharmony_ci 3741cb0ef41Sopenharmony_cienum BaseOpcode : uint32_t {}; 3751cb0ef41Sopenharmony_ci 3761cb0ef41Sopenharmony_ci// ----- RISC-V Opcodes and Function Fields. 3771cb0ef41Sopenharmony_cienum Opcode : uint32_t { 3781cb0ef41Sopenharmony_ci LOAD = 0b0000011, // I form: LB LH LW LBU LHU 3791cb0ef41Sopenharmony_ci LOAD_FP = 0b0000111, // I form: FLW FLD FLQ 3801cb0ef41Sopenharmony_ci MISC_MEM = 0b0001111, // I special form: FENCE FENCE.I 3811cb0ef41Sopenharmony_ci OP_IMM = 0b0010011, // I form: ADDI SLTI SLTIU XORI ORI ANDI SLLI SRLI SARI 3821cb0ef41Sopenharmony_ci // Note: SLLI/SRLI/SRAI I form first, then func3 001/101 => R type 3831cb0ef41Sopenharmony_ci AUIPC = 0b0010111, // U form: AUIPC 3841cb0ef41Sopenharmony_ci OP_IMM_32 = 0b0011011, // I form: ADDIW SLLIW SRLIW SRAIW 3851cb0ef41Sopenharmony_ci // Note: SRLIW SRAIW I form first, then func3 101 special shift encoding 3861cb0ef41Sopenharmony_ci STORE = 0b0100011, // S form: SB SH SW SD 3871cb0ef41Sopenharmony_ci STORE_FP = 0b0100111, // S form: FSW FSD FSQ 3881cb0ef41Sopenharmony_ci AMO = 0b0101111, // R form: All A instructions 3891cb0ef41Sopenharmony_ci OP = 0b0110011, // R: ADD SUB SLL SLT SLTU XOR SRL SRA OR AND and 32M set 3901cb0ef41Sopenharmony_ci LUI = 0b0110111, // U form: LUI 3911cb0ef41Sopenharmony_ci OP_32 = 0b0111011, // R: ADDW SUBW SLLW SRLW SRAW MULW DIVW DIVUW REMW REMUW 3921cb0ef41Sopenharmony_ci MADD = 0b1000011, // R4 type: FMADD.S FMADD.D FMADD.Q 3931cb0ef41Sopenharmony_ci MSUB = 0b1000111, // R4 type: FMSUB.S FMSUB.D FMSUB.Q 3941cb0ef41Sopenharmony_ci NMSUB = 0b1001011, // R4 type: FNMSUB.S FNMSUB.D FNMSUB.Q 3951cb0ef41Sopenharmony_ci NMADD = 0b1001111, // R4 type: FNMADD.S FNMADD.D FNMADD.Q 3961cb0ef41Sopenharmony_ci OP_FP = 0b1010011, // R type: Q ext 3971cb0ef41Sopenharmony_ci BRANCH = 0b1100011, // B form: BEQ BNE, BLT, BGE, BLTU BGEU 3981cb0ef41Sopenharmony_ci JALR = 0b1100111, // I form: JALR 3991cb0ef41Sopenharmony_ci JAL = 0b1101111, // J form: JAL 4001cb0ef41Sopenharmony_ci SYSTEM = 0b1110011, // I form: ECALL EBREAK Zicsr ext 4011cb0ef41Sopenharmony_ci // C extension 4021cb0ef41Sopenharmony_ci C0 = 0b00, 4031cb0ef41Sopenharmony_ci C1 = 0b01, 4041cb0ef41Sopenharmony_ci C2 = 0b10, 4051cb0ef41Sopenharmony_ci FUNCT2_0 = 0b00, 4061cb0ef41Sopenharmony_ci FUNCT2_1 = 0b01, 4071cb0ef41Sopenharmony_ci FUNCT2_2 = 0b10, 4081cb0ef41Sopenharmony_ci FUNCT2_3 = 0b11, 4091cb0ef41Sopenharmony_ci 4101cb0ef41Sopenharmony_ci // Note use RO (RiscV Opcode) prefix 4111cb0ef41Sopenharmony_ci // RV32I Base Instruction Set 4121cb0ef41Sopenharmony_ci RO_LUI = LUI, 4131cb0ef41Sopenharmony_ci RO_AUIPC = AUIPC, 4141cb0ef41Sopenharmony_ci RO_JAL = JAL, 4151cb0ef41Sopenharmony_ci RO_JALR = JALR | (0b000 << kFunct3Shift), 4161cb0ef41Sopenharmony_ci RO_BEQ = BRANCH | (0b000 << kFunct3Shift), 4171cb0ef41Sopenharmony_ci RO_BNE = BRANCH | (0b001 << kFunct3Shift), 4181cb0ef41Sopenharmony_ci RO_BLT = BRANCH | (0b100 << kFunct3Shift), 4191cb0ef41Sopenharmony_ci RO_BGE = BRANCH | (0b101 << kFunct3Shift), 4201cb0ef41Sopenharmony_ci RO_BLTU = BRANCH | (0b110 << kFunct3Shift), 4211cb0ef41Sopenharmony_ci RO_BGEU = BRANCH | (0b111 << kFunct3Shift), 4221cb0ef41Sopenharmony_ci RO_LB = LOAD | (0b000 << kFunct3Shift), 4231cb0ef41Sopenharmony_ci RO_LH = LOAD | (0b001 << kFunct3Shift), 4241cb0ef41Sopenharmony_ci RO_LW = LOAD | (0b010 << kFunct3Shift), 4251cb0ef41Sopenharmony_ci RO_LBU = LOAD | (0b100 << kFunct3Shift), 4261cb0ef41Sopenharmony_ci RO_LHU = LOAD | (0b101 << kFunct3Shift), 4271cb0ef41Sopenharmony_ci RO_SB = STORE | (0b000 << kFunct3Shift), 4281cb0ef41Sopenharmony_ci RO_SH = STORE | (0b001 << kFunct3Shift), 4291cb0ef41Sopenharmony_ci RO_SW = STORE | (0b010 << kFunct3Shift), 4301cb0ef41Sopenharmony_ci RO_ADDI = OP_IMM | (0b000 << kFunct3Shift), 4311cb0ef41Sopenharmony_ci RO_SLTI = OP_IMM | (0b010 << kFunct3Shift), 4321cb0ef41Sopenharmony_ci RO_SLTIU = OP_IMM | (0b011 << kFunct3Shift), 4331cb0ef41Sopenharmony_ci RO_XORI = OP_IMM | (0b100 << kFunct3Shift), 4341cb0ef41Sopenharmony_ci RO_ORI = OP_IMM | (0b110 << kFunct3Shift), 4351cb0ef41Sopenharmony_ci RO_ANDI = OP_IMM | (0b111 << kFunct3Shift), 4361cb0ef41Sopenharmony_ci RO_SLLI = OP_IMM | (0b001 << kFunct3Shift), 4371cb0ef41Sopenharmony_ci RO_SRLI = OP_IMM | (0b101 << kFunct3Shift), 4381cb0ef41Sopenharmony_ci // RO_SRAI = OP_IMM | (0b101 << kFunct3Shift), // Same as SRLI, use func7 4391cb0ef41Sopenharmony_ci RO_ADD = OP | (0b000 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4401cb0ef41Sopenharmony_ci RO_SUB = OP | (0b000 << kFunct3Shift) | (0b0100000 << kFunct7Shift), 4411cb0ef41Sopenharmony_ci RO_SLL = OP | (0b001 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4421cb0ef41Sopenharmony_ci RO_SLT = OP | (0b010 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4431cb0ef41Sopenharmony_ci RO_SLTU = OP | (0b011 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4441cb0ef41Sopenharmony_ci RO_XOR = OP | (0b100 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4451cb0ef41Sopenharmony_ci RO_SRL = OP | (0b101 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4461cb0ef41Sopenharmony_ci RO_SRA = OP | (0b101 << kFunct3Shift) | (0b0100000 << kFunct7Shift), 4471cb0ef41Sopenharmony_ci RO_OR = OP | (0b110 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4481cb0ef41Sopenharmony_ci RO_AND = OP | (0b111 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4491cb0ef41Sopenharmony_ci RO_FENCE = MISC_MEM | (0b000 << kFunct3Shift), 4501cb0ef41Sopenharmony_ci RO_ECALL = SYSTEM | (0b000 << kFunct3Shift), 4511cb0ef41Sopenharmony_ci // RO_EBREAK = SYSTEM | (0b000 << kFunct3Shift), // Same as ECALL, use imm12 4521cb0ef41Sopenharmony_ci 4531cb0ef41Sopenharmony_ci // RV64I Base Instruction Set (in addition to RV32I) 4541cb0ef41Sopenharmony_ci RO_LWU = LOAD | (0b110 << kFunct3Shift), 4551cb0ef41Sopenharmony_ci RO_LD = LOAD | (0b011 << kFunct3Shift), 4561cb0ef41Sopenharmony_ci RO_SD = STORE | (0b011 << kFunct3Shift), 4571cb0ef41Sopenharmony_ci RO_ADDIW = OP_IMM_32 | (0b000 << kFunct3Shift), 4581cb0ef41Sopenharmony_ci RO_SLLIW = OP_IMM_32 | (0b001 << kFunct3Shift), 4591cb0ef41Sopenharmony_ci RO_SRLIW = OP_IMM_32 | (0b101 << kFunct3Shift), 4601cb0ef41Sopenharmony_ci // RO_SRAIW = OP_IMM_32 | (0b101 << kFunct3Shift), // Same as SRLIW, use func7 4611cb0ef41Sopenharmony_ci RO_ADDW = OP_32 | (0b000 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4621cb0ef41Sopenharmony_ci RO_SUBW = OP_32 | (0b000 << kFunct3Shift) | (0b0100000 << kFunct7Shift), 4631cb0ef41Sopenharmony_ci RO_SLLW = OP_32 | (0b001 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4641cb0ef41Sopenharmony_ci RO_SRLW = OP_32 | (0b101 << kFunct3Shift) | (0b0000000 << kFunct7Shift), 4651cb0ef41Sopenharmony_ci RO_SRAW = OP_32 | (0b101 << kFunct3Shift) | (0b0100000 << kFunct7Shift), 4661cb0ef41Sopenharmony_ci 4671cb0ef41Sopenharmony_ci // RV32/RV64 Zifencei Standard Extension 4681cb0ef41Sopenharmony_ci RO_FENCE_I = MISC_MEM | (0b001 << kFunct3Shift), 4691cb0ef41Sopenharmony_ci 4701cb0ef41Sopenharmony_ci // RV32/RV64 Zicsr Standard Extension 4711cb0ef41Sopenharmony_ci RO_CSRRW = SYSTEM | (0b001 << kFunct3Shift), 4721cb0ef41Sopenharmony_ci RO_CSRRS = SYSTEM | (0b010 << kFunct3Shift), 4731cb0ef41Sopenharmony_ci RO_CSRRC = SYSTEM | (0b011 << kFunct3Shift), 4741cb0ef41Sopenharmony_ci RO_CSRRWI = SYSTEM | (0b101 << kFunct3Shift), 4751cb0ef41Sopenharmony_ci RO_CSRRSI = SYSTEM | (0b110 << kFunct3Shift), 4761cb0ef41Sopenharmony_ci RO_CSRRCI = SYSTEM | (0b111 << kFunct3Shift), 4771cb0ef41Sopenharmony_ci 4781cb0ef41Sopenharmony_ci // RV32M Standard Extension 4791cb0ef41Sopenharmony_ci RO_MUL = OP | (0b000 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4801cb0ef41Sopenharmony_ci RO_MULH = OP | (0b001 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4811cb0ef41Sopenharmony_ci RO_MULHSU = OP | (0b010 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4821cb0ef41Sopenharmony_ci RO_MULHU = OP | (0b011 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4831cb0ef41Sopenharmony_ci RO_DIV = OP | (0b100 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4841cb0ef41Sopenharmony_ci RO_DIVU = OP | (0b101 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4851cb0ef41Sopenharmony_ci RO_REM = OP | (0b110 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4861cb0ef41Sopenharmony_ci RO_REMU = OP | (0b111 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_ci // RV64M Standard Extension (in addition to RV32M) 4891cb0ef41Sopenharmony_ci RO_MULW = OP_32 | (0b000 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4901cb0ef41Sopenharmony_ci RO_DIVW = OP_32 | (0b100 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4911cb0ef41Sopenharmony_ci RO_DIVUW = OP_32 | (0b101 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4921cb0ef41Sopenharmony_ci RO_REMW = OP_32 | (0b110 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4931cb0ef41Sopenharmony_ci RO_REMUW = OP_32 | (0b111 << kFunct3Shift) | (0b0000001 << kFunct7Shift), 4941cb0ef41Sopenharmony_ci 4951cb0ef41Sopenharmony_ci // RV32A Standard Extension 4961cb0ef41Sopenharmony_ci RO_LR_W = AMO | (0b010 << kFunct3Shift) | (0b00010 << kFunct5Shift), 4971cb0ef41Sopenharmony_ci RO_SC_W = AMO | (0b010 << kFunct3Shift) | (0b00011 << kFunct5Shift), 4981cb0ef41Sopenharmony_ci RO_AMOSWAP_W = AMO | (0b010 << kFunct3Shift) | (0b00001 << kFunct5Shift), 4991cb0ef41Sopenharmony_ci RO_AMOADD_W = AMO | (0b010 << kFunct3Shift) | (0b00000 << kFunct5Shift), 5001cb0ef41Sopenharmony_ci RO_AMOXOR_W = AMO | (0b010 << kFunct3Shift) | (0b00100 << kFunct5Shift), 5011cb0ef41Sopenharmony_ci RO_AMOAND_W = AMO | (0b010 << kFunct3Shift) | (0b01100 << kFunct5Shift), 5021cb0ef41Sopenharmony_ci RO_AMOOR_W = AMO | (0b010 << kFunct3Shift) | (0b01000 << kFunct5Shift), 5031cb0ef41Sopenharmony_ci RO_AMOMIN_W = AMO | (0b010 << kFunct3Shift) | (0b10000 << kFunct5Shift), 5041cb0ef41Sopenharmony_ci RO_AMOMAX_W = AMO | (0b010 << kFunct3Shift) | (0b10100 << kFunct5Shift), 5051cb0ef41Sopenharmony_ci RO_AMOMINU_W = AMO | (0b010 << kFunct3Shift) | (0b11000 << kFunct5Shift), 5061cb0ef41Sopenharmony_ci RO_AMOMAXU_W = AMO | (0b010 << kFunct3Shift) | (0b11100 << kFunct5Shift), 5071cb0ef41Sopenharmony_ci 5081cb0ef41Sopenharmony_ci // RV64A Standard Extension (in addition to RV32A) 5091cb0ef41Sopenharmony_ci RO_LR_D = AMO | (0b011 << kFunct3Shift) | (0b00010 << kFunct5Shift), 5101cb0ef41Sopenharmony_ci RO_SC_D = AMO | (0b011 << kFunct3Shift) | (0b00011 << kFunct5Shift), 5111cb0ef41Sopenharmony_ci RO_AMOSWAP_D = AMO | (0b011 << kFunct3Shift) | (0b00001 << kFunct5Shift), 5121cb0ef41Sopenharmony_ci RO_AMOADD_D = AMO | (0b011 << kFunct3Shift) | (0b00000 << kFunct5Shift), 5131cb0ef41Sopenharmony_ci RO_AMOXOR_D = AMO | (0b011 << kFunct3Shift) | (0b00100 << kFunct5Shift), 5141cb0ef41Sopenharmony_ci RO_AMOAND_D = AMO | (0b011 << kFunct3Shift) | (0b01100 << kFunct5Shift), 5151cb0ef41Sopenharmony_ci RO_AMOOR_D = AMO | (0b011 << kFunct3Shift) | (0b01000 << kFunct5Shift), 5161cb0ef41Sopenharmony_ci RO_AMOMIN_D = AMO | (0b011 << kFunct3Shift) | (0b10000 << kFunct5Shift), 5171cb0ef41Sopenharmony_ci RO_AMOMAX_D = AMO | (0b011 << kFunct3Shift) | (0b10100 << kFunct5Shift), 5181cb0ef41Sopenharmony_ci RO_AMOMINU_D = AMO | (0b011 << kFunct3Shift) | (0b11000 << kFunct5Shift), 5191cb0ef41Sopenharmony_ci RO_AMOMAXU_D = AMO | (0b011 << kFunct3Shift) | (0b11100 << kFunct5Shift), 5201cb0ef41Sopenharmony_ci 5211cb0ef41Sopenharmony_ci // RV32F Standard Extension 5221cb0ef41Sopenharmony_ci RO_FLW = LOAD_FP | (0b010 << kFunct3Shift), 5231cb0ef41Sopenharmony_ci RO_FSW = STORE_FP | (0b010 << kFunct3Shift), 5241cb0ef41Sopenharmony_ci RO_FMADD_S = MADD | (0b00 << kFunct2Shift), 5251cb0ef41Sopenharmony_ci RO_FMSUB_S = MSUB | (0b00 << kFunct2Shift), 5261cb0ef41Sopenharmony_ci RO_FNMSUB_S = NMSUB | (0b00 << kFunct2Shift), 5271cb0ef41Sopenharmony_ci RO_FNMADD_S = NMADD | (0b00 << kFunct2Shift), 5281cb0ef41Sopenharmony_ci RO_FADD_S = OP_FP | (0b0000000 << kFunct7Shift), 5291cb0ef41Sopenharmony_ci RO_FSUB_S = OP_FP | (0b0000100 << kFunct7Shift), 5301cb0ef41Sopenharmony_ci RO_FMUL_S = OP_FP | (0b0001000 << kFunct7Shift), 5311cb0ef41Sopenharmony_ci RO_FDIV_S = OP_FP | (0b0001100 << kFunct7Shift), 5321cb0ef41Sopenharmony_ci RO_FSQRT_S = OP_FP | (0b0101100 << kFunct7Shift) | (0b00000 << kRs2Shift), 5331cb0ef41Sopenharmony_ci RO_FSGNJ_S = OP_FP | (0b000 << kFunct3Shift) | (0b0010000 << kFunct7Shift), 5341cb0ef41Sopenharmony_ci RO_FSGNJN_S = OP_FP | (0b001 << kFunct3Shift) | (0b0010000 << kFunct7Shift), 5351cb0ef41Sopenharmony_ci RO_FSQNJX_S = OP_FP | (0b010 << kFunct3Shift) | (0b0010000 << kFunct7Shift), 5361cb0ef41Sopenharmony_ci RO_FMIN_S = OP_FP | (0b000 << kFunct3Shift) | (0b0010100 << kFunct7Shift), 5371cb0ef41Sopenharmony_ci RO_FMAX_S = OP_FP | (0b001 << kFunct3Shift) | (0b0010100 << kFunct7Shift), 5381cb0ef41Sopenharmony_ci RO_FCVT_W_S = OP_FP | (0b1100000 << kFunct7Shift) | (0b00000 << kRs2Shift), 5391cb0ef41Sopenharmony_ci RO_FCVT_WU_S = OP_FP | (0b1100000 << kFunct7Shift) | (0b00001 << kRs2Shift), 5401cb0ef41Sopenharmony_ci RO_FMV = OP_FP | (0b1110000 << kFunct7Shift) | (0b000 << kFunct3Shift) | 5411cb0ef41Sopenharmony_ci (0b00000 << kRs2Shift), 5421cb0ef41Sopenharmony_ci RO_FEQ_S = OP_FP | (0b010 << kFunct3Shift) | (0b1010000 << kFunct7Shift), 5431cb0ef41Sopenharmony_ci RO_FLT_S = OP_FP | (0b001 << kFunct3Shift) | (0b1010000 << kFunct7Shift), 5441cb0ef41Sopenharmony_ci RO_FLE_S = OP_FP | (0b000 << kFunct3Shift) | (0b1010000 << kFunct7Shift), 5451cb0ef41Sopenharmony_ci RO_FCLASS_S = OP_FP | (0b001 << kFunct3Shift) | (0b1110000 << kFunct7Shift), 5461cb0ef41Sopenharmony_ci RO_FCVT_S_W = OP_FP | (0b1101000 << kFunct7Shift) | (0b00000 << kRs2Shift), 5471cb0ef41Sopenharmony_ci RO_FCVT_S_WU = OP_FP | (0b1101000 << kFunct7Shift) | (0b00001 << kRs2Shift), 5481cb0ef41Sopenharmony_ci RO_FMV_W_X = OP_FP | (0b000 << kFunct3Shift) | (0b1111000 << kFunct7Shift), 5491cb0ef41Sopenharmony_ci 5501cb0ef41Sopenharmony_ci // RV64F Standard Extension (in addition to RV32F) 5511cb0ef41Sopenharmony_ci RO_FCVT_L_S = OP_FP | (0b1100000 << kFunct7Shift) | (0b00010 << kRs2Shift), 5521cb0ef41Sopenharmony_ci RO_FCVT_LU_S = OP_FP | (0b1100000 << kFunct7Shift) | (0b00011 << kRs2Shift), 5531cb0ef41Sopenharmony_ci RO_FCVT_S_L = OP_FP | (0b1101000 << kFunct7Shift) | (0b00010 << kRs2Shift), 5541cb0ef41Sopenharmony_ci RO_FCVT_S_LU = OP_FP | (0b1101000 << kFunct7Shift) | (0b00011 << kRs2Shift), 5551cb0ef41Sopenharmony_ci 5561cb0ef41Sopenharmony_ci // RV32D Standard Extension 5571cb0ef41Sopenharmony_ci RO_FLD = LOAD_FP | (0b011 << kFunct3Shift), 5581cb0ef41Sopenharmony_ci RO_FSD = STORE_FP | (0b011 << kFunct3Shift), 5591cb0ef41Sopenharmony_ci RO_FMADD_D = MADD | (0b01 << kFunct2Shift), 5601cb0ef41Sopenharmony_ci RO_FMSUB_D = MSUB | (0b01 << kFunct2Shift), 5611cb0ef41Sopenharmony_ci RO_FNMSUB_D = NMSUB | (0b01 << kFunct2Shift), 5621cb0ef41Sopenharmony_ci RO_FNMADD_D = NMADD | (0b01 << kFunct2Shift), 5631cb0ef41Sopenharmony_ci RO_FADD_D = OP_FP | (0b0000001 << kFunct7Shift), 5641cb0ef41Sopenharmony_ci RO_FSUB_D = OP_FP | (0b0000101 << kFunct7Shift), 5651cb0ef41Sopenharmony_ci RO_FMUL_D = OP_FP | (0b0001001 << kFunct7Shift), 5661cb0ef41Sopenharmony_ci RO_FDIV_D = OP_FP | (0b0001101 << kFunct7Shift), 5671cb0ef41Sopenharmony_ci RO_FSQRT_D = OP_FP | (0b0101101 << kFunct7Shift) | (0b00000 << kRs2Shift), 5681cb0ef41Sopenharmony_ci RO_FSGNJ_D = OP_FP | (0b000 << kFunct3Shift) | (0b0010001 << kFunct7Shift), 5691cb0ef41Sopenharmony_ci RO_FSGNJN_D = OP_FP | (0b001 << kFunct3Shift) | (0b0010001 << kFunct7Shift), 5701cb0ef41Sopenharmony_ci RO_FSQNJX_D = OP_FP | (0b010 << kFunct3Shift) | (0b0010001 << kFunct7Shift), 5711cb0ef41Sopenharmony_ci RO_FMIN_D = OP_FP | (0b000 << kFunct3Shift) | (0b0010101 << kFunct7Shift), 5721cb0ef41Sopenharmony_ci RO_FMAX_D = OP_FP | (0b001 << kFunct3Shift) | (0b0010101 << kFunct7Shift), 5731cb0ef41Sopenharmony_ci RO_FCVT_S_D = OP_FP | (0b0100000 << kFunct7Shift) | (0b00001 << kRs2Shift), 5741cb0ef41Sopenharmony_ci RO_FCVT_D_S = OP_FP | (0b0100001 << kFunct7Shift) | (0b00000 << kRs2Shift), 5751cb0ef41Sopenharmony_ci RO_FEQ_D = OP_FP | (0b010 << kFunct3Shift) | (0b1010001 << kFunct7Shift), 5761cb0ef41Sopenharmony_ci RO_FLT_D = OP_FP | (0b001 << kFunct3Shift) | (0b1010001 << kFunct7Shift), 5771cb0ef41Sopenharmony_ci RO_FLE_D = OP_FP | (0b000 << kFunct3Shift) | (0b1010001 << kFunct7Shift), 5781cb0ef41Sopenharmony_ci RO_FCLASS_D = OP_FP | (0b001 << kFunct3Shift) | (0b1110001 << kFunct7Shift) | 5791cb0ef41Sopenharmony_ci (0b00000 << kRs2Shift), 5801cb0ef41Sopenharmony_ci RO_FCVT_W_D = OP_FP | (0b1100001 << kFunct7Shift) | (0b00000 << kRs2Shift), 5811cb0ef41Sopenharmony_ci RO_FCVT_WU_D = OP_FP | (0b1100001 << kFunct7Shift) | (0b00001 << kRs2Shift), 5821cb0ef41Sopenharmony_ci RO_FCVT_D_W = OP_FP | (0b1101001 << kFunct7Shift) | (0b00000 << kRs2Shift), 5831cb0ef41Sopenharmony_ci RO_FCVT_D_WU = OP_FP | (0b1101001 << kFunct7Shift) | (0b00001 << kRs2Shift), 5841cb0ef41Sopenharmony_ci 5851cb0ef41Sopenharmony_ci // RV64D Standard Extension (in addition to RV32D) 5861cb0ef41Sopenharmony_ci RO_FCVT_L_D = OP_FP | (0b1100001 << kFunct7Shift) | (0b00010 << kRs2Shift), 5871cb0ef41Sopenharmony_ci RO_FCVT_LU_D = OP_FP | (0b1100001 << kFunct7Shift) | (0b00011 << kRs2Shift), 5881cb0ef41Sopenharmony_ci RO_FMV_X_D = OP_FP | (0b000 << kFunct3Shift) | (0b1110001 << kFunct7Shift) | 5891cb0ef41Sopenharmony_ci (0b00000 << kRs2Shift), 5901cb0ef41Sopenharmony_ci RO_FCVT_D_L = OP_FP | (0b1101001 << kFunct7Shift) | (0b00010 << kRs2Shift), 5911cb0ef41Sopenharmony_ci RO_FCVT_D_LU = OP_FP | (0b1101001 << kFunct7Shift) | (0b00011 << kRs2Shift), 5921cb0ef41Sopenharmony_ci RO_FMV_D_X = OP_FP | (0b000 << kFunct3Shift) | (0b1111001 << kFunct7Shift) | 5931cb0ef41Sopenharmony_ci (0b00000 << kRs2Shift), 5941cb0ef41Sopenharmony_ci 5951cb0ef41Sopenharmony_ci // RV64C Standard Extension 5961cb0ef41Sopenharmony_ci RO_C_ADDI4SPN = C0 | (0b000 << kRvcFunct3Shift), 5971cb0ef41Sopenharmony_ci RO_C_FLD = C0 | (0b001 << kRvcFunct3Shift), 5981cb0ef41Sopenharmony_ci RO_C_LW = C0 | (0b010 << kRvcFunct3Shift), 5991cb0ef41Sopenharmony_ci RO_C_LD = C0 | (0b011 << kRvcFunct3Shift), 6001cb0ef41Sopenharmony_ci RO_C_FSD = C0 | (0b101 << kRvcFunct3Shift), 6011cb0ef41Sopenharmony_ci RO_C_SW = C0 | (0b110 << kRvcFunct3Shift), 6021cb0ef41Sopenharmony_ci RO_C_SD = C0 | (0b111 << kRvcFunct3Shift), 6031cb0ef41Sopenharmony_ci RO_C_NOP_ADDI = C1 | (0b000 << kRvcFunct3Shift), 6041cb0ef41Sopenharmony_ci RO_C_ADDIW = C1 | (0b001 << kRvcFunct3Shift), 6051cb0ef41Sopenharmony_ci RO_C_LI = C1 | (0b010 << kRvcFunct3Shift), 6061cb0ef41Sopenharmony_ci RO_C_SUB = C1 | (0b100011 << kRvcFunct6Shift) | (FUNCT2_0 << kRvcFunct2Shift), 6071cb0ef41Sopenharmony_ci RO_C_XOR = C1 | (0b100011 << kRvcFunct6Shift) | (FUNCT2_1 << kRvcFunct2Shift), 6081cb0ef41Sopenharmony_ci RO_C_OR = C1 | (0b100011 << kRvcFunct6Shift) | (FUNCT2_2 << kRvcFunct2Shift), 6091cb0ef41Sopenharmony_ci RO_C_AND = C1 | (0b100011 << kRvcFunct6Shift) | (FUNCT2_3 << kRvcFunct2Shift), 6101cb0ef41Sopenharmony_ci RO_C_SUBW = 6111cb0ef41Sopenharmony_ci C1 | (0b100111 << kRvcFunct6Shift) | (FUNCT2_0 << kRvcFunct2Shift), 6121cb0ef41Sopenharmony_ci RO_C_ADDW = 6131cb0ef41Sopenharmony_ci C1 | (0b100111 << kRvcFunct6Shift) | (FUNCT2_1 << kRvcFunct2Shift), 6141cb0ef41Sopenharmony_ci RO_C_LUI_ADD = C1 | (0b011 << kRvcFunct3Shift), 6151cb0ef41Sopenharmony_ci RO_C_MISC_ALU = C1 | (0b100 << kRvcFunct3Shift), 6161cb0ef41Sopenharmony_ci RO_C_J = C1 | (0b101 << kRvcFunct3Shift), 6171cb0ef41Sopenharmony_ci RO_C_BEQZ = C1 | (0b110 << kRvcFunct3Shift), 6181cb0ef41Sopenharmony_ci RO_C_BNEZ = C1 | (0b111 << kRvcFunct3Shift), 6191cb0ef41Sopenharmony_ci RO_C_SLLI = C2 | (0b000 << kRvcFunct3Shift), 6201cb0ef41Sopenharmony_ci RO_C_FLDSP = C2 | (0b001 << kRvcFunct3Shift), 6211cb0ef41Sopenharmony_ci RO_C_LWSP = C2 | (0b010 << kRvcFunct3Shift), 6221cb0ef41Sopenharmony_ci RO_C_LDSP = C2 | (0b011 << kRvcFunct3Shift), 6231cb0ef41Sopenharmony_ci RO_C_JR_MV_ADD = C2 | (0b100 << kRvcFunct3Shift), 6241cb0ef41Sopenharmony_ci RO_C_JR = C2 | (0b1000 << kRvcFunct4Shift), 6251cb0ef41Sopenharmony_ci RO_C_MV = C2 | (0b1000 << kRvcFunct4Shift), 6261cb0ef41Sopenharmony_ci RO_C_EBREAK = C2 | (0b1001 << kRvcFunct4Shift), 6271cb0ef41Sopenharmony_ci RO_C_JALR = C2 | (0b1001 << kRvcFunct4Shift), 6281cb0ef41Sopenharmony_ci RO_C_ADD = C2 | (0b1001 << kRvcFunct4Shift), 6291cb0ef41Sopenharmony_ci RO_C_FSDSP = C2 | (0b101 << kRvcFunct3Shift), 6301cb0ef41Sopenharmony_ci RO_C_SWSP = C2 | (0b110 << kRvcFunct3Shift), 6311cb0ef41Sopenharmony_ci RO_C_SDSP = C2 | (0b111 << kRvcFunct3Shift), 6321cb0ef41Sopenharmony_ci 6331cb0ef41Sopenharmony_ci // RVV Extension 6341cb0ef41Sopenharmony_ci OP_V = 0b1010111, 6351cb0ef41Sopenharmony_ci OP_IVV = OP_V | (0b000 << kFunct3Shift), 6361cb0ef41Sopenharmony_ci OP_FVV = OP_V | (0b001 << kFunct3Shift), 6371cb0ef41Sopenharmony_ci OP_MVV = OP_V | (0b010 << kFunct3Shift), 6381cb0ef41Sopenharmony_ci OP_IVI = OP_V | (0b011 << kFunct3Shift), 6391cb0ef41Sopenharmony_ci OP_IVX = OP_V | (0b100 << kFunct3Shift), 6401cb0ef41Sopenharmony_ci OP_FVF = OP_V | (0b101 << kFunct3Shift), 6411cb0ef41Sopenharmony_ci OP_MVX = OP_V | (0b110 << kFunct3Shift), 6421cb0ef41Sopenharmony_ci 6431cb0ef41Sopenharmony_ci RO_V_VSETVLI = OP_V | (0b111 << kFunct3Shift) | 0b0 << 31, 6441cb0ef41Sopenharmony_ci RO_V_VSETIVLI = OP_V | (0b111 << kFunct3Shift) | 0b11 << 30, 6451cb0ef41Sopenharmony_ci RO_V_VSETVL = OP_V | (0b111 << kFunct3Shift) | 0b1 << 31, 6461cb0ef41Sopenharmony_ci 6471cb0ef41Sopenharmony_ci // RVV LOAD/STORE 6481cb0ef41Sopenharmony_ci RO_V_VL = LOAD_FP | (0b00 << kRvvMopShift) | (0b000 << kRvvNfShift), 6491cb0ef41Sopenharmony_ci RO_V_VLS = LOAD_FP | (0b10 << kRvvMopShift) | (0b000 << kRvvNfShift), 6501cb0ef41Sopenharmony_ci RO_V_VLX = LOAD_FP | (0b11 << kRvvMopShift) | (0b000 << kRvvNfShift), 6511cb0ef41Sopenharmony_ci 6521cb0ef41Sopenharmony_ci RO_V_VS = STORE_FP | (0b00 << kRvvMopShift) | (0b000 << kRvvNfShift), 6531cb0ef41Sopenharmony_ci RO_V_VSS = STORE_FP | (0b10 << kRvvMopShift) | (0b000 << kRvvNfShift), 6541cb0ef41Sopenharmony_ci RO_V_VSX = STORE_FP | (0b11 << kRvvMopShift) | (0b000 << kRvvNfShift), 6551cb0ef41Sopenharmony_ci RO_V_VSU = STORE_FP | (0b01 << kRvvMopShift) | (0b000 << kRvvNfShift), 6561cb0ef41Sopenharmony_ci // THE kFunct6Shift is mop 6571cb0ef41Sopenharmony_ci RO_V_VLSEG2 = LOAD_FP | (0b00 << kRvvMopShift) | (0b001 << kRvvNfShift), 6581cb0ef41Sopenharmony_ci RO_V_VLSEG3 = LOAD_FP | (0b00 << kRvvMopShift) | (0b010 << kRvvNfShift), 6591cb0ef41Sopenharmony_ci RO_V_VLSEG4 = LOAD_FP | (0b00 << kRvvMopShift) | (0b011 << kRvvNfShift), 6601cb0ef41Sopenharmony_ci RO_V_VLSEG5 = LOAD_FP | (0b00 << kRvvMopShift) | (0b100 << kRvvNfShift), 6611cb0ef41Sopenharmony_ci RO_V_VLSEG6 = LOAD_FP | (0b00 << kRvvMopShift) | (0b101 << kRvvNfShift), 6621cb0ef41Sopenharmony_ci RO_V_VLSEG7 = LOAD_FP | (0b00 << kRvvMopShift) | (0b110 << kRvvNfShift), 6631cb0ef41Sopenharmony_ci RO_V_VLSEG8 = LOAD_FP | (0b00 << kRvvMopShift) | (0b111 << kRvvNfShift), 6641cb0ef41Sopenharmony_ci 6651cb0ef41Sopenharmony_ci RO_V_VSSEG2 = STORE_FP | (0b00 << kRvvMopShift) | (0b001 << kRvvNfShift), 6661cb0ef41Sopenharmony_ci RO_V_VSSEG3 = STORE_FP | (0b00 << kRvvMopShift) | (0b010 << kRvvNfShift), 6671cb0ef41Sopenharmony_ci RO_V_VSSEG4 = STORE_FP | (0b00 << kRvvMopShift) | (0b011 << kRvvNfShift), 6681cb0ef41Sopenharmony_ci RO_V_VSSEG5 = STORE_FP | (0b00 << kRvvMopShift) | (0b100 << kRvvNfShift), 6691cb0ef41Sopenharmony_ci RO_V_VSSEG6 = STORE_FP | (0b00 << kRvvMopShift) | (0b101 << kRvvNfShift), 6701cb0ef41Sopenharmony_ci RO_V_VSSEG7 = STORE_FP | (0b00 << kRvvMopShift) | (0b110 << kRvvNfShift), 6711cb0ef41Sopenharmony_ci RO_V_VSSEG8 = STORE_FP | (0b00 << kRvvMopShift) | (0b111 << kRvvNfShift), 6721cb0ef41Sopenharmony_ci 6731cb0ef41Sopenharmony_ci RO_V_VLSSEG2 = LOAD_FP | (0b10 << kRvvMopShift) | (0b001 << kRvvNfShift), 6741cb0ef41Sopenharmony_ci RO_V_VLSSEG3 = LOAD_FP | (0b10 << kRvvMopShift) | (0b010 << kRvvNfShift), 6751cb0ef41Sopenharmony_ci RO_V_VLSSEG4 = LOAD_FP | (0b10 << kRvvMopShift) | (0b011 << kRvvNfShift), 6761cb0ef41Sopenharmony_ci RO_V_VLSSEG5 = LOAD_FP | (0b10 << kRvvMopShift) | (0b100 << kRvvNfShift), 6771cb0ef41Sopenharmony_ci RO_V_VLSSEG6 = LOAD_FP | (0b10 << kRvvMopShift) | (0b101 << kRvvNfShift), 6781cb0ef41Sopenharmony_ci RO_V_VLSSEG7 = LOAD_FP | (0b10 << kRvvMopShift) | (0b110 << kRvvNfShift), 6791cb0ef41Sopenharmony_ci RO_V_VLSSEG8 = LOAD_FP | (0b10 << kRvvMopShift) | (0b111 << kRvvNfShift), 6801cb0ef41Sopenharmony_ci 6811cb0ef41Sopenharmony_ci RO_V_VSSSEG2 = STORE_FP | (0b10 << kRvvMopShift) | (0b001 << kRvvNfShift), 6821cb0ef41Sopenharmony_ci RO_V_VSSSEG3 = STORE_FP | (0b10 << kRvvMopShift) | (0b010 << kRvvNfShift), 6831cb0ef41Sopenharmony_ci RO_V_VSSSEG4 = STORE_FP | (0b10 << kRvvMopShift) | (0b011 << kRvvNfShift), 6841cb0ef41Sopenharmony_ci RO_V_VSSSEG5 = STORE_FP | (0b10 << kRvvMopShift) | (0b100 << kRvvNfShift), 6851cb0ef41Sopenharmony_ci RO_V_VSSSEG6 = STORE_FP | (0b10 << kRvvMopShift) | (0b101 << kRvvNfShift), 6861cb0ef41Sopenharmony_ci RO_V_VSSSEG7 = STORE_FP | (0b10 << kRvvMopShift) | (0b110 << kRvvNfShift), 6871cb0ef41Sopenharmony_ci RO_V_VSSSEG8 = STORE_FP | (0b10 << kRvvMopShift) | (0b111 << kRvvNfShift), 6881cb0ef41Sopenharmony_ci 6891cb0ef41Sopenharmony_ci RO_V_VLXSEG2 = LOAD_FP | (0b11 << kRvvMopShift) | (0b001 << kRvvNfShift), 6901cb0ef41Sopenharmony_ci RO_V_VLXSEG3 = LOAD_FP | (0b11 << kRvvMopShift) | (0b010 << kRvvNfShift), 6911cb0ef41Sopenharmony_ci RO_V_VLXSEG4 = LOAD_FP | (0b11 << kRvvMopShift) | (0b011 << kRvvNfShift), 6921cb0ef41Sopenharmony_ci RO_V_VLXSEG5 = LOAD_FP | (0b11 << kRvvMopShift) | (0b100 << kRvvNfShift), 6931cb0ef41Sopenharmony_ci RO_V_VLXSEG6 = LOAD_FP | (0b11 << kRvvMopShift) | (0b101 << kRvvNfShift), 6941cb0ef41Sopenharmony_ci RO_V_VLXSEG7 = LOAD_FP | (0b11 << kRvvMopShift) | (0b110 << kRvvNfShift), 6951cb0ef41Sopenharmony_ci RO_V_VLXSEG8 = LOAD_FP | (0b11 << kRvvMopShift) | (0b111 << kRvvNfShift), 6961cb0ef41Sopenharmony_ci 6971cb0ef41Sopenharmony_ci RO_V_VSXSEG2 = STORE_FP | (0b11 << kRvvMopShift) | (0b001 << kRvvNfShift), 6981cb0ef41Sopenharmony_ci RO_V_VSXSEG3 = STORE_FP | (0b11 << kRvvMopShift) | (0b010 << kRvvNfShift), 6991cb0ef41Sopenharmony_ci RO_V_VSXSEG4 = STORE_FP | (0b11 << kRvvMopShift) | (0b011 << kRvvNfShift), 7001cb0ef41Sopenharmony_ci RO_V_VSXSEG5 = STORE_FP | (0b11 << kRvvMopShift) | (0b100 << kRvvNfShift), 7011cb0ef41Sopenharmony_ci RO_V_VSXSEG6 = STORE_FP | (0b11 << kRvvMopShift) | (0b101 << kRvvNfShift), 7021cb0ef41Sopenharmony_ci RO_V_VSXSEG7 = STORE_FP | (0b11 << kRvvMopShift) | (0b110 << kRvvNfShift), 7031cb0ef41Sopenharmony_ci RO_V_VSXSEG8 = STORE_FP | (0b11 << kRvvMopShift) | (0b111 << kRvvNfShift), 7041cb0ef41Sopenharmony_ci 7051cb0ef41Sopenharmony_ci // RVV Vector Arithmetic Instruction 7061cb0ef41Sopenharmony_ci VADD_FUNCT6 = 0b000000, 7071cb0ef41Sopenharmony_ci RO_V_VADD_VI = OP_IVI | (VADD_FUNCT6 << kRvvFunct6Shift), 7081cb0ef41Sopenharmony_ci RO_V_VADD_VV = OP_IVV | (VADD_FUNCT6 << kRvvFunct6Shift), 7091cb0ef41Sopenharmony_ci RO_V_VADD_VX = OP_IVX | (VADD_FUNCT6 << kRvvFunct6Shift), 7101cb0ef41Sopenharmony_ci 7111cb0ef41Sopenharmony_ci VSUB_FUNCT6 = 0b000010, 7121cb0ef41Sopenharmony_ci RO_V_VSUB_VX = OP_IVX | (VSUB_FUNCT6 << kRvvFunct6Shift), 7131cb0ef41Sopenharmony_ci RO_V_VSUB_VV = OP_IVV | (VSUB_FUNCT6 << kRvvFunct6Shift), 7141cb0ef41Sopenharmony_ci 7151cb0ef41Sopenharmony_ci VDIVU_FUNCT6 = 0b100000, 7161cb0ef41Sopenharmony_ci RO_V_VDIVU_VX = OP_MVX | (VDIVU_FUNCT6 << kRvvFunct6Shift), 7171cb0ef41Sopenharmony_ci RO_V_VDIVU_VV = OP_MVV | (VDIVU_FUNCT6 << kRvvFunct6Shift), 7181cb0ef41Sopenharmony_ci 7191cb0ef41Sopenharmony_ci VDIV_FUNCT6 = 0b100001, 7201cb0ef41Sopenharmony_ci RO_V_VDIV_VX = OP_MVX | (VDIV_FUNCT6 << kRvvFunct6Shift), 7211cb0ef41Sopenharmony_ci RO_V_VDIV_VV = OP_MVV | (VDIV_FUNCT6 << kRvvFunct6Shift), 7221cb0ef41Sopenharmony_ci 7231cb0ef41Sopenharmony_ci VREMU_FUNCT6 = 0b100010, 7241cb0ef41Sopenharmony_ci RO_V_VREMU_VX = OP_MVX | (VREMU_FUNCT6 << kRvvFunct6Shift), 7251cb0ef41Sopenharmony_ci RO_V_VREMU_VV = OP_MVV | (VREMU_FUNCT6 << kRvvFunct6Shift), 7261cb0ef41Sopenharmony_ci 7271cb0ef41Sopenharmony_ci VREM_FUNCT6 = 0b100011, 7281cb0ef41Sopenharmony_ci RO_V_VREM_VX = OP_MVX | (VREM_FUNCT6 << kRvvFunct6Shift), 7291cb0ef41Sopenharmony_ci RO_V_VREM_VV = OP_MVV | (VREM_FUNCT6 << kRvvFunct6Shift), 7301cb0ef41Sopenharmony_ci 7311cb0ef41Sopenharmony_ci VMULHU_FUNCT6 = 0b100100, 7321cb0ef41Sopenharmony_ci RO_V_VMULHU_VX = OP_MVX | (VMULHU_FUNCT6 << kRvvFunct6Shift), 7331cb0ef41Sopenharmony_ci RO_V_VMULHU_VV = OP_MVV | (VMULHU_FUNCT6 << kRvvFunct6Shift), 7341cb0ef41Sopenharmony_ci 7351cb0ef41Sopenharmony_ci VMUL_FUNCT6 = 0b100101, 7361cb0ef41Sopenharmony_ci RO_V_VMUL_VX = OP_MVX | (VMUL_FUNCT6 << kRvvFunct6Shift), 7371cb0ef41Sopenharmony_ci RO_V_VMUL_VV = OP_MVV | (VMUL_FUNCT6 << kRvvFunct6Shift), 7381cb0ef41Sopenharmony_ci 7391cb0ef41Sopenharmony_ci VWMUL_FUNCT6 = 0b111011, 7401cb0ef41Sopenharmony_ci RO_V_VWMUL_VX = OP_MVX | (VWMUL_FUNCT6 << kRvvFunct6Shift), 7411cb0ef41Sopenharmony_ci RO_V_VWMUL_VV = OP_MVV | (VWMUL_FUNCT6 << kRvvFunct6Shift), 7421cb0ef41Sopenharmony_ci 7431cb0ef41Sopenharmony_ci VWMULU_FUNCT6 = 0b111000, 7441cb0ef41Sopenharmony_ci RO_V_VWMULU_VX = OP_MVX | (VWMULU_FUNCT6 << kRvvFunct6Shift), 7451cb0ef41Sopenharmony_ci RO_V_VWMULU_VV = OP_MVV | (VWMULU_FUNCT6 << kRvvFunct6Shift), 7461cb0ef41Sopenharmony_ci 7471cb0ef41Sopenharmony_ci VMULHSU_FUNCT6 = 0b100110, 7481cb0ef41Sopenharmony_ci RO_V_VMULHSU_VX = OP_MVX | (VMULHSU_FUNCT6 << kRvvFunct6Shift), 7491cb0ef41Sopenharmony_ci RO_V_VMULHSU_VV = OP_MVV | (VMULHSU_FUNCT6 << kRvvFunct6Shift), 7501cb0ef41Sopenharmony_ci 7511cb0ef41Sopenharmony_ci VMULH_FUNCT6 = 0b100111, 7521cb0ef41Sopenharmony_ci RO_V_VMULH_VX = OP_MVX | (VMULH_FUNCT6 << kRvvFunct6Shift), 7531cb0ef41Sopenharmony_ci RO_V_VMULH_VV = OP_MVV | (VMULH_FUNCT6 << kRvvFunct6Shift), 7541cb0ef41Sopenharmony_ci 7551cb0ef41Sopenharmony_ci VWADD_FUNCT6 = 0b110001, 7561cb0ef41Sopenharmony_ci RO_V_VWADD_VV = OP_MVV | (VWADD_FUNCT6 << kRvvFunct6Shift), 7571cb0ef41Sopenharmony_ci RO_V_VWADD_VX = OP_MVX | (VWADD_FUNCT6 << kRvvFunct6Shift), 7581cb0ef41Sopenharmony_ci 7591cb0ef41Sopenharmony_ci VWADDU_FUNCT6 = 0b110000, 7601cb0ef41Sopenharmony_ci RO_V_VWADDU_VV = OP_MVV | (VWADDU_FUNCT6 << kRvvFunct6Shift), 7611cb0ef41Sopenharmony_ci RO_V_VWADDU_VX = OP_MVX | (VWADDU_FUNCT6 << kRvvFunct6Shift), 7621cb0ef41Sopenharmony_ci 7631cb0ef41Sopenharmony_ci VWADDUW_FUNCT6 = 0b110101, 7641cb0ef41Sopenharmony_ci RO_V_VWADDUW_VX = OP_MVX | (VWADDUW_FUNCT6 << kRvvFunct6Shift), 7651cb0ef41Sopenharmony_ci RO_V_VWADDUW_VV = OP_MVV | (VWADDUW_FUNCT6 << kRvvFunct6Shift), 7661cb0ef41Sopenharmony_ci 7671cb0ef41Sopenharmony_ci VCOMPRESS_FUNCT6 = 0b010111, 7681cb0ef41Sopenharmony_ci RO_V_VCOMPRESS_VV = OP_MVV | (VCOMPRESS_FUNCT6 << kRvvFunct6Shift), 7691cb0ef41Sopenharmony_ci 7701cb0ef41Sopenharmony_ci VSADDU_FUNCT6 = 0b100000, 7711cb0ef41Sopenharmony_ci RO_V_VSADDU_VI = OP_IVI | (VSADDU_FUNCT6 << kRvvFunct6Shift), 7721cb0ef41Sopenharmony_ci RO_V_VSADDU_VV = OP_IVV | (VSADDU_FUNCT6 << kRvvFunct6Shift), 7731cb0ef41Sopenharmony_ci RO_V_VSADDU_VX = OP_IVX | (VSADDU_FUNCT6 << kRvvFunct6Shift), 7741cb0ef41Sopenharmony_ci 7751cb0ef41Sopenharmony_ci VSADD_FUNCT6 = 0b100001, 7761cb0ef41Sopenharmony_ci RO_V_VSADD_VI = OP_IVI | (VSADD_FUNCT6 << kRvvFunct6Shift), 7771cb0ef41Sopenharmony_ci RO_V_VSADD_VV = OP_IVV | (VSADD_FUNCT6 << kRvvFunct6Shift), 7781cb0ef41Sopenharmony_ci RO_V_VSADD_VX = OP_IVX | (VSADD_FUNCT6 << kRvvFunct6Shift), 7791cb0ef41Sopenharmony_ci 7801cb0ef41Sopenharmony_ci VSSUB_FUNCT6 = 0b100011, 7811cb0ef41Sopenharmony_ci RO_V_VSSUB_VV = OP_IVV | (VSSUB_FUNCT6 << kRvvFunct6Shift), 7821cb0ef41Sopenharmony_ci RO_V_VSSUB_VX = OP_IVX | (VSSUB_FUNCT6 << kRvvFunct6Shift), 7831cb0ef41Sopenharmony_ci 7841cb0ef41Sopenharmony_ci VSSUBU_FUNCT6 = 0b100010, 7851cb0ef41Sopenharmony_ci RO_V_VSSUBU_VV = OP_IVV | (VSSUBU_FUNCT6 << kRvvFunct6Shift), 7861cb0ef41Sopenharmony_ci RO_V_VSSUBU_VX = OP_IVX | (VSSUBU_FUNCT6 << kRvvFunct6Shift), 7871cb0ef41Sopenharmony_ci 7881cb0ef41Sopenharmony_ci VRSUB_FUNCT6 = 0b000011, 7891cb0ef41Sopenharmony_ci RO_V_VRSUB_VX = OP_IVX | (VRSUB_FUNCT6 << kRvvFunct6Shift), 7901cb0ef41Sopenharmony_ci RO_V_VRSUB_VI = OP_IVI | (VRSUB_FUNCT6 << kRvvFunct6Shift), 7911cb0ef41Sopenharmony_ci 7921cb0ef41Sopenharmony_ci VMINU_FUNCT6 = 0b000100, 7931cb0ef41Sopenharmony_ci RO_V_VMINU_VX = OP_IVX | (VMINU_FUNCT6 << kRvvFunct6Shift), 7941cb0ef41Sopenharmony_ci RO_V_VMINU_VV = OP_IVV | (VMINU_FUNCT6 << kRvvFunct6Shift), 7951cb0ef41Sopenharmony_ci 7961cb0ef41Sopenharmony_ci VMIN_FUNCT6 = 0b000101, 7971cb0ef41Sopenharmony_ci RO_V_VMIN_VX = OP_IVX | (VMIN_FUNCT6 << kRvvFunct6Shift), 7981cb0ef41Sopenharmony_ci RO_V_VMIN_VV = OP_IVV | (VMIN_FUNCT6 << kRvvFunct6Shift), 7991cb0ef41Sopenharmony_ci 8001cb0ef41Sopenharmony_ci VMAXU_FUNCT6 = 0b000110, 8011cb0ef41Sopenharmony_ci RO_V_VMAXU_VX = OP_IVX | (VMAXU_FUNCT6 << kRvvFunct6Shift), 8021cb0ef41Sopenharmony_ci RO_V_VMAXU_VV = OP_IVV | (VMAXU_FUNCT6 << kRvvFunct6Shift), 8031cb0ef41Sopenharmony_ci 8041cb0ef41Sopenharmony_ci VMAX_FUNCT6 = 0b000111, 8051cb0ef41Sopenharmony_ci RO_V_VMAX_VX = OP_IVX | (VMAX_FUNCT6 << kRvvFunct6Shift), 8061cb0ef41Sopenharmony_ci RO_V_VMAX_VV = OP_IVV | (VMAX_FUNCT6 << kRvvFunct6Shift), 8071cb0ef41Sopenharmony_ci 8081cb0ef41Sopenharmony_ci VAND_FUNCT6 = 0b001001, 8091cb0ef41Sopenharmony_ci RO_V_VAND_VI = OP_IVI | (VAND_FUNCT6 << kRvvFunct6Shift), 8101cb0ef41Sopenharmony_ci RO_V_VAND_VV = OP_IVV | (VAND_FUNCT6 << kRvvFunct6Shift), 8111cb0ef41Sopenharmony_ci RO_V_VAND_VX = OP_IVX | (VAND_FUNCT6 << kRvvFunct6Shift), 8121cb0ef41Sopenharmony_ci 8131cb0ef41Sopenharmony_ci VOR_FUNCT6 = 0b001010, 8141cb0ef41Sopenharmony_ci RO_V_VOR_VI = OP_IVI | (VOR_FUNCT6 << kRvvFunct6Shift), 8151cb0ef41Sopenharmony_ci RO_V_VOR_VV = OP_IVV | (VOR_FUNCT6 << kRvvFunct6Shift), 8161cb0ef41Sopenharmony_ci RO_V_VOR_VX = OP_IVX | (VOR_FUNCT6 << kRvvFunct6Shift), 8171cb0ef41Sopenharmony_ci 8181cb0ef41Sopenharmony_ci VXOR_FUNCT6 = 0b001011, 8191cb0ef41Sopenharmony_ci RO_V_VXOR_VI = OP_IVI | (VXOR_FUNCT6 << kRvvFunct6Shift), 8201cb0ef41Sopenharmony_ci RO_V_VXOR_VV = OP_IVV | (VXOR_FUNCT6 << kRvvFunct6Shift), 8211cb0ef41Sopenharmony_ci RO_V_VXOR_VX = OP_IVX | (VXOR_FUNCT6 << kRvvFunct6Shift), 8221cb0ef41Sopenharmony_ci 8231cb0ef41Sopenharmony_ci VRGATHER_FUNCT6 = 0b001100, 8241cb0ef41Sopenharmony_ci RO_V_VRGATHER_VI = OP_IVI | (VRGATHER_FUNCT6 << kRvvFunct6Shift), 8251cb0ef41Sopenharmony_ci RO_V_VRGATHER_VV = OP_IVV | (VRGATHER_FUNCT6 << kRvvFunct6Shift), 8261cb0ef41Sopenharmony_ci RO_V_VRGATHER_VX = OP_IVX | (VRGATHER_FUNCT6 << kRvvFunct6Shift), 8271cb0ef41Sopenharmony_ci 8281cb0ef41Sopenharmony_ci VMV_FUNCT6 = 0b010111, 8291cb0ef41Sopenharmony_ci RO_V_VMV_VI = OP_IVI | (VMV_FUNCT6 << kRvvFunct6Shift), 8301cb0ef41Sopenharmony_ci RO_V_VMV_VV = OP_IVV | (VMV_FUNCT6 << kRvvFunct6Shift), 8311cb0ef41Sopenharmony_ci RO_V_VMV_VX = OP_IVX | (VMV_FUNCT6 << kRvvFunct6Shift), 8321cb0ef41Sopenharmony_ci RO_V_VFMV_VF = OP_FVF | (VMV_FUNCT6 << kRvvFunct6Shift), 8331cb0ef41Sopenharmony_ci 8341cb0ef41Sopenharmony_ci RO_V_VMERGE_VI = RO_V_VMV_VI, 8351cb0ef41Sopenharmony_ci RO_V_VMERGE_VV = RO_V_VMV_VV, 8361cb0ef41Sopenharmony_ci RO_V_VMERGE_VX = RO_V_VMV_VX, 8371cb0ef41Sopenharmony_ci 8381cb0ef41Sopenharmony_ci VMSEQ_FUNCT6 = 0b011000, 8391cb0ef41Sopenharmony_ci RO_V_VMSEQ_VI = OP_IVI | (VMSEQ_FUNCT6 << kRvvFunct6Shift), 8401cb0ef41Sopenharmony_ci RO_V_VMSEQ_VV = OP_IVV | (VMSEQ_FUNCT6 << kRvvFunct6Shift), 8411cb0ef41Sopenharmony_ci RO_V_VMSEQ_VX = OP_IVX | (VMSEQ_FUNCT6 << kRvvFunct6Shift), 8421cb0ef41Sopenharmony_ci 8431cb0ef41Sopenharmony_ci VMSNE_FUNCT6 = 0b011001, 8441cb0ef41Sopenharmony_ci RO_V_VMSNE_VI = OP_IVI | (VMSNE_FUNCT6 << kRvvFunct6Shift), 8451cb0ef41Sopenharmony_ci RO_V_VMSNE_VV = OP_IVV | (VMSNE_FUNCT6 << kRvvFunct6Shift), 8461cb0ef41Sopenharmony_ci RO_V_VMSNE_VX = OP_IVX | (VMSNE_FUNCT6 << kRvvFunct6Shift), 8471cb0ef41Sopenharmony_ci 8481cb0ef41Sopenharmony_ci VMSLTU_FUNCT6 = 0b011010, 8491cb0ef41Sopenharmony_ci RO_V_VMSLTU_VV = OP_IVV | (VMSLTU_FUNCT6 << kRvvFunct6Shift), 8501cb0ef41Sopenharmony_ci RO_V_VMSLTU_VX = OP_IVX | (VMSLTU_FUNCT6 << kRvvFunct6Shift), 8511cb0ef41Sopenharmony_ci 8521cb0ef41Sopenharmony_ci VMSLT_FUNCT6 = 0b011011, 8531cb0ef41Sopenharmony_ci RO_V_VMSLT_VV = OP_IVV | (VMSLT_FUNCT6 << kRvvFunct6Shift), 8541cb0ef41Sopenharmony_ci RO_V_VMSLT_VX = OP_IVX | (VMSLT_FUNCT6 << kRvvFunct6Shift), 8551cb0ef41Sopenharmony_ci 8561cb0ef41Sopenharmony_ci VMSLE_FUNCT6 = 0b011101, 8571cb0ef41Sopenharmony_ci RO_V_VMSLE_VI = OP_IVI | (VMSLE_FUNCT6 << kRvvFunct6Shift), 8581cb0ef41Sopenharmony_ci RO_V_VMSLE_VV = OP_IVV | (VMSLE_FUNCT6 << kRvvFunct6Shift), 8591cb0ef41Sopenharmony_ci RO_V_VMSLE_VX = OP_IVX | (VMSLE_FUNCT6 << kRvvFunct6Shift), 8601cb0ef41Sopenharmony_ci 8611cb0ef41Sopenharmony_ci VMSLEU_FUNCT6 = 0b011100, 8621cb0ef41Sopenharmony_ci RO_V_VMSLEU_VI = OP_IVI | (VMSLEU_FUNCT6 << kRvvFunct6Shift), 8631cb0ef41Sopenharmony_ci RO_V_VMSLEU_VV = OP_IVV | (VMSLEU_FUNCT6 << kRvvFunct6Shift), 8641cb0ef41Sopenharmony_ci RO_V_VMSLEU_VX = OP_IVX | (VMSLEU_FUNCT6 << kRvvFunct6Shift), 8651cb0ef41Sopenharmony_ci 8661cb0ef41Sopenharmony_ci VMSGTU_FUNCT6 = 0b011110, 8671cb0ef41Sopenharmony_ci RO_V_VMSGTU_VI = OP_IVI | (VMSGTU_FUNCT6 << kRvvFunct6Shift), 8681cb0ef41Sopenharmony_ci RO_V_VMSGTU_VX = OP_IVX | (VMSGTU_FUNCT6 << kRvvFunct6Shift), 8691cb0ef41Sopenharmony_ci 8701cb0ef41Sopenharmony_ci VMSGT_FUNCT6 = 0b011111, 8711cb0ef41Sopenharmony_ci RO_V_VMSGT_VI = OP_IVI | (VMSGT_FUNCT6 << kRvvFunct6Shift), 8721cb0ef41Sopenharmony_ci RO_V_VMSGT_VX = OP_IVX | (VMSGT_FUNCT6 << kRvvFunct6Shift), 8731cb0ef41Sopenharmony_ci 8741cb0ef41Sopenharmony_ci VSLIDEUP_FUNCT6 = 0b001110, 8751cb0ef41Sopenharmony_ci RO_V_VSLIDEUP_VI = OP_IVI | (VSLIDEUP_FUNCT6 << kRvvFunct6Shift), 8761cb0ef41Sopenharmony_ci RO_V_VSLIDEUP_VX = OP_IVX | (VSLIDEUP_FUNCT6 << kRvvFunct6Shift), 8771cb0ef41Sopenharmony_ci 8781cb0ef41Sopenharmony_ci VSLIDEDOWN_FUNCT6 = 0b001111, 8791cb0ef41Sopenharmony_ci RO_V_VSLIDEDOWN_VI = OP_IVI | (VSLIDEDOWN_FUNCT6 << kRvvFunct6Shift), 8801cb0ef41Sopenharmony_ci RO_V_VSLIDEDOWN_VX = OP_IVX | (VSLIDEDOWN_FUNCT6 << kRvvFunct6Shift), 8811cb0ef41Sopenharmony_ci 8821cb0ef41Sopenharmony_ci VSRL_FUNCT6 = 0b101000, 8831cb0ef41Sopenharmony_ci RO_V_VSRL_VI = OP_IVI | (VSRL_FUNCT6 << kRvvFunct6Shift), 8841cb0ef41Sopenharmony_ci RO_V_VSRL_VV = OP_IVV | (VSRL_FUNCT6 << kRvvFunct6Shift), 8851cb0ef41Sopenharmony_ci RO_V_VSRL_VX = OP_IVX | (VSRL_FUNCT6 << kRvvFunct6Shift), 8861cb0ef41Sopenharmony_ci 8871cb0ef41Sopenharmony_ci VSRA_FUNCT6 = 0b101001, 8881cb0ef41Sopenharmony_ci RO_V_VSRA_VI = OP_IVI | (VSRA_FUNCT6 << kRvvFunct6Shift), 8891cb0ef41Sopenharmony_ci RO_V_VSRA_VV = OP_IVV | (VSRA_FUNCT6 << kRvvFunct6Shift), 8901cb0ef41Sopenharmony_ci RO_V_VSRA_VX = OP_IVX | (VSRA_FUNCT6 << kRvvFunct6Shift), 8911cb0ef41Sopenharmony_ci 8921cb0ef41Sopenharmony_ci VSLL_FUNCT6 = 0b100101, 8931cb0ef41Sopenharmony_ci RO_V_VSLL_VI = OP_IVI | (VSLL_FUNCT6 << kRvvFunct6Shift), 8941cb0ef41Sopenharmony_ci RO_V_VSLL_VV = OP_IVV | (VSLL_FUNCT6 << kRvvFunct6Shift), 8951cb0ef41Sopenharmony_ci RO_V_VSLL_VX = OP_IVX | (VSLL_FUNCT6 << kRvvFunct6Shift), 8961cb0ef41Sopenharmony_ci 8971cb0ef41Sopenharmony_ci VSMUL_FUNCT6 = 0b100111, 8981cb0ef41Sopenharmony_ci RO_V_VSMUL_VV = OP_IVV | (VSMUL_FUNCT6 << kRvvFunct6Shift), 8991cb0ef41Sopenharmony_ci RO_V_VSMUL_VX = OP_IVX | (VSMUL_FUNCT6 << kRvvFunct6Shift), 9001cb0ef41Sopenharmony_ci 9011cb0ef41Sopenharmony_ci VADC_FUNCT6 = 0b010000, 9021cb0ef41Sopenharmony_ci RO_V_VADC_VI = OP_IVI | (VADC_FUNCT6 << kRvvFunct6Shift), 9031cb0ef41Sopenharmony_ci RO_V_VADC_VV = OP_IVV | (VADC_FUNCT6 << kRvvFunct6Shift), 9041cb0ef41Sopenharmony_ci RO_V_VADC_VX = OP_IVX | (VADC_FUNCT6 << kRvvFunct6Shift), 9051cb0ef41Sopenharmony_ci 9061cb0ef41Sopenharmony_ci VMADC_FUNCT6 = 0b010001, 9071cb0ef41Sopenharmony_ci RO_V_VMADC_VI = OP_IVI | (VMADC_FUNCT6 << kRvvFunct6Shift), 9081cb0ef41Sopenharmony_ci RO_V_VMADC_VV = OP_IVV | (VMADC_FUNCT6 << kRvvFunct6Shift), 9091cb0ef41Sopenharmony_ci RO_V_VMADC_VX = OP_IVX | (VMADC_FUNCT6 << kRvvFunct6Shift), 9101cb0ef41Sopenharmony_ci 9111cb0ef41Sopenharmony_ci VWXUNARY0_FUNCT6 = 0b010000, 9121cb0ef41Sopenharmony_ci VRXUNARY0_FUNCT6 = 0b010000, 9131cb0ef41Sopenharmony_ci VMUNARY0_FUNCT6 = 0b010100, 9141cb0ef41Sopenharmony_ci 9151cb0ef41Sopenharmony_ci RO_V_VWXUNARY0 = OP_MVV | (VWXUNARY0_FUNCT6 << kRvvFunct6Shift), 9161cb0ef41Sopenharmony_ci RO_V_VRXUNARY0 = OP_MVX | (VRXUNARY0_FUNCT6 << kRvvFunct6Shift), 9171cb0ef41Sopenharmony_ci RO_V_VMUNARY0 = OP_MVV | (VMUNARY0_FUNCT6 << kRvvFunct6Shift), 9181cb0ef41Sopenharmony_ci 9191cb0ef41Sopenharmony_ci VID_V = 0b10001, 9201cb0ef41Sopenharmony_ci 9211cb0ef41Sopenharmony_ci VXUNARY0_FUNCT6 = 0b010010, 9221cb0ef41Sopenharmony_ci RO_V_VXUNARY0 = OP_MVV | (VXUNARY0_FUNCT6 << kRvvFunct6Shift), 9231cb0ef41Sopenharmony_ci 9241cb0ef41Sopenharmony_ci VWFUNARY0_FUNCT6 = 0b010000, 9251cb0ef41Sopenharmony_ci RO_V_VFMV_FS = OP_FVV | (VWFUNARY0_FUNCT6 << kRvvFunct6Shift), 9261cb0ef41Sopenharmony_ci 9271cb0ef41Sopenharmony_ci VRFUNARY0_FUNCT6 = 0b010000, 9281cb0ef41Sopenharmony_ci RO_V_VFMV_SF = OP_FVF | (VRFUNARY0_FUNCT6 << kRvvFunct6Shift), 9291cb0ef41Sopenharmony_ci 9301cb0ef41Sopenharmony_ci VREDMAXU_FUNCT6 = 0b000110, 9311cb0ef41Sopenharmony_ci RO_V_VREDMAXU = OP_MVV | (VREDMAXU_FUNCT6 << kRvvFunct6Shift), 9321cb0ef41Sopenharmony_ci VREDMAX_FUNCT6 = 0b000111, 9331cb0ef41Sopenharmony_ci RO_V_VREDMAX = OP_MVV | (VREDMAX_FUNCT6 << kRvvFunct6Shift), 9341cb0ef41Sopenharmony_ci 9351cb0ef41Sopenharmony_ci VREDMINU_FUNCT6 = 0b000100, 9361cb0ef41Sopenharmony_ci RO_V_VREDMINU = OP_MVV | (VREDMINU_FUNCT6 << kRvvFunct6Shift), 9371cb0ef41Sopenharmony_ci VREDMIN_FUNCT6 = 0b000101, 9381cb0ef41Sopenharmony_ci RO_V_VREDMIN = OP_MVV | (VREDMIN_FUNCT6 << kRvvFunct6Shift), 9391cb0ef41Sopenharmony_ci 9401cb0ef41Sopenharmony_ci VFUNARY0_FUNCT6 = 0b010010, 9411cb0ef41Sopenharmony_ci RO_V_VFUNARY0 = OP_FVV | (VFUNARY0_FUNCT6 << kRvvFunct6Shift), 9421cb0ef41Sopenharmony_ci VFUNARY1_FUNCT6 = 0b010011, 9431cb0ef41Sopenharmony_ci RO_V_VFUNARY1 = OP_FVV | (VFUNARY1_FUNCT6 << kRvvFunct6Shift), 9441cb0ef41Sopenharmony_ci 9451cb0ef41Sopenharmony_ci VFCVT_XU_F_V = 0b00000, 9461cb0ef41Sopenharmony_ci VFCVT_X_F_V = 0b00001, 9471cb0ef41Sopenharmony_ci VFCVT_F_XU_V = 0b00010, 9481cb0ef41Sopenharmony_ci VFCVT_F_X_V = 0b00011, 9491cb0ef41Sopenharmony_ci VFWCVT_XU_F_V = 0b01000, 9501cb0ef41Sopenharmony_ci VFWCVT_X_F_V = 0b01001, 9511cb0ef41Sopenharmony_ci VFWCVT_F_XU_V = 0b01010, 9521cb0ef41Sopenharmony_ci VFWCVT_F_X_V = 0b01011, 9531cb0ef41Sopenharmony_ci VFWCVT_F_F_V = 0b01100, 9541cb0ef41Sopenharmony_ci VFNCVT_F_F_W = 0b10100, 9551cb0ef41Sopenharmony_ci VFNCVT_X_F_W = 0b10001, 9561cb0ef41Sopenharmony_ci VFNCVT_XU_F_W = 0b10000, 9571cb0ef41Sopenharmony_ci 9581cb0ef41Sopenharmony_ci VFCLASS_V = 0b10000, 9591cb0ef41Sopenharmony_ci VFSQRT_V = 0b00000, 9601cb0ef41Sopenharmony_ci VFRSQRT7_V = 0b00100, 9611cb0ef41Sopenharmony_ci VFREC7_V = 0b00101, 9621cb0ef41Sopenharmony_ci 9631cb0ef41Sopenharmony_ci VFADD_FUNCT6 = 0b000000, 9641cb0ef41Sopenharmony_ci RO_V_VFADD_VV = OP_FVV | (VFADD_FUNCT6 << kRvvFunct6Shift), 9651cb0ef41Sopenharmony_ci RO_V_VFADD_VF = OP_FVF | (VFADD_FUNCT6 << kRvvFunct6Shift), 9661cb0ef41Sopenharmony_ci 9671cb0ef41Sopenharmony_ci VFSUB_FUNCT6 = 0b000010, 9681cb0ef41Sopenharmony_ci RO_V_VFSUB_VV = OP_FVV | (VFSUB_FUNCT6 << kRvvFunct6Shift), 9691cb0ef41Sopenharmony_ci RO_V_VFSUB_VF = OP_FVF | (VFSUB_FUNCT6 << kRvvFunct6Shift), 9701cb0ef41Sopenharmony_ci 9711cb0ef41Sopenharmony_ci VFDIV_FUNCT6 = 0b100000, 9721cb0ef41Sopenharmony_ci RO_V_VFDIV_VV = OP_FVV | (VFDIV_FUNCT6 << kRvvFunct6Shift), 9731cb0ef41Sopenharmony_ci RO_V_VFDIV_VF = OP_FVF | (VFDIV_FUNCT6 << kRvvFunct6Shift), 9741cb0ef41Sopenharmony_ci 9751cb0ef41Sopenharmony_ci VFMUL_FUNCT6 = 0b100100, 9761cb0ef41Sopenharmony_ci RO_V_VFMUL_VV = OP_FVV | (VFMUL_FUNCT6 << kRvvFunct6Shift), 9771cb0ef41Sopenharmony_ci RO_V_VFMUL_VF = OP_FVF | (VFMUL_FUNCT6 << kRvvFunct6Shift), 9781cb0ef41Sopenharmony_ci 9791cb0ef41Sopenharmony_ci // Vector Widening Floating-Point Add/Subtract Instructions 9801cb0ef41Sopenharmony_ci VFWADD_FUNCT6 = 0b110000, 9811cb0ef41Sopenharmony_ci RO_V_VFWADD_VV = OP_FVV | (VFWADD_FUNCT6 << kRvvFunct6Shift), 9821cb0ef41Sopenharmony_ci RO_V_VFWADD_VF = OP_FVF | (VFWADD_FUNCT6 << kRvvFunct6Shift), 9831cb0ef41Sopenharmony_ci 9841cb0ef41Sopenharmony_ci VFWSUB_FUNCT6 = 0b110010, 9851cb0ef41Sopenharmony_ci RO_V_VFWSUB_VV = OP_FVV | (VFWSUB_FUNCT6 << kRvvFunct6Shift), 9861cb0ef41Sopenharmony_ci RO_V_VFWSUB_VF = OP_FVF | (VFWSUB_FUNCT6 << kRvvFunct6Shift), 9871cb0ef41Sopenharmony_ci 9881cb0ef41Sopenharmony_ci VFWADD_W_FUNCT6 = 0b110100, 9891cb0ef41Sopenharmony_ci RO_V_VFWADD_W_VV = OP_FVV | (VFWADD_W_FUNCT6 << kRvvFunct6Shift), 9901cb0ef41Sopenharmony_ci RO_V_VFWADD_W_VF = OP_FVF | (VFWADD_W_FUNCT6 << kRvvFunct6Shift), 9911cb0ef41Sopenharmony_ci 9921cb0ef41Sopenharmony_ci VFWSUB_W_FUNCT6 = 0b110110, 9931cb0ef41Sopenharmony_ci RO_V_VFWSUB_W_VV = OP_FVV | (VFWSUB_W_FUNCT6 << kRvvFunct6Shift), 9941cb0ef41Sopenharmony_ci RO_V_VFWSUB_W_VF = OP_FVF | (VFWSUB_W_FUNCT6 << kRvvFunct6Shift), 9951cb0ef41Sopenharmony_ci 9961cb0ef41Sopenharmony_ci // Vector Widening Floating-Point Reduction Instructions 9971cb0ef41Sopenharmony_ci VFWREDUSUM_FUNCT6 = 0b110001, 9981cb0ef41Sopenharmony_ci RO_V_VFWREDUSUM_VV = OP_FVV | (VFWREDUSUM_FUNCT6 << kRvvFunct6Shift), 9991cb0ef41Sopenharmony_ci 10001cb0ef41Sopenharmony_ci VFWREDOSUM_FUNCT6 = 0b110011, 10011cb0ef41Sopenharmony_ci RO_V_VFWREDOSUM_VV = OP_FVV | (VFWREDOSUM_FUNCT6 << kRvvFunct6Shift), 10021cb0ef41Sopenharmony_ci 10031cb0ef41Sopenharmony_ci // Vector Widening Floating-Point Multiply 10041cb0ef41Sopenharmony_ci VFWMUL_FUNCT6 = 0b111000, 10051cb0ef41Sopenharmony_ci RO_V_VFWMUL_VV = OP_FVV | (VFWMUL_FUNCT6 << kRvvFunct6Shift), 10061cb0ef41Sopenharmony_ci RO_V_VFWMUL_VF = OP_FVF | (VFWMUL_FUNCT6 << kRvvFunct6Shift), 10071cb0ef41Sopenharmony_ci 10081cb0ef41Sopenharmony_ci VMFEQ_FUNCT6 = 0b011000, 10091cb0ef41Sopenharmony_ci RO_V_VMFEQ_VV = OP_FVV | (VMFEQ_FUNCT6 << kRvvFunct6Shift), 10101cb0ef41Sopenharmony_ci RO_V_VMFEQ_VF = OP_FVF | (VMFEQ_FUNCT6 << kRvvFunct6Shift), 10111cb0ef41Sopenharmony_ci 10121cb0ef41Sopenharmony_ci VMFNE_FUNCT6 = 0b011100, 10131cb0ef41Sopenharmony_ci RO_V_VMFNE_VV = OP_FVV | (VMFNE_FUNCT6 << kRvvFunct6Shift), 10141cb0ef41Sopenharmony_ci RO_V_VMFNE_VF = OP_FVF | (VMFNE_FUNCT6 << kRvvFunct6Shift), 10151cb0ef41Sopenharmony_ci 10161cb0ef41Sopenharmony_ci VMFLT_FUNCT6 = 0b011011, 10171cb0ef41Sopenharmony_ci RO_V_VMFLT_VV = OP_FVV | (VMFLT_FUNCT6 << kRvvFunct6Shift), 10181cb0ef41Sopenharmony_ci RO_V_VMFLT_VF = OP_FVF | (VMFLT_FUNCT6 << kRvvFunct6Shift), 10191cb0ef41Sopenharmony_ci 10201cb0ef41Sopenharmony_ci VMFLE_FUNCT6 = 0b011001, 10211cb0ef41Sopenharmony_ci RO_V_VMFLE_VV = OP_FVV | (VMFLE_FUNCT6 << kRvvFunct6Shift), 10221cb0ef41Sopenharmony_ci RO_V_VMFLE_VF = OP_FVF | (VMFLE_FUNCT6 << kRvvFunct6Shift), 10231cb0ef41Sopenharmony_ci 10241cb0ef41Sopenharmony_ci VMFGE_FUNCT6 = 0b011111, 10251cb0ef41Sopenharmony_ci RO_V_VMFGE_VF = OP_FVF | (VMFGE_FUNCT6 << kRvvFunct6Shift), 10261cb0ef41Sopenharmony_ci 10271cb0ef41Sopenharmony_ci VMFGT_FUNCT6 = 0b011101, 10281cb0ef41Sopenharmony_ci RO_V_VMFGT_VF = OP_FVF | (VMFGT_FUNCT6 << kRvvFunct6Shift), 10291cb0ef41Sopenharmony_ci 10301cb0ef41Sopenharmony_ci VFMAX_FUNCT6 = 0b000110, 10311cb0ef41Sopenharmony_ci RO_V_VFMAX_VV = OP_FVV | (VFMAX_FUNCT6 << kRvvFunct6Shift), 10321cb0ef41Sopenharmony_ci RO_V_VFMAX_VF = OP_FVF | (VFMAX_FUNCT6 << kRvvFunct6Shift), 10331cb0ef41Sopenharmony_ci 10341cb0ef41Sopenharmony_ci VFREDMAX_FUNCT6 = 0b0001111, 10351cb0ef41Sopenharmony_ci RO_V_VFREDMAX_VV = OP_FVV | (VFREDMAX_FUNCT6 << kRvvFunct6Shift), 10361cb0ef41Sopenharmony_ci 10371cb0ef41Sopenharmony_ci VFMIN_FUNCT6 = 0b000100, 10381cb0ef41Sopenharmony_ci RO_V_VFMIN_VV = OP_FVV | (VFMIN_FUNCT6 << kRvvFunct6Shift), 10391cb0ef41Sopenharmony_ci RO_V_VFMIN_VF = OP_FVF | (VFMIN_FUNCT6 << kRvvFunct6Shift), 10401cb0ef41Sopenharmony_ci 10411cb0ef41Sopenharmony_ci VFSGNJ_FUNCT6 = 0b001000, 10421cb0ef41Sopenharmony_ci RO_V_VFSGNJ_VV = OP_FVV | (VFSGNJ_FUNCT6 << kRvvFunct6Shift), 10431cb0ef41Sopenharmony_ci RO_V_VFSGNJ_VF = OP_FVF | (VFSGNJ_FUNCT6 << kRvvFunct6Shift), 10441cb0ef41Sopenharmony_ci 10451cb0ef41Sopenharmony_ci VFSGNJN_FUNCT6 = 0b001001, 10461cb0ef41Sopenharmony_ci RO_V_VFSGNJN_VV = OP_FVV | (VFSGNJN_FUNCT6 << kRvvFunct6Shift), 10471cb0ef41Sopenharmony_ci RO_V_VFSGNJN_VF = OP_FVF | (VFSGNJN_FUNCT6 << kRvvFunct6Shift), 10481cb0ef41Sopenharmony_ci 10491cb0ef41Sopenharmony_ci VFSGNJX_FUNCT6 = 0b001010, 10501cb0ef41Sopenharmony_ci RO_V_VFSGNJX_VV = OP_FVV | (VFSGNJX_FUNCT6 << kRvvFunct6Shift), 10511cb0ef41Sopenharmony_ci RO_V_VFSGNJX_VF = OP_FVF | (VFSGNJX_FUNCT6 << kRvvFunct6Shift), 10521cb0ef41Sopenharmony_ci 10531cb0ef41Sopenharmony_ci VFMADD_FUNCT6 = 0b101000, 10541cb0ef41Sopenharmony_ci RO_V_VFMADD_VV = OP_FVV | (VFMADD_FUNCT6 << kRvvFunct6Shift), 10551cb0ef41Sopenharmony_ci RO_V_VFMADD_VF = OP_FVF | (VFMADD_FUNCT6 << kRvvFunct6Shift), 10561cb0ef41Sopenharmony_ci 10571cb0ef41Sopenharmony_ci VFNMADD_FUNCT6 = 0b101001, 10581cb0ef41Sopenharmony_ci RO_V_VFNMADD_VV = OP_FVV | (VFNMADD_FUNCT6 << kRvvFunct6Shift), 10591cb0ef41Sopenharmony_ci RO_V_VFNMADD_VF = OP_FVF | (VFNMADD_FUNCT6 << kRvvFunct6Shift), 10601cb0ef41Sopenharmony_ci 10611cb0ef41Sopenharmony_ci VFMSUB_FUNCT6 = 0b101010, 10621cb0ef41Sopenharmony_ci RO_V_VFMSUB_VV = OP_FVV | (VFMSUB_FUNCT6 << kRvvFunct6Shift), 10631cb0ef41Sopenharmony_ci RO_V_VFMSUB_VF = OP_FVF | (VFMSUB_FUNCT6 << kRvvFunct6Shift), 10641cb0ef41Sopenharmony_ci 10651cb0ef41Sopenharmony_ci VFNMSUB_FUNCT6 = 0b101011, 10661cb0ef41Sopenharmony_ci RO_V_VFNMSUB_VV = OP_FVV | (VFNMSUB_FUNCT6 << kRvvFunct6Shift), 10671cb0ef41Sopenharmony_ci RO_V_VFNMSUB_VF = OP_FVF | (VFNMSUB_FUNCT6 << kRvvFunct6Shift), 10681cb0ef41Sopenharmony_ci 10691cb0ef41Sopenharmony_ci VFMACC_FUNCT6 = 0b101100, 10701cb0ef41Sopenharmony_ci RO_V_VFMACC_VV = OP_FVV | (VFMACC_FUNCT6 << kRvvFunct6Shift), 10711cb0ef41Sopenharmony_ci RO_V_VFMACC_VF = OP_FVF | (VFMACC_FUNCT6 << kRvvFunct6Shift), 10721cb0ef41Sopenharmony_ci 10731cb0ef41Sopenharmony_ci VFNMACC_FUNCT6 = 0b101101, 10741cb0ef41Sopenharmony_ci RO_V_VFNMACC_VV = OP_FVV | (VFNMACC_FUNCT6 << kRvvFunct6Shift), 10751cb0ef41Sopenharmony_ci RO_V_VFNMACC_VF = OP_FVF | (VFNMACC_FUNCT6 << kRvvFunct6Shift), 10761cb0ef41Sopenharmony_ci 10771cb0ef41Sopenharmony_ci VFMSAC_FUNCT6 = 0b101110, 10781cb0ef41Sopenharmony_ci RO_V_VFMSAC_VV = OP_FVV | (VFMSAC_FUNCT6 << kRvvFunct6Shift), 10791cb0ef41Sopenharmony_ci RO_V_VFMSAC_VF = OP_FVF | (VFMSAC_FUNCT6 << kRvvFunct6Shift), 10801cb0ef41Sopenharmony_ci 10811cb0ef41Sopenharmony_ci VFNMSAC_FUNCT6 = 0b101111, 10821cb0ef41Sopenharmony_ci RO_V_VFNMSAC_VV = OP_FVV | (VFNMSAC_FUNCT6 << kRvvFunct6Shift), 10831cb0ef41Sopenharmony_ci RO_V_VFNMSAC_VF = OP_FVF | (VFNMSAC_FUNCT6 << kRvvFunct6Shift), 10841cb0ef41Sopenharmony_ci 10851cb0ef41Sopenharmony_ci // Vector Widening Floating-Point Fused Multiply-Add Instructions 10861cb0ef41Sopenharmony_ci VFWMACC_FUNCT6 = 0b111100, 10871cb0ef41Sopenharmony_ci RO_V_VFWMACC_VV = OP_FVV | (VFWMACC_FUNCT6 << kRvvFunct6Shift), 10881cb0ef41Sopenharmony_ci RO_V_VFWMACC_VF = OP_FVF | (VFWMACC_FUNCT6 << kRvvFunct6Shift), 10891cb0ef41Sopenharmony_ci 10901cb0ef41Sopenharmony_ci VFWNMACC_FUNCT6 = 0b111101, 10911cb0ef41Sopenharmony_ci RO_V_VFWNMACC_VV = OP_FVV | (VFWNMACC_FUNCT6 << kRvvFunct6Shift), 10921cb0ef41Sopenharmony_ci RO_V_VFWNMACC_VF = OP_FVF | (VFWNMACC_FUNCT6 << kRvvFunct6Shift), 10931cb0ef41Sopenharmony_ci 10941cb0ef41Sopenharmony_ci VFWMSAC_FUNCT6 = 0b111110, 10951cb0ef41Sopenharmony_ci RO_V_VFWMSAC_VV = OP_FVV | (VFWMSAC_FUNCT6 << kRvvFunct6Shift), 10961cb0ef41Sopenharmony_ci RO_V_VFWMSAC_VF = OP_FVF | (VFWMSAC_FUNCT6 << kRvvFunct6Shift), 10971cb0ef41Sopenharmony_ci 10981cb0ef41Sopenharmony_ci VFWNMSAC_FUNCT6 = 0b111111, 10991cb0ef41Sopenharmony_ci RO_V_VFWNMSAC_VV = OP_FVV | (VFWNMSAC_FUNCT6 << kRvvFunct6Shift), 11001cb0ef41Sopenharmony_ci RO_V_VFWNMSAC_VF = OP_FVF | (VFWNMSAC_FUNCT6 << kRvvFunct6Shift), 11011cb0ef41Sopenharmony_ci 11021cb0ef41Sopenharmony_ci VNCLIP_FUNCT6 = 0b101111, 11031cb0ef41Sopenharmony_ci RO_V_VNCLIP_WV = OP_IVV | (VNCLIP_FUNCT6 << kRvvFunct6Shift), 11041cb0ef41Sopenharmony_ci RO_V_VNCLIP_WX = OP_IVX | (VNCLIP_FUNCT6 << kRvvFunct6Shift), 11051cb0ef41Sopenharmony_ci RO_V_VNCLIP_WI = OP_IVI | (VNCLIP_FUNCT6 << kRvvFunct6Shift), 11061cb0ef41Sopenharmony_ci 11071cb0ef41Sopenharmony_ci VNCLIPU_FUNCT6 = 0b101110, 11081cb0ef41Sopenharmony_ci RO_V_VNCLIPU_WV = OP_IVV | (VNCLIPU_FUNCT6 << kRvvFunct6Shift), 11091cb0ef41Sopenharmony_ci RO_V_VNCLIPU_WX = OP_IVX | (VNCLIPU_FUNCT6 << kRvvFunct6Shift), 11101cb0ef41Sopenharmony_ci RO_V_VNCLIPU_WI = OP_IVI | (VNCLIPU_FUNCT6 << kRvvFunct6Shift), 11111cb0ef41Sopenharmony_ci}; 11121cb0ef41Sopenharmony_ci 11131cb0ef41Sopenharmony_ci// ----- Emulated conditions. 11141cb0ef41Sopenharmony_ci// On RISC-V we use this enum to abstract from conditional branch instructions. 11151cb0ef41Sopenharmony_ci// The 'U' prefix is used to specify unsigned comparisons. 11161cb0ef41Sopenharmony_ci// Opposite conditions must be paired as odd/even numbers 11171cb0ef41Sopenharmony_ci// because 'NegateCondition' function flips LSB to negate condition. 11181cb0ef41Sopenharmony_cienum Condition { // Any value < 0 is considered no_condition. 11191cb0ef41Sopenharmony_ci kNoCondition = -1, 11201cb0ef41Sopenharmony_ci overflow = 0, 11211cb0ef41Sopenharmony_ci no_overflow = 1, 11221cb0ef41Sopenharmony_ci Uless = 2, 11231cb0ef41Sopenharmony_ci Ugreater_equal = 3, 11241cb0ef41Sopenharmony_ci Uless_equal = 4, 11251cb0ef41Sopenharmony_ci Ugreater = 5, 11261cb0ef41Sopenharmony_ci equal = 6, 11271cb0ef41Sopenharmony_ci not_equal = 7, // Unordered or Not Equal. 11281cb0ef41Sopenharmony_ci less = 8, 11291cb0ef41Sopenharmony_ci greater_equal = 9, 11301cb0ef41Sopenharmony_ci less_equal = 10, 11311cb0ef41Sopenharmony_ci greater = 11, 11321cb0ef41Sopenharmony_ci cc_always = 12, 11331cb0ef41Sopenharmony_ci 11341cb0ef41Sopenharmony_ci // Aliases. 11351cb0ef41Sopenharmony_ci eq = equal, 11361cb0ef41Sopenharmony_ci ne = not_equal, 11371cb0ef41Sopenharmony_ci ge = greater_equal, 11381cb0ef41Sopenharmony_ci lt = less, 11391cb0ef41Sopenharmony_ci gt = greater, 11401cb0ef41Sopenharmony_ci le = less_equal, 11411cb0ef41Sopenharmony_ci al = cc_always, 11421cb0ef41Sopenharmony_ci ult = Uless, 11431cb0ef41Sopenharmony_ci uge = Ugreater_equal, 11441cb0ef41Sopenharmony_ci ule = Uless_equal, 11451cb0ef41Sopenharmony_ci ugt = Ugreater, 11461cb0ef41Sopenharmony_ci}; 11471cb0ef41Sopenharmony_ci 11481cb0ef41Sopenharmony_ci// Returns the equivalent of !cc. 11491cb0ef41Sopenharmony_ci// Negation of the default kNoCondition (-1) results in a non-default 11501cb0ef41Sopenharmony_ci// no_condition value (-2). As long as tests for no_condition check 11511cb0ef41Sopenharmony_ci// for condition < 0, this will work as expected. 11521cb0ef41Sopenharmony_ciinline Condition NegateCondition(Condition cc) { 11531cb0ef41Sopenharmony_ci DCHECK(cc != cc_always); 11541cb0ef41Sopenharmony_ci return static_cast<Condition>(cc ^ 1); 11551cb0ef41Sopenharmony_ci} 11561cb0ef41Sopenharmony_ci 11571cb0ef41Sopenharmony_ciinline Condition NegateFpuCondition(Condition cc) { 11581cb0ef41Sopenharmony_ci DCHECK(cc != cc_always); 11591cb0ef41Sopenharmony_ci switch (cc) { 11601cb0ef41Sopenharmony_ci case ult: 11611cb0ef41Sopenharmony_ci return ge; 11621cb0ef41Sopenharmony_ci case ugt: 11631cb0ef41Sopenharmony_ci return le; 11641cb0ef41Sopenharmony_ci case uge: 11651cb0ef41Sopenharmony_ci return lt; 11661cb0ef41Sopenharmony_ci case ule: 11671cb0ef41Sopenharmony_ci return gt; 11681cb0ef41Sopenharmony_ci case lt: 11691cb0ef41Sopenharmony_ci return uge; 11701cb0ef41Sopenharmony_ci case gt: 11711cb0ef41Sopenharmony_ci return ule; 11721cb0ef41Sopenharmony_ci case ge: 11731cb0ef41Sopenharmony_ci return ult; 11741cb0ef41Sopenharmony_ci case le: 11751cb0ef41Sopenharmony_ci return ugt; 11761cb0ef41Sopenharmony_ci case eq: 11771cb0ef41Sopenharmony_ci return ne; 11781cb0ef41Sopenharmony_ci case ne: 11791cb0ef41Sopenharmony_ci return eq; 11801cb0ef41Sopenharmony_ci default: 11811cb0ef41Sopenharmony_ci return cc; 11821cb0ef41Sopenharmony_ci } 11831cb0ef41Sopenharmony_ci} 11841cb0ef41Sopenharmony_ci 11851cb0ef41Sopenharmony_ci// ----- Coprocessor conditions. 11861cb0ef41Sopenharmony_cienum FPUCondition { 11871cb0ef41Sopenharmony_ci kNoFPUCondition = -1, 11881cb0ef41Sopenharmony_ci EQ = 0x02, // Ordered and Equal 11891cb0ef41Sopenharmony_ci NE = 0x03, // Unordered or Not Equal 11901cb0ef41Sopenharmony_ci LT = 0x04, // Ordered and Less Than 11911cb0ef41Sopenharmony_ci GE = 0x05, // Ordered and Greater Than or Equal 11921cb0ef41Sopenharmony_ci LE = 0x06, // Ordered and Less Than or Equal 11931cb0ef41Sopenharmony_ci GT = 0x07, // Ordered and Greater Than 11941cb0ef41Sopenharmony_ci}; 11951cb0ef41Sopenharmony_ci 11961cb0ef41Sopenharmony_cienum CheckForInexactConversion { 11971cb0ef41Sopenharmony_ci kCheckForInexactConversion, 11981cb0ef41Sopenharmony_ci kDontCheckForInexactConversion 11991cb0ef41Sopenharmony_ci}; 12001cb0ef41Sopenharmony_ci 12011cb0ef41Sopenharmony_cienum class MaxMinKind : int { kMin = 0, kMax = 1 }; 12021cb0ef41Sopenharmony_ci 12031cb0ef41Sopenharmony_ci// ---------------------------------------------------------------------------- 12041cb0ef41Sopenharmony_ci// RISCV flags 12051cb0ef41Sopenharmony_ci 12061cb0ef41Sopenharmony_cienum ControlStatusReg { 12071cb0ef41Sopenharmony_ci csr_fflags = 0x001, // Floating-Point Accrued Exceptions (RW) 12081cb0ef41Sopenharmony_ci csr_frm = 0x002, // Floating-Point Dynamic Rounding Mode (RW) 12091cb0ef41Sopenharmony_ci csr_fcsr = 0x003, // Floating-Point Control and Status Register (RW) 12101cb0ef41Sopenharmony_ci csr_cycle = 0xc00, // Cycle counter for RDCYCLE instruction (RO) 12111cb0ef41Sopenharmony_ci csr_time = 0xc01, // Timer for RDTIME instruction (RO) 12121cb0ef41Sopenharmony_ci csr_instret = 0xc02, // Insns-retired counter for RDINSTRET instruction (RO) 12131cb0ef41Sopenharmony_ci csr_cycleh = 0xc80, // Upper 32 bits of cycle, RV32I only (RO) 12141cb0ef41Sopenharmony_ci csr_timeh = 0xc81, // Upper 32 bits of time, RV32I only (RO) 12151cb0ef41Sopenharmony_ci csr_instreth = 0xc82 // Upper 32 bits of instret, RV32I only (RO) 12161cb0ef41Sopenharmony_ci}; 12171cb0ef41Sopenharmony_ci 12181cb0ef41Sopenharmony_cienum FFlagsMask { 12191cb0ef41Sopenharmony_ci kInvalidOperation = 0b10000, // NV: Invalid 12201cb0ef41Sopenharmony_ci kDivideByZero = 0b1000, // DZ: Divide by Zero 12211cb0ef41Sopenharmony_ci kOverflow = 0b100, // OF: Overflow 12221cb0ef41Sopenharmony_ci kUnderflow = 0b10, // UF: Underflow 12231cb0ef41Sopenharmony_ci kInexact = 0b1 // NX: Inexact 12241cb0ef41Sopenharmony_ci}; 12251cb0ef41Sopenharmony_ci 12261cb0ef41Sopenharmony_cienum RoundingMode { 12271cb0ef41Sopenharmony_ci RNE = 0b000, // Round to Nearest, ties to Even 12281cb0ef41Sopenharmony_ci RTZ = 0b001, // Round towards Zero 12291cb0ef41Sopenharmony_ci RDN = 0b010, // Round Down (towards -infinity) 12301cb0ef41Sopenharmony_ci RUP = 0b011, // Round Up (towards +infinity) 12311cb0ef41Sopenharmony_ci RMM = 0b100, // Round to Nearest, tiest to Max Magnitude 12321cb0ef41Sopenharmony_ci DYN = 0b111 // In instruction's rm field, selects dynamic rounding mode; 12331cb0ef41Sopenharmony_ci // In Rounding Mode register, Invalid 12341cb0ef41Sopenharmony_ci}; 12351cb0ef41Sopenharmony_ci 12361cb0ef41Sopenharmony_cienum MemoryOdering { 12371cb0ef41Sopenharmony_ci PSI = 0b1000, // PI or SI 12381cb0ef41Sopenharmony_ci PSO = 0b0100, // PO or SO 12391cb0ef41Sopenharmony_ci PSR = 0b0010, // PR or SR 12401cb0ef41Sopenharmony_ci PSW = 0b0001, // PW or SW 12411cb0ef41Sopenharmony_ci PSIORW = PSI | PSO | PSR | PSW 12421cb0ef41Sopenharmony_ci}; 12431cb0ef41Sopenharmony_ci 12441cb0ef41Sopenharmony_ciconst int kFloat32ExponentBias = 127; 12451cb0ef41Sopenharmony_ciconst int kFloat32MantissaBits = 23; 12461cb0ef41Sopenharmony_ciconst int kFloat32ExponentBits = 8; 12471cb0ef41Sopenharmony_ciconst int kFloat64ExponentBias = 1023; 12481cb0ef41Sopenharmony_ciconst int kFloat64MantissaBits = 52; 12491cb0ef41Sopenharmony_ciconst int kFloat64ExponentBits = 11; 12501cb0ef41Sopenharmony_ci 12511cb0ef41Sopenharmony_cienum FClassFlag { 12521cb0ef41Sopenharmony_ci kNegativeInfinity = 1, 12531cb0ef41Sopenharmony_ci kNegativeNormalNumber = 1 << 1, 12541cb0ef41Sopenharmony_ci kNegativeSubnormalNumber = 1 << 2, 12551cb0ef41Sopenharmony_ci kNegativeZero = 1 << 3, 12561cb0ef41Sopenharmony_ci kPositiveZero = 1 << 4, 12571cb0ef41Sopenharmony_ci kPositiveSubnormalNumber = 1 << 5, 12581cb0ef41Sopenharmony_ci kPositiveNormalNumber = 1 << 6, 12591cb0ef41Sopenharmony_ci kPositiveInfinity = 1 << 7, 12601cb0ef41Sopenharmony_ci kSignalingNaN = 1 << 8, 12611cb0ef41Sopenharmony_ci kQuietNaN = 1 << 9 12621cb0ef41Sopenharmony_ci}; 12631cb0ef41Sopenharmony_ci 12641cb0ef41Sopenharmony_ci#define RVV_SEW(V) \ 12651cb0ef41Sopenharmony_ci V(E8) \ 12661cb0ef41Sopenharmony_ci V(E16) \ 12671cb0ef41Sopenharmony_ci V(E32) \ 12681cb0ef41Sopenharmony_ci V(E64) 12691cb0ef41Sopenharmony_ci 12701cb0ef41Sopenharmony_ci#define DEFINE_FLAG(name) name, 12711cb0ef41Sopenharmony_cienum VSew { 12721cb0ef41Sopenharmony_ci RVV_SEW(DEFINE_FLAG) 12731cb0ef41Sopenharmony_ci#undef DEFINE_FLAG 12741cb0ef41Sopenharmony_ci}; 12751cb0ef41Sopenharmony_ci 12761cb0ef41Sopenharmony_ci#define RVV_LMUL(V) \ 12771cb0ef41Sopenharmony_ci V(m1) \ 12781cb0ef41Sopenharmony_ci V(m2) \ 12791cb0ef41Sopenharmony_ci V(m4) \ 12801cb0ef41Sopenharmony_ci V(m8) \ 12811cb0ef41Sopenharmony_ci V(RESERVERD) \ 12821cb0ef41Sopenharmony_ci V(mf8) \ 12831cb0ef41Sopenharmony_ci V(mf4) \ 12841cb0ef41Sopenharmony_ci V(mf2) 12851cb0ef41Sopenharmony_ci 12861cb0ef41Sopenharmony_cienum Vlmul { 12871cb0ef41Sopenharmony_ci#define DEFINE_FLAG(name) name, 12881cb0ef41Sopenharmony_ci RVV_LMUL(DEFINE_FLAG) 12891cb0ef41Sopenharmony_ci#undef DEFINE_FLAG 12901cb0ef41Sopenharmony_ci}; 12911cb0ef41Sopenharmony_ci 12921cb0ef41Sopenharmony_cienum TailAgnosticType { 12931cb0ef41Sopenharmony_ci ta = 0x1, // Tail agnostic 12941cb0ef41Sopenharmony_ci tu = 0x0, // Tail undisturbed 12951cb0ef41Sopenharmony_ci}; 12961cb0ef41Sopenharmony_ci 12971cb0ef41Sopenharmony_cienum MaskAgnosticType { 12981cb0ef41Sopenharmony_ci ma = 0x1, // Mask agnostic 12991cb0ef41Sopenharmony_ci mu = 0x0, // Mask undisturbed 13001cb0ef41Sopenharmony_ci}; 13011cb0ef41Sopenharmony_cienum MaskType { 13021cb0ef41Sopenharmony_ci Mask = 0x0, // use the mask 13031cb0ef41Sopenharmony_ci NoMask = 0x1, 13041cb0ef41Sopenharmony_ci}; 13051cb0ef41Sopenharmony_ci 13061cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 13071cb0ef41Sopenharmony_ci// Hints. 13081cb0ef41Sopenharmony_ci 13091cb0ef41Sopenharmony_ci// Branch hints are not used on RISC-V. They are defined so that they can 13101cb0ef41Sopenharmony_ci// appear in shared function signatures, but will be ignored in RISC-V 13111cb0ef41Sopenharmony_ci// implementations. 13121cb0ef41Sopenharmony_cienum Hint { no_hint = 0 }; 13131cb0ef41Sopenharmony_ci 13141cb0ef41Sopenharmony_ciinline Hint NegateHint(Hint hint) { return no_hint; } 13151cb0ef41Sopenharmony_ci 13161cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 13171cb0ef41Sopenharmony_ci// Specific instructions, constants, and masks. 13181cb0ef41Sopenharmony_ci// These constants are declared in assembler-riscv64.cc, as they use named 13191cb0ef41Sopenharmony_ci// registers and other constants. 13201cb0ef41Sopenharmony_ci 13211cb0ef41Sopenharmony_ci// An Illegal instruction 13221cb0ef41Sopenharmony_ciconst Instr kIllegalInstr = 0; // All other bits are 0s (i.e., ecall) 13231cb0ef41Sopenharmony_ci// An ECALL instruction, used for redirected real time call 13241cb0ef41Sopenharmony_ciconst Instr rtCallRedirInstr = SYSTEM; // All other bits are 0s (i.e., ecall) 13251cb0ef41Sopenharmony_ci// An EBreak instruction, used for debugging and semi-hosting 13261cb0ef41Sopenharmony_ciconst Instr kBreakInstr = SYSTEM | 1 << kImm12Shift; // ebreak 13271cb0ef41Sopenharmony_ci 13281cb0ef41Sopenharmony_ciconstexpr uint8_t kInstrSize = 4; 13291cb0ef41Sopenharmony_ciconstexpr uint8_t kShortInstrSize = 2; 13301cb0ef41Sopenharmony_ciconstexpr uint8_t kInstrSizeLog2 = 2; 13311cb0ef41Sopenharmony_ci 13321cb0ef41Sopenharmony_ciclass InstructionBase { 13331cb0ef41Sopenharmony_ci public: 13341cb0ef41Sopenharmony_ci enum { 13351cb0ef41Sopenharmony_ci // On RISC-V, PC cannot actually be directly accessed. We behave as if PC 13361cb0ef41Sopenharmony_ci // was always the value of the current instruction being executed. 13371cb0ef41Sopenharmony_ci kPCReadOffset = 0 13381cb0ef41Sopenharmony_ci }; 13391cb0ef41Sopenharmony_ci 13401cb0ef41Sopenharmony_ci // Instruction type. 13411cb0ef41Sopenharmony_ci enum Type { 13421cb0ef41Sopenharmony_ci kRType, 13431cb0ef41Sopenharmony_ci kR4Type, // Special R4 for Q extension 13441cb0ef41Sopenharmony_ci kIType, 13451cb0ef41Sopenharmony_ci kSType, 13461cb0ef41Sopenharmony_ci kBType, 13471cb0ef41Sopenharmony_ci kUType, 13481cb0ef41Sopenharmony_ci kJType, 13491cb0ef41Sopenharmony_ci // C extension 13501cb0ef41Sopenharmony_ci kCRType, 13511cb0ef41Sopenharmony_ci kCIType, 13521cb0ef41Sopenharmony_ci kCSSType, 13531cb0ef41Sopenharmony_ci kCIWType, 13541cb0ef41Sopenharmony_ci kCLType, 13551cb0ef41Sopenharmony_ci kCSType, 13561cb0ef41Sopenharmony_ci kCAType, 13571cb0ef41Sopenharmony_ci kCBType, 13581cb0ef41Sopenharmony_ci kCJType, 13591cb0ef41Sopenharmony_ci // V extension 13601cb0ef41Sopenharmony_ci kVType, 13611cb0ef41Sopenharmony_ci kVLType, 13621cb0ef41Sopenharmony_ci kVSType, 13631cb0ef41Sopenharmony_ci kVAMOType, 13641cb0ef41Sopenharmony_ci kVIVVType, 13651cb0ef41Sopenharmony_ci kVFVVType, 13661cb0ef41Sopenharmony_ci kVMVVType, 13671cb0ef41Sopenharmony_ci kVIVIType, 13681cb0ef41Sopenharmony_ci kVIVXType, 13691cb0ef41Sopenharmony_ci kVFVFType, 13701cb0ef41Sopenharmony_ci kVMVXType, 13711cb0ef41Sopenharmony_ci kVSETType, 13721cb0ef41Sopenharmony_ci kUnsupported = -1 13731cb0ef41Sopenharmony_ci }; 13741cb0ef41Sopenharmony_ci 13751cb0ef41Sopenharmony_ci inline bool IsIllegalInstruction() const { 13761cb0ef41Sopenharmony_ci uint16_t FirstHalfWord = *reinterpret_cast<const uint16_t*>(this); 13771cb0ef41Sopenharmony_ci return FirstHalfWord == 0; 13781cb0ef41Sopenharmony_ci } 13791cb0ef41Sopenharmony_ci 13801cb0ef41Sopenharmony_ci inline bool IsShortInstruction() const { 13811cb0ef41Sopenharmony_ci uint8_t FirstByte = *reinterpret_cast<const uint8_t*>(this); 13821cb0ef41Sopenharmony_ci return (FirstByte & 0x03) <= C2; 13831cb0ef41Sopenharmony_ci } 13841cb0ef41Sopenharmony_ci 13851cb0ef41Sopenharmony_ci inline uint8_t InstructionSize() const { 13861cb0ef41Sopenharmony_ci return (FLAG_riscv_c_extension && this->IsShortInstruction()) 13871cb0ef41Sopenharmony_ci ? kShortInstrSize 13881cb0ef41Sopenharmony_ci : kInstrSize; 13891cb0ef41Sopenharmony_ci } 13901cb0ef41Sopenharmony_ci 13911cb0ef41Sopenharmony_ci // Get the raw instruction bits. 13921cb0ef41Sopenharmony_ci inline Instr InstructionBits() const { 13931cb0ef41Sopenharmony_ci if (FLAG_riscv_c_extension && this->IsShortInstruction()) { 13941cb0ef41Sopenharmony_ci return 0x0000FFFF & (*reinterpret_cast<const ShortInstr*>(this)); 13951cb0ef41Sopenharmony_ci } 13961cb0ef41Sopenharmony_ci return *reinterpret_cast<const Instr*>(this); 13971cb0ef41Sopenharmony_ci } 13981cb0ef41Sopenharmony_ci 13991cb0ef41Sopenharmony_ci // Set the raw instruction bits to value. 14001cb0ef41Sopenharmony_ci inline void SetInstructionBits(Instr value) { 14011cb0ef41Sopenharmony_ci *reinterpret_cast<Instr*>(this) = value; 14021cb0ef41Sopenharmony_ci } 14031cb0ef41Sopenharmony_ci 14041cb0ef41Sopenharmony_ci // Read one particular bit out of the instruction bits. 14051cb0ef41Sopenharmony_ci inline int Bit(int nr) const { return (InstructionBits() >> nr) & 1; } 14061cb0ef41Sopenharmony_ci 14071cb0ef41Sopenharmony_ci // Read a bit field out of the instruction bits. 14081cb0ef41Sopenharmony_ci inline int Bits(int hi, int lo) const { 14091cb0ef41Sopenharmony_ci return (InstructionBits() >> lo) & ((2U << (hi - lo)) - 1); 14101cb0ef41Sopenharmony_ci } 14111cb0ef41Sopenharmony_ci 14121cb0ef41Sopenharmony_ci // Accessors for the different named fields used in the RISC-V encoding. 14131cb0ef41Sopenharmony_ci inline Opcode BaseOpcodeValue() const { 14141cb0ef41Sopenharmony_ci return static_cast<Opcode>( 14151cb0ef41Sopenharmony_ci Bits(kBaseOpcodeShift + kBaseOpcodeBits - 1, kBaseOpcodeShift)); 14161cb0ef41Sopenharmony_ci } 14171cb0ef41Sopenharmony_ci 14181cb0ef41Sopenharmony_ci // Return the fields at their original place in the instruction encoding. 14191cb0ef41Sopenharmony_ci inline Opcode BaseOpcodeFieldRaw() const { 14201cb0ef41Sopenharmony_ci return static_cast<Opcode>(InstructionBits() & kBaseOpcodeMask); 14211cb0ef41Sopenharmony_ci } 14221cb0ef41Sopenharmony_ci 14231cb0ef41Sopenharmony_ci // Safe to call within R-type instructions 14241cb0ef41Sopenharmony_ci inline int Funct7FieldRaw() const { return InstructionBits() & kFunct7Mask; } 14251cb0ef41Sopenharmony_ci 14261cb0ef41Sopenharmony_ci // Safe to call within R-, I-, S-, or B-type instructions 14271cb0ef41Sopenharmony_ci inline int Funct3FieldRaw() const { return InstructionBits() & kFunct3Mask; } 14281cb0ef41Sopenharmony_ci 14291cb0ef41Sopenharmony_ci // Safe to call within R-, I-, S-, or B-type instructions 14301cb0ef41Sopenharmony_ci inline int Rs1FieldRawNoAssert() const { 14311cb0ef41Sopenharmony_ci return InstructionBits() & kRs1FieldMask; 14321cb0ef41Sopenharmony_ci } 14331cb0ef41Sopenharmony_ci 14341cb0ef41Sopenharmony_ci // Safe to call within R-, S-, or B-type instructions 14351cb0ef41Sopenharmony_ci inline int Rs2FieldRawNoAssert() const { 14361cb0ef41Sopenharmony_ci return InstructionBits() & kRs2FieldMask; 14371cb0ef41Sopenharmony_ci } 14381cb0ef41Sopenharmony_ci 14391cb0ef41Sopenharmony_ci // Safe to call within R4-type instructions 14401cb0ef41Sopenharmony_ci inline int Rs3FieldRawNoAssert() const { 14411cb0ef41Sopenharmony_ci return InstructionBits() & kRs3FieldMask; 14421cb0ef41Sopenharmony_ci } 14431cb0ef41Sopenharmony_ci 14441cb0ef41Sopenharmony_ci inline int32_t ITypeBits() const { return InstructionBits() & kITypeMask; } 14451cb0ef41Sopenharmony_ci 14461cb0ef41Sopenharmony_ci inline int32_t InstructionOpcodeType() const { 14471cb0ef41Sopenharmony_ci if (IsShortInstruction()) { 14481cb0ef41Sopenharmony_ci return InstructionBits() & kRvcOpcodeMask; 14491cb0ef41Sopenharmony_ci } else { 14501cb0ef41Sopenharmony_ci return InstructionBits() & kBaseOpcodeMask; 14511cb0ef41Sopenharmony_ci } 14521cb0ef41Sopenharmony_ci } 14531cb0ef41Sopenharmony_ci 14541cb0ef41Sopenharmony_ci // Get the encoding type of the instruction. 14551cb0ef41Sopenharmony_ci Type InstructionType() const; 14561cb0ef41Sopenharmony_ci 14571cb0ef41Sopenharmony_ci protected: 14581cb0ef41Sopenharmony_ci InstructionBase() {} 14591cb0ef41Sopenharmony_ci}; 14601cb0ef41Sopenharmony_ci 14611cb0ef41Sopenharmony_citemplate <class T> 14621cb0ef41Sopenharmony_ciclass InstructionGetters : public T { 14631cb0ef41Sopenharmony_ci public: 14641cb0ef41Sopenharmony_ci inline int BaseOpcode() const { 14651cb0ef41Sopenharmony_ci return this->InstructionBits() & kBaseOpcodeMask; 14661cb0ef41Sopenharmony_ci } 14671cb0ef41Sopenharmony_ci 14681cb0ef41Sopenharmony_ci inline int RvcOpcode() const { 14691cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 14701cb0ef41Sopenharmony_ci return this->InstructionBits() & kRvcOpcodeMask; 14711cb0ef41Sopenharmony_ci } 14721cb0ef41Sopenharmony_ci 14731cb0ef41Sopenharmony_ci inline int Rs1Value() const { 14741cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kRType || 14751cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kR4Type || 14761cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 14771cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kSType || 14781cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kBType || 14791cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 14801cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kVType); 14811cb0ef41Sopenharmony_ci return this->Bits(kRs1Shift + kRs1Bits - 1, kRs1Shift); 14821cb0ef41Sopenharmony_ci } 14831cb0ef41Sopenharmony_ci 14841cb0ef41Sopenharmony_ci inline int Rs2Value() const { 14851cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kRType || 14861cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kR4Type || 14871cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kSType || 14881cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kBType || 14891cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 14901cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kVType); 14911cb0ef41Sopenharmony_ci return this->Bits(kRs2Shift + kRs2Bits - 1, kRs2Shift); 14921cb0ef41Sopenharmony_ci } 14931cb0ef41Sopenharmony_ci 14941cb0ef41Sopenharmony_ci inline int Rs3Value() const { 14951cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kR4Type); 14961cb0ef41Sopenharmony_ci return this->Bits(kRs3Shift + kRs3Bits - 1, kRs3Shift); 14971cb0ef41Sopenharmony_ci } 14981cb0ef41Sopenharmony_ci 14991cb0ef41Sopenharmony_ci inline int Vs1Value() const { 15001cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kVType || 15011cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 15021cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kSType); 15031cb0ef41Sopenharmony_ci return this->Bits(kVs1Shift + kVs1Bits - 1, kVs1Shift); 15041cb0ef41Sopenharmony_ci } 15051cb0ef41Sopenharmony_ci 15061cb0ef41Sopenharmony_ci inline int Vs2Value() const { 15071cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kVType || 15081cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 15091cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kSType); 15101cb0ef41Sopenharmony_ci return this->Bits(kVs2Shift + kVs2Bits - 1, kVs2Shift); 15111cb0ef41Sopenharmony_ci } 15121cb0ef41Sopenharmony_ci 15131cb0ef41Sopenharmony_ci inline int VdValue() const { 15141cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kVType || 15151cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 15161cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kSType); 15171cb0ef41Sopenharmony_ci return this->Bits(kVdShift + kVdBits - 1, kVdShift); 15181cb0ef41Sopenharmony_ci } 15191cb0ef41Sopenharmony_ci 15201cb0ef41Sopenharmony_ci inline int RdValue() const { 15211cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kRType || 15221cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kR4Type || 15231cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 15241cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kSType || 15251cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kUType || 15261cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kJType || 15271cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kVType); 15281cb0ef41Sopenharmony_ci return this->Bits(kRdShift + kRdBits - 1, kRdShift); 15291cb0ef41Sopenharmony_ci } 15301cb0ef41Sopenharmony_ci 15311cb0ef41Sopenharmony_ci inline int RvcRdValue() const { 15321cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15331cb0ef41Sopenharmony_ci return this->Bits(kRvcRdShift + kRvcRdBits - 1, kRvcRdShift); 15341cb0ef41Sopenharmony_ci } 15351cb0ef41Sopenharmony_ci 15361cb0ef41Sopenharmony_ci inline int RvcRs1Value() const { return this->RvcRdValue(); } 15371cb0ef41Sopenharmony_ci 15381cb0ef41Sopenharmony_ci inline int RvcRs2Value() const { 15391cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15401cb0ef41Sopenharmony_ci return this->Bits(kRvcRs2Shift + kRvcRs2Bits - 1, kRvcRs2Shift); 15411cb0ef41Sopenharmony_ci } 15421cb0ef41Sopenharmony_ci 15431cb0ef41Sopenharmony_ci inline int RvcRs1sValue() const { 15441cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15451cb0ef41Sopenharmony_ci return 0b1000 + this->Bits(kRvcRs1sShift + kRvcRs1sBits - 1, kRvcRs1sShift); 15461cb0ef41Sopenharmony_ci } 15471cb0ef41Sopenharmony_ci 15481cb0ef41Sopenharmony_ci inline int RvcRs2sValue() const { 15491cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15501cb0ef41Sopenharmony_ci return 0b1000 + this->Bits(kRvcRs2sShift + kRvcRs2sBits - 1, kRvcRs2sShift); 15511cb0ef41Sopenharmony_ci } 15521cb0ef41Sopenharmony_ci 15531cb0ef41Sopenharmony_ci inline int Funct7Value() const { 15541cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kRType); 15551cb0ef41Sopenharmony_ci return this->Bits(kFunct7Shift + kFunct7Bits - 1, kFunct7Shift); 15561cb0ef41Sopenharmony_ci } 15571cb0ef41Sopenharmony_ci 15581cb0ef41Sopenharmony_ci inline int Funct3Value() const { 15591cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kRType || 15601cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 15611cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kSType || 15621cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kBType); 15631cb0ef41Sopenharmony_ci return this->Bits(kFunct3Shift + kFunct3Bits - 1, kFunct3Shift); 15641cb0ef41Sopenharmony_ci } 15651cb0ef41Sopenharmony_ci 15661cb0ef41Sopenharmony_ci inline int Funct5Value() const { 15671cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kRType && 15681cb0ef41Sopenharmony_ci this->BaseOpcode() == OP_FP); 15691cb0ef41Sopenharmony_ci return this->Bits(kFunct5Shift + kFunct5Bits - 1, kFunct5Shift); 15701cb0ef41Sopenharmony_ci } 15711cb0ef41Sopenharmony_ci 15721cb0ef41Sopenharmony_ci inline int RvcFunct6Value() const { 15731cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15741cb0ef41Sopenharmony_ci return this->Bits(kRvcFunct6Shift + kRvcFunct6Bits - 1, kRvcFunct6Shift); 15751cb0ef41Sopenharmony_ci } 15761cb0ef41Sopenharmony_ci 15771cb0ef41Sopenharmony_ci inline int RvcFunct4Value() const { 15781cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15791cb0ef41Sopenharmony_ci return this->Bits(kRvcFunct4Shift + kRvcFunct4Bits - 1, kRvcFunct4Shift); 15801cb0ef41Sopenharmony_ci } 15811cb0ef41Sopenharmony_ci 15821cb0ef41Sopenharmony_ci inline int RvcFunct3Value() const { 15831cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15841cb0ef41Sopenharmony_ci return this->Bits(kRvcFunct3Shift + kRvcFunct3Bits - 1, kRvcFunct3Shift); 15851cb0ef41Sopenharmony_ci } 15861cb0ef41Sopenharmony_ci 15871cb0ef41Sopenharmony_ci inline int RvcFunct2Value() const { 15881cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15891cb0ef41Sopenharmony_ci return this->Bits(kRvcFunct2Shift + kRvcFunct2Bits - 1, kRvcFunct2Shift); 15901cb0ef41Sopenharmony_ci } 15911cb0ef41Sopenharmony_ci 15921cb0ef41Sopenharmony_ci inline int RvcFunct2BValue() const { 15931cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 15941cb0ef41Sopenharmony_ci return this->Bits(kRvcFunct2BShift + kRvcFunct2Bits - 1, kRvcFunct2BShift); 15951cb0ef41Sopenharmony_ci } 15961cb0ef41Sopenharmony_ci 15971cb0ef41Sopenharmony_ci inline int CsrValue() const { 15981cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kIType && 15991cb0ef41Sopenharmony_ci this->BaseOpcode() == SYSTEM); 16001cb0ef41Sopenharmony_ci return (this->Bits(kCsrShift + kCsrBits - 1, kCsrShift)); 16011cb0ef41Sopenharmony_ci } 16021cb0ef41Sopenharmony_ci 16031cb0ef41Sopenharmony_ci inline int RoundMode() const { 16041cb0ef41Sopenharmony_ci DCHECK((this->InstructionType() == InstructionBase::kRType || 16051cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kR4Type) && 16061cb0ef41Sopenharmony_ci this->BaseOpcode() == OP_FP); 16071cb0ef41Sopenharmony_ci return this->Bits(kFunct3Shift + kFunct3Bits - 1, kFunct3Shift); 16081cb0ef41Sopenharmony_ci } 16091cb0ef41Sopenharmony_ci 16101cb0ef41Sopenharmony_ci inline int MemoryOrder(bool is_pred) const { 16111cb0ef41Sopenharmony_ci DCHECK((this->InstructionType() == InstructionBase::kIType && 16121cb0ef41Sopenharmony_ci this->BaseOpcode() == MISC_MEM)); 16131cb0ef41Sopenharmony_ci if (is_pred) { 16141cb0ef41Sopenharmony_ci return this->Bits(kPredOrderShift + kMemOrderBits - 1, kPredOrderShift); 16151cb0ef41Sopenharmony_ci } else { 16161cb0ef41Sopenharmony_ci return this->Bits(kSuccOrderShift + kMemOrderBits - 1, kSuccOrderShift); 16171cb0ef41Sopenharmony_ci } 16181cb0ef41Sopenharmony_ci } 16191cb0ef41Sopenharmony_ci 16201cb0ef41Sopenharmony_ci inline int Imm12Value() const { 16211cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kIType); 16221cb0ef41Sopenharmony_ci int Value = this->Bits(kImm12Shift + kImm12Bits - 1, kImm12Shift); 16231cb0ef41Sopenharmony_ci return Value << 20 >> 20; 16241cb0ef41Sopenharmony_ci } 16251cb0ef41Sopenharmony_ci 16261cb0ef41Sopenharmony_ci inline int32_t Imm12SExtValue() const { 16271cb0ef41Sopenharmony_ci int32_t Value = this->Imm12Value() << 20 >> 20; 16281cb0ef41Sopenharmony_ci return Value; 16291cb0ef41Sopenharmony_ci } 16301cb0ef41Sopenharmony_ci 16311cb0ef41Sopenharmony_ci inline int BranchOffset() const { 16321cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kBType); 16331cb0ef41Sopenharmony_ci // | imm[12|10:5] | rs2 | rs1 | funct3 | imm[4:1|11] | opcode | 16341cb0ef41Sopenharmony_ci // 31 25 11 7 16351cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 16361cb0ef41Sopenharmony_ci int16_t imm13 = ((Bits & 0xf00) >> 7) | ((Bits & 0x7e000000) >> 20) | 16371cb0ef41Sopenharmony_ci ((Bits & 0x80) << 4) | ((Bits & 0x80000000) >> 19); 16381cb0ef41Sopenharmony_ci return imm13 << 19 >> 19; 16391cb0ef41Sopenharmony_ci } 16401cb0ef41Sopenharmony_ci 16411cb0ef41Sopenharmony_ci inline int StoreOffset() const { 16421cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kSType); 16431cb0ef41Sopenharmony_ci // | imm[11:5] | rs2 | rs1 | funct3 | imm[4:0] | opcode | 16441cb0ef41Sopenharmony_ci // 31 25 11 7 16451cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 16461cb0ef41Sopenharmony_ci int16_t imm12 = ((Bits & 0xf80) >> 7) | ((Bits & 0xfe000000) >> 20); 16471cb0ef41Sopenharmony_ci return imm12 << 20 >> 20; 16481cb0ef41Sopenharmony_ci } 16491cb0ef41Sopenharmony_ci 16501cb0ef41Sopenharmony_ci inline int Imm20UValue() const { 16511cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kUType); 16521cb0ef41Sopenharmony_ci // | imm[31:12] | rd | opcode | 16531cb0ef41Sopenharmony_ci // 31 12 16541cb0ef41Sopenharmony_ci int32_t Bits = this->InstructionBits(); 16551cb0ef41Sopenharmony_ci return Bits >> 12; 16561cb0ef41Sopenharmony_ci } 16571cb0ef41Sopenharmony_ci 16581cb0ef41Sopenharmony_ci inline int Imm20JValue() const { 16591cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kJType); 16601cb0ef41Sopenharmony_ci // | imm[20|10:1|11|19:12] | rd | opcode | 16611cb0ef41Sopenharmony_ci // 31 12 16621cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 16631cb0ef41Sopenharmony_ci int32_t imm20 = ((Bits & 0x7fe00000) >> 20) | ((Bits & 0x100000) >> 9) | 16641cb0ef41Sopenharmony_ci (Bits & 0xff000) | ((Bits & 0x80000000) >> 11); 16651cb0ef41Sopenharmony_ci return imm20 << 11 >> 11; 16661cb0ef41Sopenharmony_ci } 16671cb0ef41Sopenharmony_ci 16681cb0ef41Sopenharmony_ci inline bool IsArithShift() const { 16691cb0ef41Sopenharmony_ci // Valid only for right shift operations 16701cb0ef41Sopenharmony_ci DCHECK((this->BaseOpcode() == OP || this->BaseOpcode() == OP_32 || 16711cb0ef41Sopenharmony_ci this->BaseOpcode() == OP_IMM || this->BaseOpcode() == OP_IMM_32) && 16721cb0ef41Sopenharmony_ci this->Funct3Value() == 0b101); 16731cb0ef41Sopenharmony_ci return this->InstructionBits() & 0x40000000; 16741cb0ef41Sopenharmony_ci } 16751cb0ef41Sopenharmony_ci 16761cb0ef41Sopenharmony_ci inline int Shamt() const { 16771cb0ef41Sopenharmony_ci // Valid only for shift instructions (SLLI, SRLI, SRAI) 16781cb0ef41Sopenharmony_ci DCHECK((this->InstructionBits() & kBaseOpcodeMask) == OP_IMM && 16791cb0ef41Sopenharmony_ci (this->Funct3Value() == 0b001 || this->Funct3Value() == 0b101)); 16801cb0ef41Sopenharmony_ci // | 0A0000 | shamt | rs1 | funct3 | rd | opcode | 16811cb0ef41Sopenharmony_ci // 31 25 20 16821cb0ef41Sopenharmony_ci return this->Bits(kImm12Shift + 5, kImm12Shift); 16831cb0ef41Sopenharmony_ci } 16841cb0ef41Sopenharmony_ci 16851cb0ef41Sopenharmony_ci inline int Shamt32() const { 16861cb0ef41Sopenharmony_ci // Valid only for shift instructions (SLLIW, SRLIW, SRAIW) 16871cb0ef41Sopenharmony_ci DCHECK((this->InstructionBits() & kBaseOpcodeMask) == OP_IMM_32 && 16881cb0ef41Sopenharmony_ci (this->Funct3Value() == 0b001 || this->Funct3Value() == 0b101)); 16891cb0ef41Sopenharmony_ci // | 0A00000 | shamt | rs1 | funct3 | rd | opcode | 16901cb0ef41Sopenharmony_ci // 31 24 20 16911cb0ef41Sopenharmony_ci return this->Bits(kImm12Shift + 4, kImm12Shift); 16921cb0ef41Sopenharmony_ci } 16931cb0ef41Sopenharmony_ci 16941cb0ef41Sopenharmony_ci inline int RvcImm6Value() const { 16951cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 16961cb0ef41Sopenharmony_ci // | funct3 | imm[5] | rs1/rd | imm[4:0] | opcode | 16971cb0ef41Sopenharmony_ci // 15 12 6 2 16981cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 16991cb0ef41Sopenharmony_ci int32_t imm6 = ((Bits & 0x1000) >> 7) | ((Bits & 0x7c) >> 2); 17001cb0ef41Sopenharmony_ci return imm6 << 26 >> 26; 17011cb0ef41Sopenharmony_ci } 17021cb0ef41Sopenharmony_ci 17031cb0ef41Sopenharmony_ci inline int RvcImm6Addi16spValue() const { 17041cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17051cb0ef41Sopenharmony_ci // | funct3 | nzimm[9] | 2 | nzimm[4|6|8:7|5] | opcode | 17061cb0ef41Sopenharmony_ci // 15 12 6 2 17071cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17081cb0ef41Sopenharmony_ci int32_t imm10 = ((Bits & 0x1000) >> 3) | ((Bits & 0x40) >> 2) | 17091cb0ef41Sopenharmony_ci ((Bits & 0x20) << 1) | ((Bits & 0x18) << 4) | 17101cb0ef41Sopenharmony_ci ((Bits & 0x4) << 3); 17111cb0ef41Sopenharmony_ci DCHECK_NE(imm10, 0); 17121cb0ef41Sopenharmony_ci return imm10 << 22 >> 22; 17131cb0ef41Sopenharmony_ci } 17141cb0ef41Sopenharmony_ci 17151cb0ef41Sopenharmony_ci inline int RvcImm8Addi4spnValue() const { 17161cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17171cb0ef41Sopenharmony_ci // | funct3 | nzimm[11] | rd' | opcode | 17181cb0ef41Sopenharmony_ci // 15 13 5 2 17191cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17201cb0ef41Sopenharmony_ci int32_t uimm10 = ((Bits & 0x20) >> 2) | ((Bits & 0x40) >> 4) | 17211cb0ef41Sopenharmony_ci ((Bits & 0x780) >> 1) | ((Bits & 0x1800) >> 7); 17221cb0ef41Sopenharmony_ci DCHECK_NE(uimm10, 0); 17231cb0ef41Sopenharmony_ci return uimm10; 17241cb0ef41Sopenharmony_ci } 17251cb0ef41Sopenharmony_ci 17261cb0ef41Sopenharmony_ci inline int RvcShamt6() const { 17271cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17281cb0ef41Sopenharmony_ci // | funct3 | nzuimm[5] | rs1/rd | nzuimm[4:0] | opcode | 17291cb0ef41Sopenharmony_ci // 15 12 6 2 17301cb0ef41Sopenharmony_ci int32_t imm6 = this->RvcImm6Value(); 17311cb0ef41Sopenharmony_ci return imm6 & 0x3f; 17321cb0ef41Sopenharmony_ci } 17331cb0ef41Sopenharmony_ci 17341cb0ef41Sopenharmony_ci inline int RvcImm6LwspValue() const { 17351cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17361cb0ef41Sopenharmony_ci // | funct3 | uimm[5] | rs1 | uimm[4:2|7:6] | opcode | 17371cb0ef41Sopenharmony_ci // 15 12 6 2 17381cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17391cb0ef41Sopenharmony_ci int32_t imm8 = 17401cb0ef41Sopenharmony_ci ((Bits & 0x1000) >> 7) | ((Bits & 0x70) >> 2) | ((Bits & 0xc) << 4); 17411cb0ef41Sopenharmony_ci return imm8; 17421cb0ef41Sopenharmony_ci } 17431cb0ef41Sopenharmony_ci 17441cb0ef41Sopenharmony_ci inline int RvcImm6LdspValue() const { 17451cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17461cb0ef41Sopenharmony_ci // | funct3 | uimm[5] | rs1 | uimm[4:3|8:6] | opcode | 17471cb0ef41Sopenharmony_ci // 15 12 6 2 17481cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17491cb0ef41Sopenharmony_ci int32_t imm9 = 17501cb0ef41Sopenharmony_ci ((Bits & 0x1000) >> 7) | ((Bits & 0x60) >> 2) | ((Bits & 0x1c) << 4); 17511cb0ef41Sopenharmony_ci return imm9; 17521cb0ef41Sopenharmony_ci } 17531cb0ef41Sopenharmony_ci 17541cb0ef41Sopenharmony_ci inline int RvcImm6SwspValue() const { 17551cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17561cb0ef41Sopenharmony_ci // | funct3 | uimm[5:2|7:6] | rs2 | opcode | 17571cb0ef41Sopenharmony_ci // 15 12 7 17581cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17591cb0ef41Sopenharmony_ci int32_t imm8 = ((Bits & 0x1e00) >> 7) | ((Bits & 0x180) >> 1); 17601cb0ef41Sopenharmony_ci return imm8; 17611cb0ef41Sopenharmony_ci } 17621cb0ef41Sopenharmony_ci 17631cb0ef41Sopenharmony_ci inline int RvcImm6SdspValue() const { 17641cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17651cb0ef41Sopenharmony_ci // | funct3 | uimm[5:3|8:6] | rs2 | opcode | 17661cb0ef41Sopenharmony_ci // 15 12 7 17671cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17681cb0ef41Sopenharmony_ci int32_t imm9 = ((Bits & 0x1c00) >> 7) | ((Bits & 0x380) >> 1); 17691cb0ef41Sopenharmony_ci return imm9; 17701cb0ef41Sopenharmony_ci } 17711cb0ef41Sopenharmony_ci 17721cb0ef41Sopenharmony_ci inline int RvcImm5WValue() const { 17731cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17741cb0ef41Sopenharmony_ci // | funct3 | imm[5:3] | rs1 | imm[2|6] | rd | opcode | 17751cb0ef41Sopenharmony_ci // 15 12 10 6 4 2 17761cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17771cb0ef41Sopenharmony_ci int32_t imm7 = 17781cb0ef41Sopenharmony_ci ((Bits & 0x1c00) >> 7) | ((Bits & 0x40) >> 4) | ((Bits & 0x20) << 1); 17791cb0ef41Sopenharmony_ci return imm7; 17801cb0ef41Sopenharmony_ci } 17811cb0ef41Sopenharmony_ci 17821cb0ef41Sopenharmony_ci inline int RvcImm5DValue() const { 17831cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17841cb0ef41Sopenharmony_ci // | funct3 | imm[5:3] | rs1 | imm[7:6] | rd | opcode | 17851cb0ef41Sopenharmony_ci // 15 12 10 6 4 2 17861cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17871cb0ef41Sopenharmony_ci int32_t imm8 = ((Bits & 0x1c00) >> 7) | ((Bits & 0x60) << 1); 17881cb0ef41Sopenharmony_ci return imm8; 17891cb0ef41Sopenharmony_ci } 17901cb0ef41Sopenharmony_ci 17911cb0ef41Sopenharmony_ci inline int RvcImm11CJValue() const { 17921cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 17931cb0ef41Sopenharmony_ci // | funct3 | [11|4|9:8|10|6|7|3:1|5] | opcode | 17941cb0ef41Sopenharmony_ci // 15 12 2 17951cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 17961cb0ef41Sopenharmony_ci int32_t imm12 = ((Bits & 0x4) << 3) | ((Bits & 0x38) >> 2) | 17971cb0ef41Sopenharmony_ci ((Bits & 0x40) << 1) | ((Bits & 0x80) >> 1) | 17981cb0ef41Sopenharmony_ci ((Bits & 0x100) << 2) | ((Bits & 0x600) >> 1) | 17991cb0ef41Sopenharmony_ci ((Bits & 0x800) >> 7) | ((Bits & 0x1000) >> 1); 18001cb0ef41Sopenharmony_ci return imm12 << 20 >> 20; 18011cb0ef41Sopenharmony_ci } 18021cb0ef41Sopenharmony_ci 18031cb0ef41Sopenharmony_ci inline int RvcImm8BValue() const { 18041cb0ef41Sopenharmony_ci DCHECK(this->IsShortInstruction()); 18051cb0ef41Sopenharmony_ci // | funct3 | imm[8|4:3] | rs1` | imm[7:6|2:1|5] | opcode | 18061cb0ef41Sopenharmony_ci // 15 12 10 7 2 18071cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 18081cb0ef41Sopenharmony_ci int32_t imm9 = ((Bits & 0x4) << 3) | ((Bits & 0x18) >> 2) | 18091cb0ef41Sopenharmony_ci ((Bits & 0x60) << 1) | ((Bits & 0xc00) >> 7) | 18101cb0ef41Sopenharmony_ci ((Bits & 0x1000) >> 4); 18111cb0ef41Sopenharmony_ci return imm9 << 23 >> 23; 18121cb0ef41Sopenharmony_ci } 18131cb0ef41Sopenharmony_ci 18141cb0ef41Sopenharmony_ci inline int vl_vs_width() { 18151cb0ef41Sopenharmony_ci int width = 0; 18161cb0ef41Sopenharmony_ci if ((this->InstructionBits() & kBaseOpcodeMask) != LOAD_FP && 18171cb0ef41Sopenharmony_ci (this->InstructionBits() & kBaseOpcodeMask) != STORE_FP) 18181cb0ef41Sopenharmony_ci return -1; 18191cb0ef41Sopenharmony_ci switch (this->InstructionBits() & (kRvvWidthMask | kRvvMewMask)) { 18201cb0ef41Sopenharmony_ci case 0x0: 18211cb0ef41Sopenharmony_ci width = 8; 18221cb0ef41Sopenharmony_ci break; 18231cb0ef41Sopenharmony_ci case 0x00005000: 18241cb0ef41Sopenharmony_ci width = 16; 18251cb0ef41Sopenharmony_ci break; 18261cb0ef41Sopenharmony_ci case 0x00006000: 18271cb0ef41Sopenharmony_ci width = 32; 18281cb0ef41Sopenharmony_ci break; 18291cb0ef41Sopenharmony_ci case 0x00007000: 18301cb0ef41Sopenharmony_ci width = 64; 18311cb0ef41Sopenharmony_ci break; 18321cb0ef41Sopenharmony_ci case 0x10000000: 18331cb0ef41Sopenharmony_ci width = 128; 18341cb0ef41Sopenharmony_ci break; 18351cb0ef41Sopenharmony_ci case 0x10005000: 18361cb0ef41Sopenharmony_ci width = 256; 18371cb0ef41Sopenharmony_ci break; 18381cb0ef41Sopenharmony_ci case 0x10006000: 18391cb0ef41Sopenharmony_ci width = 512; 18401cb0ef41Sopenharmony_ci break; 18411cb0ef41Sopenharmony_ci case 0x10007000: 18421cb0ef41Sopenharmony_ci width = 1024; 18431cb0ef41Sopenharmony_ci break; 18441cb0ef41Sopenharmony_ci default: 18451cb0ef41Sopenharmony_ci width = -1; 18461cb0ef41Sopenharmony_ci break; 18471cb0ef41Sopenharmony_ci } 18481cb0ef41Sopenharmony_ci return width; 18491cb0ef41Sopenharmony_ci } 18501cb0ef41Sopenharmony_ci 18511cb0ef41Sopenharmony_ci inline uint32_t Rvvzimm() const { 18521cb0ef41Sopenharmony_ci if ((this->InstructionBits() & 18531cb0ef41Sopenharmony_ci (kBaseOpcodeMask | kFunct3Mask | 0x80000000)) == RO_V_VSETVLI) { 18541cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 18551cb0ef41Sopenharmony_ci uint32_t zimm = Bits & kRvvZimmMask; 18561cb0ef41Sopenharmony_ci return zimm >> kRvvZimmShift; 18571cb0ef41Sopenharmony_ci } else { 18581cb0ef41Sopenharmony_ci DCHECK_EQ(this->InstructionBits() & 18591cb0ef41Sopenharmony_ci (kBaseOpcodeMask | kFunct3Mask | 0xC0000000), 18601cb0ef41Sopenharmony_ci RO_V_VSETIVLI); 18611cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 18621cb0ef41Sopenharmony_ci uint32_t zimm = Bits & kRvvZimmMask; 18631cb0ef41Sopenharmony_ci return (zimm >> kRvvZimmShift) & 0x3FF; 18641cb0ef41Sopenharmony_ci } 18651cb0ef41Sopenharmony_ci } 18661cb0ef41Sopenharmony_ci 18671cb0ef41Sopenharmony_ci inline uint32_t Rvvuimm() const { 18681cb0ef41Sopenharmony_ci DCHECK_EQ( 18691cb0ef41Sopenharmony_ci this->InstructionBits() & (kBaseOpcodeMask | kFunct3Mask | 0xC0000000), 18701cb0ef41Sopenharmony_ci RO_V_VSETIVLI); 18711cb0ef41Sopenharmony_ci uint32_t Bits = this->InstructionBits(); 18721cb0ef41Sopenharmony_ci uint32_t uimm = Bits & kRvvUimmMask; 18731cb0ef41Sopenharmony_ci return uimm >> kRvvUimmShift; 18741cb0ef41Sopenharmony_ci } 18751cb0ef41Sopenharmony_ci 18761cb0ef41Sopenharmony_ci inline uint32_t RvvVsew() const { 18771cb0ef41Sopenharmony_ci uint32_t zimm = this->Rvvzimm(); 18781cb0ef41Sopenharmony_ci uint32_t vsew = (zimm >> 3) & 0x7; 18791cb0ef41Sopenharmony_ci return vsew; 18801cb0ef41Sopenharmony_ci } 18811cb0ef41Sopenharmony_ci 18821cb0ef41Sopenharmony_ci inline uint32_t RvvVlmul() const { 18831cb0ef41Sopenharmony_ci uint32_t zimm = this->Rvvzimm(); 18841cb0ef41Sopenharmony_ci uint32_t vlmul = zimm & 0x7; 18851cb0ef41Sopenharmony_ci return vlmul; 18861cb0ef41Sopenharmony_ci } 18871cb0ef41Sopenharmony_ci 18881cb0ef41Sopenharmony_ci inline uint8_t RvvVM() const { 18891cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kVType || 18901cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kIType || 18911cb0ef41Sopenharmony_ci this->InstructionType() == InstructionBase::kSType); 18921cb0ef41Sopenharmony_ci return this->Bits(kRvvVmShift + kRvvVmBits - 1, kRvvVmShift); 18931cb0ef41Sopenharmony_ci } 18941cb0ef41Sopenharmony_ci 18951cb0ef41Sopenharmony_ci inline const char* RvvSEW() const { 18961cb0ef41Sopenharmony_ci uint32_t vsew = this->RvvVsew(); 18971cb0ef41Sopenharmony_ci switch (vsew) { 18981cb0ef41Sopenharmony_ci#define CAST_VSEW(name) \ 18991cb0ef41Sopenharmony_ci case name: \ 19001cb0ef41Sopenharmony_ci return #name; 19011cb0ef41Sopenharmony_ci RVV_SEW(CAST_VSEW) 19021cb0ef41Sopenharmony_ci default: 19031cb0ef41Sopenharmony_ci return "unknown"; 19041cb0ef41Sopenharmony_ci#undef CAST_VSEW 19051cb0ef41Sopenharmony_ci } 19061cb0ef41Sopenharmony_ci } 19071cb0ef41Sopenharmony_ci 19081cb0ef41Sopenharmony_ci inline const char* RvvLMUL() const { 19091cb0ef41Sopenharmony_ci uint32_t vlmul = this->RvvVlmul(); 19101cb0ef41Sopenharmony_ci switch (vlmul) { 19111cb0ef41Sopenharmony_ci#define CAST_VLMUL(name) \ 19121cb0ef41Sopenharmony_ci case name: \ 19131cb0ef41Sopenharmony_ci return #name; 19141cb0ef41Sopenharmony_ci RVV_LMUL(CAST_VLMUL) 19151cb0ef41Sopenharmony_ci default: 19161cb0ef41Sopenharmony_ci return "unknown"; 19171cb0ef41Sopenharmony_ci#undef CAST_VLMUL 19181cb0ef41Sopenharmony_ci } 19191cb0ef41Sopenharmony_ci } 19201cb0ef41Sopenharmony_ci 19211cb0ef41Sopenharmony_ci#define sext(x, len) (((int32_t)(x) << (32 - len)) >> (32 - len)) 19221cb0ef41Sopenharmony_ci#define zext(x, len) (((uint32_t)(x) << (32 - len)) >> (32 - len)) 19231cb0ef41Sopenharmony_ci 19241cb0ef41Sopenharmony_ci inline int32_t RvvSimm5() const { 19251cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kVType); 19261cb0ef41Sopenharmony_ci return sext(this->Bits(kRvvImm5Shift + kRvvImm5Bits - 1, kRvvImm5Shift), 19271cb0ef41Sopenharmony_ci kRvvImm5Bits); 19281cb0ef41Sopenharmony_ci } 19291cb0ef41Sopenharmony_ci 19301cb0ef41Sopenharmony_ci inline uint32_t RvvUimm5() const { 19311cb0ef41Sopenharmony_ci DCHECK(this->InstructionType() == InstructionBase::kVType); 19321cb0ef41Sopenharmony_ci uint32_t imm = this->Bits(kRvvImm5Shift + kRvvImm5Bits - 1, kRvvImm5Shift); 19331cb0ef41Sopenharmony_ci return zext(imm, kRvvImm5Bits); 19341cb0ef41Sopenharmony_ci } 19351cb0ef41Sopenharmony_ci#undef sext 19361cb0ef41Sopenharmony_ci#undef zext 19371cb0ef41Sopenharmony_ci inline bool AqValue() const { return this->Bits(kAqShift, kAqShift); } 19381cb0ef41Sopenharmony_ci 19391cb0ef41Sopenharmony_ci inline bool RlValue() const { return this->Bits(kRlShift, kRlShift); } 19401cb0ef41Sopenharmony_ci 19411cb0ef41Sopenharmony_ci // Say if the instruction is a break or a trap. 19421cb0ef41Sopenharmony_ci bool IsTrap() const; 19431cb0ef41Sopenharmony_ci}; 19441cb0ef41Sopenharmony_ci 19451cb0ef41Sopenharmony_ciclass Instruction : public InstructionGetters<InstructionBase> { 19461cb0ef41Sopenharmony_ci public: 19471cb0ef41Sopenharmony_ci // Instructions are read of out a code stream. The only way to get a 19481cb0ef41Sopenharmony_ci // reference to an instruction is to convert a pointer. There is no way 19491cb0ef41Sopenharmony_ci // to allocate or create instances of class Instruction. 19501cb0ef41Sopenharmony_ci // Use the At(pc) function to create references to Instruction. 19511cb0ef41Sopenharmony_ci static Instruction* At(byte* pc) { 19521cb0ef41Sopenharmony_ci return reinterpret_cast<Instruction*>(pc); 19531cb0ef41Sopenharmony_ci } 19541cb0ef41Sopenharmony_ci 19551cb0ef41Sopenharmony_ci private: 19561cb0ef41Sopenharmony_ci // We need to prevent the creation of instances of class Instruction. 19571cb0ef41Sopenharmony_ci DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction); 19581cb0ef41Sopenharmony_ci}; 19591cb0ef41Sopenharmony_ci 19601cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 19611cb0ef41Sopenharmony_ci// RISC-V assembly various constants. 19621cb0ef41Sopenharmony_ci 19631cb0ef41Sopenharmony_ci// C/C++ argument slots size. 19641cb0ef41Sopenharmony_ciconst int kCArgSlotCount = 0; 19651cb0ef41Sopenharmony_ci 19661cb0ef41Sopenharmony_ci// TODO(plind): below should be based on kSystemPointerSize 19671cb0ef41Sopenharmony_ci// TODO(plind): find all usages and remove the needless instructions for n64. 19681cb0ef41Sopenharmony_ciconst int kCArgsSlotsSize = kCArgSlotCount * kInstrSize * 2; 19691cb0ef41Sopenharmony_ci 19701cb0ef41Sopenharmony_ciconst int kInvalidStackOffset = -1; 19711cb0ef41Sopenharmony_ciconst int kBranchReturnOffset = 2 * kInstrSize; 19721cb0ef41Sopenharmony_ci 19731cb0ef41Sopenharmony_cistatic const int kNegOffset = 0x00008000; 19741cb0ef41Sopenharmony_ci 19751cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 19761cb0ef41Sopenharmony_ci// Instructions. 19771cb0ef41Sopenharmony_ci 19781cb0ef41Sopenharmony_citemplate <class P> 19791cb0ef41Sopenharmony_cibool InstructionGetters<P>::IsTrap() const { 19801cb0ef41Sopenharmony_ci return (this->InstructionBits() == kBreakInstr); 19811cb0ef41Sopenharmony_ci} 19821cb0ef41Sopenharmony_ci 19831cb0ef41Sopenharmony_ci} // namespace internal 19841cb0ef41Sopenharmony_ci} // namespace v8 19851cb0ef41Sopenharmony_ci 19861cb0ef41Sopenharmony_ci#endif // V8_CODEGEN_RISCV64_CONSTANTS_RISCV64_H_ 1987