This 4-patch series adds struct and union return support for the DS390 flat24 model.
This work is for B1a of the NGI0-funded SDCC project.
Scope:
--xstack and --stack-8bit are rejected for nowTested:
make test-ds390
0 failures, 31971 tests, 6414 test cases.
Patches:
I would especially appreciate review of the struct return calling convention and the DPTR save/restore code in patch 2.
Patch 4:
tests/dynamiccstructret.c.in?tests/bigreturn-remat.c.inis outdated, I think. AFAIK all ports (except unmaintained pic) now supportstructparameters, so it is only missingstructreturn that stopped us from enabling this test.Patch 3:
Patch 2:
stackAdjust (int n, bool a_dead)function (like many other ports have) instead ofemitDiscardStructReturnPointer, that you can also use for the parameter stack adjustment in genCall, and also do the struct return and stack parameter adjustement in one call toadjustStack.Patch 1:
Last edit: Philipp Klaus Krause 2026-10-08
Hi,
Thanks for the detailed review and suggestions!
Patch 4:
I enabled dynamiccstructret.c.in for ds390 and removed the old restriction in bigreturn-remat.c.in.
Patch 3:
I've added short comments explaining the new conditions for ds390 flat24.
Patch 2:
I updated the code based on Maarten’s feedback. The caller now passes the hidden result pointer in registers, not on the stack.
I added stackAdjust() to share the cleanup code in genCall() and genPcall(). The callee also uses it to remove its saved pointer. There is no longer a pointer on the caller’s stack to clean up with the arguments.
I kept the existing handling of A, so the helper does not need a_dead.
Patch 1:
I used Maarten’s refactoring for stack offsets and pointer handling, including the mcs51 changes.
Patch 1:
But I would
make stackOffsetForSym() return short instead of int andremove a lot of casts.Last edit: Maarten Brock 2026-10-11
And since mcs51 and ds390 are so very much alike, try to keep their code as close as possible. Thus this would be more appropriate:
Instead of your 0001-ds390-refactor-stack-helper-code.patch I propose this patch.
It has stackoffset() as mentioned above and modifies pointerCode() instead of introducing genericPointerSpaceTag().
It also beter optimizes aopForSym() stack offset calculations.
Thank!
Thanks for your explanation of the 8-bit stack.
I used your proposed refactoring in v2 Patch 1, including stackoffset() and pointerCode(). The offsets in aopForSym() now use int without the old casts.
Patch 2:
then becomes
IMHO this could work for all memory models and stack models.
Thanks!
I changed Patch 2 so the caller passes the result pointer in dpl/dph/dpx/b, the registers used for the first parameter. The callee saves it until it returns.
I've attached the four v2 patches.
Looks good to me (though I'm not a ds390 expert).
I wonder if adjustStack could be made slightly more efficient by doing "sp += -n" instead of "sp -= n", since addition is a bit cheaper than subtraction. But that would be an optimisation, and IMO the patches could also go in as-is.
Last edit: Philipp Klaus Krause 3 days ago
Thanks @spth !
I'll look into using addition instead of subtraction for the stack adjustment. (Will prepare a v3
Thanks for the suggestion and reivew!
@maartenbrock, could you also have a look at the v2 patches when you have time? I'd really appreciate your feedback!
Thanks again.
Last edit: Li-Hsin Chien 17 hours ago