vec: some useful functions (#103)

These functions are added:
- abs(): absolute value
- fract(): fractional part
- norm_one(): L1 norm
- norm_inf(): infinity norm
- hadd(): horizontal add
- hmax(): horizontal max
This commit is contained in:
Luigi Castelli
2019-08-31 23:30:15 +02:00
committed by Recep Aslantas
parent 6af1f5af04
commit 27cc9c3351
14 changed files with 552 additions and 0 deletions

View File

@@ -13,6 +13,12 @@
#define glmm_load(p) vld1q_f32(p)
#define glmm_store(p, a) vst1q_f32(p, a)
static inline
float32x4_t
glmm_abs(float32x4_t v) {
return vabsq_f32(v);
}
static inline
float
glmm_hadd(float32x4_t v) {
@@ -25,6 +31,22 @@ glmm_hadd(float32x4_t v) {
#endif
}
static inline
float
glmm_hmin(float32x4_t v) {
v = vpmin_f32(vget_low_f32(v), vget_high_f32(v));
v = vpmin_f32(v, v);
return vget_lane_f32(v, 0);
}
static inline
float
glmm_hmax(float32x4_t v) {
v = vpmax_f32(vget_low_f32(v), vget_high_f32(v));
v = vpmax_f32(v, v);
return vget_lane_f32(v, 0);
}
static inline
float
glmm_dot(float32x4_t a, float32x4_t b) {
@@ -43,5 +65,17 @@ glmm_norm2(float32x4_t a) {
return glmm_dot(a, a);
}
static inline
float
glmm_norm_one(float32x4_t a) {
return glmm_hadd(glmm_abs(a));
}
static inline
float
glmm_norm_inf(float32x4_t a) {
return glmm_hmax(glmm_abs(a));
}
#endif
#endif /* cglm_simd_arm_h */