Blame sysdeps/s390/fpu/s_lrint.c

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