xref: /haiku/src/system/libroot/posix/glibc/arch/sparc/submul_1.S (revision 4b2da9c371d02367607d33358d88ac5996fb5ea0)
1*4b2da9c3SPulkoMandy/* SPARC v9 __mpn_submul_1 -- Multiply a limb vector with a single limb and
2*4b2da9c3SPulkoMandy   subtract the product from a second limb vector.
3*4b2da9c3SPulkoMandy
4*4b2da9c3SPulkoMandy   Copyright (C) 1996-2018 Free Software Foundation, Inc.
5*4b2da9c3SPulkoMandy
6*4b2da9c3SPulkoMandy   This file is part of the GNU MP Library.
7*4b2da9c3SPulkoMandy
8*4b2da9c3SPulkoMandy   The GNU MP Library is free software; you can redistribute it and/or modify
9*4b2da9c3SPulkoMandy   it under the terms of the GNU Lesser General Public License as published by
10*4b2da9c3SPulkoMandy   the Free Software Foundation; either version 2.1 of the License, or (at your
11*4b2da9c3SPulkoMandy   option) any later version.
12*4b2da9c3SPulkoMandy
13*4b2da9c3SPulkoMandy   The GNU MP Library is distributed in the hope that it will be useful, but
14*4b2da9c3SPulkoMandy   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15*4b2da9c3SPulkoMandy   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16*4b2da9c3SPulkoMandy   License for more details.
17*4b2da9c3SPulkoMandy
18*4b2da9c3SPulkoMandy   You should have received a copy of the GNU Lesser General Public License
19*4b2da9c3SPulkoMandy   along with the GNU MP Library; see the file COPYING.LIB.  If not,
20*4b2da9c3SPulkoMandy   see <http://www.gnu.org/licenses/>.  */
21*4b2da9c3SPulkoMandy
22*4b2da9c3SPulkoMandy#include <sysdep.h>
23*4b2da9c3SPulkoMandy
24*4b2da9c3SPulkoMandy
25*4b2da9c3SPulkoMandy/* INPUT PARAMETERS
26*4b2da9c3SPulkoMandy   res_ptr	o0
27*4b2da9c3SPulkoMandy   s1_ptr	o1
28*4b2da9c3SPulkoMandy   size		o2
29*4b2da9c3SPulkoMandy   s2_limb	o3  */
30*4b2da9c3SPulkoMandy
31*4b2da9c3SPulkoMandyENTRY(__mpn_submul_1)
32*4b2da9c3SPulkoMandy	save	%sp,-192,%sp
33*4b2da9c3SPulkoMandy
34*4b2da9c3SPulkoMandy	sub	%g0,%i2,%o7
35*4b2da9c3SPulkoMandy	mov	0,%o0			! zero cy_limb
36*4b2da9c3SPulkoMandy	sllx	%o7,3,%o7
37*4b2da9c3SPulkoMandy	sethi	%hi(0x80000000),%o2
38*4b2da9c3SPulkoMandy	srl	%i3,0,%o1		! extract low 32 bits of s2_limb
39*4b2da9c3SPulkoMandy	sub	%i1,%o7,%o3
40*4b2da9c3SPulkoMandy	srlx	%i3,32,%i3		! extract high 32 bits of s2_limb
41*4b2da9c3SPulkoMandy	sub	%i0,%o7,%o4
42*4b2da9c3SPulkoMandy	add	%o2,%o2,%o2		! o2 = 0x100000000
43*4b2da9c3SPulkoMandy
44*4b2da9c3SPulkoMandy	!   hi   !
45*4b2da9c3SPulkoMandy             !  mid-1 !
46*4b2da9c3SPulkoMandy             !  mid-2 !
47*4b2da9c3SPulkoMandy		 !   lo   !
48*4b2da9c3SPulkoMandy1:
49*4b2da9c3SPulkoMandy	ldx	[%o3+%o7],%g5
50*4b2da9c3SPulkoMandy	srl	%g5,0,%i0		! zero hi bits
51*4b2da9c3SPulkoMandy	ldx	[%o4+%o7],%l1
52*4b2da9c3SPulkoMandy	srlx	%g5,32,%g5
53*4b2da9c3SPulkoMandy	mulx	%o1,%i0,%i4		! lo product
54*4b2da9c3SPulkoMandy	mulx	%i3,%i0,%i1		! mid-1 product
55*4b2da9c3SPulkoMandy	mulx	%o1,%g5,%l2		! mid-2 product
56*4b2da9c3SPulkoMandy	mulx	%i3,%g5,%i5		! hi product
57*4b2da9c3SPulkoMandy	srlx	%i4,32,%i0		! extract high 32 bits of lo product...
58*4b2da9c3SPulkoMandy	add	%i1,%i0,%i1		! ...and add it to the mid-1 product
59*4b2da9c3SPulkoMandy	addcc	%i1,%l2,%i1		! add mid products
60*4b2da9c3SPulkoMandy	mov	0,%l0			! we need the carry from that add...
61*4b2da9c3SPulkoMandy	movcs	%xcc,%o2,%l0		! ...compute it and...
62*4b2da9c3SPulkoMandy	sllx	%i1,32,%i0		!  align low bits of mid product
63*4b2da9c3SPulkoMandy	add	%i5,%l0,%i5		! ...add to bit 32 of the hi product
64*4b2da9c3SPulkoMandy	srl	%i4,0,%g5		! zero high 32 bits of lo product
65*4b2da9c3SPulkoMandy	add	%i0,%g5,%i0		! combine into low 64 bits of result
66*4b2da9c3SPulkoMandy	srlx	%i1,32,%i1		! extract high bits of mid product...
67*4b2da9c3SPulkoMandy	addcc	%i0,%o0,%i0		!  add cy_limb to low 64 bits of result
68*4b2da9c3SPulkoMandy	add	%i5,%i1,%i1		! ...and add them to the high result
69*4b2da9c3SPulkoMandy	mov	0,%g5
70*4b2da9c3SPulkoMandy	movcs	%xcc,1,%g5
71*4b2da9c3SPulkoMandy	subcc	%l1,%i0,%i0
72*4b2da9c3SPulkoMandy	stx	%i0,[%o4+%o7]
73*4b2da9c3SPulkoMandy	add	%g5,1,%l1
74*4b2da9c3SPulkoMandy	movcs	%xcc,%l1,%g5
75*4b2da9c3SPulkoMandy	addcc	%o7,8,%o7
76*4b2da9c3SPulkoMandy	bne,pt	%xcc,1b
77*4b2da9c3SPulkoMandy	 add	%i1,%g5,%o0		! compute new cy_limb
78*4b2da9c3SPulkoMandy
79*4b2da9c3SPulkoMandy	jmpl	%i7+8, %g0
80*4b2da9c3SPulkoMandy	 restore %o0,%g0,%o0
81*4b2da9c3SPulkoMandy
82*4b2da9c3SPulkoMandyEND(__mpn_submul_1)
83