xref: /freebsd/contrib/arm-optimized-routines/math/aarch64/sve/modff.c (revision dd21556857e8d40f66bf5ad54754d9d52669ebf7)
1 /*
2  * Single-precision SVE modff(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 "sv_math.h"
9 #include "test_sig.h"
10 #include "test_defs.h"
11 
12 /* Modff algorithm. Produces exact values in all rounding modes.  */
13 svfloat32_t SV_NAME_F1_L1 (modf) (svfloat32_t x, float *out_int,
14 				  const svbool_t pg)
15 {
16   /* Get integer component of x.  */
17   svfloat32_t fint_comp = svrintz_x (pg, x);
18 
19   svst1_f32 (pg, out_int, fint_comp);
20 
21   /* Subtract integer component from input.  */
22   svfloat32_t remaining = svsub_f32_x (svptrue_b32 (), x, fint_comp);
23 
24   /* Return +0 for integer x.  */
25   svbool_t is_integer = svcmpeq (pg, x, fint_comp);
26   return svsel (is_integer, sv_f32 (0), remaining);
27 }
28 
29 TEST_ULP (_ZGVsMxvl4_modff_frac, 0.0)
30 TEST_SYM_INTERVAL (_ZGVsMxvl4_modff_frac, 0, 1, 20000)
31 TEST_SYM_INTERVAL (_ZGVsMxvl4_modff_frac, 1, inf, 20000)
32 
33 TEST_ULP (_ZGVsMxvl4_modff_int, 0.0)
34 TEST_SYM_INTERVAL (_ZGVsMxvl4_modff_int, 0, 1, 20000)
35 TEST_SYM_INTERVAL (_ZGVsMxvl4_modff_int, 1, inf, 20000)
36 CLOSE_SVE_ATTR
37