Upload Tizen:Base source
[external/gmp.git] / mpn / m68k / aors_n.asm
1 dnl  mc68020 mpn_add_n, mpn_sub_n -- add or subtract limb vectors
2
3 dnl  Copyright 1992, 1994, 1996, 1999, 2000, 2001, 2002, 2003, 2005 Free
4 dnl  Software 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:      6
25
26 ifdef(`OPERATION_add_n',`
27   define(M4_inst,       addxl)
28   define(M4_function_n, mpn_add_n)
29 ',`ifdef(`OPERATION_sub_n',`
30   define(M4_inst,       subxl)
31   define(M4_function_n, mpn_sub_n)
32 ',
33 `m4_error(`Need OPERATION_add_n or OPERATION_sub_n
34 ')')')
35
36 MULFUNC_PROLOGUE(mpn_add_n mpn_sub_n)
37
38
39 C INPUT PARAMETERS
40 C res_ptr       (sp + 4)
41 C s1_ptr        (sp + 8)
42 C s2_ptr        (sp + 12)
43 C size          (sp + 16)
44
45
46 PROLOGUE(M4_function_n)
47
48 C Save used registers on the stack.
49         movel   d2, M(-,sp)
50         movel   a2, M(-,sp)
51
52 C Copy the arguments to registers.  Better use movem?
53         movel   M(sp,12), a2
54         movel   M(sp,16), a0
55         movel   M(sp,20), a1
56         movel   M(sp,24), d2
57
58         eorw    #1, d2
59         lsrl    #1, d2
60         bcc     L(L1)
61         subql   #1, d2  C clears cy as side effect
62
63 L(Loop):
64         movel   M(a0,+), d0
65         movel   M(a1,+), d1
66         M4_inst d1, d0
67         movel   d0, M(a2,+)
68 L(L1):  movel   M(a0,+), d0
69         movel   M(a1,+), d1
70         M4_inst d1, d0
71         movel   d0, M(a2,+)
72
73         dbf     d2, L(Loop)             C loop until 16 lsb of %4 == -1
74         subxl   d0, d0                  C d0 <= -cy; save cy as 0 or -1 in d0
75         subl    #0x10000, d2
76         bcs     L(L2)
77         addl    d0, d0                  C restore cy
78         bra     L(Loop)
79
80 L(L2):
81         negl    d0
82
83 C Restore used registers from stack frame.
84         movel   M(sp,+), a2
85         movel   M(sp,+), d2
86
87         rts
88
89 EPILOGUE(M4_function_n)