xref: /freebsd/contrib/arm-optimized-routines/math/aarch64/advsimd/modff.c (revision dd21556857e8d40f66bf5ad54754d9d52669ebf7)
1 /*
2  * Single-precision vector modf(x, *y) function.
3  *
4  * Copyright (c) 2024, Arm Limited.
5  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6  */
7 
8 #include "v_math.h"
9 #include "test_sig.h"
10 #include "test_defs.h"
11 
12 /* Modff algorithm. Produces exact values in all rounding modes.  */
13 float32x4_t VPCS_ATTR NOINLINE V_NAME_F1_L1 (modf) (float32x4_t x,
14 						    float *out_int)
15 {
16   /* Get integer component of x.  */
17   float32x4_t rounded = vrndq_f32 (x);
18   vst1q_f32 (out_int, rounded);
19 
20   /* Subtract integer component from input.  */
21   uint32x4_t remaining = vreinterpretq_u32_f32 (vsubq_f32 (x, rounded));
22 
23   /* Return +0 for integer x.  */
24   uint32x4_t is_integer = vceqq_f32 (x, rounded);
25   return vreinterpretq_f32_u32 (vbicq_u32 (remaining, is_integer));
26 }
27 
28 TEST_ULP (_ZGVnN4vl4_modff_frac, 0.0)
29 TEST_SYM_INTERVAL (_ZGVnN4vl4_modff_frac, 0, 1, 20000)
30 TEST_SYM_INTERVAL (_ZGVnN4vl4_modff_frac, 1, inf, 20000)
31 
32 TEST_ULP (_ZGVnN4vl4_modff_int, 0.0)
33 TEST_SYM_INTERVAL (_ZGVnN4vl4_modff_int, 0, 1, 20000)
34 TEST_SYM_INTERVAL (_ZGVnN4vl4_modff_int, 1, inf, 20000)
35