6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 10:54 am

All times are UTC




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Tue Jun 23, 2020 2:58 am 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
BigDumbDinosaur wrote:
johnwbyrd wrote:
For that reason, a 65816-only solution, that may or may not use the Z accumulator, is also of interest.

There is no "Z accumulator" in the 65C816. The 65C816's registers are .A, .B, .X, .Y, DB, DP, PB, PC and SP.


D'oh! I was confusing the 65816 and the obscure 65CE02, which apparently had a Z register.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 23, 2020 3:13 am 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
barrym95838 wrote:
I certainly don't know if I'm misunderstanding or oversimplifying, but my attempt which does what you seem to describe would be:
Code:
; add two 16-bit numbers in zp:
; x and y point to the addends, a points to the sum
; a and x are modified, y is preserved

If I count correctly (big if), 57 cycles between jmp main and brk, one cycle faster than BillG's fastest NMOS attempt.


At first glance, this code seems to me to behave as per the specifications -- let's see if any more cycles can be shaved off by others...


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 23, 2020 3:48 am 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
BillG wrote:
Code:
        org     0

P3      db      0       ; Pointer to third operand
SumLow  db      0

Num1    dw      1234    ; First number
Num2    dw      5678    ; Second number
Num3    dw      0       ; Sum

;
; (P1) + (P2) -> (P3)
;
Add
        sta     P3

        clc
 
        lda     0,Y
        adc     0,X
        sta     SumLow
 
        lda     1,Y
        adc     1,X
        ldx     P3      ; Point to sum
        sta     1,X
        lda     SumLow
        sta     0,X

        rts

;
Start
        ldy     #Num1   ; Store pointer to first number

        ldx     #Num2   ; Store pointer to second number
 
        lda     #Num3   ; Store pointer to sum

        jsr     Add     ; Add them

        end     Start



It's fascinating that juggling SumLow into a temporary zero page location, and handling the low byte last, seems to produce a faster result.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 23, 2020 4:06 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8390
Location: Midwestern USA
johnwbyrd wrote:
BigDumbDinosaur wrote:
johnwbyrd wrote:
For that reason, a 65816-only solution, that may or may not use the Z accumulator, is also of interest.

There is no "Z accumulator" in the 65C816. The 65C816's registers are .A, .B, .X, .Y, DB, DP, PB, PC and SP.


D'oh! I was confusing the 65816 and the obscure 65CE02, which apparently had a Z register.

The Z register in the 65CE02 has no analog in the 65C816.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 16, 2020 10:24 am 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
Any more suggestions? The existing entries seem optimal superficially, but I still hold out hope.

Lest that any of you think that this is purely an academic competition, let me quietly tease some screenshots of my current work.

Note the line number 7773, which is my attempt at a l33t spelling of LLVM.


Attachments:
File comment: Hello, LLVM for 6502 for Apple II
hello-apple2.png
hello-apple2.png [ 6.41 KiB | Viewed 972 times ]
File comment: Hello, LLVM for 6502 for VIC 20
hello-vic20.png
hello-vic20.png [ 76.19 KiB | Viewed 996 times ]
File comment: Hello, LLVM for 6502 for C64
hello-llvm.png
hello-llvm.png [ 90.79 KiB | Viewed 1028 times ]


Last edited by johnwbyrd on Sat Jul 18, 2020 12:22 am, edited 3 times in total.
Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 16, 2020 2:38 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 702
Location: North Tejas
Are you working on a virtual machine or compiler backend infrastructure?


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 16, 2020 8:09 pm 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
BillG wrote:
Are you working on a virtual machine or compiler backend infrastructure?


Yes to both. The first is a by-product of the second. Code optimized for speed would be emitted in ordinary 6502 assembly. But code optimized for size would be emitted in an LLVM IR-like bytecode, to be parsed by a runtime language interpreter, and hence this calling convention would apply.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 10, 2020 7:27 pm 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
Going once...


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 14, 2020 7:57 pm 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
Going twice...


Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 13, 2020 8:33 pm 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
The optimization competition is now over!

:idea: :idea: :idea:

I award Top Honors to BillG for embracing the problem so completely, and for eventually finding the fastest solution. :D

However, an important Inspirational Award goes to barrym95838, for finding the creative breakthrough that enabled the fastest solution to exist. 8)

Congratulations everyone, and thank you so much for playing!

:!: :!: :!: :!:


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 15, 2020 1:41 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 702
Location: North Tejas
I would like to thank the Academy...

Actually, I thank barrym95838 as well for the competitive spirit and out-of-the-box thinking which made the final result possible.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: