From ac0e2db600593d5b30550453b78874bfa0611751 Mon Sep 17 00:00:00 2001 From: wkj Date: Wed, 21 Apr 2004 04:45:31 +0000 Subject: Add basic libmp support for the x86. --- src/libmp/386/mpvecsub.s | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/libmp/386/mpvecsub.s (limited to 'src/libmp/386/mpvecsub.s') diff --git a/src/libmp/386/mpvecsub.s b/src/libmp/386/mpvecsub.s new file mode 100644 index 00000000..a56b4968 --- /dev/null +++ b/src/libmp/386/mpvecsub.s @@ -0,0 +1,62 @@ +/* + * mpvecsub(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *diff) + * + * diff[0:alen-1] = a[0:alen-1] - b[0:blen-1] + * + * prereq: alen >= blen, diff has room for alen digits + */ +.text + +.p2align 2,0x90 +.globl mpvecsub + .type mpvecsub, @function +mpvecsub: + /* Prelude */ + pushl %ebp + movl %ebx, -4(%esp) /* save on stack */ + movl %esi, -8(%esp) + movl %edi, -12(%esp) + + movl 8(%esp), %esi /* a */ + movl 16(%esp), %ebx /* b */ + movl 12(%esp), %edx /* alen */ + movl 20(%esp), %ecx /* blen */ + movl 24(%esp), %edi /* diff */ + subl %ecx,%edx + xorl %ebp,%ebp /* this also sets carry to 0 */ + + /* skip subraction if b is zero */ + testl %ecx,%ecx + jz _sub1 + + /* diff[0:blen-1],borrow = a[0:blen-1] - b[0:blen-1] */ +_subloop1: + movl (%esi, %ebp, 4), %eax + sbbl (%ebx, %ebp, 4), %eax + movl %eax, (%edi, %ebp, 4) + incl %ebp + loop _subloop1 + +_sub1: + incl %edx + movl %edx,%ecx + loop _subloop2 + jmp done + + /* diff[blen:alen-1] = a[blen:alen-1] - 0 */ +_subloop2: + movl (%esi, %ebp, 4), %eax + sbbl $0, %eax + movl %eax, (%edi, %ebp, 4) + INCL %ebp + LOOP _subloop2 + +done: + /* Postlude */ + movl -4(%esp), %ebx /* restore from stack */ + movl -8(%esp), %esi + movl -12(%esp), %edi + movl %esp, %ebp + leave + ret + -- cgit v1.2.3