Author Topic: Asm how optimize if elseif code structure  (Read 360 times)

0 Members and 1 Guest are viewing this topic.

Offline Arnaud

  • Supporter
  • 6128 Plus
  • *
  • Posts: 709
  • Country: fr
    • Awards
Asm how optimize if elseif code structure
« on: 15:41, 23 August 21 »
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.

Code: [Select]
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]
like
0
No reactions

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 1.154
  • Country: fr
    • urban exploration
    • Awards
like
0
No reactions
use RASM, the best assembler ever made :p

I will survive

Offline Fessor

  • CPC6128
  • ****
  • Posts: 265
  • Country: de
    • Awards
Re: Asm how optimize if elseif code structure
« Reply #2 on: 19:44, 23 August 21 »
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.
why not putting the tilenumbers in a table and compare a to them via cpi/cpir?
like
0
No reactions

Offline zhulien

  • 6128 Plus
  • ******
  • Posts: 920
  • Country: au
  • aka Vorax
    • 8bitology
    • Awards
Re: Asm how optimize if elseif code structure
« Reply #3 on: 17:34, 26 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.

like
0
No reactions