Initial import from FreeBSD RELENG_4:
[games.git] / contrib / libgmp / mpn / alpha / mul_1.s
1 /* $Id$
2  # Alpha 21064 __mpn_mul_1 -- Multiply a limb vector with a limb and store
3  # the result in a second limb vector.
4
5  # Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc.
6
7  # This file is part of the GNU MP Library.
8
9  # The GNU MP Library is free software; you can redistribute it and/or modify
10  # it under the terms of the GNU Library General Public License as published by
11  # the Free Software Foundation; either version 2 of the License, or (at your
12  # option) any later version.
13
14  # The GNU MP Library is distributed in the hope that it will be useful, but
15  # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
17  # License for more details.
18
19  # You should have received a copy of the GNU Library General Public License
20  # along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
21  # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22  # MA 02111-1307, USA.
23
24
25  # INPUT PARAMETERS
26  # res_ptr      r16
27  # s1_ptr       r17
28  # size         r18
29  # s2_limb      r19
30
31  # This code runs at 42 cycles/limb on the EV4 and 18 cycles/limb on the EV5.
32
33  # To improve performance for long multiplications, we would use
34  # 'fetch' for S1 and 'fetch_m' for RES.  It's not obvious how to use
35  # these instructions without slowing down the general code: 1. We can
36  # only have two prefetches in operation at any time in the Alpha
37  # architecture.  2. There will seldom be any special alignment
38  # between RES_PTR and S1_PTR.  Maybe we can simply divide the current
39  # loop into an inner and outer loop, having the inner loop handle
40  # exactly one prefetch block?
41 */
42
43         .set    noreorder
44         .set    noat
45 .text
46         .align  3
47         .globl  __mpn_mul_1
48         .ent    __mpn_mul_1 2
49 __mpn_mul_1:
50         .frame  $30,0,$26
51
52         ldq     $2,0($17)       # $2 = s1_limb
53         subq    $18,1,$18       # size--
54         mulq    $2,$19,$3       # $3 = prod_low
55         bic     $31,$31,$4      # clear cy_limb
56         umulh   $2,$19,$0       # $0 = prod_high
57         beq     $18,Lend1       # jump if size was == 1
58         ldq     $2,8($17)       # $2 = s1_limb
59         subq    $18,1,$18       # size--
60         stq     $3,0($16)
61         beq     $18,Lend2       # jump if size was == 2
62
63         .align  3
64 Loop:   mulq    $2,$19,$3       # $3 = prod_low
65         addq    $4,$0,$0        # cy_limb = cy_limb + 'cy'
66         subq    $18,1,$18       # size--
67         umulh   $2,$19,$4       # $4 = cy_limb
68         ldq     $2,16($17)      # $2 = s1_limb
69         addq    $17,8,$17       # s1_ptr++
70         addq    $3,$0,$3        # $3 = cy_limb + prod_low
71         stq     $3,8($16)
72         cmpult  $3,$0,$0        # $0 = carry from (cy_limb + prod_low)
73         addq    $16,8,$16       # res_ptr++
74         bne     $18,Loop
75
76 Lend2:  mulq    $2,$19,$3       # $3 = prod_low
77         addq    $4,$0,$0        # cy_limb = cy_limb + 'cy'
78         umulh   $2,$19,$4       # $4 = cy_limb
79         addq    $3,$0,$3        # $3 = cy_limb + prod_low
80         cmpult  $3,$0,$0        # $0 = carry from (cy_limb + prod_low)
81         stq     $3,8($16)
82         addq    $4,$0,$0        # cy_limb = prod_high + cy
83         ret     $31,($26),1
84 Lend1:  stq     $3,0($16)
85         ret     $31,($26),1
86
87         .end    __mpn_mul_1