1 /* lrintf() - S390 version.
2    Copyright (C) 2019-2022 Free Software Foundation, Inc.
3 
4    This file is part of the GNU C Library.
5 
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public License as
8    published by the Free Software Foundation; either version 2.1 of the
9    License, or (at your option) any later version.
10 
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15 
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <https://www.gnu.org/licenses/>.  */
19 
20 #ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
21 # include <math.h>
22 # include <libm-alias-float.h>
23 
24 /* The sizeof (long int) differs between s390x (8byte) and s390 (4byte).
25    Thus we need different instructions as the target size is encoded there.
26    Note: On s390 this instruction is only used if build with -mzarch.  */
27 # ifdef __s390x__
28 #  define INSN "cgebra"
29 # else
30 #  define INSN "cfebra"
31 # endif
32 
33 long int
__lrintf(float x)34 __lrintf (float x)
35 {
36   long int y;
37   /* The z196 zarch "convert to fixed" (cgebra) instruction is rounding
38      according to current rounding mode (M3-field: 0).
39      First convert x with suppressed inexact exception and check if the
40      resulting value is beyond the target limits (indicated by cc=3;
41      Note: a nan is also indicated by cc=3).
42      If the resulting value is within the target limits, redo
43      without suppressing the inexact exception.  */
44   __asm__ (INSN " %0,0,%1,4 \n\t"
45 	   "jo 1f \n\t"
46 	   INSN " %0,0,%1,0 \n\t"
47 	   "1:"
48 	   : "=&d" (y) : "f" (x) : "cc");
49   return y;
50 }
51 libm_alias_float (__lrint, lrint)
52 
53 #else
54 # include <sysdeps/ieee754/flt-32/s_lrintf.c>
55 #endif
56