On Thu, 12 Jun 2025 9:59:56 +0000, Paul Rubin wrote:
This version with the string in memory, no error checking, and using a
variable, seems simplest to me.
>
variable p
: advance ( -- ) 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + ;
: hms ( a u -- h m s ) drop p !
2digit advance 2digit advance 2digit advance ;
It doesn't do the same thing. It isn't faster, which points out
the '60 *' and 'M* D+' are not the limiting factors.
: TEST ( -- )
CR ." \ dtimescan : " S" 12:34:56" TICKS-RESET dtimescan
TICKS? UD. ." clock ticks elapsed, " UD.
CR ." \ timestrscan : " S" 12:34:56" TICKS-RESET timestrscan
TICKS? UD. ." clock ticks elapsed, " UD.
CR ." \ HMS : " S" 12:34:56" TICKS-RESET hms
TICKS? UD. ." clock ticks elapsed, " ROT . SWAP . . ;
FORTH> TEST TEST TEST TEST
\ dtimescan : 1257 clock ticks elapsed, 45296
\ timestrscan : 419 clock ticks elapsed, 45296
\ HMS : 419 clock ticks elapsed, 12 34 56
\ dtimescan : 419 clock ticks elapsed, 45296
\ timestrscan : 420 clock ticks elapsed, 45296
\ HMS : 0 clock ticks elapsed, 12 34 56
\ dtimescan : 419 clock ticks elapsed, 45296
\ timestrscan : 419 clock ticks elapsed, 45296
\ HMS : 419 clock ticks elapsed, 12 34 56
\ dtimescan : 419 clock ticks elapsed, 45296
\ timestrscan : 420 clock ticks elapsed, 45296
\ HMS : 419 clock ticks elapsed, 12 34 56 ok
FORTH> ' hms idis
$01466000 : hms
$0146600A pop rbx
$0146600B pop rbx
$0146600C mov $01463210 qword-offset, rbx
$01466013 mov rbx, $01463210 qword-offset
$0146601A movzx rbx, [rbx] byte
$0146601D add $01463210 qword-offset, 1 b#
$01466025 lea rbx, [rbx #-48 +] qword
$01466029 lea rbx, [rbx rbx*4] qword
$0146602D mov rdi, $01463210 qword-offset
$01466034 movzx rdi, [rdi] byte
$01466038 add $01463210 qword-offset, 1 b#
$01466040 add $01463210 qword-offset, 1 b#
$01466048 mov rax, $01463210 qword-offset
$0146604F movzx rax, [rax] byte
$01466052 add $01463210 qword-offset, 1 b#
$0146605A lea rax, [rax #-48 +] qword
$0146605E lea rax, [rax rax*4] qword
$01466062 mov rdx, $01463210 qword-offset
$01466069 movzx rdx, [rdx] byte
$0146606C add $01463210 qword-offset, 1 b#
$01466074 add $01463210 qword-offset, 1 b#
$0146607C mov r9, $01463210 qword-offset
$01466083 movzx r9, [r9 ] byte
$01466087 add $01463210 qword-offset, 1 b#
$0146608F lea r9, [r9 #-48 +] qword
$01466093 lea r9, [r9 r9*4 ] qword
$01466097 mov r10, $01463210 qword-offset
$0146609E movzx r10, [r10] byte
$014660A2 add $01463210 qword-offset, 1 b#
$014660AA add $01463210 qword-offset, 1 b#
$014660B2 lea rbx, [rdi rbx*2 #-48 +] qword
$014660B7 push rbx
$014660B8 lea rbx, [rdx rax*2 #-48 +] qword
$014660BD push rbx
$014660BE lea rbx, [r10 r9*2 #-48 +] qword
$014660C3 push rbx
$014660C4 ;
-marcel