PDP Endian 和位移位
PDP Endian and bit shifts
当您在 PDP 端进行位移时,此操作是否比在小端或大端系统上花费的时间长一点?
我问这个问题的原因是,似乎比特在一个班次中向各个方向移动,这对计算机来说很难做到。
我无法以任何方式对此进行测试,因为我无权访问 PDP endian 机器。 =(
Middle-Endian or PDP-Endian systems save the most significant word
first, with each word having the least significant byte first. For
developers of new software, it is not only perfectly reasonable, but
strongly recommended, to ignore this possiblity. I don't think there
ever was a processor that stored 32-bit integer values to memory in a
middle-endian format, though middle-endianness has occasionally
appeared in things like packed-decimal formats, floating point
formats, and obscure communications protocols (it's used for the
length of TCP/IP packets in Visa's "Visa Base I" protocol).
我认为这不言而喻。
当你说移位时,你的意思是位移位?
这样想,如果一个处理器确实支持它,那么它可能有执行各种类似功能的指令。无论如何,一些处理器一次只移出一位到进位位或循环。因此,无论如何,它与那些无关紧要,速度相同。
与其他人一样。如果您正在查看它并以字节的形式对其进行操作,那么您只是为了让它变得缓慢而痛苦而变得缓慢而痛苦。但是字节是无序的,所以没关系。
您正在处理单词(希望如此),其中一种字节顺序消失了。但是,即使每个其他单词都采用不同的字节序,并且您有能力读取任何一种(可能在许多处理器上),您仍然不在乎您仍然在一个单词中移动位,字节顺序在那个时候也消失了.
神话下的同一网页。
PDP-11's were "middle-endian". Only sort of. The PDP-11 didn't have
instructions to store 32-bit values to memory, so the particular weird
"middle-endian" value couldn't possibly apply to the way it stored
values in memory. It stored 16-bit values to memory in the usual
little endian manner. It could do 32-bit arithmatic, storing the
values in pairs of 16-bit CPU registers (not memory). The most
signficant word went into the lower numbered register, but within each
register values were stored little-endian. So that could be viewed as
"middle-endian", but in a sense that could only matter to assembly
language programmers and compiler writers, whose code could never hope
to be portable anyway.
仅当您存储一个单词然后分别查看字节时才能观察到字节顺序。
在任何类型的机器上,寄存器中的数据始终表现为二进制,MSB 位于左侧(就像您将其写成 0b10110101
那样的位值表示形式)。左移总是乘以 2 的幂,右移总是除以 2 的幂,无论机器是大的、小的还是 pdp-endian。
当执行宽度大于一个字节的加载或存储时,将字节顺序视为应用于 CPU 的加载存储单元。内核的寄存器和执行单元部分只看到寄存器宽度的二进制整数。
可以编写 "endian agnostic" code 序列化整数 to/from 字节流,而不依赖于机器的本机字节顺序。例如将额外的 4 个字节放入 int
:
i = (data[0]<<0) | (data[1]<<8) | (data[2]<<16) | (data[3]<<24);
PDP11 的中间端格式是出于在 16 位机器上模拟 32 位操作的需要。这是通过首先存储高位字,然后是内存中的低位字来完成的,即使 PDP11 对其数据使用小端。这导致了奇怪的字节顺序。但是,实际上并没有真正的性能差异。将存储在内存中的整数左移一位仍然需要三个指令完成:
mov #var+2,r0 ; load the address of the low word
asl (r0) ; left shift low word
rol -(r0) ; left shift high word with carry
如果var
存储在little endian中,代码将类似:
move #var,r0 ; load address of the low word
asl (r0)+ ; left shift low word
rol (r0) ; left shift high word
当您在 PDP 端进行位移时,此操作是否比在小端或大端系统上花费的时间长一点?
我问这个问题的原因是,似乎比特在一个班次中向各个方向移动,这对计算机来说很难做到。
我无法以任何方式对此进行测试,因为我无权访问 PDP endian 机器。 =(
Middle-Endian or PDP-Endian systems save the most significant word first, with each word having the least significant byte first. For developers of new software, it is not only perfectly reasonable, but strongly recommended, to ignore this possiblity. I don't think there ever was a processor that stored 32-bit integer values to memory in a middle-endian format, though middle-endianness has occasionally appeared in things like packed-decimal formats, floating point formats, and obscure communications protocols (it's used for the length of TCP/IP packets in Visa's "Visa Base I" protocol).
我认为这不言而喻。
当你说移位时,你的意思是位移位?
这样想,如果一个处理器确实支持它,那么它可能有执行各种类似功能的指令。无论如何,一些处理器一次只移出一位到进位位或循环。因此,无论如何,它与那些无关紧要,速度相同。
与其他人一样。如果您正在查看它并以字节的形式对其进行操作,那么您只是为了让它变得缓慢而痛苦而变得缓慢而痛苦。但是字节是无序的,所以没关系。
您正在处理单词(希望如此),其中一种字节顺序消失了。但是,即使每个其他单词都采用不同的字节序,并且您有能力读取任何一种(可能在许多处理器上),您仍然不在乎您仍然在一个单词中移动位,字节顺序在那个时候也消失了.
神话下的同一网页。
PDP-11's were "middle-endian". Only sort of. The PDP-11 didn't have instructions to store 32-bit values to memory, so the particular weird "middle-endian" value couldn't possibly apply to the way it stored values in memory. It stored 16-bit values to memory in the usual little endian manner. It could do 32-bit arithmatic, storing the values in pairs of 16-bit CPU registers (not memory). The most signficant word went into the lower numbered register, but within each register values were stored little-endian. So that could be viewed as "middle-endian", but in a sense that could only matter to assembly language programmers and compiler writers, whose code could never hope to be portable anyway.
仅当您存储一个单词然后分别查看字节时才能观察到字节顺序。
在任何类型的机器上,寄存器中的数据始终表现为二进制,MSB 位于左侧(就像您将其写成 0b10110101
那样的位值表示形式)。左移总是乘以 2 的幂,右移总是除以 2 的幂,无论机器是大的、小的还是 pdp-endian。
当执行宽度大于一个字节的加载或存储时,将字节顺序视为应用于 CPU 的加载存储单元。内核的寄存器和执行单元部分只看到寄存器宽度的二进制整数。
可以编写 "endian agnostic" code 序列化整数 to/from 字节流,而不依赖于机器的本机字节顺序。例如将额外的 4 个字节放入 int
:
i = (data[0]<<0) | (data[1]<<8) | (data[2]<<16) | (data[3]<<24);
PDP11 的中间端格式是出于在 16 位机器上模拟 32 位操作的需要。这是通过首先存储高位字,然后是内存中的低位字来完成的,即使 PDP11 对其数据使用小端。这导致了奇怪的字节顺序。但是,实际上并没有真正的性能差异。将存储在内存中的整数左移一位仍然需要三个指令完成:
mov #var+2,r0 ; load the address of the low word
asl (r0) ; left shift low word
rol -(r0) ; left shift high word with carry
如果var
存储在little endian中,代码将类似:
move #var,r0 ; load address of the low word
asl (r0)+ ; left shift low word
rol (r0) ; left shift high word