summaryrefslogtreecommitdiff
path: root/lib/libc/arch/sparc64
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2001-08-29 01:45:25 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2001-08-29 01:45:25 +0000
commit4efad2c97d2ecee9981d79bc459035f0c91c28d8 (patch)
treef2823177e855466905dbe53552e6f23460c7a0fe /lib/libc/arch/sparc64
parenta342443c5dab7553d5f2ee794b3b8ead49db20c7 (diff)
Bunch of necessary files from NetBSD.
Diffstat (limited to 'lib/libc/arch/sparc64')
-rw-r--r--lib/libc/arch/sparc64/gen/_setjmp.S86
-rw-r--r--lib/libc/arch/sparc64/gen/fabs.S48
-rw-r--r--lib/libc/arch/sparc64/gen/fixunsdfsi.S94
-rw-r--r--lib/libc/arch/sparc64/gen/flt_rounds.c26
-rw-r--r--lib/libc/arch/sparc64/gen/ldexp.c152
-rw-r--r--lib/libc/arch/sparc64/gen/modf.S185
-rw-r--r--lib/libc/arch/sparc64/gen/mul.S60
-rw-r--r--lib/libc/arch/sparc64/gen/saveregs.S64
-rw-r--r--lib/libc/arch/sparc64/gen/setjmp.S115
-rw-r--r--lib/libc/arch/sparc64/gen/sigsetjmp.S75
-rw-r--r--lib/libc/arch/sparc64/gen/umul.S60
11 files changed, 965 insertions, 0 deletions
diff --git a/lib/libc/arch/sparc64/gen/_setjmp.S b/lib/libc/arch/sparc64/gen/_setjmp.S
new file mode 100644
index 00000000000..237fdb36934
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/_setjmp.S
@@ -0,0 +1,86 @@
+/* $NetBSD: _setjmp.S,v 1.4 1998/10/08 02:27:59 eeh Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+/*
+ * C library -- _setjmp, _longjmp
+ *
+ * _longjmp(a,v)
+ * will generate a "return(v?v:1)" from
+ * the last call to
+ * _setjmp(a)
+ * by unwinding the call stack.
+ * The previous signal state is NOT restored.
+ */
+
+ENTRY(_setjmp)
+ stx %sp, [%o0+0x00] /* store caller's stack pointer */
+ stx %o7, [%o0+0x08] /* ... return pc */
+ stx %fp, [%o0+0x10] /* ... and frame pointer */
+ retl
+ clr %o0 ! return 0
+
+ENTRY(_longjmp)
+ mov 1, %g6
+ movrnz %o1, %o1, %g6 ! compute v ? v : 1 in a global register
+ mov %o0, %g1 ! save a in another global register
+ ldx [%g1+0x10], %g7 /* get caller's frame */
+1:
+ cmp %fp, %g7 ! compare against desired frame
+ bl,a 1b ! if below,
+ restore ! pop frame and loop
+ be,a 2f ! if there,
+ ldx [%g1+0], %o2 ! fetch return %sp
+
+Lbotch:
+ call _C_LABEL(longjmperror) ! otherwise, went too far; bomb out
+ nop
+ unimp 0
+
+2:
+ cmp %o2, %sp ! %sp must not decrease
+ bge,a 3f
+ mov %o2, %sp ! it is OK, put it in place
+ b,a Lbotch
+3:
+ ldx [%g1+0x8], %o3 ! fetch pc
+ jmp %o3 + 8 ! success, return %g6
+ mov %g6, %o0
+
diff --git a/lib/libc/arch/sparc64/gen/fabs.S b/lib/libc/arch/sparc64/gen/fabs.S
new file mode 100644
index 00000000000..57a223c3841
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/fabs.S
@@ -0,0 +1,48 @@
+/* $OpenBSD: fabs.S,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: fabs.S,v 1.2 2000/07/23 07:12:22 eeh Exp $ */
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+/* fabs - floating absolute value */
+
+ENTRY(fabs)
+ stx %o0, [%sp + BIAS + 32] ! return value => %f0:f1
+ ldd [%sp + BIAS + 32], %f0 ! (via kernel %o0/%o1 slot)
+ retl
+ fabss %f0, %f0 ! return absolute value
diff --git a/lib/libc/arch/sparc64/gen/fixunsdfsi.S b/lib/libc/arch/sparc64/gen/fixunsdfsi.S
new file mode 100644
index 00000000000..04b9658ea3e
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/fixunsdfsi.S
@@ -0,0 +1,94 @@
+/* $OpenBSD: fixunsdfsi.S,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: fixunsdfsi.S,v 1.3 2000/07/25 04:26:12 mycroft Exp $ */
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+#define _LOCORE
+#include <machine/frame.h>
+
+/*
+ * Convert double to unsigned integer (for gcc).
+ *
+ * I have made the output for NaN agree with the Sun compiler, not
+ * that it really matters, by using `fbul,a'.
+ */
+
+ .align 8
+Lbig:
+ .word 0x43e00000 ! .double 2^63
+ .word 0 ! (who me, not trust the assembler?)
+
+/*
+ * Same as above but to unsigned long
+ */
+ENTRY(__dtoul)
+ sub %sp, 16, %sp
+ std %f2, [%sp + 64 + BIAS + 8]
+#ifdef PIC
+ PICCY_SET(Lbig, %g1, %o0)
+ ldd [%g1], %f2
+#else
+ sethi %hi(Lbig), %g1
+ ldd [%g1 + %lo(Lbig)], %f2
+#endif
+ fcmped %f0, %f2 ! d < 2^63, or NaN, or -Inf?
+ nop ! (fpop2 delay)
+ fbul,a 1f ! if so, use fdtoi to convert to int
+ fdtox %f0, %f0 ! (this includes negatives!)
+
+ ! d does not fit in an int, so subtract 2^63, convert,
+ ! and add 2^63 again (sigh). Just hope the intermediate
+ ! fits (if not, the result is undefined anyway).
+
+ fsubd %f0, %f2, %f0 ! d -= 2^63
+ fdtox %f0, %f0 ! convert to int
+ std %f0, [%sp + 64 + BIAS] ! move into return reg
+ ldx [%sp + 64 + BIAS], %o0
+ sethi %hi(0x80000000), %o1
+ sllx %o1, 32, %o1
+ add %o0, %o1, %o0 ! add 2^63
+ ldd [%sp + 64 + BIAS + 8], %f2
+ retl
+ add %sp, 16, %sp
+
+1:
+ std %f0, [%sp + 64 + BIAS] ! return result
+ ldx [%sp + 64 + BIAS], %o0
+ ldd [%sp + 64 + BIAS + 8], %f2
+ retl
+ add %sp, 16, %sp
diff --git a/lib/libc/arch/sparc64/gen/flt_rounds.c b/lib/libc/arch/sparc64/gen/flt_rounds.c
new file mode 100644
index 00000000000..b8f0f69a2c2
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/flt_rounds.c
@@ -0,0 +1,26 @@
+/* $OpenBSD: flt_rounds.c,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: flt_rounds.c,v 1.1 1998/09/11 04:56:23 eeh Exp $ */
+
+/*
+ * Written by J.T. Conklin, Apr 10, 1995
+ * Public domain.
+ */
+
+#include <sys/types.h>
+#include <machine/float.h>
+
+static const int map[] = {
+ 1, /* round to nearest */
+ 0, /* round to zero */
+ 3, /* round to negative infinity */
+ 2 /* round to positive infinity */
+};
+
+int
+__flt_rounds()
+{
+ int x;
+
+ __asm__("st %%fsr,%0" : "=m" (*&x));
+ return map[(x >> 30) & 0x03];
+}
diff --git a/lib/libc/arch/sparc64/gen/ldexp.c b/lib/libc/arch/sparc64/gen/ldexp.c
new file mode 100644
index 00000000000..6bfb8ded718
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/ldexp.c
@@ -0,0 +1,152 @@
+/* $OpenBSD: ldexp.c,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: ldexp.c,v 1.8 1999/08/30 18:28:26 mycroft Exp $ */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+#include <sys/types.h>
+#include <machine/ieee.h>
+#include <errno.h>
+#include <math.h>
+
+/*
+ * Multiply the given value by 2^exp.
+ */
+double
+ldexp(val, exp)
+ double val;
+ int exp;
+{
+ register int oldexp, newexp;
+ union {
+ double v;
+ struct ieee_double s;
+ } u, mul;
+
+ u.v = val;
+ oldexp = u.s.dbl_exp;
+
+ /*
+ * If input is zero, Inf or NaN, just return it.
+ */
+ if (u.v == 0.0 || oldexp == DBL_EXP_INFNAN)
+ return (val);
+
+ if (oldexp == 0) {
+ /*
+ * u.v is denormal. We must adjust it so that the exponent
+ * arithmetic below will work.
+ */
+ if (exp <= DBL_EXP_BIAS) {
+ /*
+ * Optimization: if the scaling can be done in a single
+ * multiply, or underflows, just do it now.
+ */
+ if (exp <= -DBL_FRACBITS) {
+ errno = ERANGE;
+ return (0.0);
+ }
+ mul.v = 0.0;
+ mul.s.dbl_exp = exp + DBL_EXP_BIAS;
+ u.v *= mul.v;
+ if (u.v == 0.0) {
+ errno = ERANGE;
+ return (0.0);
+ }
+ return (u.v);
+ } else {
+ /*
+ * We know that exp is very large, and therefore the
+ * result cannot be denormal (though it may be Inf).
+ * Shift u.v by just enough to make it normal.
+ */
+ mul.v = 0.0;
+ mul.s.dbl_exp = DBL_FRACBITS + DBL_EXP_BIAS;
+ u.v *= mul.v;
+ exp -= DBL_FRACBITS;
+ oldexp = u.s.dbl_exp;
+ }
+ }
+
+ /*
+ * u.v is now normalized and oldexp has been adjusted if necessary.
+ * Calculate the new exponent and check for underflow and overflow.
+ */
+ newexp = oldexp + exp;
+
+ if (newexp <= 0) {
+ /*
+ * The output number is either denormal or underflows (see
+ * comments in machine/ieee.h).
+ */
+ if (newexp <= -DBL_FRACBITS) {
+ errno = ERANGE;
+ return (0.0);
+ }
+ /*
+ * Denormalize the result. We do this with a multiply. If exp
+ * is very large, it won't fit in a double, so we have to
+ * adjust the exponent first. This is safe because we know
+ * that u.v is normal at this point.
+ */
+ if (exp <= -DBL_EXP_BIAS) {
+ u.s.dbl_exp = 1;
+ exp += oldexp - 1;
+ }
+ mul.v = 0.0;
+ mul.s.dbl_exp = exp + DBL_EXP_BIAS;
+ u.v *= mul.v;
+ return (u.v);
+ } else if (newexp >= DBL_EXP_INFNAN) {
+ /*
+ * The result overflowed; return +/-Inf.
+ */
+ u.s.dbl_exp = DBL_EXP_INFNAN;
+ u.s.dbl_frach = 0;
+ u.s.dbl_fracl = 0;
+ errno = ERANGE;
+ return (u.v);
+ } else {
+ /*
+ * The result is normal; just replace the old exponent with the
+ * new one.
+ */
+ u.s.dbl_exp = newexp;
+ return (u.v);
+ }
+}
diff --git a/lib/libc/arch/sparc64/gen/modf.S b/lib/libc/arch/sparc64/gen/modf.S
new file mode 100644
index 00000000000..9915daeab01
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/modf.S
@@ -0,0 +1,185 @@
+/* $OpenBSD: modf.S,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: modf.S,v 1.3 2000/11/01 23:32:41 eeh Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+#include <machine/fsr.h>
+
+/*
+ * double modf(double val, double *iptr)
+ *
+ * Returns the fractional part of `val', storing the integer part of
+ * `val' in *iptr. Both *iptr and the return value have the same sign
+ * as `val'.
+ *
+ * Method:
+ *
+ * We use the fpu's normalization hardware to compute the integer portion
+ * of the double precision argument. Sun IEEE double precision numbers
+ * have 52 bits of mantissa, 11 bits of exponent, and one bit of sign,
+ * with the sign occupying bit 31 of word 0, and the exponent bits 30:20
+ * of word 0. Thus, values >= 2^52 are by definition integers.
+ *
+ * If we take a value that is in the range [+0..2^52) and add 2^52, all
+ * of the fractional bits fall out and all of the integer bits are summed
+ * with 2^52. If we then subtract 2^52, we get those integer bits back.
+ * This must be done with rounding set to `towards 0' or `towards -inf'.
+ * `Toward -inf' fails when the value is 0 (we get -0 back)....
+ *
+ * Note that this method will work anywhere, but is machine dependent in
+ * various aspects.
+ *
+ * Stack usage:
+ * 4@[%fp + BIAS - 4] saved %fsr
+ * 4@[%fp + BIAS - 8] new %fsr with rounding set to `towards 0'
+ * 8@[%fp + BIAS - 16] space for moving between %i and %f registers
+ * Register usage:
+ * %f0:f1 double val;
+ * %l0 scratch
+ * %l1 sign bit (0x80000000)
+ * %i1 double *iptr;
+ * %f2:f3 `magic number' 2^52, in fpu registers
+ * %f4:f5 double v, in fpu registers
+ * %f6:f7 double temp.
+ */
+
+ .align 8
+Lmagic:
+ .word 0x43300000 ! sign = 0, exponent = 52 + 1023, mantissa = 0
+ .word 0 ! (i.e., .double 0r4503599627370496e+00)
+
+L0:
+ .word 0 ! 0.0
+ .word 0
+
+ENTRY(modf)
+ save %sp, -CC64FSZ-16, %sp
+
+ /*
+ * First, compute v = abs(val)
+ */
+ fabsd %f0, %f4 ! %f4:f5 = v
+ fcmped %fcc1, %f0, %f4 ! %fcc1 = (val == abs(val))
+#ifdef PIC
+ PICCY_SET(Lmagic, %l0, %o7)
+ ldd [%l0], %f2
+#else
+ sethi %hi(Lmagic), %l0
+ ldd [%l0 + %lo(Lmagic)], %f2
+#endif
+
+ /*
+ * Is %f4:f5 >= %f2:f3 ? If so, it is all integer bits.
+ * It is probably less, though.
+ */
+ fcmped %f4, %f2
+ fbuge Lbig ! if >= (or unordered), go out
+ nop
+
+ /*
+ * v < 2^52, so add 2^52, then subtract 2^52, but do it all
+ * with rounding set towards zero. We leave any enabled
+ * traps enabled, but change the rounding mode. This might
+ * not be so good. Oh well....
+ */
+ st %fsr, [%fp + BIAS - 4] ! %l5 = current FSR mode
+ set FSR_RD, %l3 ! %l3 = rounding direction mask
+ ld [%fp + BIAS - 4], %l5
+ set FSR_RD_RZ << FSR_RD_SHIFT, %l4
+ andn %l5, %l3, %l6
+ or %l6, %l4, %l6 ! round towards zero, please
+ and %l5, %l3, %l5 ! save original rounding mode
+ st %l6, [%fp + BIAS - 8]
+ ld [%fp + BIAS - 8], %fsr
+
+ faddd %f4, %f2, %f4 ! %f4:f5 += 2^52
+ fsubd %f4, %f2, %f4 ! %f4:f5 -= 2^52
+
+ /*
+ * Restore %fsr, but leave exceptions accrued.
+ */
+ st %fsr, [%fp + BIAS - 4]
+ ld [%fp + BIAS - 4], %l6
+ andn %l6, %l3, %l6 ! %l6 = %fsr & ~FSR_RD;
+ or %l5, %l6, %l5 ! %l5 |= %l6;
+ st %l5, [%fp + BIAS - 4]
+ ld [%fp + BIAS - 4], %fsr ! restore %fsr, leaving accrued stuff
+
+ /*
+ * Now insert the original sign in %f4:f5.
+ * %fcc1 should still have the reults of (val == abs(val))
+ * from above, so we use a conditional move on %fcc1 to:
+ *
+ * %f4 = (val == abs(val)) ? %f4 : -%f4
+ *
+ */
+ fnegd %f4, %f6
+ fmovdnz %fcc1, %f6, %f4
+1:
+
+ /*
+ * The value in %f4:f5 is now the integer portion of the original
+ * argument. We need to store this in *ival (%i1), subtract it
+ * from the original value argument (%d0), and return the result.
+ */
+ std %f4, [%i1] ! *ival = %f4:f5;
+ fsubd %f0, %f4, %f0 ! %f0:f1 -= %f4:f5;
+ ret
+ restore
+
+Lbig:
+ /*
+ * We get here if the original comparison of %f4:f5 (v) to
+ * %f2:f3 (2^52) came out `greater or unordered'. In this
+ * case the integer part is the original value, and the
+ * fractional part is 0.
+ */
+#ifdef PIC
+ PICCY_SET(L0, %l0, %o7)
+ std %f0, [%i1] ! *ival = val;
+ ldd [%l0], %f0 ! return 0.0;
+#else
+ sethi %hi(L0), %l0
+ std %f0, [%i1] ! *ival = val;
+ ldd [%l0 + %lo(L0)], %f0 ! return 0.0;
+#endif
+ ret
+ restore
+
diff --git a/lib/libc/arch/sparc64/gen/mul.S b/lib/libc/arch/sparc64/gen/mul.S
new file mode 100644
index 00000000000..dd0f8ca394c
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/mul.S
@@ -0,0 +1,60 @@
+/* $OpenBSD: mul.S,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: mul.S,v 1.1 1998/09/11 04:56:28 eeh Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+/*
+ * Signed multiply.
+ *
+ * Returns %o0 * %o1 in %o0
+ *
+ * According to the manual the smaller parameter should be in
+ * rs1, so we'll move it there.
+ */
+
+FUNC(.mul)
+ cmp %o0, %o1
+ bge 1f
+ nop
+ retl
+ mulx %o0, %o1, %o0
+1:
+ retl
+ mulx %o1, %o0, %o0
diff --git a/lib/libc/arch/sparc64/gen/saveregs.S b/lib/libc/arch/sparc64/gen/saveregs.S
new file mode 100644
index 00000000000..81bb00ea670
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/saveregs.S
@@ -0,0 +1,64 @@
+/* $OpenBSD: saveregs.S,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: saveregs.S,v 1.2 2000/07/21 03:14:15 eeh Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: saveregs.s,v 1.1 91/07/06 17:22:33 torek Exp
+ */
+
+#include <machine/asm.h>
+
+/*
+ * Save register arguments in caller's `arg dump' area, so that
+ * stdarg functions work.
+ *
+ * This really should be done with a pointer to the arg dump area;
+ * our caller should allocate that area, not our caller's caller.
+ * But then, they did not let me invent the calling sequence....
+ *
+ * We assume the caller has executed a `save' instruction.
+ */
+#define REGOFF (BIAS - CC64FSZ)
+
+ENTRY(__builtin_saveregs)
+ stx %i0, [%fp + REGOFF + 0x00] ! fr->fr_argd[0]
+ stx %i1, [%fp + REGOFF + 0x08] ! fr->fr_argd[1]
+ stx %i2, [%fp + REGOFF + 0x10] ! fr->fr_argd[2]
+ stx %i3, [%fp + REGOFF + 0x18] ! fr->fr_argd[3]
+ stx %i4, [%fp + REGOFF + 0x20] ! fr->fr_argd[4]
+ retl
+ stx %i5, [%fp + REGOFF + 0x28] ! fr->fr_argd[5]
diff --git a/lib/libc/arch/sparc64/gen/setjmp.S b/lib/libc/arch/sparc64/gen/setjmp.S
new file mode 100644
index 00000000000..955a91ffc5e
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/setjmp.S
@@ -0,0 +1,115 @@
+/* $OpenBSD: setjmp.S,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: setjmp.S,v 1.4 2000/08/28 00:45:59 eeh Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#define _LOCORE
+#include <machine/asm.h>
+#include <machine/frame.h>
+
+/*
+ * C library -- setjmp, longjmp
+ *
+ * longjmp(a,v)
+ * will generate a "return(v)" from
+ * the last call to
+ * setjmp(a)
+ * by restoring registers from the stack,
+ * and a struct sigcontext, see <signal.h>
+ */
+
+#include "SYS.h"
+
+#define STACK_T_SZ
+ENTRY(setjmp)
+ /*
+ * We use the part of the sigcontext structure, the sp, pc, and npc fields,
+ * for the sigstack call so we don't need to get our own stackframe. It
+ * won't be filled out till later anyway.
+ */
+ mov %o0, %o3 /* Save our jmp_buf in %o3 */
+ mov %o0, %o2 /* build sigcontext in [%o2] */
+ mov 1, %o0 /* SIG_BLOCK */
+ mov SYS_sigprocmask, %g1
+ clr %o1 /* sigprocmask(SIG_BLOCK, (sigset_t *)NULL, (sigset_t *)a) */
+ t ST_SYSCALL
+
+ st %o0, [%o3 + 0x04] /* sc.sc_mask = current mask; */
+ mov SYS_sigaltstack, %g1
+ clr %o0 /* sigstack(NULL, &foo) */
+ add %o3, 0x38, %o1 /* (foo being the sigcontext14 sc_mask) */
+ t ST_SYSCALL
+
+ lduw [%o3 + 0x38+0x10], %o0 /* foo.ss_flags */
+ and %o0, 1, %o1 /* onstack = foo.ss_flags & 1; */
+ st %o0, [%o3 + 0x00] /* sc.sc_onstack = current onstack; */
+ stx %sp, [%o3 + 0x08] /* sc.sc_sp = sp (both ours and caller's) */
+ add %o7, 8, %o0
+ stx %o0, [%o3 + 0x10] /* sc.sc_pc = return_pc */
+ add %o7, 12, %o0
+ stx %o0, [%o3 + 0x18] /* sc.sc_npc = return_pc + 4 */
+ stx %g0, [%o3 + 0x20] /* sc.sc_psr = (clean psr) */
+ stx %fp, [%o3 + 0x28] /* sc.sc_g1 = %fp (misuse, but what the heck) */
+ /* sc.sc_o0 = random(), set in longjmp */
+ retl /* return 0 */
+ clr %o0
+
+/*
+ * All we need to do here is force sigreturn to load a new stack pointer,
+ * new <pc,npc>, and appropriate %o0 return value from the sigcontext built
+ * in setjmp. The %i and %l registers will be reloaded from the place to
+ * which %sp points, due to sigreturn() semantics (sigreturn does not modify
+ * the window pointer in the psr, hence it must force all windows to reload).
+ */
+ENTRY(longjmp)
+ save %sp, -CC64FSZ, %sp
+ ldx [%i0 + 0x08], %o2 /* make sure sc->sc_sp, sc->sc_fp nonzero */
+ ldx [%i0 + 0x28], %o3
+ orcc %o2, %o3, %g0
+ bz,pn %xcc, Lbotch
+ movrz %i1, 1, %i1 /* if (v == 0) v = 1; */
+ st %i1, [%i0 + 0x30] /* sc.sc_o0 = v; */
+ mov SYS_sigreturn, %g1
+ mov %i0, %o0
+ t ST_SYSCALL /* sigreturn(scp); */
+
+Lbotch:
+ /* oops, caller botched it */
+ call _C_LABEL(longjmperror)
+ nop
+ unimp 0
diff --git a/lib/libc/arch/sparc64/gen/sigsetjmp.S b/lib/libc/arch/sparc64/gen/sigsetjmp.S
new file mode 100644
index 00000000000..a7d71420ee1
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/sigsetjmp.S
@@ -0,0 +1,75 @@
+/* $OpenBSD: sigsetjmp.S,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: sigsetjmp.S,v 1.5 2000/08/28 00:45:59 eeh Exp $ */
+/*
+ * Copyright (c) 1995 Paul Kranenburg
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Paul Kranenburg.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "SYS.h"
+
+#ifdef PIC
+
+ENTRY(sigsetjmp)
+ PIC_PROLOGUE(%g1,%o2) ! %g1 = _GLOBAL_OFFSET_TABLE
+ set _C_LABEL(setjmp), %o2 ! if (%o1 != 0) goto _setjmp;
+ set _C_LABEL(_setjmp), %o3 ! else goto __setjmp;
+ movrnz %o1, %o2, %o3
+ ldx [%g1+%o3], %g1
+ jmp %g1
+ st %o1,[%o0+0x48] ! jmpbuf[JBLEN]
+
+
+ENTRY(siglongjmp)
+ PIC_PROLOGUE(%g1,%o2) ! %g1 = _GLOBAL_OFFSET_TABLE
+ ld [%o0 + 0x48],%o2 ! jmpbuf[JBLEN]
+ set _C_LABEL(longjmp), %o3 ! if (%o2 != 0) goto _longjmp;
+ set _C_LABEL(_longjmp), %o4 ! else goto __longjmp;
+ movrnz %o2, %o3, %o4
+ ldx [%g1 + %o4], %g1
+ jmp %g1
+ nop
+ unimp 0
+
+#else /* PIC */
+
+ENTRY(sigsetjmp)
+ brz,pt %o1,_C_LABEL(_setjmp)
+ st %o1,[%o0+0x48] ! jmpbuf[JBLEN]
+ ba,a,pt %icc,_C_LABEL(setjmp)
+ nop ! spitfire bug
+ unimp 0
+
+ENTRY(siglongjmp)
+ ld [%o0 + 0x48], %g1
+ brz,pt %g1, _C_LABEL(_longjmp)
+ nop
+ ba,a,pt %icc, _C_LABEL(longjmp)
+ unimp 0
+
+#endif /* PIC */
diff --git a/lib/libc/arch/sparc64/gen/umul.S b/lib/libc/arch/sparc64/gen/umul.S
new file mode 100644
index 00000000000..24ed2b210b8
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/umul.S
@@ -0,0 +1,60 @@
+/* $OpenBSD: umul.S,v 1.1 2001/08/29 01:45:24 art Exp $ */
+/* $NetBSD: umul.S,v 1.1 1998/09/11 04:56:30 eeh Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Header: umul.s,v 1.4 92/06/25 13:24:05 torek Exp
+ */
+
+#include <machine/asm.h>
+
+/*
+ * Unsigned multiply. Returns %o0 * %o1 in %o0
+ *
+ * According to the manual the smaller parameter should be in
+ * rs1, so we'll move it there.
+ */
+
+FUNC(.umul)
+ cmp %o0, %o1
+ bge 1f
+ nop
+ retl
+ mulx %o0, %o1, %o0
+1:
+ retl
+ mulx %o1, %o0, %o0