-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toolchain: Add assembly-side counterpart of __aligned #85758
Conversation
4260068
to
8e0624a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer having the macro named ALIGN
.
include/zephyr/toolchain/common.h
Outdated
defined(CONFIG_XTENSA) || defined(CONFIG_MIPS) || \ | ||
defined(CONFIG_ARCH_POSIX) | ||
|
||
#define BALIGN(x) .balign x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ALIGN
is a better term because alignment is what we want.
I know the differences between .align
and .balign
, but for the code that wants to use alignment, then ALIGN
is a better macro name and aligns with the PERFOPT_ALIGN
macros in naming (which also uses .balign
when possible).
include/zephyr/toolchain/common.h
Outdated
|
||
#define BALIGN(x) .balign x | ||
|
||
#elif defined(CONFIG_ARC) || defined(CONFIG_SPARC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically support for .balign
is not an architecture thing but a toolchain supported instruction, whereas .align
is generally supported across toolchains (but where the behavior is system specific 😞 ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed. For preprocessor conditionals, I just followed the similar scheme that the logically close existing macro PERFOPT_ALIGN
is using. But theoretically, yes, this is a bit off. However, it won't cause any trouble unless we (need to) support multiple toolchains for an architecture that either treat .align
differently (i.e. one interprets its param as number of bytes and other as number of lower order bits to be zeroed) and/or one supports .balign
and other doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep for now.
Just wanted to point it out.
Perhaps a code comment would be appropriate so someone later don't change this by accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed that PERFOPT_ALIGN
implementation has a comment exactly for this clarification for the ARC
case - I have updated the code to reuse the same comment.
Currently IAR use GNU assembler, but if we start using
Maybe this is a shortcoming we will need to fix in our toolchain however, because I am not sure how to make a clean solution that would allow both @bjorniuppsala any ideas? |
I think fixing our assembler is the way to go. |
include/zephyr/toolchain/common.h
Outdated
|
||
#define BALIGN(x) .balign x | ||
|
||
#elif defined(CONFIG_ARC) || defined(CONFIG_SPARC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For ARC classic there are multiple compilers, gnu and MetaWare. Metaware indeed doesn't support .balign, and .align works for both gnu and MetaWare. Should the condition for this choice be architecture, or rather toolchain variant? Maybe this shouldn't be in 'common.h' but specified per toolchain?
I also preferred it but unfortunately it conflicts with a (GNU/GNU-compatible) linker script directive of the same name and syntax. So instances like
Or we can consider some other good name, but I don't have any in my mind, as of yet. |
You just need to properly safe guard the definition so that it's not used for linker script preprocessing, like this:
|
include/zephyr/toolchain/common.h
Outdated
* 'test_symbol' will get aligned to 4 bytes. | ||
*/ | ||
|
||
#ifdef _ASMLANGUAGE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use:
#ifdef _ASMLANGUAGE | |
#if defined(_ASMLANGUAGE) && !defined(_LINKER) |
then it will be defined for the linker script template pre-processin, and thus not conflict with the linker directive of same name and you can use ALIGN
as macro name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointer. I have updated it.
8e0624a
to
e8411f4
Compare
@tejlmand BTW, now If you agree, I can post a follow-up PR afterwards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit observed, rest looks good.
include/zephyr/toolchain/common.h
Outdated
|
||
#elif defined(CONFIG_ARC) | ||
|
||
/* .align assembler directive is supposed by all ARC toolchains and it is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supposed ?
/* .align assembler directive is supposed by all ARC toolchains and it is | |
/* .align assembler directive is supported by all ARC toolchains and it is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Carry over from the existing comment in PERFOPT_ALIGN that I reused. Fixed here. Will also fix the old reference comment in the follow-up PR while rebasing PERFOPT_ALIGN over this newly introduced ALIGN macro.
will be appreciated 👍 |
e8411f4
to
899b376
Compare
Zephyr toolchain abstraction provides a macro __aligned(x) to add specified alignment, in bytes, to a chosen symbol for C/C++ source files but there is no portable counterpart available for symbols defined in assembly source files. This change-set adds a new macro ALIGN(x) for this purpose. Signed-off-by: Irfan Ahmad <irfan.ahmad@siemens.com>
899b376
to
553927d
Compare
Created #86366 - will rebase and put in review, once this PR gets merged. |
@stephanosio, @nordicjm Can you please review/re-review and give your +1 or feedback? This PR is blocking other PRs. Already has +1 from @tejlmand - needs one more. |
Zephyr toolchain abstraction provides a macro __aligned(x) to add specified alignment, in bytes, to a chosen symbol for C/C++ source files but there is no portable counterpart available for symbols defined in assembly source files. This change-set adds a new macro ALIGN(x) for this purpose.