Blame sysdeps/s390/fpu/s_lrint.c

Packit Service 797f29
/* lrint() - S390 version.
Packit Service 797f29
   Copyright (C) 2019 Free Software Foundation, Inc.
Packit Service 797f29
Packit Service 797f29
   This file is part of the GNU C Library.
Packit Service 797f29
Packit Service 797f29
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 797f29
   modify it under the terms of the GNU Lesser General Public License as
Packit Service 797f29
   published by the Free Software Foundation; either version 2.1 of the
Packit Service 797f29
   License, or (at your option) any later version.
Packit Service 797f29
Packit Service 797f29
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 797f29
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 797f29
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 797f29
   Lesser General Public License for more details.
Packit Service 797f29
Packit Service 797f29
   You should have received a copy of the GNU Lesser General Public
Packit Service 797f29
   License along with the GNU C Library; if not, see
Packit Service 797f29
   <https://www.gnu.org/licenses/>.  */
Packit Service 797f29
Packit Service 797f29
#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
Packit Service 797f29
# include <math.h>
Packit Service 797f29
# include <libm-alias-double.h>
Packit Service 797f29
Packit Service 797f29
/* The sizeof (long int) differs between s390x (8byte) and s390 (4byte).
Packit Service 797f29
   Thus we need different instructions as the target size is encoded there.
Packit Service 797f29
   Note: On s390 this instruction is only used if build with -mzarch.  */
Packit Service 797f29
# ifdef __s390x__
Packit Service 797f29
#  define INSN "cgdbra"
Packit Service 797f29
# else
Packit Service 797f29
#  define INSN "cfdbra"
Packit Service 797f29
# endif
Packit Service 797f29
Packit Service 797f29
long int
Packit Service 797f29
__lrint (double x)
Packit Service 797f29
{
Packit Service 797f29
  long int y;
Packit Service 797f29
  /* The z196 zarch "convert to fixed" (cgdbra) instruction is rounding
Packit Service 797f29
     according to current rounding mode (M3-field: 0).
Packit Service 797f29
     First convert x with suppressed inexact exception and check if the
Packit Service 797f29
     resulting value is beyond the target limits (indicated by cc=3;
Packit Service 797f29
     Note: a nan is also indicated by cc=3).
Packit Service 797f29
     If the resulting value is within the target limits, redo
Packit Service 797f29
     without suppressing the inexact exception.  */
Packit Service 797f29
  __asm__ (INSN " %0,0,%1,4 \n\t"
Packit Service 797f29
	   "jo 1f \n\t"
Packit Service 797f29
	   INSN " %0,0,%1,0 \n\t"
Packit Service 797f29
	   "1:"
Packit Service 797f29
	   : "=&d" (y) : "f" (x) : "cc");
Packit Service 797f29
  return y;
Packit Service 797f29
}
Packit Service 797f29
libm_alias_double (__lrint, lrint)
Packit Service 797f29
Packit Service 797f29
#else
Packit Service 797f29
# include <sysdeps/ieee754/dbl-64/s_lrint.c>
Packit Service 797f29
#endif