Skip to content

Faster and simpler _strleft routine with instruction time comparison table between clr.b (An) and cmp.b #0,(An) #126

@ManuelAndre123

Description

@ManuelAndre123

====
; for testing purposes in easy68K program
; lea string1,A0
; lea string2,A1
; moveq #1,d0
; Notepad _leftstr source is included with proper tabulation since Github messes this up?

MOVE.L	A1,A3

_leftstr:
SUBQ.L #1,D0 :substract 1 from bytes to copy
BGE.B StringLeftCopy :branch when greater or equal than 0 (0 = 1 byte to copy)
CLR.B (A1) :on 68040 and 68060 CPU's move.b #0,(An) is faster than clr.b so use of it is debatable
MOVE.L A3,A0
RTS
StringLeftCopy:
MOVE.B (A0)+,(A1)+
TST.B (A0) ;CMP.B #nn,(An)= a lot slower, see table below
BEQ.S StringLeftDone
SUBQ.L #1,D0 :next char
BGT.S StringLeftCopy :#chars to copy >0 copy next byte
StringLeftDone:
CLR.B (A1) :on 68040 and 68060 CPU's move.b #0,(An) is faster than clr.b so use of it is debatable
MOVE.L A3,A0
RTS

;Comparison between TST.B (An) and CMP.B (An) for all 68K CPU's

;Timings for each CPU;
;CPU TST.B (An) CMP.B #0,(An) differences
;===================================================
;68000 4 12 TST 3× faster
;68010 4 12 TST 3× faster
;68020 2 ~4 TST ~2× faster
;68030 2 ~4 TST ~2× faster
;68040 ~1 ~2–3 TST 2-3x faster
;68060 ~1 ~1–2 TST same or upto 2x faster

_strlleft.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions