diff --git a/rtl/powerpc/powerpc.inc b/rtl/powerpc/powerpc.inc index 40ea6bfea8..f9bfa45dfa 100644 --- a/rtl/powerpc/powerpc.inc +++ b/rtl/powerpc/powerpc.inc @@ -819,64 +819,6 @@ end; String ****************************************************************************} -{$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN} -{$define FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN} -function fpc_shortstr_to_shortstr(len:longint; const sstr: shortstring): shortstring; [public,alias: 'FPC_SHORTSTR_TO_SHORTSTR']; compilerproc; -assembler; nostackframe; -{ input: r3: pointer to result, r4: len, r5: sstr } -asm - { load length source } - lbz r10,0(r5) - { load the begin of the dest buffer in the data cache } - dcbtst 0,r3 - - { put min(length(sstr),len) in r4 } - subfc r7,r10,r4 { r0 := r4 - r10 } - subfe r4,r4,r4 { if r3 >= r4 then r3' := 0 else r3' := -1 } - and r7,r7,r4 { if r3 >= r4 then r3' := 0 else r3' := r3-r10 } - add r4,r10,r7 { if r3 >= r4 then r3' := r10 else r3' := r3 } - - cmplwi r4,0 - { put length in ctr } - mtctr r4 - stb r4,0(r3) - beq .LShortStrCopyDone -.LShortStrCopyLoop: - lbzu r0,1(r5) - stbu r0,1(r3) - bdnz .LShortStrCopyLoop -.LShortStrCopyDone: -end; - - -procedure fpc_shortstr_assign(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_ASSIGN']; -assembler; nostackframe; -{ input: r3: len, r4: sstr, r5: dstr } -asm - { load length source } - lbz r10,0(r4) - { load the begin of the dest buffer in the data cache } - dcbtst 0,r5 - - { put min(length(sstr),len) in r3 } - subc r0,r3,r10 { r0 := r3 - r10 } - subfe r3,r3,r3 { if r3 >= r4 then r3' := 0 else r3' := -1 } - and r3,r0,r3 { if r3 >= r4 then r3' := 0 else r3' := r3-r10 } - add r3,r3,r10 { if r3 >= r4 then r3' := r10 else r3' := r3 } - - cmplwi r3,0 - { put length in ctr } - mtctr r3 - stb r3,0(r5) - beq .LShortStrCopyDone2 -.LShortStrCopyLoop2: - lbzu r0,1(r4) - stbu r0,1(r5) - bdnz .LShortStrCopyLoop2 -.LShortStrCopyDone2: -end; -{$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN} - {$ifndef STR_CONCAT_PROCS} (* @@ -1035,9 +977,14 @@ end; {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR} {$define FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR} -function fpc_pchar_to_shortstr(p:pchar):shortstring;[public,alias:'FPC_PCHAR_TO_SHORTSTR']; compilerproc; -assembler; nostackframe; +{$ifndef FPC_STRTOSHORTSTRINGPROC} +function fpc_pchar_to_shortstr(p:pchar):shortstring;[public,alias:'FPC_PCHAR_TO_SHORTSTR']; compilerproc; assembler; nostackframe; +{$else FPC_STRTOSHORTSTRINGPROC} +procedure fpc_pchar_to_shortstr(out res : shortstring;p:pchar);assembler;[public,alias:'FPC_PCHAR_TO_SHORTSTR']; compilerproc; nostackframe; +{$define FPC_STRPASPROC} +{$endif FPC_STRTOSHORTSTRINGPROC} {$include strpas.inc} +{$undef FPC_STRPASPROC} {$endif FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR} diff --git a/rtl/powerpc/strpas.inc b/rtl/powerpc/strpas.inc index 3ccf9ef5ef..2444359d11 100644 --- a/rtl/powerpc/strpas.inc +++ b/rtl/powerpc/strpas.inc @@ -13,28 +13,39 @@ **********************************************************************} { + ifndef FPC_STRPASPROC r3: result address - r4: src + r4: p (source) + else + r3: result address + r4: high(result) + r5: p (source) + endif } asm { nil? } - cmplwi r4, 0 + mr r8, p + cmplwi p, 0 { load the begin of the string in the data cache } - dcbt 0,r4 + dcbt 0, p { maxlength } +{$ifdef FPC_STRPASPROC} + mr r10,r4 +{$else FPC_STRPASPROC} li r10,255 +{$endif FPC_STRPASPROC} mtctr r10 { at LStrPasDone, we set the length of the result to 255 - r10 - r4 } { = 255 - 255 - 0 if the soure = nil -> perfect :) } beq .LStrPasDone - { save address for at the end and use r5 in loop } - mr r5,r3 - { no "subi r5,r5,1" because the first byte = length byte } - subi r4,r4,1 + { save address for at the end and use r7 in loop } + mr r7,r3 + { no "subi r7,r7,1" because the first byte = length byte } + subi r8,r8,1 .LStrPasLoop: - lbzu r10,1(r4) + lbzu r10,1(r8) cmplwi cr0,r10,0 - stbu r10,1(r5) + stbu r10,1(r7) bdnzf cr0*4+eq, .LStrPasLoop { if we stopped because of a terminating #0, decrease the length by 1 } diff --git a/rtl/powerpc64/powerpc64.inc b/rtl/powerpc64/powerpc64.inc index 2712f1660b..a53d782ecd 100644 --- a/rtl/powerpc64/powerpc64.inc +++ b/rtl/powerpc64/powerpc64.inc @@ -329,63 +329,6 @@ end; String ****************************************************************************} -{$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN} -{$define FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN} -function fpc_shortstr_to_shortstr(len:longint; const sstr: shortstring): shortstring; [public,alias: 'FPC_SHORTSTR_TO_SHORTSTR']; compilerproc; -assembler; nostackframe; -{ input: r3: pointer to result, r4: len, r5: sstr } -asm - { load length source } - lbz r10,0(r5) - { load the begin of the dest buffer in the data cache } - dcbtst 0,r3 - - { put min(length(sstr),len) in r4 } - subfc r7,r10,r4 { r0 := r4 - r10 } - subfe r4,r4,r4 { if r3 >= r4 then r3' := 0 else r3' := -1 } - and r7,r7,r4 { if r3 >= r4 then r3' := 0 else r3' := r3-r10 } - add r4,r10,r7 { if r3 >= r4 then r3' := r10 else r3' := r3 } - - cmpldi r4,0 - { put length in ctr } - mtctr r4 - stb r4,0(r3) - beq .LShortStrCopyDone -.LShortStrCopyLoop: - lbzu r0,1(r5) - stbu r0,1(r3) - bdnz .LShortStrCopyLoop -.LShortStrCopyDone: -end; - -procedure fpc_shortstr_assign(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_ASSIGN']; -assembler; nostackframe; -{ input: r3: len, r4: sstr, r5: dstr } -asm - { load length source } - lbz r10,0(r4) - { load the begin of the dest buffer in the data cache } - dcbtst 0,r5 - - { put min(length(sstr),len) in r3 } - subc r0,r3,r10 { r0 := r3 - r10 } - subfe r3,r3,r3 { if r3 >= r4 then r3' := 0 else r3' := -1 } - and r3,r0,r3 { if r3 >= r4 then r3' := 0 else r3' := r3-r10 } - add r3,r3,r10 { if r3 >= r4 then r3' := r10 else r3' := r3 } - - cmpldi r3,0 - { put length in ctr } - mtctr r3 - stb r3,0(r5) - beq .LShortStrCopyDone2 -.LShortStrCopyLoop2: - lbzu r0,1(r4) - stbu r0,1(r5) - bdnz .LShortStrCopyLoop2 -.LShortStrCopyDone2: -end; -{$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN} - {$ifndef STR_CONCAT_PROCS} (* @@ -547,9 +490,16 @@ end; {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR} {$define FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR} +{$ifndef FPC_STRTOSHORTSTRINGPROC} function fpc_pchar_to_shortstr(p:pchar):shortstring;[public,alias:'FPC_PCHAR_TO_SHORTSTR']; compilerproc; assembler; nostackframe; +{$else FPC_STRTOSHORTSTRINGPROC} +procedure fpc_pchar_to_shortstr(out res : shortstring;p:pchar);[public,alias:'FPC_PCHAR_TO_SHORTSTR']; compilerproc; +assembler; nostackframe; +{$define FPC_STRPASPROC} +{$endif FPC_STRTOSHORTSTRINGPROC} {$include strpas.inc} +{$undef FPC_STRPASPROC} {$endif FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR} (* diff --git a/rtl/powerpc64/strpas.inc b/rtl/powerpc64/strpas.inc index bcb6d38f0a..53d3364e6d 100644 --- a/rtl/powerpc64/strpas.inc +++ b/rtl/powerpc64/strpas.inc @@ -13,28 +13,39 @@ **********************************************************************} { + ifndef FPC_STRPASPROC r3: result address - r4: src + r4: p (source) + else + r3: result address + r4: high(result) + r5: p (source) + endif } asm { nil? } - cmpldi r4, 0 + mr r8, p + cmpldi p, 0 { load the begin of the string in the data cache } - dcbt 0,r4 + dcbt 0, p { maxlength } +{$ifdef FPC_STRPASPROC} + mr r10,r4 +{$else FPC_STRPASPROC} li r10,255 +{$endif FPC_STRPASPROC} mtctr r10 { at LStrPasDone, we set the length of the result to 255 - r10 - r4 } { = 255 - 255 - 0 if the soure = nil -> perfect :) } beq .LStrPasDone - { save address for at the end and use r5 in loop } - mr r5,r3 - { no "subi r5,r5,1" because the first byte = length byte } - subi r4,r4,1 + { save address for at the end and use r7 in loop } + mr r7,r3 + { no "subi r7,r7,1" because the first byte = length byte } + subi r8,r8,1 .LStrPasLoop: - lbzu r10,1(r4) - cmpldi cr0,r10,0 - stbu r10,1(r5) + lbzu r10,1(r8) + cmplwi cr0,r10,0 + stbu r10,1(r7) bdnzf cr0*4+eq, .LStrPasLoop { if we stopped because of a terminating #0, decrease the length by 1 }