2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A .file "hwmuldiv.s"
2N/A
2N/A#include <sys/asm_linkage.h>
2N/A
2N/A/*
2N/A * Versions of .mul .umul .div .udiv .rem .urem written using
2N/A * appropriate SPARC V8 instructions.
2N/A */
2N/A
2N/A ENTRY(.mul)
2N/A smul %o0, %o1, %o0
2N/A rd %y, %o1
2N/A sra %o0, 31, %o2
2N/A retl
2N/A cmp %o1, %o2 ! return with Z set if %y == (%o0 >> 31)
2N/A SET_SIZE(.mul)
2N/A
2N/A ENTRY(.umul)
2N/A umul %o0, %o1, %o0
2N/A rd %y, %o1
2N/A retl
2N/A tst %o1 ! return with Z set if high order bits are zero
2N/A SET_SIZE(.umul)
2N/A
2N/A ENTRY(.div)
2N/A sra %o0, 31, %o2
2N/A wr %g0, %o2, %y
2N/A nop
2N/A nop
2N/A nop
2N/A sdivcc %o0, %o1, %o0
2N/A bvs,a 1f
2N/A xnor %o0, %g0, %o0 ! Corbett Correction Factor
2N/A1: retl
2N/A nop
2N/A SET_SIZE(.div)
2N/A
2N/A ENTRY(.udiv)
2N/A wr %g0, %g0, %y
2N/A nop
2N/A nop
2N/A retl
2N/A udiv %o0, %o1, %o0
2N/A SET_SIZE(.udiv)
2N/A
2N/A ENTRY(.rem)
2N/A sra %o0, 31, %o4
2N/A wr %o4, %g0, %y
2N/A nop
2N/A nop
2N/A nop
2N/A sdivcc %o0, %o1, %o2
2N/A bvs,a 1f
2N/A xnor %o2, %g0, %o2 ! Corbett Correction Factor
2N/A1: smul %o2, %o1, %o2
2N/A retl
2N/A sub %o0, %o2, %o0
2N/A SET_SIZE(.rem)
2N/A
2N/A ENTRY(.urem)
2N/A wr %g0, %g0, %y
2N/A nop
2N/A nop
2N/A nop
2N/A udiv %o0, %o1, %o2
2N/A umul %o2, %o1, %o2
2N/A retl
2N/A sub %o0, %o2, %o0
2N/A SET_SIZE(.urem)
2N/A
2N/A/*
2N/A * v8plus versions of __{u,}{mul,div,rem}64 compiler support routines
2N/A */
2N/A
2N/A/*
2N/A * Convert 32-bit arg pairs in %o0:o1 and %o2:%o3 to 64-bit args in %o1 and %o2
2N/A */
2N/A#define ARGS_TO_64 \
2N/A sllx %o0, 32, %o0; \
2N/A srl %o1, 0, %o1; \
2N/A sllx %o2, 32, %o2; \
2N/A srl %o3, 0, %o3; \
2N/A or %o0, %o1, %o1; \
2N/A or %o2, %o3, %o2
2N/A
2N/A!
2N/A! division, signed
2N/A!
2N/A ENTRY(__div64)
2N/A ARGS_TO_64
2N/A sdivx %o1, %o2, %o1
2N/A retl
2N/A srax %o1, 32, %o0
2N/A SET_SIZE(__div64)
2N/A
2N/A!
2N/A! division, unsigned
2N/A!
2N/A ENTRY(__udiv64)
2N/A ARGS_TO_64
2N/A udivx %o1, %o2, %o1
2N/A retl
2N/A srax %o1, 32, %o0
2N/A SET_SIZE(__udiv64)
2N/A
2N/A!
2N/A! multiplication, signed and unsigned
2N/A!
2N/A ENTRY(__mul64)
2N/A ALTENTRY(__umul64)
2N/A ARGS_TO_64
2N/A sub %o1, %o2, %o0 ! %o0 = a - b
2N/A movrlz %o0, %g0, %o0 ! %o0 = (a < b) ? 0 : a - b
2N/A sub %o1, %o0, %o1 ! %o1 = (a < b) ? a : b = min(a, b)
2N/A add %o2, %o0, %o2 ! %o2 = (a < b) ? b : a = max(a, b)
2N/A mulx %o1, %o2, %o1 ! min(a, b) in "rs1" for early exit
2N/A retl
2N/A srax %o1, 32, %o0
2N/A SET_SIZE(__mul64)
2N/A SET_SIZE(__umul64)
2N/A
2N/A!
2N/A! unsigned remainder
2N/A!
2N/A ENTRY(__urem64)
2N/A ARGS_TO_64
2N/A udivx %o1, %o2, %o3
2N/A mulx %o3, %o2, %o3
2N/A sub %o1, %o3, %o1
2N/A retl
2N/A srax %o1, 32, %o0
2N/A SET_SIZE(__urem64)
2N/A
2N/A!
2N/A! signed remainder
2N/A!
2N/A ENTRY(__rem64)
2N/A ARGS_TO_64
2N/A sdivx %o1, %o2, %o3
2N/A mulx %o2, %o3, %o3
2N/A sub %o1, %o3, %o1
2N/A retl
2N/A srax %o1, 32, %o0
2N/A SET_SIZE(__rem64)