flat assembler
Message board for the users of flat assembler.
Index
> Main > spilling registers on the stack VS new functions |
| Author |
|
|
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. |
|||
|
|
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). |
|||
|
|
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. |
|||
|
|
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 up 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 development cycle: program structure is far from being stable. 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. |
|||
|
|
bitRAKE 13 Jul 2026, 07:47
Early in development I stay with the "systems thinking" - just at a low level. We can use macros to abstract out the registers:
Code: macro STRLEN reg0*,reg1* local more,done ; reg0 <> reg1 assert (1 metadataof reg0 - 1 elementof (1 metadataof reg0))\ <> (1 metadataof reg1 - 1 elementof (1 metadataof reg1)) mov reg0, reg1 more: cmp byte [reg0], 0 je done inc reg0 jne more done: sub reg0, reg1 end macro The nice thing about systems thinking is that it always works at the level one is working. If it didn't then it wouldn't be system thinking. _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.