2008-06-06

Big Endian & Little Endian

 

所謂的 big endian 與 little endian 是指 CPU 處理資訊時位元排列順序的不同, 若 big 是 10101010,則  little 會是 01010101。但,CPU 真正在處理時看到的又會是如何呢 ? 是把所有的位元都倒過來放?還是照 instruction size 來做顛倒的動作?是 32 bits processor 就每 32 bits 倒一次,64 bits processor 就每 64 bits 倒一次嗎?真正運作的方法究竟是哪一個?

答案是,都不是!!

真正運作的方式是要看 processor 處理 bits swap 的定義,以 Marvell 5182 (64-bits) 為例,在 user manual 中有說到 bits swap 的運作方式是 :

Swap Mode:

    The DMA supports swapping, for descriptors only, for both receive and

transmit ports, on every access to memory space.

0 : No swapping

1 : Byte swap : In every 64-bit word of the descriptor, the byte order is

    swapped such that byte 0 is placed in byte 7, byte 7 is placed in byte 0,

    byte 1 is placed in byte 6, byte 6 is placed in byte 1, byte 2 is placed

    in byte 5, etc.

    由此可見,它的交換機制是 byte swap,也就是以 byte 為單位做倒置。但 byte 與 byte 之間的順序性卻不會被改變。

沒有留言:

★★★★★★ 傑森系列 ★★★★★★