处理器、操作系统:32位、64位

发布于 2024-07-30 20:44:09 字数 514 浏览 3 评论 0原文

我是编程新手,没有计算机科学背景(没有正式学位)。 我主要使用 C# 编写 winform 程序。

我对 32 位和 64 位感到困惑......我的意思是,听说过 32 位操作系统、32 位处理器以及基于这些的程序可以拥有最大内存。 它如何影响程序的速度。 还有很多问题不断浮现在我的脑海中。

我尝试阅读一些计算机组织和体系结构书籍。 但是,要么是我太笨,无法理解其中写的内容,要么是作者假设读者有一定的计算机科学背景。

有人可以用简单的英语向我解释这些事情,或者给我指出一些可以做到这一点的东西。

编辑:我读过类似的内容在 32 位模式下,他们可以访问高达 4GB 内存; 在 64 位模式下,他们可以访问更多...我想知道为什么要进行所有这些操作。

赏金:下面的答案非常好......尤其是马丁的一个。 但是,我正在看一个彻底的解释,但用的是简单的英语。

I am new to programming and come from a non-CS background (no formal degree). I mostly program winforms using C#.

I am confused about 32 bit and 64 bit.... I mean, have heard about 32 bit OS, 32 bit processor and based on which a program can have maximum memory. How it affects the speed of a program. There are lot more questions which keep coming to mind.

I tried to go through some Computer Organization and Architecture books. But, either I am too dumb to understand what is written in there or the writers assume that the reader has some CS background.

Can someone explain me these things in a plain simple English or point me to something which does that.

EDIT: I have read things like In 32-bit mode, they can access up to 4GB memory; in 64-bit mode, they can access much much more....I want to know WHY to all such things.

BOUNTY: Answers below are really good....esp one by Martin. But, I am looking at a thorough explanation, but in plain simple English.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

走走停停 2024-08-06 20:44:09

让我们尝试通过比较计算机来回答这个问题; 希望这能为您带来一些启示:

要记住的事情

  • 尽管计算机很神奇,但它却非常非常愚蠢。

记忆

  • 人们有记忆(可以说,丈夫和政客除外)。人们将信息存储在记忆中以供以后使用。
    • 提出问题(例如“您的电话号码是什么?”)时,人们可以检索信息来给出答案(例如“867-5309”)
  • 所有现代计算机都有内存,并将信息存储在它们的计算机中。内存以供以后使用。
    • 因为计算机很笨,所以只能通过询问一个非常具体的问题来检索信息:“您记忆中 X 的值是多少?”
      • 在上面的问题中,X被称为地址,也可以称为指针

因此,人与计算机之间有一个根本区别:要从内存中调用信息,计算机需要指定一个地址,而人则不需要。 (从某种意义上说,人们可以说“您的电话号码”是一个地址,因为它提供的信息与“您的生日”不同,但这是另一回事了。)

数字

  • 人们使用十进制数字系统。 这意味着对于十进制数中的每个数字,该数字可以是 0、1、2、3、4、5、6、7、8 或 9 之一。人们对每个数字有种选择。
  • 所有现代计算机都使用二进制数字系统。 这意味着对于二进制数中的每个数字,该数字只能是 1 或 0。计算机每个数字有两个选项。
    • 在计算机术语中,单个二进制数字称为,是binary digit<的缩写/b>

地址

  • 计算机中的每个地址都是一个二进制数。
  • 计算机中的每个地址都有其可以拥有的最大位数(或位)。 这主要是因为计算机的硬件不灵活(也称为固定)并且需要提前知道地址的长度。
  • “32 位”和“64 位”等术语指的是计算机可以存储和检索信息的最长地址。 在英语中,“32 位”在这个意义上的意思是“这台计算机期望有关其内存的指令的地址长度不超过 32 个二进制数字”。
    • 正如您可以想象的那样,计算机可以处理的位数越多,它可以查找的地址就越长,因此一次可以管理的内存就越多。

32 位与 64 位寻址

  • 对于不灵活(固定)的位数(例如 2 位十进制数字),您可以表示的可能数字称为范围(例如 00 到 99,或 100 个唯一的数字)。 添加额外的十进制数字会将范围乘以 10(例如,3 个十进制数字 -> 000 到 999,或 1000 个唯一数字)。
  • 这也适用于计算机,但因为它们是二进制机器而不是十进制机器,所以添加一个额外的二进制数字()仅将范围增加 2 倍。

    寻址范围:

    • 1 位寻址让您可以谈论 2 个唯一地址(0 和 1)。
    • 2 位寻址可让您讨论 4 个唯一地址(00、01、10 和 11)。
    • 3 位寻址可让您谈论 8 个唯一地址(000、001、010、011、100、101、110 和 111)。
    • 过了很长一段时间...32 位寻址可以让您谈论 4,294,967,296 个唯一地址。
    • 甚至更长之后...64位寻址可以让您谈论18,446,744,073,709,551,616个唯一地址。 这是很多的内存!

含义

所有这一切意味着 64 位计算机可以比 32 位计算机存储和检索多得多的信息。 对于大多数用户来说,这实际上并没有多大意义,因为浏览网页、检查电子邮件和玩纸牌等操作都可以在 32 位寻址的范围内轻松完成。 64 位的优势真正体现在计算机必须处理大量数据的领域。 数字信号处理、十亿像素摄影和高级 3D 游戏等领域的海量数据处理在 64 位环境中都将得到大幅提升。

Let's try to answer this question by looking at people versus computers; hopefully this will shed some light on things for you:

Things to Keep In Mind

  • As amazing as they are, computers are very, very dumb.

Memory

  • People have memory (with the exception, arguably, of husbands and politicians.) People store information in their memory for later use.
    • With a question (e.g, "What is your phone number?") a person is able to retrieve information to give an answer (e.g., "867-5309")
  • All modern computers have memory, and store information in their memory for later use.
    • Because computers are dumb, they can only be asked a very specific question to retrieve information: "What is the value at X in your memory?"
      • In the question above, X is known as an address, which can also be called a pointer.

So here we have a fundamental difference between people and computers: To recall information from memory, computers need to be given an address, whereas people do not. (Well in a sense one could say "your phone number" is an address because it gives different information than "your birthday", but that's another conversation.)

Numbers

  • People use the decimal number system. That means for every digit in a decimal number, the digit can be one of 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. People have ten options per digit.
  • All modern computers use the binary number system. That means for every digit in a binary number, the digit can only be either 1 or 0. Computers have two options per digit.
    • In computer jargon, a single binary digit is called a bit, short for binary digit.

Addresses

  • Every address in a computer is a binary number.
  • Every address in a computer has a maximum number of digits (or bits) that it can have. This is mostly because the computer's hardware is inflexible (also known as fixed) and needs to know ahead of time that an address will only be so long.
  • Terms like "32-bit" and "64-bit" are talking about the longest address for which a computer can store and retrieve information. In English "32-bit" in this sense means "This computer expects instructions about its memory to have addresses no more than 32 binary digits long."
    • As you can imagine, the more bits a computer can handle the longer the address it can look up and therefore the more memory it can manage at one time.

32-bit v. 64-bit Addressing

  • For an inflexible (fixed) number of digits (e.g. 2 decimal digits) the possible numbers you can represent is called the range (e.g. 00 to 99, or 100 unique numbers). Adding an additional decimal digit multiplies the range by 10 (e.g. 3 decimal digits -> 000 to 999, or 1000 unique numbers).
  • This applies to computers, too, but because they are binary machines instead of decimal machines, adding an additional binary digit (bit) only increases the range by a factor of 2.

    Addressing Ranges:

    • 1-bit addressing lets you talk about 2 unique addresses (0 and 1).
    • 2-bit addressing lets you talk about 4 unique addresses (00, 01, 10, and 11).
    • 3-bit addressing lets you talk about 8 unique addresses (000, 001, 010, 011, 100, 101, 110, and 111).
    • and after a long while... 32-bit addressing lets you talk about 4,294,967,296 unique addresses.
    • and after an even longer while... 64-bit addressing lets you talk about 18,446,744,073,709,551,616 unique addresses. That's a LOT of memory!

Implications

What all this means is that a 64-bit computer can store and retrieve much more information than a 32-bit computer. For most users this really doesn't mean a whole lot because things like browsing the web, checking email and playing Solitaire all work comfortably within the confines of 32-bit addressing. Where the 64-bit benefit will really shine is in areas where you have a lot of data the computer will have to churn through. Digital signal processing, gigapixel photography and advanced 3D gaming are all areas where their massive amounts of data processing would see a big boost in a 64-bit environment.

森林散布 2024-08-06 20:44:09

这实际上一切都归结于电线。

在数字电路中,只有0和1(通常是低电压和高电压)可以从一个元件(CPU)传输到另一元件(存储芯片)。 如果我只有 1 根线,则每个时钟周期只能通过该线发送 1 或 0。 这意味着我只能寻址 2 个字节(假设字节寻址,并且为了速度,整个地址仅在 1 个周期内传输!)。

如果我有 2 根线,我可以寻址 4 个字节。 因为我可以通过两条电线发送: (0, 0)、(0, 1)、(1, 0) 或 (1, 1)。 所以基本上是 2 的线数次方。

因此,如果我有 32 条线,我可以寻址 4 GB,如果我有 64 条线,我可以寻址更多。

工程师还可以使用其他技巧来寻址比线路允许的更大的地址空间。 例如,将地址分成两部分,并在第一个周期发送一半,在下一个周期发送另一半。 但这意味着您的内存接口速度将减半。

将我的评论编辑到此处(未编辑);)如果有人有任何有趣的内容可以添加,则将其设为维基。

就像其他评论提到的那样,2^32(2 的 32 次方)= 4294967296,即 4 GB。 2^64 是 18,446,744,073,709,551,616。 为了进一步挖掘(您可能在 Hennesey & Patterson 中读过这篇文章),处理器包含用作“临时空间”来存储其计算结果的寄存器。 CPU 只知道如何进行简单的算术并知道如何移动数据。 当然,这些寄存器的大小与架构的“#位”宽度相同,因此 32 位 CPU 的寄存器将是 32 位宽,64 位 CPU 的寄存器将是 64 位宽宽的。

当涉及浮点(处理双精度)或其他 SIMD 指令(单指令、多数据命令)时,会有例外。 CPU 将数据加载到主存储器(RAM)或从主存储器(RAM)保存数据。 由于 CPU 还使用这些寄存器来计算内存地址(物理和虚拟),因此它可以寻址的内存量也与其寄存器的宽度相同。 有一些 CPU 使用特殊的扩展寄存器来处理地址计算,但那些我称之为“事后思考”的 CPU 是在工程师意识到他们需要它之后添加的。

目前 64 位对于寻址真实物理内存来说已经足够了。 由于实用性,大多数 64 位 CPU 在将 CPU 连接到内存时会省略相当多的电线。 占用宝贵的主板空间来运行总是有 0 的电线是没有意义的。 更不用说,为了拥有当今 DIMM 密度的最大 RAM 量,需要 40 亿个 dimm 插槽:)

除了增加内存量之外,64 位处理器还可以为大于 2^32 的整数提供更快的计算速度。 以前,程序员(或编译器,也是由程序员编程的;)必须通过占用两个 32 位寄存器并处理任何溢出情况来模拟拥有 64 位寄存器。 但在 64 位 CPU 上,它将由 CPU 本身处理。

缺点是 64 位 CPU(在所有条件相同的情况下)会比 32 位 CPU 消耗更多的电量,因为所需的电路数量(大约)是 32 位 CPU 的两倍。 然而,实际上,您永远不会得到平等的比较,因为较新的 CPU 将采用较新的硅工艺制造,这些工艺具有更少的功耗,允许您在相同的芯片尺寸中塞入更多电路等。但 64 位架构的功耗会是其两倍记忆。 与使用固定指令长度的架构相比,曾经被认为“丑陋”的 x86 可变指令长度现在实际上是一个优势。

It really all comes down to wires.

In digital circuits, only 0's and 1's (usually low voltage and high voltage) can be transmitted from one element (CPU) to another element (memory chip). If I have only 1 wire, I can only send either a 1 or a 0 over the wire per clock cycle. This means I can only address 2 bytes (assuming byte addressing, and that entire addresses are transmitted in just 1 cycle for speed!).

If I have 2 wires, I can address 4 bytes. Because I can send: (0, 0), (0, 1), (1, 0), or (1, 1) over the two wires. So basically it's 2 to the power of # of wires.

So if I have 32 wires, I can address 4 GB, and if I have 64 wires, I can address a lot more.

There are other tricks that engineers can do to address a larger address space than the wires allow for. E.g. splitting up the address into two parts and sending one half in the first cycle and the second half on the next cycle. But that means that your memory interface will be half as fast.

Edited my comments into here (unedited) ;) And making it a wiki if anyone has anything interesting to add as well.

Like other comments have mentioned, 2^32 (2 to the power of 32) = 4294967296, which is 4 GB. And 2^64 is 18,446,744,073,709,551,616. To dig in further (and you probably read this in Hennesey & Patterson) processors contains registers that it uses as "scratch space" for storing the results of its computations. A CPU only knows how to do simple arithmetic and knows how to move data around. Naturally, the size of these registers are the same width in bits as the "#-bits" of architecture it is, so a 32-bit CPU's registers will be 32-bits wide, and 64-bit CPU's registers will be 64-bits wide.

There will be exceptions to this when it comes to floating point (to handle double precision) or other SIMD instructions (single-instruction, multiple data commands). The CPU loads and saves the data to and from the main memory (the RAM). Since the CPU also uses these registers to compute memory addresses (physical and virtual), the amount of memory that it can address is also the same as the width of its registers. There are some CPUs that handles address computation with special extended registers, but those I would call "after thoughts" added after engineers realize they needed it.

At the moment 64-bits is quite a lot for addressing real physical memory. Most 64-bit CPUs will omit quite a few wires when it comes to wiring up the CPU to the memory due to practicality. It won't make sense to use up precious motherboard real estate to run wires that will always have 0's. Not to mention in order to have the max amount of RAM with today's DIMM density would require 4 billion dimm slots :)

Other than the increased amount of memory, 64-bit processors offer faster computation for integer numbers larger than 2^32. Previously programmers (or compilers, which is also programmed by programmers ;) would have to simulate having a 64-bit register by taking up two 32-bit registers and handling any overflow situations. But on 64-bit CPUs it would be handled by the CPU itself.

The drawback is that a 64-bit CPU (with everything equal) would consume more power than a 32-bit CPU just due to (roughly) twice the amount of circuitry needed. However, in reality you will never get equal comparison because newer CPUs will be manufactured in newer silicon processes that have less power leakage, allow you to cram more circuit in the same die size, etc. But 64-bit architectures would consume twice as much memory. What was once considered "ugly" of x86's variable instruction length is actually an advantage now compared to architectures that uses a fixed instruction size.

蓝眸 2024-08-06 20:44:09

马丁的回答非常好。 只是添加一些额外的点...既然您提到了 .NET,您应该注意到 CLI/JIT 在 x86 和 x64 之间有一些差异,具有不同的优化(例如尾部调用),以及高级的一些微妙的不同行为诸如易失性之类的东西。 这都会对您的代码产生影响。

此外,并非所有代码都适用于 x64。 任何使用 DirectX 或某些 COM 功能的东西都可能会遇到困难。 并不是真正的性能功能,但了解这一点很重要。

(我删除了“DirectX” - 我可能在那里说垃圾......但简单地说:您需要检查您所依赖的任何内容在您的目标平台上是否稳定)

Martin's answer is excellent. Just to add some additional points... since you mention .NET, you should note that the CLI/JIT has some differences between x86 and x64, with different optimisations (tail-call, for example), and some subtle different behaviour of advanced things like volatile. This can all have an impact on your code.

Additionally, not all code works on x64. Anything that uses DirectX or certain COM features may struggle. Not really a performance feature, but important to know.

(I removed "DirectX" - I might be talking rubbish there... but simply: you need to check that anything you depend upon is stable on your target platform)

用心笑 2024-08-06 20:44:09

将通用计算机内存视为一张具有数十亿方格的大型宾果卡。 为了寻址板上的任何单个方块,有一个方案来标记每行和每列 B-5、I-12、O-52 等。

如果卡片上有足够的方块,最终您将用完字母,因此您将需要开始重复使用更多字母并写入更大的数字,以继续能够唯一地寻址每个方块。

在您意识到之前,播音员会滔滔不绝地吐出令人恼火的巨大数字和字母组合,让您知道在 100 亿方卡上标记哪个方格。
BAZC500000、IAAA12000000、OAAAAAA523111221

计算机的位数指定了对任何特定方格进行寻址的字母和数字的复杂性限制。

32 位意味着如果卡大于 2^32 方格,则计算机没有足够的电线和晶体管来允许其唯一地物理寻址读取值或将新值写入指定内存位置所需的任何特定方格。

64 位计算机可以单独寻址大量 2^64 个方格。但要做到这一点,每个方格需要更多的字母和数字,以确保每个方格都有自己唯一的地址。 这就是 64 位计算机需要更多内存的原因。

寻址限制的其他常见示例是本地电话号码。 它们通常是 7 位数字 111-2222 或重新格式化为数字 1,112,222 .. 如果有超过 9,999,999 人想要拥有自己的电话号码,会发生什么情况? 添加区号和国家/地区代码后,您的电话号码就会从 7 位数字变为 10 到 11 位,从而占用更多空间。

如果您熟悉即将到来的 IPv4 短缺问题,那么这也是同样的问题。IPv4 地址是 32 位,这意味着可能只有 2^32(约 40 亿)个唯一的 IP 地址,而且当今活着的人口数量要多得多。

我提到的所有方案(计算机、电话号码、IPv4 地址)都有开销,其中某些部分被保留用于组织目的,因此可用空间要少得多。

64 位世界的性能承诺是,64 位计算机可以一次发送 8 个字节 (ABCDEFGH),而不是一次发送 4 个字节 (ABCD),因此字母表在不同的内存区域之间传输最多两次与 32 位计算机一样快。 对于某些应用程序来说,当它们拥有更多可用内存时,运行速度会更快,这也是有好处的。

在现实世界中,英特尔等公司的 64 位桌面处理器并不是真正的 64 位处理器,并且对于多种类型的操作仍然仅限于 32 位,因此在现实世界中,32 位和 64 位应用程序之间的性能是边缘的。 64 位模式为您提供了更多的硬件寄存器,这确实可以提高性能,但在“假”64 位处理器上寻址更多内存也会损害某些区域的性能,因此通常是一种浪费。 将来,当桌面处理器完全变为 64 位时,我们将看到更多性能改进。

Think of a generic computers memory as a massive bingo card with billions of squares. To address any individual square on the board there is a scheme to label each row and column B-5, I-12, O-52..etc.

If there are enough squares on the card eventually you will run out of letters so you will need to start reusing more letters and writing larger numbers to continue to be able to uniquely address each square.

Before you know it the announcer is spouting annoyingly huge numbers and letter combinations to let you know which square to mark on your 10 billion square card.
BAZC500000, IAAA12000000, OAAAAAA523111221

The bit count of the computer specifies its limit of the complexity of the letters and numbers to address any specific square.

32-bits means if the card is any bigger than 2^32 squares the computer does not have enough wires and transisters to allow it to uniquely physically address any specific square required to read a value or write a new value to the specified memory location.

64-bit computers can individually address a massive 2^64 squares.. but to do so each square needs a lot more letters and numbers to make sure each square has its own unique address. This is why 64-bit computers need more memory.

Other common examples of addressing limits are local telephone numbers. They are ususally 7-digits 111-2222 or reformatted as a number 1,112,222 .. what happens when there are more than 9,999,999 people who want their own telelphone numbers? You add area codes and country codes and your phone number goes from 7 digits to 10 to 11 taking up more space.

If you are familiar with the impending IPv4 shortage its the same problem.. IPv4 addresses are 32-bits meaning there are only 2^32 (~4 billion) unique IP addresses possible and there are many more people than that alive today.

There is overhead in all schemes I mentioned (computers, phone numbers, IPv4 addresses) where certain portions are reserved for organizational purposes so the usable space is much less.

The performance promise for the 64-bit world is that instead of sending 4 bytes at a time (ABCD) a 64-bit computer can send 8 bytes at a time (ABCDEFGH) so the alphabet is transfered between different areas of memory up to twice as fast as a 32-bit computer. There is also benefit for some applications that just run faster when they have more memory they can use.

In the real world 64-bit desktop processors by intel et al are not really true 64-bit processors and still are limited to 32-bits for several types of operations so in the real world the performance between 32-bit and 64-bit applications is marginal. 64-bit mode gives you more hardware registers to work with which does improve performance but adressing more memory on a "fake" 64-bit processor can also hurt performance in some areas so its ususally a wash. In the future we will be seeing more performance improvements when desktop processors become fully 64-bit.

我还不会笑 2024-08-06 20:44:09

许多现代处理器可以在两种模式下运行:32 位模式和 64 位模式。 在32位模式下,它们可以访问高达4GB的内存; 在 64 位模式下,他们可以访问更多内容。 较旧的处理器仅支持 32 位模式。

操作系统选择以以下模式之一使用处理器:在安装时,选择是以 32 位模式还是以 64 位模式运行处理器。 尽管处理器可以继续在 64 位模式下运行,但从 32 位切换到 64 位需要重新安装系统。 较旧的系统仅支持 32 位模式。

应用程序还可以以 32 位或 64 位模式编写(或编译)。 这里的兼容性更加棘手,因为处理器在 64 位模式下运行时仍然可以支持 32 位应用程序作为模拟功能。 因此,在 64 位操作系统上,您可以运行 32 位应用程序或 64 位应用程序。 在 32 位操作系统上,您只能运行 32 位应用程序。

同样,选择大小主要取决于您要访问的主内存量。 在许多系统上,32 位应用程序通常限制为 2GB,因为系统本身需要一些地址空间。

从性能(速度)的角度来看,没有显着差异。 64 位应用程序可能会慢一些,因为它们使用 64 位指针,因此对于给定操作它们需要更多内存访问。 同时,它们也可能更快一点,因为它们可以将 64 位整数运算作为一条指令执行,而 32 位处理器需要使用多条指令来模拟它们。 然而,那些 64 位整数运算相当不常见。

人们可能还想知道在 64 位处理器上运行 32 位应用程序的成本是多少:在 AMD64 和 Intel64 处理器上,这种模拟模式主要是在硬件中,因此与运行 32 位应用程序相比,没有真正的性能损失原生地。 这在 Itanium 上有显着不同,其中 32 位 (x86) 应用程序的模拟效果非常差。

Many modern processors can run in two modes: 32-bit mode, and 64-bit mode. In 32-bit mode, they can access up to 4GB memory; in 64-bit mode, they can access much much more. Older processors only support 32-bit mode.

Operating systems chose to use the processors in one of these modes: at installation time, a choice is made whether to operate the processor in 32-bit mode or in 64-bit mode. Even though the processor can continue to operate in 64-bit mode, switching from 32-bit to 64-bit would require a reinstallation of the system. Older systems only support 32-bit mode.

Applications can also be written in (or compiled for) 32-bit or 64-bit mode. Compatibility here is more tricky, as the processor, when run in 64-bit mode, can still support 32-bit applications as an emulation feature. So on a 64-bit operating system, you can run either 32-bit applications or 64-bit applications. On a 32-bit operating system, you can run only 32-bit applications.

Again, chosing the size is primarily a matter of amount of main memory you want to access. 32-bit applications are often restricted to 2GB on many systems, since the system needs some address space for itself.

From a performance (speed) point of view, there is no significant difference. 64-bit applications may be bit slower because they use 64-bit pointers, so they need more memory accesses for a given operation. At the same time, they may also be a bit faster, since they can perform 64-bit integer operations as one instruction, whereas 32-bit processors need to emulate them with multiple instructions. However, those 64-bit integer operations are fairly uncommon.

One also may wonder what the cost is of running a 32-bit application on a 64-bit processor: on AMD64 and Intel64 processors, this emulation mode is mostly in hardware, so there is no real performance loss over running the 32-bit application natively. This is significantly different on Itanium, where 32-bit (x86) applications are emulated very poorly.

不气馁 2024-08-06 20:44:09

让我告诉你宾维尔的故事,这是一个偏僻的小镇。 宾维尔只有一条路通向那里。 每个来到或离开宾维尔的人都必须开车走这条路。 但当你接近城镇时,出现了一个岔路口。 你可以向左走,也可以向右走。

事实上,除了通向房屋的道路外,每条路都有岔路口。 那些路就到了那所房子为止。 没有一条路有名字; 由于宾维尔规划委员会制定了巧妙的寻址方案,他们不需要名字。 这是宾维尔的地图,显示了道路和房屋:

              ------- []  00
             /
       ------
      /      \
     /        ------- []  01
-----
     \        ------- []  10
      \      /
       ------
             \
              ------- []  11

如您所见,每栋房屋都有一个两位数的地址。 仅该地址就足以 a) 唯一地标识每栋房屋(没有重复)和 b) 告诉您如何到达那里。 你瞧,去城里转转很方便。 每个岔路口都标有零或一,规划委员会将其称为宾维尔交叉口追踪器,简称为。 当您接近第一个岔路口时,请查看地址的第一位。 如果是零,则向左走; 如果是一个,则向右走。 然后,当您到达第二个岔路口时,查看第二个数字,根据情况向左或向右移动。

假设您想拜访住在宾维尔的朋友。 她说她住在 10 号房子。当您到达 Binville 的第一个岔路口时,向右走 (1)。 然后在第二个岔路口向左走 (0)。 你在那儿!

宾维尔这样存在了好几年,但有关其田园诗般的环境、出色的公园系统和慷慨的医疗保健的消息开始传开。 (毕竟,如果你不必花钱买路牌,你可以把钱用在更好的东西上。)但是有一个问题。 由于只有两位,寻址方案仅限于四个房屋!

于是,规划委员会集思广益,想出了一个计划:他们将在每个地址上加一点,从而使房屋数量增加一倍。 为了实施该计划,他们将在城镇边缘建造一个新的岔路口,每个人都会获得新的地址。 这是新地图,显示了通往城镇的新岔路口和宾维尔的新部分:

                     ------- []  000
                    /
              ------
             /      \
            /        ------- []  001
       -----                            Old Binville
      /     \        ------- []  010
     /       \      /
    /         ------
   /                \
  /                  ------- []  011
--
  \                  -------     100
   \                /
    \         ------
     \       /      \
      \     /        ------- []  101
       -----                            New Binville (some homes not built yet)
            \        -------     110
             \      /
              ------
                    \
                     -------     111

您是否注意到宾维尔原来部分的每个人都只是在地址前面添加了一个零? 新位代表已建成的新交叉路口。 当位数增加一位时,地址数量就会加倍。 公民总是知道他们城镇的最大规模:他们所要做的就是计算 2 的位数次方的值。 有了三位,他们就可以拥有 23 = 8 栋房子。

几年过去了,宾维尔再次爆满。 更多的人想要搬进来,因此又增加了一点(以及必要的十字路口),使城镇的规模扩大了一倍,达到十六栋房屋。 然后又一位,又一位,又一位……宾维尔的地址很快就达到了 16 位,能够容纳最多 216 (16,384) 栋房屋,但这还不够。 人们不断地来来往往!

因此,规划委员会决定一劳永逸地解决这个问题:他们将一直跳到三十二位。 拥有足够超过 40 亿个家庭 (232) 的地址,这当然就足够了!

大约二十五年来,宾维尔不再是一个偏僻的小镇。 它现在是一个大都市。 事实上,它已经变得像一个拥有数十亿居民的国家一样大。 但公园仍然很好,每个人都享有良好的医疗保健,因此人口不断增长。

面对不断增长的人口,规划委员会再次集思广益,提出了再次扩建城市的建议。 这次他们将使用 64 位。 您知道宾维尔市范围内现在可以容纳多少房屋吗? 没错:18,446,744,073,709,551,616。 这个数字是如此之大,我们可以在大约二十亿个地球上居住并为每个人提供自己的地址。

使用 64 位并不是解决所有寻址问题的灵丹妙药。 这些地址的写入空间是旧 32 位地址的两倍。 更糟糕的是,一些市民尚未更新他们的地址以使用新的 64 位格式,因此他们被迫进入城市中专门为仍在使用 32 位地址的人保留的隔离区域。 但这没关系:使用 32 位的人们可以访问城市的足够多的地方来满足他们的需求。 他们还不觉得有必要改变。

64 位就够了吗? 谁知道这个时候,Binville 的公民正在等待 128 位地址的公布......

Let me tell you the story of Binville, a small town in the middle of nowhere. Binville had one road leading to it. Every person either coming to or leaving Binville had to drive on this road. But as you approached the town, there was a fork. You could either go left or go right.

In fact, every road had a fork in it, except for the roads leading up to the homes themselves. Those roads simply ended at the house. None of the roads had names; they didn't need names thanks to an ingenious addressing scheme created by the Binville Planning Commission. Here's a map of Binville, showing the roads and the houses:

              ------- []  00
             /
       ------
      /      \
     /        ------- []  01
-----
     \        ------- []  10
      \      /
       ------
             \
              ------- []  11

As you can see, each house has a two-digit address. That address alone is enough to a) uniquely identify each house (there are no repeats) and b) tell you how to get there. It's easy to get around town, you see. Each fork is labeled with a zero or one, which the Planning Commission calls the Binville Intersection Tracer, or bit for short. As you approach the first fork, look at the first bit of the address. If it's a zero, go left; if it's a one, go right. Then look at the second digit when you get to the second fork, going left or right as appropriate.

Let's say you want visit your friend who lives in Binville. She says she lives in house 10. When you get to Binville's first fork, go right (1). Then at the second fork, go left (0). You're there!

Binville existed like this for several years but word started to get around about its idyllic setting, great park system, and generous health care. (After all, if you don't have to spend money on street signs, you can use it on better things.) But there was a problem. With only two bits, the addressing scheme was limited to four houses!

So the Planning Commission put their heads together and came up with a plan: they would add a bit to each address, thereby doubling the number of houses. To implement the plan, they would build a new fork at the edge of town and everyone would get new addresses. Here's the new map, showing the new fork leading into town and the new part of Binville:

                     ------- []  000
                    /
              ------
             /      \
            /        ------- []  001
       -----                            Old Binville
      /     \        ------- []  010
     /       \      /
    /         ------
   /                \
  /                  ------- []  011
--
  \                  -------     100
   \                /
    \         ------
     \       /      \
      \     /        ------- []  101
       -----                            New Binville (some homes not built yet)
            \        -------     110
             \      /
              ------
                    \
                     -------     111

Did you notice that everyone in the original part of Binville simply added a zero to the front of their address? The new bit represents the new intersection that was built. When the number of bits is increased by one, the number of addresses doubles. The citizens always knew the maximum size of their town: all they had to do was compute the value of two raised to the power of the number of bits. With three bits, they could have 23 = 8 houses.

A few years went by and Binville was once again filled to capacity. More people wanted to move in, so another bit was added (along with the requisite intersection), doubling the size of the town to sixteen houses. Then another bit, and another, and another... Binville's addresses were soon at sixteen bits, able to accommodate up to 216 (16,384) houses, but it wasn't enough. The people kept coming and coming!

So the Planning Commission decided to solve the problem once and for all: they would jump all the way to thirty-two bits. With sufficient addresses for over four billion homes (232), surely that would be enough!

And it was... for about twenty-five years, when Binville was no longer a small town in the middle of nowhere. It was now a major metropolis. In fact, it was getting to be as big as a whole nation with billions of residents. But the parks were still nice and everyone had great health care, so the population kept growing.

Faced with the ever-increasing population, the Planning Commission once again put their heads together and proposed another expansion of the city. This time they would use 64 bits. Do you know how many homes could fit within the Binville city limits now? That's right: 18,446,744,073,709,551,616. That number is so big, we could populate about two billion Earths and give everyone their own address.

Using 64 bits wasn't a panacea for all their addressing problems. The addresses take twice as much space to write as the old 32-bit addresses did. Worse, some citizens hadn't yet updated their addresses to use the new 64-bit format, so they were forced into a walled-off section of the city reserved specifically for those still using 32-bit addresses. But that was OK: the people using 32 bits had access to more than enough of the city to suit their needs. They didn't feel the need to change just yet.

Will 64 bits be enough? Who knows at this time, but citizens of Binville are waiting for the announcement of 128-bit addresses...

寻梦旅人 2024-08-06 20:44:09

马丁的回答大部分是正确且详细的。

我想我只想提到所有内存限制都是每个应用程序虚拟内存的限制,而不是计算机中实际物理内存的限制。 事实上,即使在 32 位系统中,也可以在单个应用程序中使用超过 4Gb 的内存,只是需要更多的工作,因为无法同时使用指针访问所有内存。 链接文本

另一件没有提到的事情是传统的x86处理器和x86-64不仅表现在指针大小上,还表现在指令集上。 虽然指针更大并且消耗更多内存(8 个字节而不是 4 个字节),但它可以通过更大的寄存器集(15 个通用寄存器而不是 8 个 iirc)进行补偿,因此对于执行计算工作的代码来说,性能实际上可以更好。

Martin's answer is mostly correct and detailed.

I thought I would just mention that all the memory limits are per-application virtual memory limits, not limits for the actual physical memory in the computer. In fact it's possible to work with more than 4Gb of memory in single application even in 32-bit systems, it just requires more work, since it can't all be accessible using pointers at one time. link text

Another thing that was not mentioned is that the difference between traditional x86 processor and x86-64 is not only in the pointer size, but also in the instruction set. While the pointers are larger and consume more memory (8 bytes instead of 4) it is compensated by larger register set (15 general purpose registers instead of 8, iirc), so the performance can actually be better for code that does computational work.

不甘平庸 2024-08-06 20:44:09

解释为什么 32 位模式只能访问 4GB RAM:

最大可访问内存空间 = 2n 字节,其中 n 是架构的字长。 因此,在 32 位架构中,最大可访问内存空间为 232 = 4294967296 = 4GB RAM。

64 位架构将能够访问 264 = LOTS 内存。

刚刚注意到陈的评论对此进行了评论。 无论如何,如果没有计算机科学背景,计算机组织和体系结构书籍充其量也很难理解。

to explain WHY 32 bit mode can only access 4GB of RAM:

Maximum accessible memory space = 2n bytes where n is the word length of the architecture. So in a 32 bit architecture, maximum accessible memory space is 232 = 4294967296 = 4GB of RAM.

64 bit architecture would be able to access 264 = LOTS of memory.

Just noticed Tchens comments going over this. Anyways, without a CS background, yes computer organization and architecture books are going to be difficult to understand at best.

茶底世界 2024-08-06 20:44:09
  • 处理器使用基数 2 来存储数字。 选择基数 2 可能是因为它是所有基数中“最简单”的:例如基数 2 乘法表只有 4 个单元格,而基数“10”乘法​​表有 100 个单元格。
  • 2003 年之前,常见的 PC 处理器仅“支持 32 位”。
    • 这意味着处理器的本机数值运算适用于 32 位数字。
    • 您仍然可以对更大的数字进行数值运算,但这些操作必须由处理器执行的程序来执行,而不是像 32 那样由处理器支持的“原始操作”(机器语言命令) -位整数(当时)
    • 选择 32 位是因为 CPU 工程师喜欢 2 的幂,16 位还不够
  • 为什么16位还不够呢? 使用 16 位可以表示 0-65535 范围内的整数
    • 65535 = 1111111111111111 二进制 (= 20+21+22...+ 215 = 216-1)
    • 65535 还不够,因为例如,医院管理软件需要能够统计超过 65535 名患者
    • 通常人们在讨论整数应该有多大时会考虑计算机内存的大小。 65535肯定不够。 计算机的 RAM 比这多得多,无论您以“字节”还是“位”来计算
  • 32 位在一段时间内都被认为足够了。 2003 年,AMD 推出了首款支持 64 位的“x86”处理器。 英特尔很快也紧随其后。
  • 实际上,很久以前就认为 16 位就足够了。
  • 许多硬件和软件向后兼容是常见的做法。 在这种情况下,这意味着 64 位 CPU 也可以运行 32 位 CPU 可以运行的所有软件。
    • 向后兼容性是我们努力实现的一项业务策略。 如果更好的处理器也能完成以前处理器的所有功能,更多用户会希望升级到该处理器。
    • 在CPU中,向后兼容性意味着CPU支持的新操作被添加到以前的机器语言中。 例如,以前的机器语言可能有一些规范,例如“所有以1111开始的操作码都保留供将来使用”
    • 理论上,这种 CPU 向后兼容性是不必要的,因为所有软件都可以重新编译为新的且不兼容的机器语言。 然而,由于公司战略和政治或经济制度的原因,情况并非如此。 在乌托邦的“开源”世界中,机器语言的向后兼容性可能不会成为问题。
  • x86-64(常见的64位CPU的机器语言)的向后兼容性以“兼容模式”的形式出现。 这意味着任何希望利用新 CPU 功能的程序都需要(通过操作系统)通知 CPU 它应该在“64 位模式”下运行。 然后它可以使用新的 CPU 64 位功能。
  • 因此,对于一个程序来说,要使用CPU的64位能力:CPU、操作系统和程序都必须“支持64位”。
  • 64 位足以为世界上的每个人提供几个唯一的数字。 对于当前的大多数计算工作来说,它可能足够大了。 未来的 CPU 不太可能进一步转向 128 位。 但如果他们这样做了,这绝对足以满足我能想象的一切,因此 256 位转换就没有必要了。

我希望这有帮助。

  • The processor uses base-2 to store numbers. Base 2 was probably chosen because it's the "simplest" of all bases: for example the base-2 multiplication table has only 4 cells while base "10" multiplication table has a 100 cells.
  • Before 2003, common PC processors were only "32-bit-capable".
    • That means that the processor's native numerical operations were for 32-bit numbers.
    • You can still do numerical operations for larger numbers, but those would have to be performed by programs executed by the processor, and not be the "primitive actions" (commands in machine-language) supported by the processor like those for 32-bit-integers (at the time)
    • 32 bits were chosen because CPU engineers are fond of powers of 2, and 16-bits weren't enough
  • Why weren't 16 bits enough? With 16 bits you can represent integers in the range of 0-65535
    • 65535 = 1111111111111111 in binary (= 20+21+22...+215 = 216-1)
    • 65535 is not enough because for example, a Hospital management software needs to be able to count more than 65535 patients
    • Usually people consider the size of the computer's memory when discussing how big its integers should be. 65535 is definitely not enough. Computers have way more RAM than that, and it doesn't matter if you count in "Bytes" or bits
  • 32 bits was considered enough for a while. In 2003 AMD Introduced the first 64-bit-capable "x86" processor. Intel soon followed.
  • Actually 16 bit was considered enough a long while ago.
  • It is common practice for lots of hardware and software to be backward-compatible. In this case it means the 64-bit-capable CPUs can also run every software the 32-bit-capable CPUs can.
    • Backward compatibility is strived for as a business strategy. More users will want to upgrade to the better processor if it can also do everything the previous one could.
    • In CPUs backward compatibility means that the new actions the CPU supports are added to the previous machine language. For example the previous machine language may had some specification like "all opcodes starting in 1111 are reserved for future use"
    • In theory this kind of CPU backward compatibility wouldn't had been necessary as all software could have just been recompiled to the new and not compatible machine-language. However that's not the case because of corporate strategies and political or economical systems. In a Utopic "open source" world, backward compatibility of machine languages would probably not be a concern.
  • The backward compatibility of x86-64 (the common 64-bit CPUs' machine language) comes in the form of a "compatibility mode". This means that any program wishing to make use of the new cpu capabilities needs to notify the CPU (through the OS) that it should run in "64-bit mode". And then it could use to great new CPU 64-bit capabilities.
  • Therefore, for a program to use the CPU's 64-bit capabilities: The CPU, the OS, and the program, all have to "support 64-bits".
  • 64-bits is enough to give every person in the world several unique numbers. It's probably big enough for most current computing endeavors. It's probably unlikely that future CPUs will shift further to 128 bits. But if they do, that's definitely enough for everything I can imagine, and therefore a 256-bits transition won't be necessary.

I hope this helps.

花期渐远 2024-08-06 20:44:09

我认为我在之前的答案中没有看到太多“注册”这个词。 数字计算机是一堆寄存器,具有算术逻辑和存储数据和程序的存储器。

但首先……数字计算机使用数字的二进制表示形式,因为二进制数字(“位”)0 和 1 很容易由开关的两种状态(开/关)表示。 早期的计算机使用机电开关; 现代计算机使用晶体管,因为它们更小、更快。 更小,并且更快

在 CPU 内部,开关在有限长度的寄存器中组合在一起,并且通常在整个寄存器上执行操作:例如,将此寄存器添加到那个寄存器,依此类推。 正如您所期望的,32 位 CPU 的寄存器长度为 32 位。 我在这里进行了简化,但请耐心等待。

将计算机内存组织为一系列“位置”是有意义的,每个“位置”保存与 CPU 寄存器相同的位数:例如,从该内存位置加载该寄存器。 实际上,如果我们将内存视为字节,那么这只是寄存器的一个方便的部分,我们可以从一系列内存位置(1、2、4、8)加载寄存器。

随着晶体管变得越来越小,可以在计算机芯片的有限空间内实现更复杂算术的附加逻辑。 CPU 资源总是非常宝贵。

但随着芯片制造的改进,更多的晶体管可以在稍大的芯片上可靠地制造。 寄存器可以更长,它们之间的路径可以更宽。

当保存内存位置地址的寄存器较长时,它们可以寻址更大的内存,并且可以在更大的块中操作数据。 与更复杂的算术逻辑相结合,事情可以更快地完成。

这不正是我们所追求的吗?

I don't think I've seen much of the word 'register' in the previous answers. A digital computer is a bunch of registers, with logic for arithmetic and memory to store data and programs.

But first ... digital computers use a binary representation of numbers because the binary digits ('bits') 0 and 1 are easily represented by the two states (on/off) of a switch. Early computers used electromechanical switches; modern computers use transistors because they're smaller and faster. Much smaller, and much faster.

Inside the CPU, the switches are grouped together in registers of a finite length, and operations are typically performed on entire registers: For example, add this register to that, and so on. As you would expect, a 32-bit CPU has registers 32 bits long. I'm simplifying here, but bear with me.

It makes sense to organise the computer memory as a series of 'locations', each holding the same number of bits as a CPU register: for example, load this register from that memory location. Actually, if we think of memory as bytes, that's just a convenient fraction of a register and we migh load a register from a series of memory locations (1, 2, 4, 8).

As transistors get smaller, additional logic for more complex arithmetic can be implemented in the limited space of a computer chip. CPU real estate is always at a premium.

But with improvements in chip fabrication, more transistors can be reliably made on only slightly larger chips. Registers can be longer and the paths between them can be wider.

When the registers which hold the addresses of memory locations are longer, they address larger memories and data can be manipulated in larger chunks. In combination with the more complex arithmetic logic, things get done faster.

And isn't that what we're all after?

辞旧 2024-08-06 20:44:09

解释 32 位处理器的可寻址内存范围的简单答案是:

让我们假设您只允许构造 3 位数字,因此您可以达到的最大数字是 999。数字范围是 (0 - 999)。 您只有 1000 个号码可供使用。

但如果允许有 6 位数字,那么您可以构造的最大数字是 999999。现在范围是 (0 - 999999)。 所以现在你有 100 万个号码可供使用。

同样,您可以在处理器中拥有更多的位,您可以构造并最终使用更大的地址集(前面示例中的数字)来存储数据等。

任何比这更简单的东西读起来都会很有趣!

-广告。

Simple answer to explain addressable memory range with 32 bit processors is:

Lets assume You have only 3 digit numbers allowed to construct so maximum number u can go upto is 999. Range of numbers is (0 - 999). You have just 1000 numbers to use.

But if u are allowed to have 6 digit numbers then the maximum number you can construct is 999999. Now range is (0 - 999999). So now u have 1 million numbers with you to use.

Similarly more bits you are allowed to have in a processor, larger set of addresses(numbers in previous example) you can construct and eventually use to store data etc..

Anything simpler than this would interesting to read!

-AD.

可遇━不可求 2024-08-06 20:44:09

我对这个问题有一个很好的答案,但它并不适合这个答案块中的所有内容......简单的答案是,为了让你的程序从内存中获取一个字节,它需要一个地址。 在 32 位 CPU 中,每个字节的内存地址存储在一个 32 位(无符号)整数中,最大值为 4 GB。 当您使用 64 位处理器时,内存地址是一个 64 位整数,这为您提供了大约 1.84467441 × 10^19 个可能的内存地址。 如果您是编程新手,这确实应该足够了。 您确实应该更多地关注学习如何编程,而不是了解处理器的内部工作原理以及为什么无法在 32 位 CPU 上访问超过 4 GB 的 RAM。

I have a wonderful answer for this question, but it doesn't fit all within in this answer block.... The simple answer is that for your program to get a byte out of memory, it needs an address. In 32-bit CPUs, the memory address of each byte is stored in a 32-bit (unsigned) integer, which as a maximum value of 4 GB. When you use a 64 bit processor, the memory address is a 64 bit integer, which gives you about 1.84467441 × 10^19 possible memory addresses. This really should suffice if you are new to programming. You should really be focusing more on learning how to program, than about the internal workings of your processor, and why you can't access more than 4 GB of RAM on your 32 bit CPU.

胡大本事 2024-08-06 20:44:09

鉴于上面的内容都非常详细,这是一个非常简单的解释。

32位指的是寄存器。 寄存器是存储数据的地方,所有的程序都是通过操作这些东西来运行的。 汇编直接对它们进行操作(这就是为什么人们常常对汇编编程感到兴奋)。

32位意味着基本寄存器组可以保存32位信息。 不出所料,64 位意味着 64 位信息。

为什么这可以使程序更快? 因为您可以更快地执行更大的操作。 顺便说一句,它只会使某些类型的程序更快。 通常,游戏可以充分利用每个处理器的优化,因为它们需要大量的数学运算(以及寄存器的使用)。

但有趣的是,正如 tchen 提到的,它们还有许多其他“东西”可以让您执行更大的操作。 SSE、SSE2 等将具有 64 位寄存器和 128 位寄存器,即使在“32 位”系统上也是如此。

内存寻址能力的增强直接说明了基本寄存器大小的增加,基于(我想)Windows 的特定内存寻址系统。

希望能有所帮助。 其他海报比我准确得多,我只是想非常简单地解释(这有助于我知道得很少:)

This is a very simple explanation, given that everything above is quite detailed.

32-bit refers to the registers. Registers are places to store data, and all programs operate by manipulating these things. Assembly operates directly on them (and hence why people are often excited to program in assembly).

32-bit means the basic set of registers can hold 32-bits ofinformation. 64-bit means, unsurprisingly, 64 bits of info.

Why can this make programs faster? Because you can do larger operations faster. It will only make certain types of programs faster, by the way. Games, typically, can take great advantage of optimising per processor, because of their math-heavy operations (and hence register use).

But amusingly, as tchen mentioned, their are many other 'things' that let you perform larger operations anyway. SSE, SSE2, etc, will have 64-bit registers and 128-bit registers, even on a '32 bit' system.

The increased ability to address memory speaks directly to the increase in basic register size, based on (I imagine) Windows' specific memory-addressing system.

Hope that helps a little. other posters are much more accurate than me, I am just trying to explain very simply (it helps that I know very little :)

囚我心虐我身 2024-08-06 20:44:09

对于非CS人员。 64 位将更好地进行计算(各种),它也将让您拥有更多 RAM。

此外,如果您的 RAM 有限(例如 VPS 或小 RAM 专用服务器) - 选择 32 位,那里的服务会消耗更少的 RAM。

For non CS person. 64bit will work better for calculations (all kinds of) it will be good also it will allow you to have more RAM.

Also if you have limited RAM (in VPS for example or small-RAM dedicated server) - choose 32 bit, services there will eat less RAM.

一场信仰旅途 2024-08-06 20:44:09

值得注意的是,某些应用程序(例如多媒体编码/解码和渲染)在编写为充分利用 64 位时会获得显着的 (2 倍) 性能提升。

请参阅 UbuntuWindows Vista

It's worth noting that certain applications(e.g. multimedia encoding/decoding and rendering) gain significant(2x) performance boost when written to fully utilize 64-bit.

See 32-bit vs. 64-bit benchmarks for Ubuntu and Windows Vista

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文