1b6cbf720SGianluca Guida/*- 2b6cbf720SGianluca Guida * Copyright (c) 1991, 1993 3b6cbf720SGianluca Guida * The Regents of the University of California. All rights reserved. 4b6cbf720SGianluca Guida * 5b6cbf720SGianluca Guida * This code is derived from software contributed to Berkeley by 6b6cbf720SGianluca Guida * Donn Seeley at UUNET Technologies, Inc. 7b6cbf720SGianluca Guida * 8b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without 9b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions 10b6cbf720SGianluca Guida * are met: 11b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright 12b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer. 13b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright 14b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer in the 15b6cbf720SGianluca Guida * documentation and/or other materials provided with the distribution. 16b6cbf720SGianluca Guida * 3. Neither the name of the University nor the names of its contributors 17b6cbf720SGianluca Guida * may be used to endorse or promote products derived from this software 18b6cbf720SGianluca Guida * without specific prior written permission. 19b6cbf720SGianluca Guida * 20b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21b6cbf720SGianluca Guida * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22b6cbf720SGianluca Guida * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23b6cbf720SGianluca Guida * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24b6cbf720SGianluca Guida * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25b6cbf720SGianluca Guida * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26b6cbf720SGianluca Guida * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27b6cbf720SGianluca Guida * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28b6cbf720SGianluca Guida * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29b6cbf720SGianluca Guida * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30b6cbf720SGianluca Guida * SUCH DAMAGE. 31b6cbf720SGianluca Guida */ 32b6cbf720SGianluca Guida 33b6cbf720SGianluca Guida#include <machine/asm.h> 34b6cbf720SGianluca Guida 35*f14fb602SLionel Sambuc /* .asciz "@(#)urem.s 8.1 (Berkeley) 6/4/93" */ 36*f14fb602SLionel SambucRCSID("$NetBSD: urem.S,v 1.3 2011/01/25 04:45:28 matt Exp $") 37*f14fb602SLionel Sambuc 38b6cbf720SGianluca Guida/* 39b6cbf720SGianluca Guida * Unsigned modulus, PCC flavor. 40b6cbf720SGianluca Guida * urem() takes an ordinary dividend/divisor pair; 41b6cbf720SGianluca Guida * aurem() takes a pointer to a dividend and an ordinary divisor. 42b6cbf720SGianluca Guida */ 43b6cbf720SGianluca Guida 44b6cbf720SGianluca Guida#define DIVIDEND 4(%ap) 45b6cbf720SGianluca Guida#define DIVISOR 8(%ap) 46b6cbf720SGianluca Guida 47b6cbf720SGianluca GuidaASENTRY(__urem,0) 48b6cbf720SGianluca Guida movl DIVISOR,%r2 49b6cbf720SGianluca Guida jlss Leasy # big divisor: settle by comparison 50b6cbf720SGianluca Guida movl DIVIDEND,%r0 51b6cbf720SGianluca Guida jlss Lhard # big dividend: need extended division 52b6cbf720SGianluca Guida divl3 %r2,%r0,%r1 # small divisor and dividend: signed modulus 53b6cbf720SGianluca Guida mull2 %r2,%r1 54b6cbf720SGianluca Guida subl2 %r1,%r0 55b6cbf720SGianluca Guida ret 56b6cbf720SGianluca GuidaLhard: 57b6cbf720SGianluca Guida clrl %r1 58b6cbf720SGianluca Guida ediv %r2,%r0,%r1,%r0 59b6cbf720SGianluca Guida ret 60b6cbf720SGianluca GuidaLeasy: 61b6cbf720SGianluca Guida subl3 %r2,DIVIDEND,%r0 62b6cbf720SGianluca Guida jcc Ldifference # if divisor goes in once, return difference 63b6cbf720SGianluca Guida movl DIVIDEND,%r0 # if divisor is bigger, return dividend 64b6cbf720SGianluca GuidaLdifference: 65b6cbf720SGianluca Guida ret 66*f14fb602SLionel SambucEND(__urem) 67b6cbf720SGianluca Guida 68b6cbf720SGianluca GuidaASENTRY(__aurem,0) 69b6cbf720SGianluca Guida movl DIVIDEND,%r3 70b6cbf720SGianluca Guida movl DIVISOR,%r2 71b6cbf720SGianluca Guida jlss La_easy # big divisor: settle by comparison 72b6cbf720SGianluca Guida movl (%r3),%r0 73b6cbf720SGianluca Guida jlss La_hard # big dividend: need extended division 74b6cbf720SGianluca Guida divl3 %r2,%r0,%r1 # small divisor and dividend: signed modulus 75b6cbf720SGianluca Guida mull2 %r2,%r1 76b6cbf720SGianluca Guida subl2 %r1,%r0 77b6cbf720SGianluca Guida movl %r0,(%r3) # leave the value of the assignment in %r0 78b6cbf720SGianluca Guida ret 79b6cbf720SGianluca GuidaLa_hard: 80b6cbf720SGianluca Guida clrl %r1 81b6cbf720SGianluca Guida ediv %r2,%r0,%r1,%r0 82b6cbf720SGianluca Guida movl %r0,(%r3) 83b6cbf720SGianluca Guida ret 84b6cbf720SGianluca GuidaLa_easy: 85b6cbf720SGianluca Guida subl3 %r2,(%r3),%r0 86b6cbf720SGianluca Guida jcs La_dividend # if divisor is bigger, leave dividend alone 87b6cbf720SGianluca Guida movl %r0,(%r3) # if divisor goes in once, store difference 88b6cbf720SGianluca Guida ret 89b6cbf720SGianluca GuidaLa_dividend: 90b6cbf720SGianluca Guida movl (%r3),%r0 91b6cbf720SGianluca Guida ret 92*f14fb602SLionel SambucEND(__aurem) 93