简体   繁体   English

什么将机器定义为32位

[英]What defines a machine to be 32-bit

I am just wondering that by saying 32-bit machine and 64-bit machine, what exactly is it that consists of 32(64) bits in the machine so that we define it as a 32(64)-bit machine. 我只是想知道,通过说32位机器和64位机器,它究竟是由机器中的32(64)位组成的,所以我们将其定义为32(64)位机器。 Since I'm currently learning C, I found the relationship between pointer and memory explains this quite much. 由于我目前正在学习C,因此我发现指针与内存之间的关系对此做了很多解释。 Since one memory address points to one byte, so if the memory address consists of 32 bits (ie a pointer is of 4 bytes), it can have at most 2^32 possibilities, which means it can represent at most 2^32 bytes which causes a 32-bit machine supports at most 4GB RAM. 由于一个内存地址指向一个字节,因此如果该内存地址由32位组成(即指针为4字节),则它最多可以具有2 ^ 32个可能性,这意味着它最多可以表示2 ^ 32个字节,导致32位计算机最多支持4GB RAM。 Is that fair assumption? 那是公平的假设吗? So is 32-bit or 64-bit machine defined by its memory address size? 那么32位或64位计算机是由其内存地址大小定义的吗?

Furthermore, if a machine is 32-bit, is a pointer in C on that machine always 4 bytes (32 bits)? 此外,如果机器是32位的,那么该机器上C中的指针是否总是4个字节(32位)?

There is nothing that says that the width of the ALU, address bus and data bus all have to be the same. 没有什么可以说ALU,地址总线和数据总线的宽度必须相同。 Thus there is no formal definition of what it means to be eg 32-bit. 因此,没有关于32位的含义的正式定义。

In modern, high-performance, generally available CPUs (read, x86), the N-bit architectural distinction refers to width of the data operated upon by the architecturally preferred integer operations. 在现代的高性能,普遍可用的CPU(读取,x86)中,N位体系结构区别是指由体系结构上首选的整数运算所操作的数据的宽度。 These CPUs contain registers of many different sizes, however, some which can pack multiple data values into one register as one would use with SIMD instructions. 这些CPU包含许多不同大小的寄存器,但是有些可以将多个数据值打包到一个寄存器中,就像使用SIMD指令时一样。

The relationship between memory address space and this N-bit architectural distinction simply comes from the fact that once 32bits could fit in a single register, memory offset calculations could be performed in a single cycle, and 32bits seemed like enough address space for the foreseeable future. 内存地址空间与这种N位体系结构区别之间的关系仅来自以下事实:一旦32位可以容纳在单个寄存器中,就可以在单个周期内执行内存偏移量计算,并且在可预见的将来32位似乎足够的地址空间。 Eventually, that foreseeable future expired, and now we perform memory offset calculations with 64bit values in a 64bit address space. 最终,那个可预见的未来到期了,现在我们使用64位地址空间中的64位值执行内存偏移量计算。

This relationship with address space is somewhat arbitrary and was based upon that fact that these values became large enough to provide a reasonable amount of memory. 与地址空间的这种关系在某种程度上是任意的,并且基于以下事实:这些值变得足够大,可以提供合理的内存量。 In 12-bit minicomputers for example, memory was not limited to (2^12) 4096 bytes, memory address simply spanned multiple registers and offset calculations took more than once cycle. 例如,在12位微型计算机中,内存不限于(2 ^ 12)4096字节,内存地址只是跨越多个寄存器,偏移量计算需要一个以上的周期。 The same approach is used today with some 8-bit microcontrollers, the type you would find in a microwave oven. 今天,某些微波炉使用的8位微控制器也采用了相同的方法。 They may provide a 16-bit address space, 64kB of memory, by storing addresses in two registers rather than one. 通过将地址存储在两个而不是一个寄存器中,它们可以提供16位地址空间(64kB内存)。

So, unless you're dealing with non-mainstream CPUs, you can consider the N-bit distinction the address space. 因此,除非您要处理非主流CPU,否则可以考虑N位区分地址空间。 However, there are cases even today, where this doesn't map. 但是,即使在今天,也有一些情况无法解决。 For example microcontrollers, as mentioned, and domain specific or supercomputing architectures which may use "Very Large Instruction Words", that could be considered "2048-bit CPUs" but most likely operate in a 64-bit address space. 例如,如上所述的微控制器以及可以使用“超大型指令字”的领域特定或超级计算体系结构,可以将其视为“ 2048位CPU”,但很可能在64位地址空间中运行。

Furthermore, if a machine is 32-bit, is a pointer in C on that machine always 4 bytes (32 bits)? 此外,如果机器是32位的,那么该机器上C中的指针是否总是4个字节(32位)?

You can use auto-multiplexer to address 12GB using only 32bits.(very inefficient because only 1/3 of the cycles are accessing a 4GB region) 您可以使用自动多路复用器仅使用32位来寻址12GB。(效率非常低,因为只有1/3的周期正在访问4GB区域)

  *****************************************************************
  Multiplexer clock cycle1



                            first 4GB
  32-bit wide addressing     /
 ---------------------------M----
                             \

  *************************************************************
  Multiplexer clock cycle2




  32-bit wide addressing     /
 ---------------------------M----- second 4GB
                             \


  **************************************************************
  Multiplexer clock cycle3




  32-bit wide addressing     /
 ---------------------------M-----
                             \
                           third 4GB

In the instructions design, you do: 在指令设计中,您可以执行以下操作:

 waitFor(multiplexer%3==0)write value to address;// you know this writes to first 4GB region
                                            //blocks until multiplexer is ready
  waitFor(multiplexer%3==1)write value2 to address;// you know this writes to second 4GB region
                                             //blocks until multiplexer is ready
  waitFor(multiplexer%3==2)write value3 to address;// you know this writes to last 4GB region
                                            //blocks until multiplexer is ready

 Multiplexer value can be accessed by a cpu register easily.

So, the answer is no. 因此,答案是否定的。 It can be lesser than 32 bits. 可以小于32位。

Modern Operating Systems and computers use a construct called Virtual Memory. 现代操作系统和计算机使用一种称为虚拟内存的结构。 Each program (process) thinks it has the entirety of your RAM at its disposal. 每个程序(进程)都认为它具有整个RAM可供使用。 In reality, RAM is shared among many concurrent processes. 实际上,RAM在许多并发进程之间共享。

Typically, the "address" you see in your compiler is not equivalent to the address within RAM or a physical address (PA). 通常,您在编译器中看到的“地址”不等于RAM中的地址或物理地址(PA)。 It is instead a "virtual address" (VA). 而是一个“虚拟地址”(VA)。 The OS together with your processor will translate VAs into PAs. 操作系统与处理器一起会将VA转换为PA。

Why do this? 为什么这样 Because your RAM often is too small to be addressed by 64-bits or 32-bits. 因为您的RAM通常太小,无法用64位或32位寻址。 2^64 is in Zetabytes! 2 ^ 64是Zetabytes! No RAM is that large! 没有RAM那么大! Think of RAM as a high level cache to your hard-disk: we only take the small parts of the currently running programs from disk into RAM when we need to use them. 将RAM视为硬盘的高级高速缓存:我们仅在需要使用它们时才将当前正在运行的程序的一小部分从磁盘中带入RAM。

If the piece of your program needed is not in RAM, then a "page fault" will trigger, bringing the needed data into RAM from disk, and kicking out some old, unused data from RAM in doing so. 如果所需的程序片段不在RAM中,则会触发“页面错误”,将所需的数据从磁盘带入RAM,并从内存中踢出一些未使用的旧数据。

To answer your question: The amount of RAM your computer can handle then, is (almost) entirely independent of the length of your virtual addresses in bits. 回答您的问题:您的计算机可以处理的RAM量(几乎)完全独立于虚拟地址的长度(以位为单位)。 Take a server rack with 128 GB of RAM for example. 以具有128 GB RAM的服务器机架为例。 What is the benefit of all that RAM?! 所有这些RAM有什么好处? The benefit is that you will be able to run multiple processes in parallel and still have everything running very fast. 这样做的好处是您将能够并行运行多个进程,并且仍然可以使所有进程运行得非常快。

This is a big topic in Computer Architecture. 这是计算机体系结构中的一个重要主题。 Read what you can about Virtual Memory, Paging and Page Tables, and Memory Organization to get a better understanding. 阅读有关虚拟内存,分页和页表以及内存组织的知识,以加深了解。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM