| |
mhindsbo
Registered: Dec 2014 Posts: 51 |
fastest or smallest 'switch' statment
I use the following code a lot to switch between two values and was wondering what others do and if there is a faster, smaller or simply more elegant way someone has come up with.
lda #value1 ; default value: AR = value1
ldy switch ; get value of switch in YR
cpy #case1 ; compare switch
beq @cont
lda #value2 ; if switch != #case1 then AR = value2
@cont ... ; AR = value1/value2 depending on switch
|
|
... 20 posts hidden. Click here to view all posts.... |
| |
lft
Registered: Jul 2007 Posts: 369 |
Or, you know, don't use addition in the first place.
; accumulator is either 00 or ff
and #value2 ^ value1
eor #value1
|
| |
soci
Registered: Sep 2003 Posts: 480 |
BB/Fred: Ok, great. As mentioned earlier there are no pipeline stalls to avoid here, and that switching construct is suboptimal in every way.
What's next, how to avoid cache line bouncing on large multi processor 6502 systems? Various synchronization primitives for my threaded code? Pre-fetching? How to optimize unaligned access? Use of barriers for memory mapped I/O? |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Sure, but optimising is fun :-D |
| |
soci
Registered: Sep 2003 Posts: 480 |
Yes, no problem with that. But it seemed quite a bit pointless, and then it was pushed even further ;) |
Previous - 1 | 2 | 3 - Next |