xref: /openbsd/sys/lib/libkern/arch/m88k/divsi3.S (revision 143cf4a7)
1*143cf4a7Smiod/*	$OpenBSD: divsi3.S,v 1.1 2013/06/07 17:31:31 miod Exp $	*/
2*143cf4a7Smiod
3*143cf4a7Smiod/*
4*143cf4a7Smiod * Copyright (c) 2013 Miodrag Vallat.
5*143cf4a7Smiod *
6*143cf4a7Smiod * Permission to use, copy, modify, and distribute this software for any
7*143cf4a7Smiod * purpose with or without fee is hereby granted, provided that the above
8*143cf4a7Smiod * copyright notice and this permission notice appear in all copies.
9*143cf4a7Smiod *
10*143cf4a7Smiod * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*143cf4a7Smiod * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*143cf4a7Smiod * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*143cf4a7Smiod * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*143cf4a7Smiod * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15*143cf4a7Smiod * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16*143cf4a7Smiod * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*143cf4a7Smiod */
18*143cf4a7Smiod
19*143cf4a7Smiod
20*143cf4a7Smiod#include <machine/asm.h>
21*143cf4a7Smiod
22*143cf4a7Smiod/*
23*143cf4a7Smiod * int __divsi3(int n, int d);
24*143cf4a7Smiod */
25*143cf4a7Smiod
26*143cf4a7SmiodENTRY(__divsi3)
27*143cf4a7Smiod	/* if divider is zero, trap */
28*143cf4a7Smiod	bcnd	ne0, %r3, 1f
29*143cf4a7Smiod	tb0	0, %r0, 503
30*143cf4a7Smiod1:
31*143cf4a7Smiod
32*143cf4a7Smiod	bb1	31, %r2, 1f
33*143cf4a7Smiod	bb1	31, %r3, 2f
34*143cf4a7Smiod
35*143cf4a7Smiod	/* both operands are positive */
36*143cf4a7Smiod	jmp.n	%r1
37*143cf4a7Smiod	 divu	%r2, %r2, %r3
38*143cf4a7Smiod
39*143cf4a7Smiod1:
40*143cf4a7Smiod	bb1	31, %r3, 3f
41*143cf4a7Smiod
42*143cf4a7Smiod	/* r2 is negative, r3 is positive */
43*143cf4a7Smiod	subu	%r4, %r0, %r2
44*143cf4a7Smiod	divu	%r5, %r4, %r3
45*143cf4a7Smiod	jmp.n	%r1
46*143cf4a7Smiod	 subu	%r2, %r0, %r5
47*143cf4a7Smiod
48*143cf4a7Smiod2:
49*143cf4a7Smiod	/* r2 is positive, r3 is negative */
50*143cf4a7Smiod	subu	%r5, %r0, %r3
51*143cf4a7Smiod	divu	%r4, %r2, %r5
52*143cf4a7Smiod	jmp.n	%r1
53*143cf4a7Smiod	 subu	%r2, %r0, %r4
54*143cf4a7Smiod
55*143cf4a7Smiod3:
56*143cf4a7Smiod	/* both operands are negative */
57*143cf4a7Smiod	subu	%r4, %r0, %r2
58*143cf4a7Smiod	subu	%r5, %r0, %r3
59*143cf4a7Smiod	jmp.n	%r1
60*143cf4a7Smiod	 divu	%r2, %r4, %r5
61*143cf4a7SmiodEND(__divsi3)
62