2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc64 / mul_1.S
blob49f83464c4dc367c6e88a5ea108a74671e936fcb
1 /* SPARC v9 __mpn_mul_1 -- Multiply a limb vector with a single limb and
2    store the product in a second limb vector.
4    Copyright (C) 1995, 1996 Free Software Foundation, Inc.
6    This file is part of the GNU MP Library.
8    The GNU MP Library is free software; you can redistribute it and/or modify
9    it under the terms of the GNU Lesser General Public License as published by
10    the Free Software Foundation; either version 2.1 of the License, or (at your
11    option) any later version.
13    The GNU MP Library is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16    License for more details.
18    You should have received a copy of the GNU Lesser General Public License
19    along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20    the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21    MA 02111-1307, USA.  */
23 #include <sysdep.h>
26 /* INPUT PARAMETERS
27    res_ptr      o0
28    s1_ptr       o1
29    size         o2
30    s2_limb      o3  */
32 ENTRY(__mpn_mul_1)
33         !#PROLOGUE#     0
34         save    %sp,-192,%sp
35         !#PROLOGUE#     1
37         sub     %g0,%i2,%o7
38         sllx    %o7,3,%g5
39         sub     %i1,%g5,%o3
40         sub     %i0,%g5,%o4
41         mov     0,%o0                   ! zero cy_limb
43         srl     %i3,0,%o1               ! extract low 32 bits of s2_limb
44         srlx    %i3,32,%i3              ! extract high 32 bits of s2_limb
45         mov     1,%o2
46         sllx    %o2,32,%o2              ! o2 = 0x100000000
48         !   hi   !
49              !  mid-1 !
50              !  mid-2 !
51                  !   lo   !
52 .Loop:
53         sllx    %o7,3,%g1
54         ldx     [%o3+%g1],%g5
55         srl     %g5,0,%i0               ! zero hi bits
56         srlx    %g5,32,%g5
57         mulx    %o1,%i0,%i4             ! lo product
58         mulx    %i3,%i0,%i1             ! mid-1 product
59         mulx    %o1,%g5,%l2             ! mid-2 product
60         mulx    %i3,%g5,%i5             ! hi product
61         srlx    %i4,32,%i0              ! extract high 32 bits of lo product...
62         add     %i1,%i0,%i1             ! ...and add it to the mid-1 product
63         addcc   %i1,%l2,%i1             ! add mid products
64         mov     0,%l0                   ! we need the carry from that add...
65         movcs   %xcc,%o2,%l0            ! ...compute it and...
66         add     %i5,%l0,%i5             ! ...add to bit 32 of the hi product
67         sllx    %i1,32,%i0              ! align low bits of mid product
68         srl     %i4,0,%g5               ! zero high 32 bits of lo product
69         add     %i0,%g5,%i0             ! combine into low 64 bits of result
70         srlx    %i1,32,%i1              ! extract high bits of mid product...
71         add     %i5,%i1,%i1             ! ...and add them to the high result
72         addcc   %i0,%o0,%i0             ! add cy_limb to low 64 bits of result
73         mov     0,%g5
74         movcs   %xcc,1,%g5
75         addcc   %o7,1,%o7
76         stx     %i0,[%o4+%g1]
77         bne,pt  %xcc,.Loop
78          add    %i1,%g5,%o0             ! compute new cy_limb
80         jmpl    %i7+8,%g0
81          restore %o0,%g0,%o0
83 END(__mpn_mul_1)