How unaligned loads / stores are handled.
Traditional RISC processors expect that variables are aligned to their natural boundaries. For example, a 32-bit int variable is expected to be aligned to 32-bits. The C and C++ compilers will always align variables appropriately. However, through the use of casts, parameters or pointers might point to unaligned data. The compiler will assume that all data is properly aligned unless it’s obvious to the compiler that it is not. For example, ((int *) 0x1), is obviously unaligned.
Cadence offers three configuration options to deal with circumstances where unaligned accesses occur. With Align address, the hardware will zero the bottom bits of the address before performing the memory access. This is rarely the desired behavior and is mainly provided for compatibility with earlier Cadence processors that only offered this option. This option is also unsupported on configurations with a data memory interface of greater than 128-bits. With Take exception, the hardware will throw an exception whenever an unaligned access is attempted. Typically, unaligned accesses should be treated as programming errors and the exception is an aid to debugging. However, for those running Linux on Xtensa processors, the exception handler in Linux will emulate an unaligned hardware access using multiple-aligned accesses. Using the exception handler is slow, but is useful when running open source drivers that are not performance critical and assume support for unaligned accesses. Note that writing handlers that emulate unaligned accesses is not easy or supported for configurations with FLIX. The third option, Handled by hardware, has the hardware automatically support unaligned accesses. Note that the hardware for handling these accesses takes several cycles so that performance-critical code should still only issue aligned accesses. The advantage of having the hardware handle the unaligned accesses is that it is faster than the emulation routine available in the exception handler and is also able to work together with FLIX. The advantage of the exception is that it makes it easier to identify and fix unaligned accesses, leading to more efficient and reliable code. Diamond processors provided by Cadence use the Take exception option.