1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
#ifndef RVL_SDK_OS_FAST_CAST_H
#define RVL_SDK_OS_FAST_CAST_H
#include <common.h>
#ifdef __cplusplus
extern "C" {
#endif
#define OS_GQR_TYPE_U8 4
#define OS_GQR_TYPE_U16 5
#define OS_GQR_TYPE_S8 6
#define OS_GQR_TYPE_S16 7
static inline void OSInitFastCast(void) {
// clang-format off
asm {
li r3, 4
oris r3, r3, 4
mtspr 0x392, r3
li r3, 5
oris r3, r3, 5
mtspr 0x393, r3
li r3, 6
oris r3, r3, 6
mtspr 0x394, r3
li r3, 7
oris r3, r3, 7
mtspr 0x395, r3
}
// clang-format on
}
static void OSSetGQR6(register u32 type, register u32 scale) {
register u32 val = ((scale << 8 | type) << 16) | ((scale << 8) | type);
// clang-format off
asm {
mtspr 0x396, val
}
// clang-format on
}
static void OSSetGQR7(register u32 type, register u32 scale) {
register u32 val = ((scale << 8 | type) << 16) | ((scale << 8) | type);
// clang-format off
asm {
mtspr 0x397, val
}
// clang-format on
}
/******************************************************************************
*
* Convert from U8
*
******************************************************************************/
static inline f32 __OSu8tof32(register u8 *in) {
register f32 ret;
// clang-format off
asm {
psq_l ret, 0(in), 1, 2
}
// clang-format on
return ret;
}
static inline void OSu8tof32(u8 *in, volatile f32 *out) {
*out = __OSu8tof32(in);
}
/******************************************************************************
*
* Convert from U16
*
******************************************************************************/
static inline f32 __OSu16tof32(register u16 *arg) {
register f32 ret;
// clang-format off
asm {
psq_l ret, 0(arg), 1, 3
}
// clang-format on
return ret;
}
static inline void OSu16tof32(u16 *in, volatile f32 *out) {
*out = __OSu16tof32(in);
}
/******************************************************************************
*
* Convert from S16
*
******************************************************************************/
static inline f32 __OSs16tof32(register s16 *arg) {
register f32 ret;
// clang-format off
asm {
psq_l ret, 0(arg), 1, 5
}
// clang-format on
return ret;
}
static inline void OSs16tof32(s16 *in, volatile f32 *out) {
*out = __OSs16tof32(in);
}
/******************************************************************************
*
* Convert from F32
*
******************************************************************************/
static inline u8 __OSf32tou8(register f32 arg) {
f32 a;
register f32 *ptr = &a;
u8 r;
// clang-format off
asm {
psq_st arg, 0(ptr), 1, 2
}
// clang-format on
r = *(u8 *)ptr;
return r;
}
static inline void OSf32tou8(f32 *in, volatile u8 *out) {
*out = __OSf32tou8(*in);
}
static inline u16 __OSf32tou16(register f32 arg) {
f32 a;
register f32 *ptr = &a;
u16 r;
// clang-format off
asm {
psq_st arg, 0(ptr), 1, 3
}
// clang-format on
r = *(u16 *)ptr;
return r;
}
static inline void OSf32tou16(f32 *in, volatile u16 *out) {
*out = __OSf32tou16(*in);
}
static inline s16 __OSf32tos16(register f32 arg) {
f32 a;
register f32 *ptr = &a;
s16 r;
// clang-format off
asm {
psq_st arg, 0(ptr), 1, 5
}
// clang-format on
r = *(s16 *)ptr;
return r;
}
static inline void OSf32tos16(f32 *in, volatile s16 *out) {
*out = __OSf32tos16(*in);
}
#ifdef __cplusplus
}
#endif
#endif
|