10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7298SMark.J.Nelson@Sun.COM * Common Development and Distribution License (the "License"). 6*7298SMark.J.Nelson@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate/* 22544Sjwadams * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 23544Sjwadams * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 26*7298SMark.J.Nelson@Sun.COM .file "hwmuldiv.s" 270Sstevel@tonic-gate 280Sstevel@tonic-gate#include <sys/asm_linkage.h> 290Sstevel@tonic-gate 300Sstevel@tonic-gate/* 310Sstevel@tonic-gate * Versions of .mul .umul .div .udiv .rem .urem written using 320Sstevel@tonic-gate * appropriate SPARC V8 instructions. 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate ENTRY(.mul) 360Sstevel@tonic-gate smul %o0, %o1, %o0 370Sstevel@tonic-gate rd %y, %o1 380Sstevel@tonic-gate sra %o0, 31, %o2 390Sstevel@tonic-gate retl 400Sstevel@tonic-gate cmp %o1, %o2 ! return with Z set if %y == (%o0 >> 31) 410Sstevel@tonic-gate SET_SIZE(.mul) 420Sstevel@tonic-gate 430Sstevel@tonic-gate ENTRY(.umul) 440Sstevel@tonic-gate umul %o0, %o1, %o0 450Sstevel@tonic-gate rd %y, %o1 460Sstevel@tonic-gate retl 470Sstevel@tonic-gate tst %o1 ! return with Z set if high order bits are zero 480Sstevel@tonic-gate SET_SIZE(.umul) 490Sstevel@tonic-gate 500Sstevel@tonic-gate ENTRY(.div) 510Sstevel@tonic-gate sra %o0, 31, %o2 520Sstevel@tonic-gate wr %g0, %o2, %y 530Sstevel@tonic-gate nop 540Sstevel@tonic-gate nop 550Sstevel@tonic-gate nop 560Sstevel@tonic-gate sdivcc %o0, %o1, %o0 570Sstevel@tonic-gate bvs,a 1f 580Sstevel@tonic-gate xnor %o0, %g0, %o0 ! Corbett Correction Factor 590Sstevel@tonic-gate1: retl 600Sstevel@tonic-gate nop 610Sstevel@tonic-gate SET_SIZE(.div) 620Sstevel@tonic-gate 630Sstevel@tonic-gate ENTRY(.udiv) 640Sstevel@tonic-gate wr %g0, %g0, %y 650Sstevel@tonic-gate nop 660Sstevel@tonic-gate nop 670Sstevel@tonic-gate retl 680Sstevel@tonic-gate udiv %o0, %o1, %o0 690Sstevel@tonic-gate SET_SIZE(.udiv) 700Sstevel@tonic-gate 710Sstevel@tonic-gate ENTRY(.rem) 720Sstevel@tonic-gate sra %o0, 31, %o4 730Sstevel@tonic-gate wr %o4, %g0, %y 740Sstevel@tonic-gate nop 750Sstevel@tonic-gate nop 760Sstevel@tonic-gate nop 770Sstevel@tonic-gate sdivcc %o0, %o1, %o2 780Sstevel@tonic-gate bvs,a 1f 790Sstevel@tonic-gate xnor %o2, %g0, %o2 ! Corbett Correction Factor 800Sstevel@tonic-gate1: smul %o2, %o1, %o2 810Sstevel@tonic-gate retl 820Sstevel@tonic-gate sub %o0, %o2, %o0 830Sstevel@tonic-gate SET_SIZE(.rem) 840Sstevel@tonic-gate 850Sstevel@tonic-gate ENTRY(.urem) 860Sstevel@tonic-gate wr %g0, %g0, %y 870Sstevel@tonic-gate nop 880Sstevel@tonic-gate nop 890Sstevel@tonic-gate nop 900Sstevel@tonic-gate udiv %o0, %o1, %o2 910Sstevel@tonic-gate umul %o2, %o1, %o2 920Sstevel@tonic-gate retl 930Sstevel@tonic-gate sub %o0, %o2, %o0 940Sstevel@tonic-gate SET_SIZE(.urem) 95544Sjwadams 96544Sjwadams/* 97544Sjwadams * v8plus versions of __{u,}{mul,div,rem}64 compiler support routines 98544Sjwadams */ 99544Sjwadams 100544Sjwadams/* 101544Sjwadams * Convert 32-bit arg pairs in %o0:o1 and %o2:%o3 to 64-bit args in %o1 and %o2 102544Sjwadams */ 103544Sjwadams#define ARGS_TO_64 \ 104544Sjwadams sllx %o0, 32, %o0; \ 105544Sjwadams srl %o1, 0, %o1; \ 106544Sjwadams sllx %o2, 32, %o2; \ 107544Sjwadams srl %o3, 0, %o3; \ 108544Sjwadams or %o0, %o1, %o1; \ 109544Sjwadams or %o2, %o3, %o2 110544Sjwadams 111544Sjwadams! 112544Sjwadams! division, signed 113544Sjwadams! 114544Sjwadams ENTRY(__div64) 115544Sjwadams ARGS_TO_64 116544Sjwadams sdivx %o1, %o2, %o1 117544Sjwadams retl 118544Sjwadams srax %o1, 32, %o0 119544Sjwadams SET_SIZE(__div64) 120544Sjwadams 121544Sjwadams! 122544Sjwadams! division, unsigned 123544Sjwadams! 124544Sjwadams ENTRY(__udiv64) 125544Sjwadams ARGS_TO_64 126544Sjwadams udivx %o1, %o2, %o1 127544Sjwadams retl 128544Sjwadams srax %o1, 32, %o0 129544Sjwadams SET_SIZE(__udiv64) 130544Sjwadams 131544Sjwadams! 132544Sjwadams! multiplication, signed and unsigned 133544Sjwadams! 134544Sjwadams ENTRY(__mul64) 135544Sjwadams ALTENTRY(__umul64) 136544Sjwadams ARGS_TO_64 137544Sjwadams sub %o1, %o2, %o0 ! %o0 = a - b 138544Sjwadams movrlz %o0, %g0, %o0 ! %o0 = (a < b) ? 0 : a - b 139544Sjwadams sub %o1, %o0, %o1 ! %o1 = (a < b) ? a : b = min(a, b) 140544Sjwadams add %o2, %o0, %o2 ! %o2 = (a < b) ? b : a = max(a, b) 141544Sjwadams mulx %o1, %o2, %o1 ! min(a, b) in "rs1" for early exit 142544Sjwadams retl 143544Sjwadams srax %o1, 32, %o0 144544Sjwadams SET_SIZE(__mul64) 145544Sjwadams SET_SIZE(__umul64) 146544Sjwadams 147544Sjwadams! 148544Sjwadams! unsigned remainder 149544Sjwadams! 150544Sjwadams ENTRY(__urem64) 151544Sjwadams ARGS_TO_64 152544Sjwadams udivx %o1, %o2, %o3 153544Sjwadams mulx %o3, %o2, %o3 154544Sjwadams sub %o1, %o3, %o1 155544Sjwadams retl 156544Sjwadams srax %o1, 32, %o0 157544Sjwadams SET_SIZE(__urem64) 158544Sjwadams 159544Sjwadams! 160544Sjwadams! signed remainder 161544Sjwadams! 162544Sjwadams ENTRY(__rem64) 163544Sjwadams ARGS_TO_64 164544Sjwadams sdivx %o1, %o2, %o3 165544Sjwadams mulx %o2, %o3, %o3 166544Sjwadams sub %o1, %o3, %o1 167544Sjwadams retl 168544Sjwadams srax %o1, 32, %o0 169544Sjwadams SET_SIZE(__rem64) 170