6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Sep 23, 2024 2:26 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sat Aug 20, 2022 11:46 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Direct page addressing incurs a one cycle penalty (when the direct page is not pointing to a physical page boundary) because the direct page offset has to be added to the direct page register in order to compute the effective address instead of simply concatenating the offset to the high byte of the DP register when the low byte is zero.

Why doesn't stack relative addressing also incur a one cycle penalty when the stack pointer is not pointing to a physical page boundary?


Top
 Profile  
Reply with quote  
PostPosted: Sun Aug 21, 2022 12:04 am 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
i would assume because the stack always has that extra cycle pentalty as adding extra circuitry to skip some part of the stack address calculation wouldn't be worth it for the 1/256 chance that the stack happens to be on a page boundary.


Top
 Profile  
Reply with quote  
PostPosted: Sun Aug 21, 2022 12:29 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8511
Location: Southern California
I would venture a guess that it's because the processor doesn't care where you started the stack or how deep it is. All it cares about is what the pointer is at right now, and it can increment it (or decrement it) as quickly as it can increment the 16-bit program counter.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 22, 2022 12:29 am 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Proxy wrote:
i would assume because the stack always has that extra cycle pentalty as adding extra circuitry to skip some part of the stack address calculation wouldn't be worth it for the 1/256 chance that the stack happens to be on a page boundary.

That does make a lot of sense. Say, does anyone know how to get involved with the visual6502 project? I'd be very interested in a visual65816 to help get answers to some of these hardware questions. 8)
GARTHWILSON wrote:
I would venture a guess that it's because the processor doesn't care where you started the stack or how deep it is. All it cares about is what the pointer is at right now, and it can increment it (or decrement it) as quickly as it can increment the 16-bit program counter.

I recently noticed that you can even overflow or underflow the stack and the processor just keeps going, which makes it difficult to debug trashing the stack. A warning on this condition is something I'd like to see added to emulators.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 22, 2022 12:52 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8511
Location: Southern California
jeffythedragonslayer wrote:
GARTHWILSON wrote:
I would venture a guess that it's because the processor doesn't care where you started the stack or how deep it is. All it cares about is what the pointer is at right now, and it can increment it (or decrement it) as quickly as it can increment the 16-bit program counter.

I recently noticed that you can even overflow or underflow the stack and the processor just keeps going, which makes it difficult to debug trashing the stack. A warning on this condition is something I'd like to see added to emulators.

One the '816, there's no limit to the stack area. It's the entire bank 0; so a simulator would have to be told what the address range is that you're assigning to the stack area.

The '02 only has page 1 for the hardware stack, and many people have concluded that if the whole page is dedicated for the stack (which is seldom necessary) and it wraps, it doesn't matter where you start; so they don't even initialize it. In that case, a simulator might not know where the wrap-around point is. I definitely recommend initializing the stack pointer even on the '02 though, to avoid accidentally indexing into page 2 in the doubly indexed stack-relative addressing which you can do even on the '02, using X as an index. I describe it in the stack-addressing page of the 6502 treatise on stacks (stacks plural, not just the page-1 hardware stack).

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 22, 2022 2:02 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8390
Location: Midwestern USA
jeffythedragonslayer wrote:
Direct page addressing incurs a one cycle penalty (when the direct page is not pointing to a physical page boundary) because the direct page offset has to be added to the direct page register in order to compute the effective address instead of simply concatenating the offset to the high byte of the DP register when the low byte is zero.

Why doesn't stack relative addressing also incur a one cycle penalty when the stack pointer is not pointing to a physical page boundary?

Because stack relative addressing is really absolute addressing.

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 22, 2022 6:46 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
jeffythedragonslayer wrote:
Say, does anyone know how to get involved with the visual6502 project? I'd be very interested in a visual65816 to help get answers to some of these hardware questions. 8)

The visual6502 project is more or less done at this point, I think. The code base is open, and there are various forks, and various people continue to reverse-engineer chips and to extend the simulator, but the core team are not really active any more. A sign of this is that the wiki is broken and has been for a while - we refer people to the archive instead. The necessary techniques for making a visual65816 are all known, but it will take effort, and as yet, as far as I know, no-one has done it.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 22, 2022 7:06 am 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
BigEd wrote:
The necessary techniques for making a visual65816 are all known, but it will take effort, and as yet, as far as I know, no-one has done it.


Well you can put my name down as one of the people who are interested in helping, but after the first version of this 65816 compiler I'm working on is ready. 8)


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 21, 2022 12:00 pm 
Offline
User avatar

Joined: Tue Aug 11, 2020 3:45 am
Posts: 311
Location: A magnetic field
jeffythedragonslayer on Sat 20 Aug 2022 wrote:
Why doesn't stack relative addressing also incur a one cycle penalty when the stack pointer is not pointing to a physical page boundary?


65816 legacy behavior always matches or betters 65C02. Exotic behavior may not match or better 65C02.

I would say no one would use 65816 if that were not the case, however we have some very peculiar members on the 6502 Forum who would probably use it for convenience rather than speed (which is approximately zero, nowadays). A good counter-example is Intel's Pentium4 which failed to match clock cycles of its predecessor. It runs contemporary GCC output very well but, at launch, some new and old software ran slower.

Actually, adding pointers is a subject of architectural improvement because it requires O(n log n) transistors to add n bits with the least delay. We also have the case where (d,S),Y addressing mode may require adding 16 bit stack pointer to 16 bit RegY and 8 bit immediate value. That is five 8 bit addition operations. One addition can be overlapped with operand fetch and one addition can be eliminated if DP is page aligned.

_________________
Modules | Processors | Boards | Boxes | Beep, Beep! I'm a sheep!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 20 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: