"each CPU instruction can manipulate 32 bits of data" 是什么意思?
What's the meaning of "each CPU instruction can manipulate 32 bits of data"?
发件人:https://www.webopedia.com/TERM/R/register.html
The number of registers that a CPU has and the size of each (number of bits) help determine the power and speed of a CPU. For example a 32-bit CPU is one in which each register is 32 bits wide. Therefore, each CPU instruction can manipulate 32 bits of data.
"each CPU instruction can manipulate 32 bits of data"w.r.t我们写的C/C++程序,我们用记事本写的文字是什么意思?
能够一次传输 32 位数据的计算机、操作系统或软件程序。对于计算机处理器(例如 80386、80486 和奔腾),它们是 32 位处理器,这意味着处理器能够处理 32 位二进制数(十进制数最大为 4,294,967,295)。任何更大的数字,计算机都需要将数字分解成更小的部分
一个"word"是大小变化的基本单位
这个 CPU 除了是 32 位 CPU 之外,还有一个 32 位大小的字。如果它正在更改一项,除非使用额外的 CPU 周期,否则它可以更改的最大 "single" 项是一个 32 位值。
这并不意味着可以用一条指令更改任何 32 位。但是如果32位都是同一个字的一部分,它们可能可以在一条指令中改变。
首先; "each CPU instruction can manipulate 32 bits of data" 是(技术上不正确的)概括。例如(32 位 80x86)有指令(例如 cmpxchg8b
、pushad
、shrd
)和整个扩展(MMX、SSE、AVX),其中一条指令可以操作超过 32 位数据。
为了表现;最好将其视为 "amount of work that can be done in a fixed amount of time" 或 "amount of time to do a fixed amount of work"。这可以分为 2 个值——完成一定量的工作需要多少条指令,以及在固定时间内可以执行多少条指令(每秒指令数)。
现在考虑添加一对 128 位整数。对于 32 位 CPU 这必须分解为四个 32 位加法,并且可能看起来像这样:
;Do a = a + b
mov eax,[b]
mov ebx,[b+4]
mov ecx,[b+8]
mov edx,[b+12]
add [a],eax
adc [a+4],ebx
adc [a+8],ecx
adc [a+12],edx
在这种情况下 "how many instructions you need to do an amount of work" 是 8 条指令。
对于 16 位 CPU,您需要更多指令。例如,它可能更像这样:
mov ax,[b]
mov bx,[b+2]
mov cx,[b+4]
mov dx,[b+6]
add [a],ax
mov ax,[b+8]
adc [a+2],bx
mov bx,[b+10]
adc [a+4],cx
mov cx,[b+12]
adc [a+6],dx
mov dx,[b+14]
add [a+8],ax
adc [a+10],bx
adc [a+12],cx
adc [a+14],dx
在这种情况下 "how many instructions you need to do an amount of work" 是 16 条指令。使用相同的 "instructions per second",对于这项工作,16 位 CPU 的速度将是 32 位 CPU 的一半。
使用 64 位CPU这项工作只需要 4 条指令,可能是这样的:
mov eax,[b]
mov ebx,[b+8]
add [a],eax
adc [a+8],ebx
在这种情况下,使用相同的 "instructions per second",64 位 CPU 将是 32 位 CPU 的两倍(并且是 4 倍16 位 CPU).
当然,高级源代码在所有情况下都是相同的 - 区别在于编译器生成的内容。
请注意,我在这里展示的(128 位整数加法)是一个 "happy case" - 我特地选择这个是因为它很容易显示更大的寄存器可以 reduce/improve "how many instructions you need to do an amount of work" 从而提高性能(同时 "instructions per second")。对于不同的工作,您可能不会获得相同的改进。例如,对于一个使用 8 位整数的函数(例如 char
),"larger than 8-bit registers" 可能根本没有帮助(在某些情况下可能会使事情变得更糟)。
发件人:https://www.webopedia.com/TERM/R/register.html
The number of registers that a CPU has and the size of each (number of bits) help determine the power and speed of a CPU. For example a 32-bit CPU is one in which each register is 32 bits wide. Therefore, each CPU instruction can manipulate 32 bits of data.
"each CPU instruction can manipulate 32 bits of data"w.r.t我们写的C/C++程序,我们用记事本写的文字是什么意思?
能够一次传输 32 位数据的计算机、操作系统或软件程序。对于计算机处理器(例如 80386、80486 和奔腾),它们是 32 位处理器,这意味着处理器能够处理 32 位二进制数(十进制数最大为 4,294,967,295)。任何更大的数字,计算机都需要将数字分解成更小的部分
一个"word"是大小变化的基本单位
这个 CPU 除了是 32 位 CPU 之外,还有一个 32 位大小的字。如果它正在更改一项,除非使用额外的 CPU 周期,否则它可以更改的最大 "single" 项是一个 32 位值。
这并不意味着可以用一条指令更改任何 32 位。但是如果32位都是同一个字的一部分,它们可能可以在一条指令中改变。
首先; "each CPU instruction can manipulate 32 bits of data" 是(技术上不正确的)概括。例如(32 位 80x86)有指令(例如 cmpxchg8b
、pushad
、shrd
)和整个扩展(MMX、SSE、AVX),其中一条指令可以操作超过 32 位数据。
为了表现;最好将其视为 "amount of work that can be done in a fixed amount of time" 或 "amount of time to do a fixed amount of work"。这可以分为 2 个值——完成一定量的工作需要多少条指令,以及在固定时间内可以执行多少条指令(每秒指令数)。
现在考虑添加一对 128 位整数。对于 32 位 CPU 这必须分解为四个 32 位加法,并且可能看起来像这样:
;Do a = a + b
mov eax,[b]
mov ebx,[b+4]
mov ecx,[b+8]
mov edx,[b+12]
add [a],eax
adc [a+4],ebx
adc [a+8],ecx
adc [a+12],edx
在这种情况下 "how many instructions you need to do an amount of work" 是 8 条指令。
对于 16 位 CPU,您需要更多指令。例如,它可能更像这样:
mov ax,[b]
mov bx,[b+2]
mov cx,[b+4]
mov dx,[b+6]
add [a],ax
mov ax,[b+8]
adc [a+2],bx
mov bx,[b+10]
adc [a+4],cx
mov cx,[b+12]
adc [a+6],dx
mov dx,[b+14]
add [a+8],ax
adc [a+10],bx
adc [a+12],cx
adc [a+14],dx
在这种情况下 "how many instructions you need to do an amount of work" 是 16 条指令。使用相同的 "instructions per second",对于这项工作,16 位 CPU 的速度将是 32 位 CPU 的一半。
使用 64 位CPU这项工作只需要 4 条指令,可能是这样的:
mov eax,[b]
mov ebx,[b+8]
add [a],eax
adc [a+8],ebx
在这种情况下,使用相同的 "instructions per second",64 位 CPU 将是 32 位 CPU 的两倍(并且是 4 倍16 位 CPU).
当然,高级源代码在所有情况下都是相同的 - 区别在于编译器生成的内容。
请注意,我在这里展示的(128 位整数加法)是一个 "happy case" - 我特地选择这个是因为它很容易显示更大的寄存器可以 reduce/improve "how many instructions you need to do an amount of work" 从而提高性能(同时 "instructions per second")。对于不同的工作,您可能不会获得相同的改进。例如,对于一个使用 8 位整数的函数(例如 char
),"larger than 8-bit registers" 可能根本没有帮助(在某些情况下可能会使事情变得更糟)。