v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
base-assembler-riscv.h
Go to the documentation of this file.
1// Copyright (c) 1994-2006 Sun Microsystems Inc.
2// All Rights Reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// - Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10//
11// - Redistribution in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// - Neither the name of Sun Microsystems or the names of contributors may
16// be used to endorse or promote products derived from this software without
17// specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// The original source code covered by the above license above has been
32// modified significantly by Google Inc.
33// Copyright 2021 the V8 project authors. All rights reserved.
34
35#ifndef V8_CODEGEN_RISCV_BASE_ASSEMBLER_RISCV_H_
36#define V8_CODEGEN_RISCV_BASE_ASSEMBLER_RISCV_H_
37
38#include <stdio.h>
39
40#include <memory>
41#include <set>
42
46#include "src/codegen/label.h"
51#include "src/objects/smi.h"
52
53namespace v8 {
54namespace internal {
55
56#define DEBUG_PRINTF(...) \
57 if (v8_flags.riscv_debug) { \
58 printf(__VA_ARGS__); \
59 }
60
61class SafepointTableBuilder;
62
64 protected:
65 // Returns the branch offset to the given label from the current code
66 // position. Links the label to the current position if it is still unbound.
67 // Manages the jump elimination optimization if the second parameter is true.
68 enum OffsetSize : int {
69 kOffset21 = 21, // RISCV jal
70 kOffset12 = 12, // RISCV imm12
71 kOffset20 = 20, // RISCV imm20
72 kOffset13 = 13, // RISCV branch
73 kOffset32 = 32, // RISCV auipc + instr_I
74 kOffset11 = 11, // RISCV C_J
75 kOffset9 = 9 // RISCV compressed branch
76 };
77 virtual int32_t branch_offset_helper(Label* L, OffsetSize bits) = 0;
78
79 virtual void emit(Instr x) = 0;
80 virtual void emit(ShortInstr x) = 0;
81 virtual void emit(uint64_t x) = 0;
82
83 virtual void ClearVectorunit() = 0;
84 // Instruction generation.
85
86 // ----- Top-level instruction formats match those in the ISA manual
87 // (R, I, S, B, U, J). These match the formats defined in LLVM's
88 // RISCVInstrFormats.td.
89 void GenInstrR(uint8_t funct7, uint8_t funct3, BaseOpcode opcode, Register rd,
90 Register rs1, Register rs2);
91 void GenInstrR(uint8_t funct7, uint8_t funct3, BaseOpcode opcode,
93 void GenInstrR(uint8_t funct7, uint8_t funct3, BaseOpcode opcode, Register rd,
94 FPURegister rs1, Register rs2);
95 void GenInstrR(uint8_t funct7, uint8_t funct3, BaseOpcode opcode,
96 FPURegister rd, Register rs1, Register rs2);
97 void GenInstrR(uint8_t funct7, uint8_t funct3, BaseOpcode opcode,
98 FPURegister rd, FPURegister rs1, Register rs2);
99 void GenInstrR(uint8_t funct7, uint8_t funct3, BaseOpcode opcode, Register rd,
100 FPURegister rs1, FPURegister rs2);
101 void GenInstrR4(uint8_t funct2, BaseOpcode opcode, Register rd, Register rs1,
102 Register rs2, Register rs3, FPURoundingMode frm);
103 void GenInstrR4(uint8_t funct2, BaseOpcode opcode, FPURegister rd,
104 FPURegister rs1, FPURegister rs2, FPURegister rs3,
105 FPURoundingMode frm);
106 void GenInstrRAtomic(uint8_t funct5, bool aq, bool rl, uint8_t funct3,
107 Register rd, Register rs1, Register rs2);
108 void GenInstrRFrm(uint8_t funct7, BaseOpcode opcode, Register rd,
109 Register rs1, Register rs2, FPURoundingMode frm);
110 void GenInstrI(uint8_t funct3, BaseOpcode opcode, Register rd, Register rs1,
111 int16_t imm12);
112 void GenInstrI(uint8_t funct3, BaseOpcode opcode, FPURegister rd,
113 Register rs1, int16_t imm12);
114 void GenInstrIShift(uint8_t funct7, uint8_t funct3, BaseOpcode opcode,
115 Register rd, Register rs1, uint8_t shamt);
116 void GenInstrIShiftW(uint8_t funct7, uint8_t funct3, BaseOpcode opcode,
117 Register rd, Register rs1, uint8_t shamt);
118 void GenInstrS(uint8_t funct3, BaseOpcode opcode, Register rs1, Register rs2,
119 int16_t imm12);
120 void GenInstrS(uint8_t funct3, BaseOpcode opcode, Register rs1,
121 FPURegister rs2, int16_t imm12);
122 void GenInstrB(uint8_t funct3, BaseOpcode opcode, Register rs1, Register rs2,
123 int16_t imm12);
124 void GenInstrU(BaseOpcode opcode, Register rd, int32_t imm20);
125 void GenInstrJ(BaseOpcode opcode, Register rd, int32_t imm20);
126 void GenInstrCR(uint8_t funct4, BaseOpcode opcode, Register rd, Register rs2);
127 void GenInstrCA(uint8_t funct6, BaseOpcode opcode, Register rd, uint8_t funct,
128 Register rs2);
129 void GenInstrCI(uint8_t funct3, BaseOpcode opcode, Register rd, int8_t imm6);
130 void GenInstrCIU(uint8_t funct3, BaseOpcode opcode, Register rd,
131 uint8_t uimm6);
132 void GenInstrCIU(uint8_t funct3, BaseOpcode opcode, FPURegister rd,
133 uint8_t uimm6);
134 void GenInstrCIW(uint8_t funct3, BaseOpcode opcode, Register rd,
135 uint8_t uimm8);
136 void GenInstrCSS(uint8_t funct3, BaseOpcode opcode, FPURegister rs2,
137 uint8_t uimm6);
138 void GenInstrCSS(uint8_t funct3, BaseOpcode opcode, Register rs2,
139 uint8_t uimm6);
140 void GenInstrCL(uint8_t funct3, BaseOpcode opcode, Register rd, Register rs1,
141 uint8_t uimm5);
142 void GenInstrCL(uint8_t funct3, BaseOpcode opcode, FPURegister rd,
143 Register rs1, uint8_t uimm5);
144 void GenInstrCS(uint8_t funct3, BaseOpcode opcode, Register rs2, Register rs1,
145 uint8_t uimm5);
146 void GenInstrCS(uint8_t funct3, BaseOpcode opcode, FPURegister rs2,
147 Register rs1, uint8_t uimm5);
148 void GenInstrCJ(uint8_t funct3, BaseOpcode opcode, uint16_t uint11);
149 void GenInstrCB(uint8_t funct3, BaseOpcode opcode, Register rs1,
150 uint8_t uimm8);
151 void GenInstrCBA(uint8_t funct3, uint8_t funct2, BaseOpcode opcode,
152 Register rs1, int8_t imm6);
153
154 // ----- Instruction class templates match those in LLVM's RISCVInstrInfo.td
155 void GenInstrBranchCC_rri(uint8_t funct3, Register rs1, Register rs2,
156 int16_t imm12);
157 void GenInstrLoad_ri(uint8_t funct3, Register rd, Register rs1,
158 int16_t imm12);
159 void GenInstrStore_rri(uint8_t funct3, Register rs1, Register rs2,
160 int16_t imm12);
161 void GenInstrALU_ri(uint8_t funct3, Register rd, Register rs1, int16_t imm12);
162 void GenInstrShift_ri(bool arithshift, uint8_t funct3, Register rd,
163 Register rs1, uint8_t shamt);
164 void GenInstrALU_rr(uint8_t funct7, uint8_t funct3, Register rd, Register rs1,
165 Register rs2);
166 void GenInstrCSR_ir(uint8_t funct3, Register rd, ControlStatusReg csr,
167 Register rs1);
168 void GenInstrCSR_ii(uint8_t funct3, Register rd, ControlStatusReg csr,
169 uint8_t rs1);
170 void GenInstrShiftW_ri(bool arithshift, uint8_t funct3, Register rd,
171 Register rs1, uint8_t shamt);
172 void GenInstrALUW_rr(uint8_t funct7, uint8_t funct3, Register rd,
173 Register rs1, Register rs2);
174 void GenInstrPriv(uint8_t funct7, Register rs1, Register rs2);
175 void GenInstrLoadFP_ri(uint8_t funct3, FPURegister rd, Register rs1,
176 int16_t imm12);
177 void GenInstrStoreFP_rri(uint8_t funct3, Register rs1, FPURegister rs2,
178 int16_t imm12);
179 void GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, FPURegister rd,
180 FPURegister rs1, FPURegister rs2);
181 void GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, FPURegister rd,
182 Register rs1, Register rs2);
183 void GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, FPURegister rd,
184 FPURegister rs1, Register rs2);
185 void GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, Register rd,
186 FPURegister rs1, Register rs2);
187 void GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, Register rd,
188 FPURegister rs1, FPURegister rs2);
189 virtual void BlockTrampolinePoolFor(int instructions) = 0;
190};
191
192} // namespace internal
193} // namespace v8
194
195#endif // V8_CODEGEN_RISCV_BASE_ASSEMBLER_RISCV_H_
void GenInstrIShiftW(uint8_t funct7, uint8_t funct3, BaseOpcode opcode, Register rd, Register rs1, uint8_t shamt)
void GenInstrR(uint8_t funct7, uint8_t funct3, BaseOpcode opcode, Register rd, Register rs1, Register rs2)
void GenInstrCI(uint8_t funct3, BaseOpcode opcode, Register rd, int8_t imm6)
virtual void emit(uint64_t x)=0
void GenInstrBranchCC_rri(uint8_t funct3, Register rs1, Register rs2, int16_t imm12)
virtual void emit(Instr x)=0
void GenInstrRFrm(uint8_t funct7, BaseOpcode opcode, Register rd, Register rs1, Register rs2, FPURoundingMode frm)
void GenInstrJ(BaseOpcode opcode, Register rd, int32_t imm20)
void GenInstrLoad_ri(uint8_t funct3, Register rd, Register rs1, int16_t imm12)
void GenInstrALU_ri(uint8_t funct3, Register rd, Register rs1, int16_t imm12)
void GenInstrR4(uint8_t funct2, BaseOpcode opcode, Register rd, Register rs1, Register rs2, Register rs3, FPURoundingMode frm)
void GenInstrShift_ri(bool arithshift, uint8_t funct3, Register rd, Register rs1, uint8_t shamt)
virtual int32_t branch_offset_helper(Label *L, OffsetSize bits)=0
virtual void emit(ShortInstr x)=0
void GenInstrALUW_rr(uint8_t funct7, uint8_t funct3, Register rd, Register rs1, Register rs2)
void GenInstrCR(uint8_t funct4, BaseOpcode opcode, Register rd, Register rs2)
void GenInstrCB(uint8_t funct3, BaseOpcode opcode, Register rs1, uint8_t uimm8)
void GenInstrCSR_ir(uint8_t funct3, Register rd, ControlStatusReg csr, Register rs1)
void GenInstrALU_rr(uint8_t funct7, uint8_t funct3, Register rd, Register rs1, Register rs2)
void GenInstrCIU(uint8_t funct3, BaseOpcode opcode, Register rd, uint8_t uimm6)
void GenInstrPriv(uint8_t funct7, Register rs1, Register rs2)
void GenInstrCJ(uint8_t funct3, BaseOpcode opcode, uint16_t uint11)
void GenInstrCSR_ii(uint8_t funct3, Register rd, ControlStatusReg csr, uint8_t rs1)
void GenInstrStore_rri(uint8_t funct3, Register rs1, Register rs2, int16_t imm12)
void GenInstrStoreFP_rri(uint8_t funct3, Register rs1, FPURegister rs2, int16_t imm12)
void GenInstrCL(uint8_t funct3, BaseOpcode opcode, Register rd, Register rs1, uint8_t uimm5)
void GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, FPURegister rd, FPURegister rs1, FPURegister rs2)
void GenInstrS(uint8_t funct3, BaseOpcode opcode, Register rs1, Register rs2, int16_t imm12)
void GenInstrCBA(uint8_t funct3, uint8_t funct2, BaseOpcode opcode, Register rs1, int8_t imm6)
void GenInstrI(uint8_t funct3, BaseOpcode opcode, Register rd, Register rs1, int16_t imm12)
void GenInstrRAtomic(uint8_t funct5, bool aq, bool rl, uint8_t funct3, Register rd, Register rs1, Register rs2)
void GenInstrU(BaseOpcode opcode, Register rd, int32_t imm20)
void GenInstrB(uint8_t funct3, BaseOpcode opcode, Register rs1, Register rs2, int16_t imm12)
virtual void BlockTrampolinePoolFor(int instructions)=0
void GenInstrCA(uint8_t funct6, BaseOpcode opcode, Register rd, uint8_t funct, Register rs2)
void GenInstrCS(uint8_t funct3, BaseOpcode opcode, Register rs2, Register rs1, uint8_t uimm5)
void GenInstrCIW(uint8_t funct3, BaseOpcode opcode, Register rd, uint8_t uimm8)
void GenInstrLoadFP_ri(uint8_t funct3, FPURegister rd, Register rs1, int16_t imm12)
void GenInstrShiftW_ri(bool arithshift, uint8_t funct3, Register rd, Register rs1, uint8_t shamt)
void GenInstrCSS(uint8_t funct3, BaseOpcode opcode, FPURegister rs2, uint8_t uimm6)
void GenInstrIShift(uint8_t funct7, uint8_t funct3, BaseOpcode opcode, Register rd, Register rs1, uint8_t shamt)
int x
constexpr int L