17c478bd9Sstevel@tonic-gate/* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57257d1b4Sraf * Common Development and Distribution License (the "License"). 67257d1b4Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217257d1b4Sraf 227c478bd9Sstevel@tonic-gate/* 237257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 27*9a70fc3bSMark J. Nelson .file "ldivide.s" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate/ Double long divide routine. 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate#include "SYS.h" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate .set lop,16 347c478bd9Sstevel@tonic-gate .set rop,24 357c478bd9Sstevel@tonic-gate .set ans,0 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate ENTRY(ldivide) 387c478bd9Sstevel@tonic-gate popl %eax 397c478bd9Sstevel@tonic-gate xchgl %eax,0(%esp) 407c478bd9Sstevel@tonic-gate pushl %eax 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate pushl %esi 437c478bd9Sstevel@tonic-gate pushl %edi 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate movl lop(%esp),%eax 467c478bd9Sstevel@tonic-gate movl lop+4(%esp),%edx 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate/ the following code is only for compatibility with original ldivide code 497c478bd9Sstevel@tonic-gate orl %edx,%edx / force numerator positive 507c478bd9Sstevel@tonic-gate jns .ldiv1 517c478bd9Sstevel@tonic-gate notl %edx 527c478bd9Sstevel@tonic-gate negl %eax 537c478bd9Sstevel@tonic-gate sbbl $0xffffffff,%edx 547c478bd9Sstevel@tonic-gate.ldiv1: 557c478bd9Sstevel@tonic-gate testl $0x80000000,rop+4(%esp) 567c478bd9Sstevel@tonic-gate jz .ldiv2 577c478bd9Sstevel@tonic-gate notl rop+4(%esp) / force denominator positive 587c478bd9Sstevel@tonic-gate negl rop(%esp) 597c478bd9Sstevel@tonic-gate sbbl $0xffffffff,rop+4(%esp) 607c478bd9Sstevel@tonic-gate.ldiv2: 617c478bd9Sstevel@tonic-gate/ end of compatibility code 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate xorl %esi,%esi / initialize remainder to 0 647c478bd9Sstevel@tonic-gate movl %esi,%edi 657c478bd9Sstevel@tonic-gate movl $64,%ecx / initialize counter for 64-bits 667c478bd9Sstevel@tonic-gate.div_mod_loop: 677c478bd9Sstevel@tonic-gate shll $1,%edi 687c478bd9Sstevel@tonic-gate rcll $1,%esi / remainder * 2 697c478bd9Sstevel@tonic-gate shll $1,%eax 707c478bd9Sstevel@tonic-gate rcll $1,%edx / numerator * 2 (also quotient) 717c478bd9Sstevel@tonic-gate adcl $0,%edi / add in any carry from the shift 727c478bd9Sstevel@tonic-gate subl rop(%esp),%edi / subtract denominator from remainder 737c478bd9Sstevel@tonic-gate sbbl rop+4(%esp),%esi 747c478bd9Sstevel@tonic-gate incl %eax / turn on quotient bit for now 757c478bd9Sstevel@tonic-gate jnc .inc_remainder / inc didn't affect carry flag 767c478bd9Sstevel@tonic-gate/ can't subtract the denominator from the remainder, add it back 777c478bd9Sstevel@tonic-gate addl rop(%esp),%edi 787c478bd9Sstevel@tonic-gate adcl rop+4(%esp),%esi 797c478bd9Sstevel@tonic-gate decl %eax / turn quotient bit off 807c478bd9Sstevel@tonic-gate.inc_remainder: 817c478bd9Sstevel@tonic-gate loop .div_mod_loop 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate/ at this point, %edx:%eax has the quotient and %edi:%esi has the remainder 847c478bd9Sstevel@tonic-gate popl %edi 857c478bd9Sstevel@tonic-gate popl %esi 867c478bd9Sstevel@tonic-gate movl %eax,%ecx 877c478bd9Sstevel@tonic-gate popl %eax 887c478bd9Sstevel@tonic-gate movl %ecx,ans(%eax) 897c478bd9Sstevel@tonic-gate movl %edx,ans+4(%eax) 907c478bd9Sstevel@tonic-gate ret 917c478bd9Sstevel@tonic-gate SET_SIZE(ldivide) 92