NEORV32 - Software Framework Documentation
Loading...
Searching...
No Matches
zicond_intrinsics.h
Go to the documentation of this file.
1// #################################################################################################
2// # << NEORV32 - Intrinsics + Emulation Functions for the RISC-V 'Zicond' ISA Extension >> #
3// # ********************************************************************************************* #
4// # The intrinsics provided by this library allow to use the conditional operations unit of the #
5// # RISC-V Zicond CPU extension without the need for support by the compiler. #
6// # ********************************************************************************************* #
7// # BSD 3-Clause License #
8// # #
9// # Copyright (c) 2023, Stephan Nolting. All rights reserved. #
10// # #
11// # Redistribution and use in source and binary forms, with or without modification, are #
12// # permitted provided that the following conditions are met: #
13// # #
14// # 1. Redistributions of source code must retain the above copyright notice, this list of #
15// # conditions and the following disclaimer. #
16// # #
17// # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
18// # conditions and the following disclaimer in the documentation and/or other materials #
19// # provided with the distribution. #
20// # #
21// # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
22// # endorse or promote products derived from this software without specific prior written #
23// # permission. #
24// # #
25// # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
26// # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
27// # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
28// # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
29// # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
30// # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
31// # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
32// # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
33// # OF THE POSSIBILITY OF SUCH DAMAGE. #
34// # ********************************************************************************************* #
35// # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting #
36// #################################################################################################
37
38
39/**********************************************************************/
49#ifndef zicond_intrinsics_h
50#define zicond_intrinsics_h
51
52
53// ################################################################################################
54// Intrinsics
55// ################################################################################################
56
57
58/**********************************************************************/
65inline uint32_t __attribute__ ((always_inline)) riscv_intrinsic_czero_eqz(uint32_t rs1, uint32_t rs2) {
66
67 return CUSTOM_INSTR_R3_TYPE(0b0000111, rs2, rs1, 0b101, 0b0110011);
68}
69
70
71/**********************************************************************/
78inline uint32_t __attribute__ ((always_inline)) riscv_intrinsic_czero_nez(uint32_t rs1, uint32_t rs2) {
79
80 return CUSTOM_INSTR_R3_TYPE(0b0000111, rs2, rs1, 0b111, 0b0110011);
81}
82
83
84// ################################################################################################
85// Emulation functions
86// ################################################################################################
87
88
89/**********************************************************************/
96uint32_t riscv_emulate_czero_eqz(uint32_t rs1, uint32_t rs2) {
97
98 if (rs2 == 0) {
99 return 0;
100 }
101 else {
102 return rs1;
103 }
104}
105
106
107/**********************************************************************/
114uint32_t riscv_emulate_czero_nez(uint32_t rs1, uint32_t rs2) {
115
116 if (rs2 != 0) {
117 return 0;
118 }
119 else {
120 return rs1;
121 }
122}
123
124
125#endif // zicond_intrinsics_h
uint32_t riscv_emulate_czero_eqz(uint32_t rs1, uint32_t rs2)
Definition: zicond_intrinsics.h:96
uint32_t riscv_intrinsic_czero_eqz(uint32_t rs1, uint32_t rs2)
Definition: zicond_intrinsics.h:65
uint32_t riscv_intrinsic_czero_nez(uint32_t rs1, uint32_t rs2)
Definition: zicond_intrinsics.h:78
uint32_t riscv_emulate_czero_nez(uint32_t rs1, uint32_t rs2)
Definition: zicond_intrinsics.h:114