ROCC软件代码介绍
-
前情提要:
需要注意的是custom0~3均采用R类指令格式。RISC-V各指令类别如下图所示。

-
mstatus的XS域
需要打开mstatus的XS域。
https://blog.youkuaiyun.com/a_weiming/article/details/111600428
我是在底层汇编*.S文件中打开的,代码如下:
其中MSTATUS_XS在encoding.h有定义。
# enable accelerator if present
li t0, MSTATUS_XS
csrs mstatus, t0
- ROCC的底层汇编
我这里有两个版本,一个是很久的,另一个是较新的,较新的需要gcc支持某些特定的语法,例如.inst,我的gcc比较旧,所以使用旧的版本。新旧都是IBM开源在github上的。
https://github.com/IBM/rocc-software - 旧版本代码:
// Copyright 2018 IBM
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ROCC_SOFTWARE_SRC_XCUSTOM_H_
#define ROCC_SOFTWARE_SRC_XCUSTOM_H_
#define STR1(x) #x
#ifndef STR
#define STR(x) STR1(x)
#endif
#define EXTRACT(a, size, offset) (((~(~0 << size) << offset) & a) >> offset)
// rd = rs2[offset + size - 1 : offset]
// rs1 is clobbered
// rs2 is left intact
#define EXTRACT_RAW(rd, rs1, rs2, size, offset) \
not x ## rs1, x0; \
slli x ## rs1, x ## rs1, size; \
not x ## rs1, x ## rs1; \
slli x ## rs1, x ## rs1, offset; \
and x ## rd, x ## rs1, x ## rs2;
RISC-V RoCC软件:自定义指令底层汇编实现

本文介绍了如何在RISC-V架构下通过ROCC软件定制指令,涉及mstatus的XS位设置,以及旧版和新版汇编代码的区别。展示了如何在底层汇编*.S文件中使用XCUSTOM宏来创建定制指令,适用于不同指令类型和参数配置。
最低0.47元/天 解锁文章
2026

被折叠的 条评论
为什么被折叠?



