xref: /freebsd/contrib/arm-optimized-routines/math/aarch64/advsimd/modf.c (revision f3087bef11543b42e0d69b708f367097a4118d24)
1 /*
2  * Double-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 /* Modf algorithm. Produces exact values in all rounding modes.  */
V_NAME_D1_L1(modf)13 float64x2_t VPCS_ATTR V_NAME_D1_L1 (modf) (float64x2_t x, double *out_int)
14 {
15   /* Get integer component of x.  */
16   float64x2_t rounded = vrndq_f64 (x);
17   vst1q_f64 (out_int, rounded);
18 
19   /* Subtract integer component from input.  */
20   uint64x2_t remaining = vreinterpretq_u64_f64 (vsubq_f64 (x, rounded));
21 
22   /* Return +0 for integer x.  */
23   uint64x2_t is_integer = vceqq_f64 (x, rounded);
24   return vreinterpretq_f64_u64 (vbicq_u64 (remaining, is_integer));
25 }
26 
27 TEST_ULP (_ZGVnN2vl8_modf_frac, 0.0)
28 TEST_SYM_INTERVAL (_ZGVnN2vl8_modf_frac, 0, 1, 20000)
29 TEST_SYM_INTERVAL (_ZGVnN2vl8_modf_frac, 1, inf, 20000)
30 
31 TEST_ULP (_ZGVnN2vl8_modf_int, 0.0)
32 TEST_SYM_INTERVAL (_ZGVnN2vl8_modf_int, 0, 1, 20000)
33 TEST_SYM_INTERVAL (_ZGVnN2vl8_modf_int, 1, inf, 20000)
34