aboutsummaryrefslogtreecommitdiff
path: root/src/libmp/386/mpvecsub-Darwin.s
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-04-21 04:25:28 +0000
committerrsc <devnull@localhost>2006-04-21 04:25:28 +0000
commit4e3a81b98b7fe89d4e081be810f76f87300c11e5 (patch)
treebdf31d21178a558600595b88ef7e645c27375851 /src/libmp/386/mpvecsub-Darwin.s
parent12e997d87c3f057018fb8f3411cd9676b416cc04 (diff)
downloadplan9port-4e3a81b98b7fe89d4e081be810f76f87300c11e5.tar.gz
plan9port-4e3a81b98b7fe89d4e081be810f76f87300c11e5.tar.bz2
plan9port-4e3a81b98b7fe89d4e081be810f76f87300c11e5.zip
darawin
Diffstat (limited to 'src/libmp/386/mpvecsub-Darwin.s')
-rw-r--r--src/libmp/386/mpvecsub-Darwin.s60
1 files changed, 60 insertions, 0 deletions
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
+