@@ -29,8 +29,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
#include <math.h>
30
30
31
31
#if defined(DOUBLE )
32
-
33
- #define ABS fabs
32
+ #define VFMVFS_FLOAT vfmv_f_s_f64m1_f64
34
33
#define VSETVL (n ) vsetvl_e64m8(n)
35
34
#define VSETVL_MAX vsetvlmax_e64m1()
36
35
#define FLOAT_V_T vfloat64m8_t
@@ -54,8 +53,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
53
#define VADDVX_UINT vadd_vx_u64m8
55
54
#define VMVVX_UINT vmv_v_x_u64m8
56
55
#else
57
-
58
- #define ABS fabsf
56
+ #define VFMVFS_FLOAT vfmv_f_s_f32m1_f32
59
57
#define VSETVL (n ) vsetvl_e32m8(n)
60
58
#define VSETVL_MAX vsetvlmax_e32m1()
61
59
#define FLOAT_V_T vfloat32m8_t
@@ -85,7 +83,11 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
85
83
{
86
84
BLASLONG i = 0 , j = 0 ;
87
85
FLOAT maxf = 0.0 ;
86
+ #ifdef DOUBLE
87
+ BLASLONG max_index = 0 ;
88
+ #else
88
89
unsigned int max_index = 0 ;
90
+ #endif
89
91
if (n <= 0 || inc_x <= 0 ) return (max_index );
90
92
91
93
FLOAT_V_T vx , v_max ;
@@ -117,11 +119,14 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
117
119
j += gvl ;
118
120
}
119
121
v_res = VFREDMAXVS_FLOAT (v_res , v_max , v_z0 , gvl );
120
- maxf = * (( FLOAT * ) & v_res );
122
+ maxf = VFMVFS_FLOAT ( v_res );
121
123
mask = VMFGEVF_FLOAT (v_max , maxf , gvl );
122
124
max_index = VMFIRSTM (mask ,gvl );
123
- max_index = * ((unsigned int * )& v_max_index + max_index );
124
-
125
+ #ifdef DOUBLE
126
+ max_index = * ((BLASLONG * )& v_max_index + max_index );
127
+ #else
128
+ max_index = * ((unsigned int * )& v_max_index + max_index );
129
+ #endif
125
130
if (j < n ){
126
131
gvl = VSETVL (n - j );
127
132
vx = VLEV_FLOAT (& x [j ], gvl );
@@ -130,15 +135,19 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
130
135
v_max = VFRSUBVF_MASK_FLOAT (mask , vx , vx , 0 , gvl );
131
136
132
137
v_res = VFREDMAXVS_FLOAT (v_res , v_max , v_z0 , gvl );
133
- FLOAT cur_maxf = * (( FLOAT * ) & v_res );
138
+ FLOAT cur_maxf = VFMVFS_FLOAT ( v_res );
134
139
if (cur_maxf > maxf ){
135
140
//tail index
136
141
v_max_index = VIDV_UINT (gvl );
137
142
v_max_index = VADDVX_UINT (v_max_index , j , gvl );
138
143
139
144
mask = VMFGEVF_FLOAT (v_max , cur_maxf , gvl );
140
145
max_index = VMFIRSTM (mask ,gvl );
146
+ #ifdef DOUBLE
147
+ max_index = * ((BLASLONG * )& v_max_index + max_index );
148
+ #else
141
149
max_index = * ((unsigned int * )& v_max_index + max_index );
150
+ #endif
142
151
}
143
152
}
144
153
}else {
@@ -165,11 +174,14 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
165
174
idx += inc_v ;
166
175
}
167
176
v_res = VFREDMAXVS_FLOAT (v_res , v_max , v_z0 , gvl );
168
- maxf = * (( FLOAT * ) & v_res );
177
+ maxf = VFMVFS_FLOAT ( v_res );
169
178
mask = VMFGEVF_FLOAT (v_max , maxf , gvl );
170
179
max_index = VMFIRSTM (mask ,gvl );
180
+ #ifdef DOUBLE
181
+ max_index = * ((BLASLONG * )& v_max_index + max_index );
182
+ #else
171
183
max_index = * ((unsigned int * )& v_max_index + max_index );
172
-
184
+ #endif
173
185
if (j < n ){
174
186
gvl = VSETVL (n - j );
175
187
vx = VLSEV_FLOAT (& x [idx ], stride_x , gvl );
@@ -178,19 +190,21 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
178
190
v_max = VFRSUBVF_MASK_FLOAT (mask , vx , vx , 0 , gvl );
179
191
180
192
v_res = VFREDMAXVS_FLOAT (v_res , v_max , v_z0 , gvl );
181
- FLOAT cur_maxf = * (( FLOAT * ) & v_res );
193
+ FLOAT cur_maxf = VFMVFS_FLOAT ( v_res );
182
194
if (cur_maxf > maxf ){
183
195
//tail index
184
196
v_max_index = VIDV_UINT (gvl );
185
197
v_max_index = VADDVX_UINT (v_max_index , j , gvl );
186
198
187
199
mask = VMFGEVF_FLOAT (v_max , cur_maxf , gvl );
188
200
max_index = VMFIRSTM (mask ,gvl );
201
+ #ifdef DOUBLE
202
+ max_index = * ((BLASLONG * )& v_max_index + max_index );
203
+ #else
189
204
max_index = * ((unsigned int * )& v_max_index + max_index );
205
+ #endif
190
206
}
191
207
}
192
208
}
193
209
return (max_index + 1 );
194
210
}
195
-
196
-
0 commit comments