Debian Codegraph @

mpi/m68k/mpih-sub1.S

raw
1 /* mc68020 __mpn_sub_n -- Subtract two limb vectors of the same length > 0 and
2 * store difference in a third limb vector.
3 *
4 * Copyright (C) 1992, 1994, 1996, 1998,
5 * 2001, 2002 Free Software Foundation, Inc.
6 *
7 * This file is part of Libgcrypt.
8 *
9 * Libgcrypt is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * Libgcrypt is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, see <https://www.gnu.org/licenses/>.
21 * SPDX-License-Identifier: LGPL-2.1-or-later
22 *
23 * Note: This code is heavily based on the GNU MP Library.
24 * Actually it's the same code with only minor changes in the
25 * way the data is stored; this is to support the abstraction
26 * of an optional secure memory allocation which may be used
27 * to avoid revealing of sensitive data due to paging etc.
28 */
29
30 #include "sysdep.h"
31 #include "asm-syntax.h"
32
33
34 /*******************
35 * mpi_limb_t
36 * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (sp + 4)
37 * mpi_ptr_t s1_ptr, (sp + 8)
38 * mpi_ptr_t s2_ptr, (sp + 16)
39 * mpi_size_t size) (sp + 12)
40 */
41
42
43 TEXT
44 ALIGN
45 GLOBL C_SYMBOL_NAME(_gcry_mpih_sub_n)
46
47 C_SYMBOL_NAME(_gcry_mpih_sub_n:)
48 PROLOG(_gcry_mpih_sub_n)
49 /* Save used registers on the stack. */
50 movel R(d2),MEM_PREDEC(sp)
51 movel R(a2),MEM_PREDEC(sp)
52
53 /* Copy the arguments to registers. Better use movem? */
54 movel MEM_DISP(sp,12),R(a2)
55 movel MEM_DISP(sp,16),R(a0)
56 movel MEM_DISP(sp,20),R(a1)
57 movel MEM_DISP(sp,24),R(d2)
58
59 eorw #1,R(d2)
60 lsrl #1,R(d2)
61 bcc L(L1)
62 subql #1,R(d2) /* clears cy as side effect */
63
64 L(Loop:)
65 movel MEM_POSTINC(a0),R(d0)
66 movel MEM_POSTINC(a1),R(d1)
67 subxl R(d1),R(d0)
68 movel R(d0),MEM_POSTINC(a2)
69 L(L1:) movel MEM_POSTINC(a0),R(d0)
70 movel MEM_POSTINC(a1),R(d1)
71 subxl R(d1),R(d0)
72 movel R(d0),MEM_POSTINC(a2)
73
74 dbf R(d2),L(Loop) /* loop until 16 lsb of %4 == -1 */
75 subxl R(d0),R(d0) /* d0 <= -cy; save cy as 0 or -1 in d0 */
76 subl #0x10000,R(d2)
77 bcs L(L2)
78 addl R(d0),R(d0) /* restore cy */
79 bra L(Loop)
80
81 L(L2:)
82 negl R(d0)
83
84 /* Restore used registers from stack frame. */
85 movel MEM_POSTINC(sp),R(a2)
86 movel MEM_POSTINC(sp),R(d2)
87
88 rts
89 EPILOG(_gcry_mpih_sub_n)
90
91