Tizen 2.1 base
[external/gmp.git] / mpn / m68k / mc68020 / aorsmul_1.asm
1 dnl  mc68020 mpn_addmul_1, mpn_submul_1 -- add or subtract mpn multiple.
2
3 dnl  Copyright 1992, 1994, 1996, 1999, 2000, 2001, 2002 Free Software
4 dnl  Foundation, Inc.
5 dnl
6 dnl  This file is part of the GNU MP Library.
7 dnl
8 dnl  The GNU MP Library is free software; you can redistribute it and/or
9 dnl  modify it under the terms of the GNU Lesser General Public License as
10 dnl  published by the Free Software Foundation; either version 3 of the
11 dnl  License, or (at your option) any later version.
12 dnl
13 dnl  The GNU MP Library is distributed in the hope that it will be useful,
14 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 dnl  Lesser General Public License for more details.
17 dnl
18 dnl  You should have received a copy of the GNU Lesser General Public License
19 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
20
21 include(`../config.m4')
22
23 C         cycles/limb
24 C 68040:     25
25
26 ifdef(`OPERATION_addmul_1',`
27   define(M4_inst,       addl)
28   define(M4_function_1, mpn_addmul_1)
29 ',`ifdef(`OPERATION_submul_1',`
30   define(M4_inst,       subl)
31   define(M4_function_1, mpn_submul_1)
32 ',
33 `m4_error(`Need OPERATION_addmul_1 or OPERATION_submul_1
34 ')')')
35
36
37 C INPUT PARAMETERS
38 C res_ptr       (sp + 4)
39 C s1_ptr        (sp + 8)
40 C s1_size       (sp + 12)
41 C s2_limb       (sp + 16)
42
43 define(res_ptr, `a0')
44 define(s1_ptr,  `a1')
45 define(s1_size, `d2')
46 define(s2_limb, `d4')
47
48
49 PROLOGUE(M4_function_1)
50
51 C Save used registers on the stack.
52         moveml  d2-d5, M(-,sp)
53
54 C Copy the arguments to registers.  Better use movem?
55         movel   M(sp,20), res_ptr
56         movel   M(sp,24), s1_ptr
57         movel   M(sp,28), s1_size
58         movel   M(sp,32), s2_limb
59
60         eorw    #1, s1_size
61         clrl    d1
62         clrl    d5
63         lsrl    #1, s1_size
64         bcc     L(L1)
65         subql   #1, s1_size
66         subl    d0, d0          C (d0,cy) <= (0,0)
67
68 L(Loop):
69         movel   M(s1_ptr,+), d3
70         mulul   s2_limb, d1:d3
71         addxl   d0, d3
72         addxl   d5, d1
73         M4_inst d3, M(res_ptr,+)
74 L(L1):  movel   M(s1_ptr,+), d3
75         mulul   s2_limb, d0:d3
76         addxl   d1, d3
77         addxl   d5, d0
78         M4_inst d3, M(res_ptr,+)
79
80         dbf     s1_size, L(Loop)
81         addxl   d5, d0
82         subl    #0x10000, s1_size
83         bcc     L(Loop)
84
85 C Restore used registers from stack frame.
86         moveml  M(sp,+), d2-d5
87
88         rts
89
90 EPILOGUE(M4_function_1)