Instruction cycle comparison tool

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
User avatar
NovaSquirrel
Posts: 483
Joined: Fri Feb 27, 2009 2:35 pm
Location: Fort Wayne, Indiana
Contact:

Instruction cycle comparison tool

Post by NovaSquirrel »

I made a little web tool to make the cycle information in the 65c816 datasheet interactive. It lets you quickly see cycle count, master cycle count (so you can see that, for example, lda (pointer) is slower than lda absolute,x despite having the same cycle count for 16-bit X/Y), available addressing modes, and what happens on each cycle.

https://novasquirrel.github.io/SnesInst ... CycleTool/
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: Instruction cycle comparison tool

Post by jeffythedragonslayer »

Good job on this. This will be very useful when I start writing compiler optimization passes. I was going to suggest renaming that leftmost column to "Addressing mode" because there are only three 65x instruction groups, but I see there are things in there like "branch taken" that are not an addressing mode.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Instruction cycle comparison tool

Post by rainwarrior »

Thanks! This will definitely make it less tedious next time I need to count SNES cycles.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Instruction cycle comparison tool

Post by calima »

Some JS errors in older browsers:
https://novasquirrel.github.io/SnesInst ... escycle.js 136:0 SyntaxError: Unexpected identifier 'a16'
https://novasquirrel.github.io/SnesInst ... CycleTool/ 7:10 ReferenceError: Can't find variable: initTable
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: Instruction cycle comparison tool

Post by jeffythedragonslayer »

So from playing with this tool, it sounds like the answer that Grog was too lazy to figure out is actually a formula that takes the checkboxes as boolean inputs:

https://wiki.superfamicom.org/grog's-gu ... n-the-snes
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Instruction cycle comparison tool

Post by rainwarrior »

Are MVN/MVP missing?
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Instruction cycle comparison tool

Post by creaothceann »

Maybe NovaSquirrel skipped it by accident; they're both on one page.

---

My notes:

1.) STP, WAI and WDM are not included, though cycle timings aren't that important for the first two, and the latter simply wasn't included in the datasheet's bus activity listings.

2.) It would be nice if the "16-bit accumulator" and "16-bit index registers" checkboxes automatically uncheck the "Emulation mode" checkbox, and vice versa.

3.) BRK, COP and RTI should change their timing depending on P.e, since in native mode the program bank byte is also pushed/pulled.

4.) Then there's this issue:

viewtopic.php?t=19163
"2-cycle opcodes with idle cycle will become bus read when an IRQ is to be triggered immediately after opcode completion. Affects the following opcodes:"

08 Accumulator: ASL DEC INC LSR ROL ROR
19a Implied: CLC CLD CLI CLV DEX DEY INX INY NOP SEC SED SEI TAX TAY TCD TCS TDC TSC TSX TXA TXS TXY TYA TYX XCE

Code: Select all

//    | x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | xA | xB | xC | xD | xE | xF |
// ---+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
// 0x |    |    |    |    |    |    |    |    |    |    | 0A |    |    |    |    |    |
// 1x |    |    |    |    |    |    |    |    | 18 |    | 1A | 1B |    |    |    |    |
// 2x |    |    |    |    |    |    |    |    |    |    | 2A |    |    |    |    |    |
// 3x |    |    |    |    |    |    |    |    | 38 |    | 3A | 3B |    |    |    |    |
// 4x |    |    |    |    |    |    |    |    |    |    | 4A |    |    |    |    |    |
// 5x |    |    |    |    |    |    |    |    | 58 |    |    | 5B |    |    |    |    |
// 6x |    |    |    |    |    |    |    |    |    |    | 6A |    |    |    |    |    |
// 7x |    |    |    |    |    |    |    |    | 78 |    |    | 7B |    |    |    |    |
// 8x |    |    |    |    |    |    |    |    | 88 |    | 8A |    |    |    |    |    |
// 9x |    |    |    |    |    |    |    |    | 98 |    | 9A | 9B |    |    |    |    |
// Ax |    |    |    |    |    |    |    |    | A8 |    | AA |    |    |    |    |    |
// Bx |    |    |    |    |    |    |    |    | B8 |    | BA | BB |    |    |    |    |
// Cx |    |    |    |    |    |    |    |    | C8 |    | CA |    |    |    |    |    |
// Dx |    |    |    |    |    |    |    |    | D8 |    |    |    |    |    |    |    |
// Ex |    |    |    |    |    |    |    |    | E8 |    | EA |    |    |    |    |    |
// Fx |    |    |    |    |    |    |    |    | F8 |    |    | FB |    |    |    |    |
http://forum.6502.org/viewtopic.php?f=4 ... t=0#p45508
"if an interrupt is asserted during the fetch of a one-byte, two-cycle instruction (CLC, SEC, TXY, etc.), the cycle of that instruction that is normally an I/O cycle also apparently turns into a read from the PC, at least for wait state purposes"

"[TXY] pretends to read an operand of the TXY instruction (although the instruction really has no operand), then on the first of the two dead bus cycles at the beginning of the interrupt sequence, without incrementing the address, it pretends to read another op code before showing a dead bus cycle for that second cycle."
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
User avatar
NovaSquirrel
Posts: 483
Joined: Fri Feb 27, 2009 2:35 pm
Location: Fort Wayne, Indiana
Contact:

Re: Instruction cycle comparison tool

Post by NovaSquirrel »

I initially misread MVN/MVP on the datasheet as having different timing on the last iteration, and I wasn't sure how to include that, but after double checking I can see that it was just the datasheet author emphasizing what the next instruction read would be. I went and fixed all of that I think?
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Instruction cycle comparison tool

Post by creaothceann »

Yep, seems to be fixed.

(Do you want to include XSlow memory regions? It probably only affects programs that don't enable automatic controller polling and read the input controller registers 4016/7 directly; afaik there's no other hardware mapped to that region.)
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
imamelia
Posts: 16
Joined: Wed Sep 01, 2010 12:17 am

Re: Instruction cycle comparison tool

Post by imamelia »

How exactly is this supposed to be read? I get the gist of it, but why would having fewer master clock cycles per cycle make an operation go slower?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Instruction cycle comparison tool

Post by lidnariq »

It ... doesn't? What makes you think that?
imamelia
Posts: 16
Joined: Wed Sep 01, 2010 12:17 am

Re: Instruction cycle comparison tool

Post by imamelia »

Well, setting it to / 8 gives smaller numbers in the total cycle column than setting it to / 6 (because it's dividing the master clock count by a larger number).
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Instruction cycle comparison tool

Post by lidnariq »

How much time would it take, relative to pretending that all instructions always took exactly 6 (running at 3.6MHz) or 8 (2.7MHz) clocks.

In other words, the "Total column" is the number of "master clocks", or is the number of master clocks divided by 8, or the number of master clocks divided by 6.
turboxray
Posts: 348
Joined: Thu Oct 31, 2019 12:56 am

Re: Instruction cycle comparison tool

Post by turboxray »

Can we sticky this thread?
Post Reply