CPU and Data alignment

后端 未结 7 1928
逝去的感伤
逝去的感伤 2020-11-29 06:22

Pardon me if you feel this has been answered numerous times, but I need answers to the following queries!

  1. Why data has to be aligned (on 2-byte / 4-byte / 8

7条回答
  •  广开言路
    2020-11-29 06:37

    Its completely depends on the CPU you are using!

    Some architectures deal only in 32 (or 36!) bit words and you need special instructions to load singel characters or haalf words.

    Some cpus (notably PowerPC and other IBM risc chips) dont care about alignments and will load integers from odd addresses.

    For most modern architectures you need to align integers to word boundies and long integers to double word boundries. This simplifies the circutry for loading registers and speeds things up ever so slighly.

提交回复
热议问题