xref: /haiku/src/system/libroot/posix/glibc/arch/m68k/submul_1.S (revision dd68e9e8b4273bb7f91680e04f5cda6ec74a73a8)
1*dd68e9e8SFrançois Revol/* mc68020 __mpn_submul_1 -- Multiply a limb vector with a limb and subtract
2*dd68e9e8SFrançois Revol   the result from a second limb vector.
3*dd68e9e8SFrançois Revol
4*dd68e9e8SFrançois RevolCopyright (C) 1992, 1994, 1996, 1998 Free Software Foundation, Inc.
5*dd68e9e8SFrançois Revol
6*dd68e9e8SFrançois RevolThis file is part of the GNU MP Library.
7*dd68e9e8SFrançois Revol
8*dd68e9e8SFrançois RevolThe GNU MP Library is free software; you can redistribute it and/or modify
9*dd68e9e8SFrançois Revolit under the terms of the GNU Lesser General Public License as published by
10*dd68e9e8SFrançois Revolthe Free Software Foundation; either version 2.1 of the License, or (at your
11*dd68e9e8SFrançois Revoloption) any later version.
12*dd68e9e8SFrançois Revol
13*dd68e9e8SFrançois RevolThe GNU MP Library is distributed in the hope that it will be useful, but
14*dd68e9e8SFrançois RevolWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15*dd68e9e8SFrançois Revolor FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16*dd68e9e8SFrançois RevolLicense for more details.
17*dd68e9e8SFrançois Revol
18*dd68e9e8SFrançois RevolYou should have received a copy of the GNU Lesser General Public License
19*dd68e9e8SFrançois Revolalong with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20*dd68e9e8SFrançois Revolthe Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21*dd68e9e8SFrançois RevolMA 02111-1307, USA. */
22*dd68e9e8SFrançois Revol
23*dd68e9e8SFrançois Revol/*
24*dd68e9e8SFrançois Revol  INPUT PARAMETERS
25*dd68e9e8SFrançois Revol  res_ptr	(sp + 4)
26*dd68e9e8SFrançois Revol  s1_ptr	(sp + 8)
27*dd68e9e8SFrançois Revol  s1_size	(sp + 12)
28*dd68e9e8SFrançois Revol  s2_limb	(sp + 16)
29*dd68e9e8SFrançois Revol*/
30*dd68e9e8SFrançois Revol
31*dd68e9e8SFrançois Revol#include "sysdep.h"
32*dd68e9e8SFrançois Revol#include "asm-syntax.h"
33*dd68e9e8SFrançois Revol
34*dd68e9e8SFrançois Revol	TEXT
35*dd68e9e8SFrançois RevolENTRY(__mpn_submul_1)
36*dd68e9e8SFrançois Revol
37*dd68e9e8SFrançois Revol#define res_ptr a0
38*dd68e9e8SFrançois Revol#define s1_ptr a1
39*dd68e9e8SFrançois Revol#define s1_size d2
40*dd68e9e8SFrançois Revol#define s2_limb d4
41*dd68e9e8SFrançois Revol
42*dd68e9e8SFrançois Revol/* Save used registers on the stack.  */
43*dd68e9e8SFrançois Revol	moveml	R(d2)-R(d5),MEM_PREDEC(sp)
44*dd68e9e8SFrançois Revol
45*dd68e9e8SFrançois Revol/* Copy the arguments to registers.  Better use movem?  */
46*dd68e9e8SFrançois Revol	movel	MEM_DISP(sp,20),R(res_ptr)
47*dd68e9e8SFrançois Revol	movel	MEM_DISP(sp,24),R(s1_ptr)
48*dd68e9e8SFrançois Revol	movel	MEM_DISP(sp,28),R(s1_size)
49*dd68e9e8SFrançois Revol	movel	MEM_DISP(sp,32),R(s2_limb)
50*dd68e9e8SFrançois Revol
51*dd68e9e8SFrançois Revol	eorw	#1,R(s1_size)
52*dd68e9e8SFrançois Revol	clrl	R(d1)
53*dd68e9e8SFrançois Revol	clrl	R(d5)
54*dd68e9e8SFrançois Revol	lsrl	#1,R(s1_size)
55*dd68e9e8SFrançois Revol	bcc	L(L1)
56*dd68e9e8SFrançois Revol	subql	#1,R(s1_size)
57*dd68e9e8SFrançois Revol	subl	R(d0),R(d0)	/* (d0,cy) <= (0,0) */
58*dd68e9e8SFrançois Revol
59*dd68e9e8SFrançois RevolL(Loop:)
60*dd68e9e8SFrançois Revol	movel	MEM_POSTINC(s1_ptr),R(d3)
61*dd68e9e8SFrançois Revol	mulul	R(s2_limb),R(d1):R(d3)
62*dd68e9e8SFrançois Revol	addxl	R(d0),R(d3)
63*dd68e9e8SFrançois Revol	addxl	R(d5),R(d1)
64*dd68e9e8SFrançois Revol	subl	R(d3),MEM_POSTINC(res_ptr)
65*dd68e9e8SFrançois RevolL(L1:)	movel	MEM_POSTINC(s1_ptr),R(d3)
66*dd68e9e8SFrançois Revol	mulul	R(s2_limb),R(d0):R(d3)
67*dd68e9e8SFrançois Revol	addxl	R(d1),R(d3)
68*dd68e9e8SFrançois Revol	addxl	R(d5),R(d0)
69*dd68e9e8SFrançois Revol	subl	R(d3),MEM_POSTINC(res_ptr)
70*dd68e9e8SFrançois Revol
71*dd68e9e8SFrançois Revol	dbf	R(s1_size),L(Loop)
72*dd68e9e8SFrançois Revol	addxl	R(d5),R(d0)
73*dd68e9e8SFrançois Revol	subl	#0x10000,R(s1_size)
74*dd68e9e8SFrançois Revol	bcc	L(Loop)
75*dd68e9e8SFrançois Revol
76*dd68e9e8SFrançois Revol/* Restore used registers from stack frame.  */
77*dd68e9e8SFrançois Revol	moveml	MEM_POSTINC(sp),R(d2)-R(d5)
78*dd68e9e8SFrançois Revol
79*dd68e9e8SFrançois Revol	rts
80*dd68e9e8SFrançois RevolEND(__mpn_submul_1)
81