Jump to content
IGNORED

efficient compilation of #batcktab()


artrag

Recommended Posts

I'm compiling this line of code

A = PEEK($0200+(X-8)/8+ (Y+3 AND $F8)/2*5)

and I get this

    MVI var_X,R1
    SUBI #8,R1
    SLR R1,2
    SLR R1,1
    ADDI #512,R1
    MVI var_Y,R2
    ADDI #3,R2
    ANDI #248,R2
    SLR R2,1
    MULT R2,R4,5
    ADDR R2,R1
    MVI@ R1,R0
    MVO R0,var_&A
 

Later I compile this line:

A = PEEKAT(X-8,Y+3) 

where I've defined

DEF FN PEEKAT(x,y) = #backtab((x)/8+ ((y) AND $F8)/2*5)

and I get this:

    MVI var_X,R1
    SUBI #8,R1
    SLR R1,2
    SLR R1,1
    MVI var_Y,R2
    ADDI #3,R2
    ANDI #248,R2
    SLR R2,1
    MULT R2,R4,5
    ADDR R2,R1
    MVII #Q2,R2
    ADDR R2,R1
    MVI@ R1,R0
    MVO R0,var_&A
 

It seems that this latter solution using backtab is slower and larger in ROM

Is this correct?

And if yes, why?

 

Link to comment
Share on other sites

  • 1 month later...
On 10/15/2019 at 10:45 AM, artrag said:

((y) AND $F8)/2*5)

I keep staring at that and it hurts my eyes.  I know you're losing 6 cycles to "ADDI" being split into "MVII + ADDR", but it feels like you're losing as much to "SLR + MULT."

 

This sequence:

    ANDI #248,R2
    SLR R2,1
    MULT R2,R4,5
    ADDR R2,R1

expands to:

    ANDI #248,R2
    SLR R2,1
    MOVR R2,R4
    SLL R2,2
    ADDR R4,R2
    ADDR R2,R1

That's 40 cycles and 7 words.

 

If you coded this in assembly yourself you could do:

    ANDI #$F8, R2
    SLR R2, 1
    ADDR R2, R1
    SLL R2, 2
    ADDR R2, R1

That's 34 cycles and 6 words, and leaves R4 untouched.

 

*shrug*

 

If you care about 6 cycles and one word, why not code directly in assembly?

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...