I have been debugging an issue where I keep getting unaligned memory access exceptions when attempting do do strcmp on a buffer and a constant. After checking the generated assembler I saw this:
This assumes that the variables are always word aligned. The Atmel assembler file seems to provide two different versions depending on if the target supports unaligned words or not. Which one it picks depends on what the __AVR32_HAS_UNALIGNED_WORD__ is set to, and it's only enabled on AP* MCUs.
This is how the strcmp version from Atmel Studio looks like:
This one correctly checks if the two variables are word aligned. If they are the fast comparison is made, otherwise it falls back to a byte-by-byte comparison.
For some reason __AVR32_HAS_UNALIGNED_WORD__ is enabled when strcmp.S is built using this toolchain. Explicitly compiling newlib using the -march=ucr3fp fixes the issue for me but I don't think that's how Atmel compiles their version.
Any ideas?
Edit: strcmp.S can be found in newlib-1.16.0/newlib/libc/machine/avr32/strcmp.S
I have been debugging an issue where I keep getting unaligned memory access exceptions when attempting do do strcmp on a buffer and a constant. After checking the generated assembler I saw this:
This assumes that the variables are always word aligned. The Atmel assembler file seems to provide two different versions depending on if the target supports unaligned words or not. Which one it picks depends on what the
__AVR32_HAS_UNALIGNED_WORD__
is set to, and it's only enabled on AP* MCUs.This is how the strcmp version from Atmel Studio looks like:
This one correctly checks if the two variables are word aligned. If they are the fast comparison is made, otherwise it falls back to a byte-by-byte comparison.
For some reason
__AVR32_HAS_UNALIGNED_WORD__
is enabled when strcmp.S is built using this toolchain. Explicitly compiling newlib using the-march=ucr3fp
fixes the issue for me but I don't think that's how Atmel compiles their version.Any ideas?
Edit: strcmp.S can be found in
newlib-1.16.0/newlib/libc/machine/avr32/strcmp.S