From 4e3a81b98b7fe89d4e081be810f76f87300c11e5 Mon Sep 17 00:00:00 2001 From: rsc Date: Fri, 21 Apr 2006 04:25:28 +0000 Subject: darawin --- src/libmp/386/mpdigdiv-Darwin.s | 33 +++++++++++++++++ src/libmp/386/mpvecadd-Darwin.s | 70 +++++++++++++++++++++++++++++++++++ src/libmp/386/mpvecdigmuladd-Darwin.s | 69 ++++++++++++++++++++++++++++++++++ src/libmp/386/mpvecdigmulsub-Darwin.s | 70 +++++++++++++++++++++++++++++++++++ src/libmp/386/mpvecsub-Darwin.s | 60 ++++++++++++++++++++++++++++++ 5 files changed, 302 insertions(+) create mode 100644 src/libmp/386/mpdigdiv-Darwin.s create mode 100644 src/libmp/386/mpvecadd-Darwin.s create mode 100644 src/libmp/386/mpvecdigmuladd-Darwin.s create mode 100644 src/libmp/386/mpvecdigmulsub-Darwin.s create mode 100644 src/libmp/386/mpvecsub-Darwin.s (limited to 'src/libmp') diff --git a/src/libmp/386/mpdigdiv-Darwin.s b/src/libmp/386/mpdigdiv-Darwin.s new file mode 100644 index 00000000..be96bf38 --- /dev/null +++ b/src/libmp/386/mpdigdiv-Darwin.s @@ -0,0 +1,33 @@ +.text +.p2align 2,0x90 +.globl _mpdigdiv +_mpdigdiv: + /* Prelude */ + pushl %ebp /* save on stack */ + pushl %ebx + + leal 12(%esp), %ebp /* %ebp = FP for now */ + movl 0(%ebp), %ebx /* dividend */ + movl 0(%ebx), %eax + movl 4(%ebx), %edx + movl 4(%ebp), %ebx /* divisor */ + movl 8(%ebp), %ebp /* quotient */ + + xorl %ecx, %ecx + cmpl %ebx, %edx /* dividend >= 2^32 * divisor */ + jae divovfl + cmpl %ecx, %ebx /* divisor == 1 */ + je divovfl + divl %ebx /* AX = DX:AX/BX */ + movl %eax, (%ebp) +done: + /* Postlude */ + popl %ebx + popl %ebp + ret + + /* return all 1's */ +divovfl: + notl %ecx + movl %ecx, (%ebp) + jmp done diff --git a/src/libmp/386/mpvecadd-Darwin.s b/src/libmp/386/mpvecadd-Darwin.s new file mode 100644 index 00000000..8d892331 --- /dev/null +++ b/src/libmp/386/mpvecadd-Darwin.s @@ -0,0 +1,70 @@ +/* mpvecadd(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *sum) */ +/* sum[0:alen] = a[0:alen-1] + b[0:blen-1] */ +/* prereq: alen >= blen, sum has room for alen+1 digits */ +/* (very old gnu assembler doesn't allow multiline comments) */ + +.text + +.p2align 2,0x90 +.globl _mpvecadd +_mpvecadd: + /* Prelude */ + pushl %ebp /* save on stack */ + pushl %ebx + pushl %esi + pushl %edi + + leal 20(%esp), %ebp /* %ebp = FP for now */ + + movl 4(%ebp), %edx /* alen */ + movl 12(%ebp), %ecx /* blen */ + movl 0(%ebp), %esi /* a */ + movl 8(%ebp), %ebx /* b */ + subl %ecx, %edx + movl 16(%ebp), %edi /* sum */ + xorl %ebp, %ebp /* this also sets carry to 0 */ + + /* skip addition if b is zero */ + testl %ecx,%ecx + je _add1 + + /* sum[0:blen-1],carry = a[0:blen-1] + b[0:blen-1] */ +_addloop1: + movl (%esi, %ebp, 4), %eax + adcl (%ebx, %ebp, 4), %eax + movl %eax, (%edi, %ebp, 4) + incl %ebp + loop _addloop1 + +_add1: + /* jump if alen > blen */ + incl %edx + movl %edx, %ecx + loop _addloop2 + + /* sum[alen] = carry */ +_addend: + jb _addcarry + movl $0, (%edi, %ebp, 4) + jmp done + +_addcarry: + movl $1, (%edi, %ebp, 4) + jmp done + + /* sum[blen:alen-1],carry = a[blen:alen-1] + 0 */ +_addloop2: + movl (%esi, %ebp, 4),%eax + adcl $0, %eax + movl %eax, (%edi, %ebp, 4) + incl %ebp + loop _addloop2 + jmp _addend + +done: + /* Postlude */ + popl %edi + popl %esi + popl %ebx + popl %ebp + ret diff --git a/src/libmp/386/mpvecdigmuladd-Darwin.s b/src/libmp/386/mpvecdigmuladd-Darwin.s new file mode 100644 index 00000000..c88dded1 --- /dev/null +++ b/src/libmp/386/mpvecdigmuladd-Darwin.s @@ -0,0 +1,69 @@ +/* + * mpvecdigmul(mpdigit *b, int n, mpdigit m, mpdigit *p) + * + * p += b*m + * + * each step look like: + * hi,lo = m*b[i] + * lo += oldhi + carry + * hi += carry + * p[i] += lo + * oldhi = hi + * + * the registers are: + * hi = DX - constrained by hardware + * lo = AX - constrained by hardware + * b+n = SI - can't be BP + * p+n = DI - can't be BP + * i-n = BP + * m = BX + * oldhi = CX + * + */ +.text + +.p2align 2,0x90 +.globl _mpvecdigmuladd +_mpvecdigmuladd: + /* Prelude */ + pushl %ebp /* save on stack */ + pushl %ebx + pushl %esi + pushl %edi + + leal 20(%esp), %ebp /* %ebp = FP for now */ + movl 0(%ebp), %esi /* b */ + movl 4(%ebp), %ecx /* n */ + movl 8(%ebp), %ebx /* m */ + movl 12(%ebp), %edi /* p */ + movl %ecx, %ebp + negl %ebp /* BP = -n */ + shll $2, %ecx + addl %ecx, %esi /* SI = b + n */ + addl %ecx, %edi /* DI = p + n */ + xorl %ecx, %ecx +_muladdloop: + movl (%esi, %ebp, 4), %eax /* lo = b[i] */ + mull %ebx /* hi, lo = b[i] * m */ + addl %ecx,%eax /* lo += oldhi */ + jae _muladdnocarry1 + incl %edx /* hi += carry */ +_muladdnocarry1: + addl %eax, (%edi, %ebp, 4) /* p[i] += lo */ + jae _muladdnocarry2 + incl %edx /* hi += carry */ +_muladdnocarry2: + movl %edx, %ecx /* oldhi = hi */ + incl %ebp /* i++ */ + jnz _muladdloop + xorl %eax, %eax + addl %ecx, (%edi, %ebp, 4) /* p[n] + oldhi */ + adcl %eax, %eax /* return carry out of p[n] */ + + /* Postlude */ + popl %edi + popl %esi + popl %ebx + popl %ebp + ret + diff --git a/src/libmp/386/mpvecdigmulsub-Darwin.s b/src/libmp/386/mpvecdigmulsub-Darwin.s new file mode 100644 index 00000000..8aef933d --- /dev/null +++ b/src/libmp/386/mpvecdigmulsub-Darwin.s @@ -0,0 +1,70 @@ +/* + * mpvecdigmulsub(mpdigit *b, int n, mpdigit m, mpdigit *p) + * + * p -= b*m + * + * each step look like: + * hi,lo = m*b[i] + * lo += oldhi + carry + * hi += carry + * p[i] += lo + * oldhi = hi + * + * the registers are: + * hi = DX - constrained by hardware + * lo = AX - constrained by hardware + * b = SI - can't be BP + * p = DI - can't be BP + * i = BP + * n = CX - constrained by LOOP instr + * m = BX + * oldhi = EX + * + */ +.text + +.p2align 2,0x90 +.globl _mpvecdigmulsub +_mpvecdigmulsub: + /* Prelude */ + pushl %ebp /* save on stack */ + pushl %ebx + pushl %esi + pushl %edi + + leal 20(%esp), %ebp /* %ebp = FP for now */ + movl 0(%ebp), %esi /* b */ + movl 4(%ebp), %ecx /* n */ + movl 8(%ebp), %ebx /* m */ + movl 12(%ebp), %edi /* p */ + xorl %ebp, %ebp + pushl %ebp +_mulsubloop: + movl (%esi, %ebp, 4),%eax /* lo = b[i] */ + mull %ebx /* hi, lo = b[i] * m */ + addl 0(%esp), %eax /* lo += oldhi */ + jae _mulsubnocarry1 + incl %edx /* hi += carry */ +_mulsubnocarry1: + subl %eax, (%edi, %ebp, 4) + jae _mulsubnocarry2 + incl %edx /* hi += carry */ +_mulsubnocarry2: + movl %edx, 0(%esp) + incl %ebp + loop _mulsubloop + popl %eax + subl %eax, (%edi, %ebp, 4) + jae _mulsubnocarry3 + movl $-1, %eax + jmp done +_mulsubnocarry3: + movl $1, %eax +done: + /* Postlude */ + popl %edi + popl %esi + popl %ebx + popl %ebp + ret + diff --git a/src/libmp/386/mpvecsub-Darwin.s b/src/libmp/386/mpvecsub-Darwin.s new file mode 100644 index 00000000..dcda49bf --- /dev/null +++ b/src/libmp/386/mpvecsub-Darwin.s @@ -0,0 +1,60 @@ +/* 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 */ +/* (very old gnu assembler doesn't allow multiline comments) */ + +.text + +.p2align 2,0x90 +.globl _mpvecsub +_mpvecsub: + /* Prelude */ + pushl %ebp /* save on stack */ + pushl %ebx + pushl %esi + pushl %edi + + leal 20(%esp), %ebp /* %ebp = FP for now */ + movl 0(%ebp), %esi /* a */ + movl 8(%ebp), %ebx /* b */ + movl 4(%ebp), %edx /* alen */ + movl 12(%ebp), %ecx /* blen */ + movl 16(%ebp), %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 */ + popl %edi + popl %esi + popl %ebx + popl %ebp + ret + -- cgit v1.2.3