-
Notifications
You must be signed in to change notification settings - Fork 13.5k
allocating 32 bit number as registers in AVR inline assembly fails #55159
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
Labels
Comments
Maybe @benshi001 could take a look? |
Current inline assembly only support the i16 and i8 types. I may need more time to fix that. |
Maybe we need to introduce 32-bit register classes. |
Would be great if this would also work for 64-bit types and aggregates like with avr-gcc. Here is a sample code that compiles with avr-gcc and executes fine with, say avrtest. typedef __UINT8_TYPE__ uint8_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __UINT64_TYPE__ uint64_t;
typedef struct { uint8_t r, g, b; } rgb_t;
uint32_t get_u32 (void)
{
uint32_t val;
__asm ("ldi %A0, lo8(%1)" "\n\t"
"ldi %B0, hi8(%1)" "\n\t"
"ldi %C0, hlo8(%1)" "\n\t"
"ldi %D0, hhi8(%1)"
: "=d" (val)
: "n" (0xddccbbaa));
return val;
}
uint64_t get_u64 (void)
{
uint64_t val;
__asm ("ldi %A0, 0x11" "\n\t"
"ldi %B0, 0x22" "\n\t"
"ldi %C0, 0x33" "\n\t"
"ldi %D0, 0x44" "\n\t"
// %r: Print operand without register prefix "r" which allows
// simple arithmetic on register numbers. You can find similar
// code for 64-bit types in AVR-LibC headers for example.
"ldi %r0+%1-1, 0x88" "\n\t"
"ldi %r0+%1-2, 0x77" "\n\t"
"ldi %r0+%1-3, 0x66" "\n\t"
"ldi %r0+%1-4, 0x55"
: "=d" (val)
: "n" (sizeof (val)));
return val;
}
rgb_t func_rgb (rgb_t rgb)
{
__asm ("dec %A0" "\n\t"
"inc %C0"
: "+r" (rgb));
return rgb;
}
int main (void)
{
rgb_t rgb = { 4, 5, 6 };
rgb = func_rgb (rgb);
if (rgb.r != 3 || rgb.b != 7)
__builtin_abort();
if (get_u32() != 0xddccbbaa)
__builtin_abort();
if (get_u64() != 0x8877665544332211)
__builtin_abort();
return 0;
} |
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following proof of concept shows the issue:
Compiling this with
avr-gcc -mmcu=atmega328p -Os -S poc.c
yields:However, compilation with clang fails:
The text was updated successfully, but these errors were encountered: