ISO C23 introduced the header stdbit.h, providing various utilities IMO quite useful to SDCC users.
C2Y will expand upon this, providing functions for bit rotation, memory reversal, and endian-aware loads and stores, including some functionality requested by SDCC users in the past.
It looks like the interface and semantics have stabilized by now; though standardization of parameter forward declarations might still subsequent trigger changes to the interface if it happens sufficiently before C2Y deadlines.
I've started work on this, and the first batch should be ready to commit to trunk soon.
In [r15635], I implemented all the new functions, except for the bit rotation functions, including tests for them, and some additional tests for functions already added in C23. Since I expect users of these functions to care for speed, I've used
inlineto make them efficient.Remaining known issues:
--stack-autois used (either explicitly or implicitly).__memcpybeing emittted in the generated code, even for ports where there should be builtinmemcpyfor better performance.Related
Bugs:
#3874Commit: [r15635]
In [r15636], the missing functions have been implemented.
Remaining known issues:
--stack-autois used (either explicitly or implicitly).__memcpybeing emittted in the generated code, even for ports where there should be builtinmemcpyfor better performance.Related
Bugs:
#3874Commit: [r15636]
Last edit: Philipp Klaus Krause 2025-09-01
In [r15638], the old AST-based rotation optimization was replaced by an iCode-based one, which works much better with function inlining. We do get ROT iCodes for the stdbit.h rotation functions now.
Related
Commit: [r15638]
In [r15639], built-in memcpy is used, where available.
Related
Commit: [r15639]
In [r15645], there is a partial fix for the inlining issue. This fix works for rotation functions, but:
Related
Bugs:
#3874Commit: [r15645]
In [r15646], the rest of that bug is fixed, so all functions are now enabled for all ports. The test failures on mos6502 and mos65c02 are the only currently known remaining problem.
Related
Commit: [r15646]
Only the right rotation test actually fails for mos65(c)02, so I enabled the tests for left rotation in [r15647].
Related
Commit: [r15647]
When committing this, I thought I had tested it on a representative selection of ports. Turns out it fails tests for multiple ports that I did not test.
The r2ka failures were due to two preexisting Rabbit codegen issues triggered by a new test. Those are fixed in [r15641].
Related
Commit: [r15641]
The pdk15-stack-auto failure was due to the new iCode rotation optimization handling volatile better than the old one, which in turn resulted in a preexisting pdk codegen bug for reads from volatile variables being triggered. Fixed in [r15642].
Related
Commit: [r15642]
The ds390 and mos65(c)02 ports ocdegen can't handle
_BitInt(N)rotations, unless N is a multiple of 8. But those ports did announced support for it in theirhasExtBitOpfunctions. Fixed in [r15643].Related
Commit: [r15643]