From 58cc2a376aa1b94e7e2f9bbd6a058f2ff7db992a Mon Sep 17 00:00:00 2001 From: faissaloo Date: Wed, 27 Jul 2016 13:03:00 +0100 Subject: Moved some stuff around to reduce jumps --- sh | Bin 1656 -> 1664 bytes sh.asm | 90 ++++++++++++++++++++++++++++++++--------------------------------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/sh b/sh index abae0ca..9ca3978 100755 Binary files a/sh and b/sh 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 -- cgit v1.2.3