It is currently Fri Sep 21, 2018 2:40 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
PostPosted: Thu Jun 28, 2018 6:06 am 
Offline
Formerly ~J-@D!~
User avatar

Joined: Sun Mar 12, 2006 12:36 am
Posts: 470
Location: Rive nord de Montréal
In addition, Microchip's XC8 C compiler does that too. In fact, depending on the chip model, it can use both a "compiled stack" (which is just fixed locations for variables) and a software stack; by default, it only use the later for functions that are called from multiple contexts (ex: from main and an ISR) or if it detects recursion.

If you're really curious about this, here's the manual, and the relevant info is at the section 5.5.2.2, "Auto variable allocation and access". Among other things, it explains the process of how variables are allocated in the "compiled stack" by analysing the call graph and observing the lifetime of individual variables in it, so variables that are not active at the same time can overlap in memory. Nothing we didn't know before, but might be interesting nevertheless.

_________________
((λ (x) (x x)) (λ (x) (x x)))


Top
 Profile  
 
PostPosted: Thu Jun 28, 2018 10:41 am 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 359
tepples wrote:
Today I learned some production C compilers actually do this. From BL51 Users Guide: Data Overlaying:

The 8051 hardware stack is limited to a maximum of 256 bytes. As such, using stack frames on the 8051 is very wasteful of the limited memory available.

The Keil C51 C Compiler works with the LX51 Linker to store function arguments and local variables in fixed memory locations using well-defined names (so that function arguments are easily passed and accessed). The linker analyzes the structure of the program and creates a call tree which it uses to overlay the data segments containing local variables and function arguments.

You too read this article yesterday? :P
https://wozniak.ca/blog/2018/06/25/Mass ... index.html


Top
 Profile  
 
PostPosted: Sat Jun 30, 2018 1:03 am 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 579
You have all seen this right? https://www.youtube.com/watch?v=zBkNBP00wJE Where is shows off how insane modern c++ compilers are at optimising things?


Top
 Profile  
 
PostPosted: Fri Jul 13, 2018 9:59 am 
Offline
User avatar

Joined: Fri Nov 24, 2017 2:40 pm
Posts: 81
Oof. That video is kind of hard to watch.

Seems like it follows the trap of "Isn't it neat that you can use zero-cost abstractions to write more code than necessary?" I've had too many cases where I found myself writing a lot of code in order to use RAII because it was the "correct" thing to do when all I really needed was malloc() / free() or alloca(). Bah!

I think that got a little rant-y because I've been enjoying NES dev so much lately because not only is C++ not really an option, but I don't feel like I even need it. Sort of a weight off the shoulders sort of thing. Heh.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google [Bot] and 3 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:  
Powered by phpBB® Forum Software © phpBB Group