This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unaligned accesses - CMSDK Example Cortex M0

The spec mentions that the M0 will generate a Hardfault when unaligned accesses are detected. I would like to find out where is this implemented in RTL and understand it a little better.

Does the GCC compiler detects unaligned code accesses during compilation as well?

Parents
  • Is the performance penalty here referring to the compiler splitting unaligned accesses into separate (more) instructions - say 1 unaligned word access into 2 aligned hword accesses?

    _Only_ if the compiler knows about the access.

    struct unaligned {
       char a;
       int b;
    } __attribute__((packed));

    Here, the compiler will likely split the access to "b" into multiple operations. But you should try. Maybe it "knows" that the Cortex-M can do unaligned accesses.

    Note: The struct must be packed, else the compiler will insert 3 dummy bytes _after_ "a".

Reply
  • Is the performance penalty here referring to the compiler splitting unaligned accesses into separate (more) instructions - say 1 unaligned word access into 2 aligned hword accesses?

    _Only_ if the compiler knows about the access.

    struct unaligned {
       char a;
       int b;
    } __attribute__((packed));

    Here, the compiler will likely split the access to "b" into multiple operations. But you should try. Maybe it "knows" that the Cortex-M can do unaligned accesses.

    Note: The struct must be packed, else the compiler will insert 3 dummy bytes _after_ "a".

Children