flat assembler
Message board for the users of flat assembler.

Index > Main > spilling registers on the stack VS new functions

Author
Thread Post new topic Reply to topic
sylware



Joined: 23 Oct 2020
Posts: 611
Location: Marseille/France
sylware 10 Jul 2026, 12:02
How do you handle arbitration between spilling call-preserved registers on the stack and the creation of new functions?

The way I see that, and I may be severely wrong: once I filled all the called-preserved registers, I would spill on the stack, but if I end up spilling on the stack all call-preserved regs, I do create new functions.
Post 10 Jul 2026, 12:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20999
Location: In your JS exploiting you and your system
revolution 10 Jul 2026, 12:10
I don't use register spill as a criterion for creating functions.

If I use some non-trivial code more than once then I will consider making it a function.

The final call will be made based upon what I need to optimise for. If I need peak performance then I will benchmark each way to decide. If I want good readability then I usually just make a new function. If I need to move on quickly to meet a deadline then I often just copy/paste with the (often unmet) hope to come back later to "fix" it.
Post 10 Jul 2026, 12:10
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 611
Location: Marseille/France
sylware 10 Jul 2026, 14:06
Indeed, the "trivial and more than once" usually does pre-empt spilling leading to function creation, that upon initial coding.

The functions I am talking about would have very probably only one call-site (ooof) and would be non-trivial (their state would eat a good part of call-preserved regs since many would perform ABI calls).

I guess I should eat the bullet: handle such huge code path with reg spilling all over the place. I should start to figure out a not too disgusting way to handle deeply nested labels (here, I use a basic C pre-processor).
Post 10 Jul 2026, 14:06
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4535
Location: vpcmpistri
bitRAKE 11 Jul 2026, 02:46
My computer science professor called it cohesion and containment. Is the function cohesive - does it do one thing well and not anything else? Is the function contained - not linked to many external things? If those things are true then you have a good function.

As we scale to greater complexity we're asking the questions at a complexity scale. This is systems thinking.

* disclaimer: that's advice from the late 80's.
Post 11 Jul 2026, 02:46
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 611
Location: Marseille/France
sylware 11 Jul 2026, 11:18
I am talking sorta more about ABI functions.

In C and similar, we write more 'logical' functions than ABI functions.

In assembly, many C functions would end as just some code blocks.

In the end, with now more perspective, I write ABI functions in assembly for flexibility mostly since I am in the middle of the dev elopment cycle: program structure is far from being stabilized.

Once program structure does settle down, some ABI functions will probably move as 'code block' functions: both are 'logical' functions following the guidelines you talked about.
Post 11 Jul 2026, 11:18
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.