summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfaissaloo <faissaloo@gmail.com>2016-07-27 13:03:00 +0100
committerfaissaloo <faissaloo@gmail.com>2016-07-27 13:03:00 +0100
commit58cc2a376aa1b94e7e2f9bbd6a058f2ff7db992a (patch)
tree526b7f94b106d59c8d23710156fa95207ea4abb6
parent39182a45f3161a8f4862b1a3086ae0f37be963c2 (diff)
downloaddbsh-58cc2a376aa1b94e7e2f9bbd6a058f2ff7db992a.tar.gz
Moved some stuff around to reduce jumps
-rwxr-xr-xshbin1656 -> 1664 bytes
-rw-r--r--sh.asm90
2 files changed, 44 insertions, 46 deletions
diff --git a/sh b/sh
index abae0ca..9ca3978 100755
--- a/sh
+++ b/sh
Binary files differ
diff --git a/sh.asm b/sh.asm
index acae19b..806fd84 100644
--- a/sh.asm
+++ b/sh.asm
@@ -48,10 +48,10 @@ section .bss
;These must all be divisible by 16!
input_buffer_size equ 4096
input_buffer resb input_buffer_size
-
+
path_buffer_size equ 4096
path_buffer resb path_buffer_size
-
+
concat_buffer_size equ 8192
concat_buffer resb concat_buffer_size ;Double so the path and input can never overflow concat_buffer when combined
@@ -252,7 +252,7 @@ _subzp:
_parse2:
push rbx
mov r14, rsp
- cmp r13, 0x0
+ test r13, r13
jg _parse7
mov r8, -0x1
@@ -276,7 +276,47 @@ _parse3:
;mov r13, r15
mov rdi, [r9+r8*8]
push r8
- jmp _concat_dir
+ ; input: rdi (a), r15 (b)
+ ; output: rbx (string)
+ ; clobbered: r8, r11
+ _concat_dir:
+ xor r8,r8 ;new string's length (and for _dirty_strcpy_1, also the
+ ;initial string length)
+ ;Copies the contents of rdi to rbx in blocks of
+ ;16, doesn't bother to clean up stuff past the null
+ ;so moves that too, but it doesn't matter, just make
+ ;sure the buffer is big enough
+ _dirty_strcpy_1:
+ movDqU xmm2, [rdi+r8]
+ movDqU [rbx+r8],xmm2
+
+ pcmpistri xmm1, xmm2, 122
+ jz _dirty_strcpy_1_exit
+
+ PcmpIstrI xmm0, xmm2, 122 ;if there was a null in the
+ ;copied string exit loop
+ jz _dirty_strcpy_1_exit
+ add r8,15
+ jmp _dirty_strcpy_1
+ _dirty_strcpy_1_exit:
+ add r8,rcx
+ inc r8
+ mov byte [rbx+r8], '/'
+ inc r8
+ xor r11, r11
+ _dirty_strcpy_2:
+ movdqu xmm2, [r15+r11]
+ movdqu [rbx+r8], xmm2
+
+ pcmpistri xmm1, xmm2, 122
+ jz _parse5
+
+ pcmpistri xmm0, xmm2, 122
+ jz _parse5
+
+ add r8, 15
+ add r11, 15
+ jmp _dirty_strcpy_2
_parse4: ; Function not found
mov rax, sys_write
@@ -336,48 +376,6 @@ _strlen:
xchg rsi,rcx
ret
-; input: rdi (a), r15 (b)
-; output: rbx (string)
-; clobbered: r8, r11
-_concat_dir:
- xor r8,r8 ;new string's length (and for _dirty_strcpy_1, also the
- ;initial string length)
- ;Copies the contents of rdi to rbx in blocks of
- ;16, doesn't bother to clean up stuff past the null
- ;so moves that too, but it doesn't matter, just make
- ;sure the buffer is big enough
- _dirty_strcpy_1:
- movDqU xmm2, [rdi+r8]
- movDqU [rbx+r8],xmm2
-
- pcmpistri xmm1, xmm2, 122
- jz _dirty_strcpy_1_exit
-
- PcmpIstrI xmm0, xmm2, 122 ;if there was a null in the
- ;copied string exit loop
- jz _dirty_strcpy_1_exit
- add r8,15
- jmp _dirty_strcpy_1
- _dirty_strcpy_1_exit:
- add r8,rcx
- inc r8
- mov byte [rbx+r8], '/'
- inc r8
- xor r11, r11
- _dirty_strcpy_2:
- movdqu xmm2, [r15+r11]
- movdqu [rbx+r8], xmm2
-
- pcmpistri xmm1, xmm2, 122
- jz _parse5
-
- pcmpistri xmm0, xmm2, 122
- jz _parse5
-
- add r8, 15
- add r11, 15
- jmp _dirty_strcpy_2
-
; interrupt signal handler
_sigint:
cmp dword [cpid], 0x0