Re: count2.asm



Frank Kotler wrote:
That thread "about jump tables" is getting old enough to vote. Besides, this version doesn't have a jump table in it. It's still "inspired" by Alex's suggestion that counting characters in a text file might be an example of where a jump table would make sense. But after thinking a bit about what we were actually *doing* with the jump table (with its targets, actually), I thought this approach might work better. It does seem to be faster, counting my 38M "test file" - 1.6+ seconds, vs 2.8+ seconds for "count1" (with the jump table). There's some variation between runs of the same thing - these figures seem to be the most common, repeatable, values... (that's a K6-300 - not the most common processor, these days)

There are a ton more improvements to be made - some I know about, and no doubt some I don't (yet). I'm posting it even if it isn't "ready". Might as well start kicking it around. No use making it "nice" if it's going to have to be rewritten from scratch :)

Best,
Frank


[code snipped]

Good lateral thinking; given a sort & output, you should be able to see the letter frequency of etaoin shrdlu too. Interestingly, perhaps the output side would benefit from the table method; there's a degree of repetitive pattern in this;

    mov esi, msg_uppercons
    call putz
    mov ebx, uppercons_list
    call add_em_up
    add [cons], eax
    add [alphas], eax
    call showeaxd

    mov esi, msg_lowercons
    call putz
    mov ebx, lowercons_list
    call add_em_up
    add [cons], eax
    add [alphas], eax
    call showeaxd

This;

ignore:
    mov ecx, eax
    cmp esi, edi
    jz show_results
    lodsb
    cmp al, 80h
    jae ignore
    add dword [charcounts + eax * 4], 1
%if 1
    cmp al, ' '
    jnz ignore
    cmp ecx, eax
    jz ignore
    add dword [words], 1
%endif

could be replaced by

ignore:
    cmp esi, edi
    jz show_results
    movzx eax, [esi]
    add dword [charcounts + eax*4], # 1
    add esi, # 1
%if 1
    mov edx, eax
    sub eax, # $21
    sbb eax, eax
    sub ecx, # $21
    sbb ecx, ecx
    not ecx
    and eax, ecx ; -1 if eax=$20<>ecx
    sub dword [words], eax
    mov ecx, edx
    jmp short ignore
%endif

Replacing the cmp/jcc is debatable; it might or might not be faster, depending on the word length.

How about unrolling some of the loop? i.e

    cmp esi, edi
    jz deal_with_last_bytes
    mov edx, [esi]
    shrd edx, eax, 8
    shr  eax, 24
    add dword [charcounts + eax*4], # 1
    shrd edx, eax, 8
    shr  eax, 24
    add dword [charcounts + eax*4], # 1
    shrd edx, eax, 8
    shr  eax, 24
    add dword [charcounts + eax*4], # 1
    add esi, # 4
    ...

--
Regards
Alex McDonald
.



Relevant Pages