* strpas is again slightly slower, but won't crash anymore if a pchar

is passed to it that starts less than 4 bbytes from the heap end
This commit is contained in:
Jonas Maebe 2000-06-30 12:20:20 +00:00
parent bfe30b974e
commit d0b7a84ef6

View File

@ -19,67 +19,55 @@ function strpas(p : pchar) : string;
begin begin
asm asm
movl __RESULT,%edi movl __RESULT,%edi
movl p,%esi
// at the end, add 255 to cl to get the string length (byte(1+255) = 0)
movb $1,%cl movb $1,%cl
movl p,%esi
// skip length byte -> align dest to multiple of 4 // skip length byte -> align dest to multiple of 4
movl (%esi),%eax .LStrCopyAlignLoop:
testl $0x0ff,%eax movb (%esi),%al
jz .LStrPasDone incl %edi
// we only need the first 3 chars currently incl %esi
shll $8,%eax testb %al,%al
jz .LStrCopyDone
incb %cl incb %cl
addl $3,%esi movb %al,(%edi)
// Store everything already, since the temp string = 255 chars anyway cmpb $4,%cl
// The length byte will contain zero this way, but it will be jne .LStrCopyAlignLoop
// overwritten at the end, so it doesn't matter incl %edi
movl %eax,(%edi) .align 16
// test the second char (we shifted left 8 bits) .LStrCopyAligned:
testl $0x0ff0000,%eax
jz .LStrPasDone
// for pairing, add 4 to edi here already
addl $4,%edi
incb %cl
// test the third char (we shifted left 8 bits)
testl $0x0ff000000,%eax
jz .LStrPasDone
incb %cl
.balign 16
.LStrPasLoop:
movl (%esi),%eax movl (%esi),%eax
addl $4,%esi addl $4,%esi
// this won't overwrite data since the result = 255 char string // this won't overwrite data since the result = 255 char string
movl %eax,(%edi) movl %eax,(%edi)
testl $0x0ff,%eax testl $0x0ff,%eax
jz .LStrPasDone jz .LStrCopyDone
testl $0x0ff00,%eax testl $0x0ff00,%eax
jz .LStrPasByte jz .LStrCopyByte
testl $0x0ff0000,%eax testl $0x0ff0000,%eax
jz .LStrPasWord jz .LStrCopyWord
testl $0x0ff000000,%eax testl $0x0ff000000,%eax
jz .LStrPas3Bytes jz .LStrCopy3Bytes
addl $4,%edi addl $4,%edi
addb $4,%cl addb $4,%cl
// since cl = 4 at the start of the loop, it will always count // since ecx = 4 at the start of the loop, it will always count
// upto exactly 0 // upto exactly 0
jnz .LStrPasLoop jnz .LStrCopyAligned
jmp .LStrPasDone jmp .LStrCopyDone
.LStrPas3Bytes: .LStrCopy3Bytes:
addb $3,%cl addb $3,%cl
jmp .LStrPasDone jmp .LStrCopyDone
.LStrPasWord: .LStrCopyWord:
addb $2,%cl addb $2,%cl
jmp .LStrPasDone jmp .LStrCopyDone
.LStrPasByte: .LStrCopyByte:
incb %cl incb %cl
.LStrPasDone: .LStrCopyDone:
movl __RESULT,%edi movl __RESULT,%edi
addb $255,%cl addb $255,%cl
movb %cl,(%edi) movb %cl,(%edi)
end ['EAX','ECX','ESI','EDI']; end ['EAX','ECX','ESI','EDI'];
end; end;
function strpcopy(d : pchar;const s : string) : pchar;assembler; function strpcopy(d : pchar;const s : string) : pchar;assembler;
asm asm
pushl %esi // Save ESI pushl %esi // Save ESI
@ -98,7 +86,11 @@ end ['EDI','EAX','ECX'];
{ {
$Log$ $Log$
Revision 1.13 2000-06-12 19:53:32 peter Revision 1.14 2000-06-30 12:20:20 jonas
* strpas is again slightly slower, but won't crash anymore if a pchar
is passed to it that starts less than 4 bbytes from the heap end
Revision 1.13 2000/06/12 19:53:32 peter
* change .align to .balign * change .align to .balign
Revision 1.12 2000/06/12 13:17:56 jonas Revision 1.12 2000/06/12 13:17:56 jonas