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