News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Arnaud

Asm how optimize if elseif code structure

Started by Arnaud, 13:41, 23 August 21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Arnaud

Hi,
here an extract of my code, it's a simple if elseif structure.

The tests take more time than the computation itself, is the better way to make these comparisons ?

Thanks.

loopTilemap:
    ld   a, (hl)     ;; [2] A = (HL) tile to compare

    ;; Select tilemap type
    or   a             ;; [1] 00 = Land Tile
    jp   z, replaceTilemap  ;; [2/3]

    cp   #40         ;; [2] 40 = Forest Tile
    jp   z, replaceTilemap  ;; [2/3] 

    cp   #05         ;; [2] 05 = Swamp Tile
    jp   z, replaceTilemap  ;; [2/3]

    cp   #79         ;; [2] 79 = Flag Tile
    jp   z, changeTilemap  ;; [2/3] 

    cp   #151        ;; [2] 151 = Fire Camp
    jp   z, changeTilemap  ;; [2/3] 

    jp   nextTileMap ;; [3]

roudoudou

My pronouns are RASM and ACE

Fessor

Quote from: Arnaud on 13:41, 23 August 21Hi,
here an extract of my code, it's a simple if elseif structure.

The tests take more time than the computation itself, is the better way to make these comparisons ?

Thanks.
why not putting the tilenumbers in a table and compare a to them via cpi/cpir?

zhulien

Quote from: roudoudou on 13:50, 23 August 21
take a look at   https://wikiti.brandonw.net/index.php?title=Z80_Optimization#Look_up_Table


fantasitc!  I always disliked the constant chain of CPs as the last one always takes longer to compare than the first.  now there are several options between consistency in speed, super fast, tight memory etc...


i also was thinking about jump tables, and of course if you have only a couple of CPs then the benefits are lost, but if you have dozens, it definitely looks like a good option.


Powered by SMFPacks Menu Editor Mod