/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* .seg "data"
* .asciz "Copyr 1987 Sun Micro"
* .align 4
*/
.seg "text"
#ident "%Z%%M% %I% %E% SMI"
#include <sys/asm_linkage.h>
/*
* procedure to perform a 32 by 32 unsigned integer multiply.
* pass the multiplier into %o0, and the multiplicand into %o1
* the least significant 32 bits of the result will be returned in %o0,
* and the most significant in %o1
*
* Most unsigned integer multiplies involve small numbers, so it is
* worthwhile to optimize for short multiplies at the expense of long
* multiplies. This code checks the size of the multiplier, and has
* special cases for the following:
*
* 4 or fewer bit multipliers: 19 or 21 instruction cycles
* 8 or fewer bit multipliers: 26 or 28 instruction cycles
* 12 or fewer bit multipliers: 34 or 36 instruction cycles
* 16 or fewer bit multipliers: 42 or 44 instruction cycles
*
* Long multipliers require 58 or 60 instruction cycles:
*
* This code indicates that overflow has occured, by leaving the Z condition
* code clear. The following call sequence would be used if you wish to
* deal with overflow:
*
* call .umul
* nop ( or set up last parameter here )
* bnz overflow_code (or tnz to overflow handler)
*/
.umul:
!
! long multiply
!
!
!
!
!
!
!
!
!
!
!
bge 1f
!
!
! if you are not interested in detecting overflow,
! replace the following code with:
!
! 1:
! rd %y, %o0
! retl
! mov %o4, %o1
!
1:
rd %y, %o0
retl ! leaf routine return
addcc %o4, %g0, %o1 ! return high-order bits and set Z if
! high order bits are 0
!
! 4-bit multiply
!
umul_4bit:
mulscc %o4, %o1, %o4 ! first iteration of 5
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4 ! 4th iteration
mulscc %o4, %g0, %o4 ! last iteration only shifts
rd %y, %o5
!
! The folowing code adds (2**32) * %o0 to the product if the
!
bge 2f
!
!
! if you are not interested in detecting overflow,
! replace the following code with:
!
! 2:
! sll %o4, 4, %o0
! srl %o5, 28, %o5
! retl
! or %o5, %o0, %o0
!
2:
sll %o4, 4, %o0 ! left shift middle bits by 4 bits
srl %o5, 28, %o5 ! right shift low bits by 28 bits
or %o5, %o0, %o0 ! merge for true product
retl ! leaf routine return
tst %o1 ! set Z if high order bits are 0
!
! 8-bit multiply
!
umul_8bit:
mulscc %o4, %o1, %o4 ! second iteration of 9
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4 ! 8th iteration
mulscc %o4, %g0, %o4 ! last iteration only shifts
rd %y, %o5
!
! The folowing code adds (2**32) * %o0 to the product if the
!
bge 3f
!
!
! if you are not interested in detecting overflow,
! replace the following code with:
!
! 3:
! sll %o4, 8, %o0
! srl %o5, 24, %o5
! retl
! or %o5, %o0, %o0
!
3:
sll %o4, 8, %o0 ! left shift middle bits by 8 bits
srl %o5, 24, %o5 ! right shift low bits by 24 bits
or %o5, %o0, %o0 ! merge for true product
retl ! leaf routine return
tst %o1 ! set Z if high order bits are 0
!
! 12-bit multiply
!
umul_12bit:
mulscc %o4, %o1, %o4 ! second iteration of 13
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4 ! 12th iteration
mulscc %o4, %g0, %o4 ! last iteration only shifts
rd %y, %o5
!
! The folowing code adds (2**32) * %o0 to the product if the
!
bge 4f
!
!
! if you are not interested in detecting overflow,
! replace the following code with:
!
! 4:
! sll %o4, 12, %o0
! srl %o5, 20, %o5
! retl
! or %o5, %o0, %o0
!
4:
sll %o4, 12, %o0 ! left shift middle bits by 12 bits
srl %o5, 20, %o5 ! right shift low bits by 20 bits
or %o5, %o0, %o0 ! merge for true product
retl ! leaf routine return
tst %o1 ! set Z if high order bits are 0
!
! 16-bit multiply
!
umul_16bit:
mulscc %o4, %o1, %o4 ! second iteration of 17
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4
mulscc %o4, %o1, %o4 ! 16th iteration
mulscc %o4, %g0, %o4 ! last iteration only shifts
rd %y, %o5
!
! The folowing code adds (2**32) * %o0 to the product if the
!
bge 5f
!
!
! if you are not interested in detecting overflow,
! replace the following code with:
!
! 5:
! sll %o4, 16, %o0
! srl %o5, 16, %o5
! retl
! or %o5, %o0, %o0
!
5:
sll %o4, 16, %o0 ! left shift middle bits by 16 bits
srl %o5, 16, %o5 ! right shift low bits by 16 bits
or %o5, %o0, %o0 ! merge for true product
retl ! leaf routine return
tst %o1 ! set Z if high order bits are 0