--- /dev/null
+/* ffs -- find first set bit in a word, counted from least significant end.
+ For Amd 290x0.
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ Contributed by Torbjorn Granlund (tege@sics.se).
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <bstring.h>
+
+#undef ffs
+
+int
+DEFUN(ffs, (x), int x)
+{
+ int cnt;
+
+ asm ("clz %0,%1" : "=r" (cnt) : "r" (x & -x));
+
+ return 32 - cnt;
+}
--- /dev/null
+/* ffs -- find first set bit in a word, counted from least significant end.
+ For mc68020, mc68030, mc68040.
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ Contributed by Torbjorn Granlund (tege@sics.se).
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <bstring.h>
+
+#undef ffs
+
+#if defined(__mc68020__) || defined(mc68020)
+
+int
+DEFUN(ffs, (x), int x)
+{
+ int cnt;
+
+ asm("bfffo %1{#0:#0},%0" : "=d" (cnt) : "rm" (x & -x));
+
+ return 32 - cnt;
+}
+
+#else
+
+#include <sysdeps/generic/ffs.c>
+
+#endif
--- /dev/null
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#ifdef __GNUC__
+
+/* IGNORE($ */
+#ifdef __STDC__
+/* $) IFANSI($ */
+#define __m81_s(x) #x
+#define __m81_ul(x) __ ## x
+/* $) IGNORE($ */
+#else
+/* $) IFTRAD($ */
+#define __m81_s(x) "x"
+#define __m81_ul(x) __/**/x
+/* $) IGNORE($ */
+#endif
+/* $) */
+
+#ifdef __NO_MATH_INLINES
+#define __m81_u(x) __m81_ul(x)
+#else
+#define __m81_u(x) x
+#define __MATH_INLINES 1
+#endif
+
+#define __inline_mathop2(func, op) \
+ extern __inline __const double \
+ __m81_u(func)(double __mathop_x) \
+ { \
+ double __result; \
+ __asm("f" __m81_s(op) "%.x %1, %0" : "=f" (__result) : "f" (__mathop_x)); \
+ return __result; \
+ }
+#define __inline_mathop(op) __inline_mathop2(op, op)
+
+__inline_mathop(acos)
+__inline_mathop(asin)
+__inline_mathop(atan)
+__inline_mathop(cos)
+__inline_mathop(sin)
+__inline_mathop(tan)
+__inline_mathop(cosh)
+__inline_mathop(sinh)
+__inline_mathop(tanh)
+__inline_mathop2(exp, etox)
+__inline_mathop2(fabs, abs)
+__inline_mathop(log10)
+__inline_mathop2(log, logn)
+__inline_mathop2(floor, intrz)
+__inline_mathop(sqrt)
+
+#ifdef __USE_MISC
+__inline_mathop2(rint, int)
+__inline_mathop2(expm1, etoxm1)
+__inline_mathop2(log1p, lognp1)
+__inline_mathop(atanh)
+#endif
+
+extern __inline __const double
+__m81_u(__drem)(double __x, double __y)
+{
+ double __result;
+ __asm("frem%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
+ return __result;
+}
+
+extern __inline __const double
+__m81_u(__scalb)(double __x, int __n)
+{
+ double __result;
+ if (__x == 0.0)
+ __result = __x;
+ else
+ __asm("fscale%.l %1, %0" : "=f" (__result) : "g" (__n), "0" (__x));
+ return __result;
+}
+
+extern __inline __const double
+__m81_u(ldexp)(double __x, int __e)
+{
+ double __result;
+ double __double_e = (double) __e;
+ __asm("fscale%.x %1, %0" : "=f" (__result) : "f" (__double_e), "0" (__x));
+ return __result;
+}
+
+extern __inline __const double
+__m81_u(fmod)(double __x, double __y)
+{
+ double __result;
+ __asm("fmod%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
+ return __result;
+}
+
+extern __inline double
+__m81_u(frexp)(double __value, int *__expptr)
+{
+ double __mantissa, __exponent;
+ __asm("fgetexp%.x %1, %0" : "=f" (__exponent) : "f" (__value));
+ __asm("fgetman%.x %1, %0" : "=f" (__mantissa) : "f" (__value));
+ *__expptr = (int) __exponent;
+ return __mantissa;
+}
+
+extern __inline __const double
+__m81_u(pow)(double __x, double __y)
+{
+ double __result;
+ if (__y == 0.0 || __x == 1.0)
+ __result = 1.0;
+ else if (__y == 1.0)
+ __result = __x;
+ else if (__y == 2.0)
+ __result = __x * __x;
+ else if (__x == 10.0)
+ __asm("ftentox%.x %1, %0" : "=f" (__result) : "f" (__y));
+ else if (__x == 2.0)
+ __asm("ftwotox%.x %1, %0" : "=f" (__result) : "f" (__y));
+ else
+ __result = __m81_u(exp)(__y * __m81_u(log)(__x));
+ return __result;
+}
+
+extern __inline __const double
+__m81_u(ceil)(double __x)
+{
+ double __result;
+ unsigned long int __ctrl_reg;
+ __asm("fmove%.l fpcr, %0" : "=g" (__ctrl_reg));
+ /* Set rounding towards positive infinity. */
+ __asm("fmove%.l %0, fpcr" : /* No outputs. */ : "g" (__ctrl_reg | 0x30));
+ /* Convert X to an integer, using +Inf rounding. */
+ __asm("fint%.x %1, %0" : "=f" (__result) : "f" (__x));
+ /* Restore the previous rounding mode. */
+ __asm("fmove%.l %0, fpcr" : /* No outputs. */ : "g" (__ctrl_reg));
+ return __result;
+}
+
+extern __inline double
+__m81_u(modf)(double __value, double *__iptr)
+{
+ double __modf_int = __m81_u(floor)(__value);
+ *__iptr = __modf_int;
+ return __value - __modf_int;
+}
+
+extern __inline int
+__m81_u(__isinf)(double __value)
+{
+ /* There is no branch-condition for infinity,
+ so we must extract and examine the condition codes manually. */
+ unsigned long int __fpsr;
+ __asm("ftst%.x %1\n"
+ "fmove%.l fpsr, %0" : "=g" (__fpsr) : "f" (__value));
+ return (__fpsr & (2 << (3 * 8))) ? (__value < 0 ? -1 : 1) : 0;
+}
+
+extern __inline int
+__m81_u(__isnan)(double __value)
+{
+ char __result;
+ __asm("ftst%.x %1\n"
+ "fsun %0" : "=g" (__result) : "f" (__value));
+ return __result;
+}
+
+#endif /* GCC. */
--- /dev/null
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <math.h>
+
+static CONST double
+PIo4 = 7.8539816339744827900E-1 , /*Hex 2^ -1 * 1.921FB54442D18 */
+PIo2 = 1.5707963267948965580E0 , /*Hex 2^ 0 * 1.921FB54442D18 */
+PI = 3.1415926535897931160E0 ; /*Hex 2^ 1 * 1.921FB54442D18 */
+
+double
+DEFUN(atan2, (y, x), double y AND double x)
+{
+ static CONST double one = 1.0, zero = 0.0;
+ double signx, signy;
+ double pi;
+
+ if (__isnan(x))
+ return x;
+ if (__isnan(y))
+ return y;
+
+ signy = __copysign(one, y);
+ signx = __copysign(one, x);
+
+ asm("fmovecr%.x %1, %0" : "=f" (pi) : "i" (0));
+
+ if (y == zero)
+ return signx == one ? y : __copysign(pi, signy);
+
+ if (x == zero)
+ return __copysign(PIo2, signy);
+
+ if (__isinf(x))
+ {
+ if (__isinf(y))
+ return __copysign(signx == one ? PIo4 : 3 * PIo4, signy);
+ else
+ return __copysign(signx == one ? zero : pi, signy);
+ }
+
+ if (__isinf(y))
+ return __copysign(PIo2, signy);
+
+ y = fabs(y);
+
+ if (x < 0.0)
+ /* X is negative. */
+ return __copysign(pi - atan(y / -x), signy);
+
+ return __copysign(atan(y / x), signy);
+}
--- /dev/null
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <math.h>
+
+/* Return the base 2 signed integral exponent of X. */
+double
+DEFUN(__logb, (x), double x)
+{
+ if (__isnan(x))
+ return x;
+ if (__isinf(x))
+ return fabs(x);
+
+ if (x == 0.0)
+ asm("flog2%.x %0" : "=f" (x) : "0" (x));
+ else
+ asm("fgetexp%.x %0" : "=f" (x) : "0" (x));
+
+ return x;
+}
--- /dev/null
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#ifndef _68881_SWITCH_H
+
+#define _68881_SWITCH_H 1
+
+
+/* This is the format of the data at the code label for a function which
+ wants to switch depending on whether or not a 68881 is present.
+
+ Initially, `insn' is a `jsr' instruction, and `target' is __68881_switch.
+ The first time such a function is called, __68881_switch determines whether
+ or not a 68881 is present, and modifies the function accordingly.
+ Then `insn' is a `jmp' instruction, and `target' is the value of `fpu'
+ if there is 68881, or the value of `soft' if not. */
+
+struct switch_caller
+ {
+ unsigned short int insn; /* The `jsr' or `jmp' instruction. */
+ PTR target; /* The target of the instruction. */
+ PTR soft; /* The address of the soft function. */
+ PTR fpu; /* The address of the 68881 function. */
+ };
+
+/* These are opcodes (values for `insn', above) for `jmp' and `jsr'
+ instructions, respectively, to 32-bit absolute addresses. */
+#define JMP 0x4ef9
+#define JSR 0x4eb9
+
+
+/* Function to determine whether or not a 68881 is available,
+ and modify its caller (which must be a `struct switch_caller', above,
+ in data space) to use the appropriate version. */
+extern void EXFUN(__68881_switch, (int __dummy));
+
+
+#ifdef __STDC__
+#define __paste(a, b) a ## b
+#else
+#define __paste(a, b) a/**/b
+#endif
+
+/* Define FUNCTION as a `struct switch_caller' which will call
+ `__FUNCTION_68881' if a 68881 is present, and `__FUNCTION_soft' if not.
+#define switching_function(FUNCTION) \
+ struct switch_caller FUNCTION = \
+ { \
+ JSR, (PTR) __68881_switch, \
+ __paste(__paste(__, FUNCTION), _soft), \
+ __paste(__paste(__, FUNCTION), _68881) \
+ }
+
+
+#endif /* 68881-switch.h */
--- /dev/null
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <signal.h>
+#include <68881-switch.h>
+
+
+/* The signal that is sent when a 68881 instruction
+ is executed and there is no 68881. */
+#ifndef TRAPSIG
+#define TRAPSIG SIGILL
+#endif
+
+/* Nonzero if we have determined whether or not there is a 68881. */
+static int tested_fpu = 0;
+
+/* Nonzero if we have a 68881. */
+static int have_fpu;
+
+
+/* Signal handler for the trap that happens if we don't have a 68881. */
+static void
+DEFUN(trap, (sig), int sig)
+{
+ have_fpu = 0;
+}
+
+/* This function is called by functions that want to switch.
+ The calling function must be a `struct switch_caller' in data space.
+ It determines whether a 68881 is present, and modifies its caller
+ to be a static jump to either the 68881 version or the soft version.
+ It then returns into the function it has chosen to do the work. */
+void
+DEFUN(__68881_switch, (dummy), int dummy)
+{
+ PTR *return_address_location = &((PTR *) &dummy)[-1];
+ struct switch_caller *CONST caller
+ = (struct switch_caller *) (((short int *) *return_address_location) - 1);
+
+ if (!tested_fpu)
+ {
+ /* Figure out whether or not we have a 68881. */
+ __sighandler_t handler = signal(TRAPSIG, trap);
+ if (handler == SIG_ERR)
+ /* We can't figure it out, so assume we don't have a 68881.
+ This assumption will never cause us any problems other than
+ lost performance, while the reverse assumption could cause
+ the program to crash. */
+ have_fpu = 0;
+ else
+ {
+ /* We set `have_fpu' to nonzero, and then execute a 68881
+ no-op instruction. If we have a 68881, this will do nothing.
+ If we don't have one, this will trap and the signal handler
+ will clear `have_fpu'. */
+ have_fpu = 1;
+ asm("fnop");
+
+ /* Restore the old signal handler. */
+ (void) signal(TRAPSIG, handler);
+ }
+
+ /* Say that we've tested for a 68881, so we only do it once. */
+ tested_fpu = 1;
+ }
+
+ /* Modify the caller to be a jump to the appropriate address. */
+ caller->insn = JMP;
+ caller->target = have_fpu ? caller->fpu : caller->soft;
+
+ /* Make the address we will return to be the target we have chosen.
+ Our return will match the `jsr' done by the caller we have
+ just modified, and it will be just as if that had instead
+ been a `jmp' to the new target. */
+ *return_address_location = caller->target;
+}
--- /dev/null
+/* ffs -- find first set bit in a word, counted from least significant end.
+ For Motorola 88000.
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ Contributed by Torbjorn Granlund (tege@sics.se).
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <bstring.h>
+
+#undef ffs
+
+int
+DEFUN(ffs, (x), int x)
+{
+ int cnt;
+
+ if (x == 0)
+ return 0;
+
+ asm ("ff1 %0,%1" : "=r" (cnt) : "r" (x & -x));
+ return cnt + 1;
+}
--- /dev/null
+/* ffs -- find first set bit in a word, counted from least significant end.
+ For IBM rs6000.
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ Contributed by Torbjorn Granlund (tege@sics.se).
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <bstring.h>
+
+#undef ffs
+
+int
+DEFUN(ffs, (x), int x)
+{
+ int cnt;
+
+ asm ("cntlz %0,%1" : "=r" (cnt) : "r" (x & -x));
+ return 32 - cnt;
+}