NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_intrinsics.h
Go to the documentation of this file.
1// ================================================================================ //
2// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
3// Copyright (c) NEORV32 contributors. //
4// Copyright (c) 2020 - 2024 Stephan Nolting. All rights reserved. //
5// Licensed under the BSD-3-Clause license, see LICENSE for details. //
6// SPDX-License-Identifier: BSD-3-Clause //
7// ================================================================================ //
8
16#ifndef neorv32_intrinsics_h
17#define neorv32_intrinsics_h
18
19#include <stdint.h>
20
21/**********************************************************************/
24asm (
25 ".set reg_x0, 0 \n"
26 ".set reg_x1, 1 \n"
27 ".set reg_x2, 2 \n"
28 ".set reg_x3, 3 \n"
29 ".set reg_x4, 4 \n"
30 ".set reg_x5, 5 \n"
31 ".set reg_x6, 6 \n"
32 ".set reg_x7, 7 \n"
33 ".set reg_x8, 8 \n"
34 ".set reg_x9, 9 \n"
35 ".set reg_x10, 10 \n"
36 ".set reg_x11, 11 \n"
37 ".set reg_x12, 12 \n"
38 ".set reg_x13, 13 \n"
39 ".set reg_x14, 14 \n"
40 ".set reg_x15, 15 \n"
41#ifndef __riscv_32e
42 ".set reg_x16, 16 \n"
43 ".set reg_x17, 17 \n"
44 ".set reg_x18, 18 \n"
45 ".set reg_x19, 19 \n"
46 ".set reg_x20, 20 \n"
47 ".set reg_x21, 21 \n"
48 ".set reg_x22, 22 \n"
49 ".set reg_x23, 23 \n"
50 ".set reg_x24, 24 \n"
51 ".set reg_x25, 25 \n"
52 ".set reg_x26, 26 \n"
53 ".set reg_x27, 27 \n"
54 ".set reg_x28, 28 \n"
55 ".set reg_x29, 29 \n"
56 ".set reg_x30, 30 \n"
57 ".set reg_x31, 31 \n"
58#endif
59 ".set reg_zero, 0 \n"
60 ".set reg_ra, 1 \n"
61 ".set reg_sp, 2 \n"
62 ".set reg_gp, 3 \n"
63 ".set reg_tp, 4 \n"
64 ".set reg_t0, 5 \n"
65 ".set reg_t1, 6 \n"
66 ".set reg_t2, 7 \n"
67 ".set reg_s0, 8 \n"
68 ".set reg_s1, 9 \n"
69 ".set reg_a0, 10 \n"
70 ".set reg_a1, 11 \n"
71 ".set reg_a2, 12 \n"
72 ".set reg_a3, 13 \n"
73 ".set reg_a4, 14 \n"
74 ".set reg_a5, 15 \n"
75#ifndef __riscv_32e
76 ".set reg_a6, 16 \n"
77 ".set reg_a7, 17 \n"
78 ".set reg_s2, 18 \n"
79 ".set reg_s3, 19 \n"
80 ".set reg_s4, 20 \n"
81 ".set reg_s5, 21 \n"
82 ".set reg_s6, 22 \n"
83 ".set reg_s7, 23 \n"
84 ".set reg_s8, 24 \n"
85 ".set reg_s9, 25 \n"
86 ".set reg_s10, 26 \n"
87 ".set reg_s11, 27 \n"
88 ".set reg_t3, 28 \n"
89 ".set reg_t4, 29 \n"
90 ".set reg_t5, 30 \n"
91 ".set reg_t6, 31 \n"
92#endif
93);
94
95
96/**********************************************************************/
99#define CUSTOM_INSTR_R2_TYPE(funct7, funct5, rs1, funct3, opcode) \
100({ \
101 uint32_t __return; \
102 asm volatile( \
103 ".word ( \
104 (((" #funct7 ") & 0x7f) << 25) | \
105 (((" #funct5 ") & 0x1f) << 20) | \
106 ((( reg_%1 ) & 0x1f) << 15) | \
107 (((" #funct3 ") & 0x07) << 12) | \
108 ((( reg_%0 ) & 0x1f) << 7) | \
109 (((" #opcode ") & 0x7f) << 0) \
110 );" \
111 : [rd] "=r" (__return) \
112 : "r" (rs1) \
113 ); \
114 __return; \
115})
116
117
118/**********************************************************************/
121#define CUSTOM_INSTR_R3_TYPE(funct7, rs2, rs1, funct3, opcode) \
122({ \
123 uint32_t __return; \
124 asm volatile ( \
125 ".word ( \
126 (((" #funct7 ") & 0x7f) << 25) | \
127 ((( reg_%2 ) & 0x1f) << 20) | \
128 ((( reg_%1 ) & 0x1f) << 15) | \
129 (((" #funct3 ") & 0x07) << 12) | \
130 ((( reg_%0 ) & 0x1f) << 7) | \
131 (((" #opcode ") & 0x7f) << 0) \
132 );" \
133 : [rd] "=r" (__return) \
134 : "r" (rs1), \
135 "r" (rs2) \
136 ); \
137 __return; \
138})
139
140
141/**********************************************************************/
144#define CUSTOM_INSTR_R4_TYPE(rs3, rs2, rs1, funct3, opcode) \
145({ \
146 uint32_t __return; \
147 asm volatile ( \
148 ".word ( \
149 ((( reg_%3 ) & 0x1f) << 27) | \
150 ((( reg_%2 ) & 0x1f) << 20) | \
151 ((( reg_%1 ) & 0x1f) << 15) | \
152 (((" #funct3 ") & 0x07) << 12) | \
153 ((( reg_%0 ) & 0x1f) << 7) | \
154 (((" #opcode ") & 0x7f) << 0) \
155 );" \
156 : [rd] "=r" (__return) \
157 : "r" (rs1), \
158 "r" (rs2), \
159 "r" (rs3) \
160 ); \
161 __return; \
162})
163
164
165/**********************************************************************/
168#define CUSTOM_INSTR_I_TYPE(imm12, rs1, funct3, opcode) \
169({ \
170 uint32_t __return; \
171 asm volatile ( \
172 ".word ( \
173 (((" #imm12 ") & 0xfff) << 20) | \
174 ((( reg_%1 ) & 0x1f) << 15) | \
175 (((" #funct3 ") & 0x07) << 12) | \
176 ((( reg_%0 ) & 0x1f) << 7) | \
177 (((" #opcode ") & 0x7f) << 0) \
178 );" \
179 : [rd] "=r" (__return) \
180 : "r" (rs1) \
181 ); \
182 __return; \
183})
184
185
186/**********************************************************************/
189#define CUSTOM_INSTR_S_TYPE(imm12, rs2, rs1, funct3, opcode) \
190({ \
191 asm volatile ( \
192 ".word ( \
193 ((((" #imm12 ") >> 5) & 0x7f) << 25) | \
194 ((( reg_%1 ) & 0x1f) << 20) | \
195 ((( reg_%0 ) & 0x1f) << 15) | \
196 (((" #funct3 ") & 0x07) << 12) | \
197 (((" #imm12 ") & 0x1f) << 7) | \
198 (((" #opcode ") & 0x7f) << 0) \
199 );" \
200 : \
201 : "r" (rs1), \
202 "r" (rs2) \
203 ); \
204})
205
206
207#endif // neorv32_intrinsics_h