KickC Optimizing C-Compiler now supports NES

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

tepples
Posts: 22052
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: KickC Optimizing C-Compiler now supports NES

Post by tepples » Thu Jun 18, 2020 1:32 pm

Does it offer something with static's speed and auto's space reuse that uses the call graph to let functions share a variable's space if the compiler can determine that they will never be in the call stack at once? I've proposed this sort of arrangement for 6502 assembly, and compilers for modern 8-bit microcontroller ISAs appear to support what Microchip calls a "compiled stack."

JesperGravgaard
Posts: 9
Joined: Fri Jul 05, 2019 1:41 pm

Re: KickC Optimizing C-Compiler now supports NES

Post by JesperGravgaard » Thu Jun 18, 2020 2:30 pm

tepples wrote:
Thu Jun 18, 2020 1:32 pm
Does it offer something with static's speed and auto's space reuse that uses the call graph to let functions share a variable's space if the compiler can determine that they will never be in the call stack at once? I've proposed this sort of arrangement for 6502 assembly, and compilers for modern 8-bit microcontroller ISAs appear to support what Microchip calls a "compiled stack."
The majority of short-lived variables can be handled directly in registers (and thus are never stored in memory). Short lived variables that have to be stored in memory tries to reuse the same zero page addresses when possible.

KickC performs variable live range analysis based on single-static assignment form of the code. This allows the compiler to reuse the same storage for multiple variables as long as they are never alive at the same time. It also tries to reuse the same storage for variables that "meet" at a single assigment), eg. if the variable a is last used in the assignment b=a+7 then it will try to reuse the same storage for a and b.

You can read a paper describing the algorithm that KickC uses for allocating variables to storage here: http://compilers.cs.ucla.edu/fernando/p ... t_tech.pdf

User avatar
Nikku4211
Posts: 107
Joined: Sun Dec 15, 2019 1:28 pm
Location: Bronx, New York
Contact:

Re: KickC Optimizing C-Compiler now supports NES

Post by Nikku4211 » Sat Jun 27, 2020 10:58 am

Do you plan to add SNES support, too? I don't care if PVSNESLib exists.
I have an ASD, so empathy is not natural for me. If I hurt you, I apologise.

User avatar
Bregalad
Posts: 7951
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: KickC Optimizing C-Compiler now supports NES

Post by Bregalad » Thu Aug 20, 2020 2:36 pm

So, out of both compilers released almost simultaneously, any particular reason why VBCC has a popular thread and not this one ? I need more info to complete this post (and probably make a Wiki page about it as well).
Sorry but I'm very lazy so I decided I'd let the others do the early testing before taking this on myself :)
Useless, lumbering half-wits don't scare us.

User avatar
Gilbert
Posts: 396
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: KickC Optimizing C-Compiler now supports NES

Post by Gilbert » Thu Aug 20, 2020 6:57 pm

Bregalad wrote:
Thu Aug 20, 2020 2:36 pm
So, out of both compilers released almost simultaneously, any particular reason why VBCC has a popular thread and not this one ?
Because the author of VBCC is more actively interacting with others in its thread?
The author of KickC last posted in mid-June here in this thread.

calima
Posts: 1189
Joined: Tue Oct 06, 2015 10:16 am

Re: KickC Optimizing C-Compiler now supports NES

Post by calima » Fri Aug 21, 2020 12:27 am

KickC is not C, but its own C-like language. That's going to limit it.

VBCC seems to be massively buggy, and it's partially closed source. So from my POV neither of these new compilers is a viable option.

User avatar
Memblers
Site Admin
Posts: 3880
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: KickC Optimizing C-Compiler now supports NES

Post by Memblers » Fri Aug 21, 2020 1:31 am

It is some incredible timing, I don't think have been new C compilers for decades. I think the difference is that VBCC is a mature compiler with a new 6502 backend, while KickC is an all-new 6502-specific compiler. It's really interesting, seeing all the code fragments and how you can add new ones. It seems to support optimizations with undocumented opcodes, too.

I have a couple demos that work on cc65 and vbcc6502, and tried to build them with KickC.

First one is a 6502 emulator demo. In fake6502 I ran into "no viable alternative" error, and I narrowed the problem down to the variable's name, "pc". Renaming it fixed the error. After that, it makes it up to the line "static void (*const addrtable[256])();" and is an error there. But the manual says function pointers aren't fully implemented, OK.

Next I tried the balls demo. To start with, I simply took out all NES-specific parts, and will try building the main logic first. It makes it up to line 77, if I comment the line out, most lines after that are also reporting missing code fragments. I attached the C file, if that helps at all.

I get the impression to be able to continue with this demo, I would need to write those code fragments, and port or adapt the OAM handling. I'm curious to see how the code can perform, but that stuff is more than I can do at the moment.

Code: Select all

Unknown fragment for statement [23] *((word*)(const struct $0*) balls + (byte~) main::$28) ? *((word*)(const struct $0*) balls + (byte~) main::$28) + *((word*)(const struct $0*) balls+(byte) 4 + (byte~) main::$28)
Missing ASM fragment Fragment not found pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_plus_pwuc2_derefidx_vbuz1. Attempted variations pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_plus_pwuc2_derefidx_vbuz1
File C:\proj\c\NES\balls\.\kickballs.c
Line 77
balls[i].x_position += balls[i].x_velocity

Compiling kickballs.c
Unknown fragment for statement [23] *((word*)(const struct $0*) balls+(byte) 6 + (byte~) main::$29) ? *((word*)(const struct $0*) balls+(byte) 6 + (byte~) main::$28) + (byte) $10
Missing ASM fragment Fragment not found pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz2_plus_vbuc2. Attempted variations pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz2_plus_vbuc2 pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz2_plus_vbsc2 pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz2_plus_vwuc2 pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz2_plus_vwsc2 pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz2_plus_vduc2 pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz2_plus_vdsc2
File C:\proj\c\NES\balls\.\kickballs.c
Line 78
balls[i].y_velocity += WEIGHT

Compiling kickballs.c
Unknown fragment for statement [23] (word~) main::$11 ? *((word*)(const struct $0*) balls + (byte~) main::$27) >> (byte) 8
Missing ASM fragment Fragment not found vwuz1=pwuc1_derefidx_vbuz2_ror_8. Attempted variations vwuz1=pwuc1_derefidx_vbuz2_ror_8
File C:\proj\c\NES\balls\.\kickballs.c
Line 80
balls[i].x_position >> 8

Compiling kickballs.c
Unknown fragment for statement [23] *((word*)(const struct $0*) balls+(byte) 4 + (byte~) main::$27) ? *((word*)(const struct $0*) balls+(byte) 4 + (byte~) main::$27) ^ (word) $ffff
Missing ASM fragment Fragment not found pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_bxor_vwuc2. Attempted variations pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_bxor_vwuc2 pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_bxor_vduc2 pwuc1_derefidx_vbuz1=pwuc1_derefidx_vbuz1_bxor_vdsc2
File C:\proj\c\NES\balls\.\kickballs.c
Line 82
balls[i].x_velocity ^= 0xFFFF
Attachments
kickballs.c
(3.07 KiB) Downloaded 15 times

mka982
Posts: 3
Joined: Thu Jan 11, 2007 6:12 pm

Re: KickC Optimizing C-Compiler now supports NES

Post by mka982 » Tue Sep 15, 2020 7:10 am

Generated code:

lda var123
cmp #0
beq lable

or

dex
cpx #0
bne loop

Can you optimize it

I try to use it to develop things (kickc_0.8.2)

Post Reply