5 ms·
The costs of the i386 to x86-64 upgrade
- gnabgib 2y agoSmall discussion already (16 points, 10 hours ago, 7 comments) https://news.ycombinator.com/item?id=41768144 https://news.ycombinator.com/item?id=41768144
- zokier 2y agoI find it weird that the convention to use char/short/int/long/long long has persisted so widely to this day. I would have thought that already back in the 16 -> 32 bit transition period people would have standardized and moved to stdint.h style types instead (i.e. int32_t etc). Sure, that doesn't change pointer sizes, but it would have reduced the impact of the different 64-bit data models, like Unix LP64 vs Windows LLP64
- chipdart 2y ago> I find it weird that the convention to use char/short/int/long/long long has persisted so widely to this day. I don't think this is a reasonable take. Beyond ABI requirements and how developers use int over short, there are indeed requirements where the size of an integer value matters a lot, specially as this has a direct impact on data size and vectorization. To frame your analysis, I would recommend you took a peek at the not-so-recent push for hardware support for IEEE754 half-precision float/float16 types.
- zokier 2y agoThe cases where you want platform-specific integer width (that is not something like size_t/uintptr_t) is extremely niche compared to cases where you want integer to have specific width. I don't see the relation to fp16; I don't think anyone is pushing for `float` to refer to fp16 (or fp64 for that matter) anywhere. `long double` is already bad enough.
- manwe150 2y agoMy recollection of history is that the standardization of stdint.h happened long after the transition to 32 bit, and is only just finishing up becoming available on some major compilers after the transition to 64 bit is well behind us
- jcranmer 2y agostdint.h was introduced in C99, and MSVC didn't introduce it until 2010.
- layer8 2y agoYou could fairly easily create your own portable stdint.h equivalent in C89 (using the preprocessor and INT_MAX etc.). I remember doing that in the 90s, before C99. However, it was also conventional wisdom to use int by default to match the architecture’s “natural” word size, and maybe add a preprocessor check when you needed it to be 32-bit. Another consideration is that the built-in types have to be used with the C standard library functions to some extent.
- chipdart 2y ago> The cases where you want platform-specific integer width (that is not something like size_t/uintptr_t) is extremely niche (...) I think you got it backwards. There are platform-specific ints because different processors have different word sizes. Programing languages then adjust their definitions for these word sizes because they are handled naturally by specific processors. So differences in word sizes exist between processors. Either programming languages support them, or they don't. Also, there is also specific needs to handle specific int sizes regardless of cpu architecture. Either programming languages support them, or don't. And you end with "platform-specific integer widths" because programming languages do the right thing and support them.
- zokier 2y agoThe fact that we have all these different 64 bit data models demonstrates clearly how the connection between word size and C types is completely arbitrary and largely meaningless. And this is not specific to 64 bit either, same sort of thing happens on 8 bit platforms too. So you can not rely on `int` (or any other type) being word sized. Furthermore I argue that word size is not really something that makes sense to even expose at language level, the whole concept of word size is somewhat questionable. CPUs operate on all sort of things that can have different sizes, trying to reduce that to single "word size" is futile.
- jraph 2y agoI see two good reasons: (1) DX: typing "int" feels more natural and less clunky than choosing some arbitrary size. (2) Perf: if you don't care about the size, you might as well use the native size, which is supposed to be faster. In Java, people do use the hardware-independent 4 byte ints and 8 byte longs. I guess (1) matters more, or that people think that the JVM will figure out the perf issue and that it'll be possible to micro-optimize if a profile pointed out an issue.
- epcoa 2y ago> Perf: if you don't care about the size, you might as well use the native size, which is supposed to be faster. You always care about the size (or should), especially if you're writing C or C++. Though it is often reasonable that 32767 is a sufficient limit and you're guaranteed at least that with int.
- jraph 2y agoWhat I meant is that if you don't specifically need a small int size (because for instance you are going to serialize it into a format that mandates it), and you will not deal with even moderately large ints, you will probably use int even if you could use a smaller type. I've not seen many codebases doing something else. Of course you need to think about it. In C, but also in many languages (not python though, which magically switch to bigint when needed). In Java, the wrong int type won't cause UB, but it will throw (unchecked) exceptions.
- Tuna-Fish 2y ago> which is supposed to be faster. If you care about this, you figure out exactly how much you need and always use the smallest type that meets this criteria. There have been architectures in the past where the "native" size was in practice faster than the smaller types, but those architectures are now long dead. On all modern architectures, none of the instructions for smaller data types are ever slower than the native size, and while using them doesn't directly win you cycles of execution time in the cpu (because they are no faster either), it wins you better cache utilization. As a rule, the fastest data type is a byte. There is no reason to ever use "int", other than inertia.
- loeg 2y agoThe stdint types only date to C99. 32-bit transition happened much earlier than that.
- blueflow 2y ago> To support those needs, there were clutches like Intel’s PAE, which allowed manipulating up to 64GB of RAM on 32-bit machines without changing the programming model, but they were just that: hacks. You can go look up how the 32-bit protected mode got hacked on top of the 16-big segmented virtual memory that the 286 introduced. The Global Descriptor Table is still with us on 64-bit long mode. So, its not PAE that is particularly hacky, its a more broader thing with x86.
- lmm 2y agoThat other hacks exist does not make a given hack any less hacky.
- af78 2y agoWhile a PAE system can address more than 4 GiB of physical memory, individual processes still use 32-bit pointers and are therefore still restricted to 4 GiB. I think this is why the author calls PAE a hack. In x86-64 long mode and i386 32-bit mode, pointers are really 64- and 32-bit, respectively; I would not call this a hack.
- junon 2y agoImportant missing info I suppose for some readers - that's what the "p" in "pae" stands for - physical address extension. It has no bearing on virtual addresses.
- rft 2y agoTo add another layer on top of these hacks, Windows has Address Windowing Extensions [1] that allows a 32bit process to use more than 4GB of RAM. Of course pointers are still 32bit, so you need to map the additional memory into and out of the virtual address space. x86 and its history is full of things that look hacky, and might be, but are often there for backward compatibility. If your x86 PC still boots in BIOS mode, it comes up in 16bit real mode [2], ready to run DOS. It then moves through the decades into protected mode and lastly (for x64 systems) long mode. [1] https://learn.microsoft.com/en-us/windows/win32/memory/address-windowing-extensions https://learn.microsoft.com/en-us/windows/win32/memory/addre... [2] https://wiki.osdev.org/Real_Mode https://wiki.osdev.org/Real_Mode
- tzot 2y agox32 ABI support exists at least in the kernel of Debian (and Debian based) distributions, and I know because I've built Python versions (along with everything else needed for specific workloads) as x32 executables. The speed difference was minor but existing, but the memory usage was quite a lot decreased. I've worked with a similar ABI known as n32 (there was o32 for old 32, n32 for new 32 and n64 for fully 64-bit programs) on SGI systems with 64-bit capable MIPS CPUs; it made a difference there too. Unfortunately I've read articles where quite-more-respected-than-me people said in a nutshell “no, x32 does not make a difference”, which is contrary to my experience, but I could only provide numbers where the reply was “that's your numbers in your case, not mine”. Amazon Linux kernel did not support x32 calls the last time I tried, so you can't provide images for more compact lambdas.
- zh3 2y agoIndeed, for many years we've been running multiple systems with X86_64 kernels and a 32-bit userspace, running many standard 32-bit applications (including browsers); only thing we've ever needed to do is run 'linux32' before starting X so that 'uname' reports i686 rather than x86_64.
- martijnvds 2y agoThe X32 ABI is not the same as the 32-bit mode used to run "i686" binaries on x86_64 (that would be the i386 ABI).
- zh3 2y agoThanks for the correction, having a read of the wikipedia x32 ABI [0] page now. [0] https://en.wikipedia.org/wiki/X32_ABI https://en.wikipedia.org/wiki/X32_ABI
- gregw2 2y agoFor the curious, "x32" Linux is a "L64P32" programming model. There is some lwn.net 2012 commentary on performance implications at: https://lwn.net/Articles/503541/ https://lwn.net/Articles/503541/
- renox 2y agothe RISC example in the article is a bit weird: on one hand, it may take even more instructions to load an address in a RISC, on the other hand all the RISC I know have an 'addi' instruction, no need to do 'li r2, 1; add r3, r1, r2' to add 1 to a register!
- jauntywundrkind 2y agoTalking about the ISA needing to spend so much time addressing memory, I'm reminded of the really interesting Streaming Semantic Registers (SSRs) in Occamy, the excellent PULP group's 4096-core RISC-V research multichip design. https://arxiv.org/abs/1911.08356 https://arxiv.org/abs/1911.08356 Just like the instruction pointer which implicitly increments as code executes, there are some dedicated data-pointer registers. There's a dedicated ALU for advancing/incrementing, so you can have interesting access patterns for your data. Rather than loops needing to load data, compute, store data, and loop, you can just compute and loop. The SSRs give the cores a DSP like level of performance. So so so neat. Ship it! (Also, what was the name of the x86 architecture some linux distros were shipp8ng with 32 bit instructions & address space, but using the new x86-64 registers?)
- tzot 2y agoRe your parenthesized question: x32, as discussed in the article, is an ABI using the full x86-64 instruction set and registers, but pointers are 32-bit. I believe you are talking about the same thing, because any “32-bit instructions” (assumably x86/i686 instructions) cannot use “new x86-64 registers” (either in full count of registers or their 64-bit width).
- sjsdaiuasgdia 2y agoI'm overly annoyed by the AI generated image of CPUs, with one showing a horrible mottled mess where the nice clean grid of contact pads should be. There's endless actual pictures of processors from both eras. Using actual images here would have been as fast, possibly faster, than the process of writing a prompt and generating this image.
- sph 2y agoNot only that, they had to manually edit the generated image to add the i386 and x86-64 labels on them. When all you have is a hammer...
- Filligree 2y agoFirst though, you would have needed to find a picture you can be sure isn’t in copyright. Or which is licensed appropriately.
- sjsdaiuasgdia 2y agoimages.google.com -> search for "386 cpu" Click "tools" then "usage rights", pick "creative commons", pick an image. Now search for "core cpu" and pick a second image. Yeah that sure was hard and time consuming!
- Kye 2y agoEven easier: Step 1: go to Wikimedia Commons https://commons.wikimedia.org/wiki/Category:Intel_i386 https://commons.wikimedia.org/wiki/Category:Intel_i386
- Retr0id 2y agoI'm sure the same diligence was also performed when constructing the AI's training data set.
- deleted 2y ago[deleted]
- chrsw 2y ago
- crest 2y agoWhat the FreeBSD ISO size comparison overlooks is that to provide 32 bit application compatibility FreeBSD/amd64 will include a i386 copy of all libraries (unless deselected).
- yjftsjthsd-h 2y agoDoes Debian not include multilib by default?
- jmmv 2y agoOh, good point. Somehow I missed that when looking at the contents. Will need to check again why.
- ChrisArchitect 2y ago[dupe] Some more discussion: https://news.ycombinator.com/item?id=41768144 https://news.ycombinator.com/item?id=41768144
- faragon 2y agoUsing indexes instead of pointers in data structures works well, and the cost of the base address + offset is negligible, as similar address calculation is already generated by the compiler when accessing into an element of a data structure. In addition to that, mention that indexes can be used as offsets, or as an actual indexes of the size of an individual element, i.e. in that case non-trivial data structures with e.g. >= 32-byte elements could address hundreds of gigabytes of RAM. A practical use could be e.g. using bit fields can be convenient, e.g. having 32-bit indexes, with the higher bit for the color in a Red-black tree. And in case of requiring dynamic-sized items in the tree nodes, these could be in different 32-bit addressable memory pools.
- armada651 2y ago> We now know that LP64 was the preferred choice and that it became the default programming model for 64-bit operating systems That is incorrect, Windows never adopted the LP64 model. Only pointers were increased to 64-bit whereas long remained 32-bit. The long datatype should be avoided in cross-platform code.
- af78 2y agoThe article focuses on Linux and FreeBSD, which are LP64.
- jagrsw 2y agoAll C's native datatypes should be avoided for cross-platform data structures (networking, databases, file storage) because the standard only guarantees minimum sizes. Additional problem is the endianess. uint64_t is a bit verbose, many re-def this to u64.
- coldpie 2y agoI think I agree, but I'd be interested in more discussion about this. I always understood the native types to be the "probably most efficient" choice, for when you don't actually care about the width. For example, you'd choose int for a loop index variable which is unlikely to hit width constraints because it's the "probably most efficient" choice. If you're forced to choose a width, you might choose a width that is less efficient for the architecture. Is that understanding correct? Historically or currently? Either way, I think I now agree that unspecified widths are an anti-feature. There's value in having explicitly specified limits on loop index variables. When you write "for(int32_t i; ...)", it causes you to think a bit, "hey can this overflow?" And now your overflow analysis will be true for all arches, because you thought about the width that is actually in use (32-bits, in this case). It keeps program behavior consistent & easier to reason over, for all arches. That's my thinking, but I'd be interested to hear other perspectives.
- 2ndbigbang 2y agoThere is int_fast32_t and int_least32_t but it is probably less confusing to just use exact sized types (and would make porting to other architectures simpler).
- gregw2 2y agoIf I recall correctly, UNIX vendors in the late 90s were debating a fair bit internally and amongst each other whether to use LP64 or ILP64 or LLP64 (where long longs and pointers were 64bit). ooh, found a link to a UNIX Open Group white paper on that discussion and reasoning why LP64 should be/was chosen: https://unix.org/version2/whatsnew/lp64_wp.html https://unix.org/version2/whatsnew/lp64_wp.html And per Raymond Chen, why Windows picked LLP64: https://devblogs.microsoft.com/oldnewthing/20050131-00/?p=36563 https://devblogs.microsoft.com/oldnewthing/20050131-00/?p=36... and https://web.archive.org/web/20060618233104/http://msdn.microsoft.com/library/en-us/win64/win64/abstract_data_models.asp https://web.archive.org/web/20060618233104/http://msdn.micro... For some history of why ILP32 was picked for 1970s 16 to 32 bit transition of C + Unix System V (Windows 3.1, Mac OS were LP32) see John Mashey's 2006 ACM piece, partcularly the section "Early Days" sechttps://queue.acm.org/detail.cfm?id=1165766 https://queue.acm.org/detail.cfm?id=1165766 No peanut gallery comments from OS/400 guys about 128-bit pointers/object handles/single store address space in the mid-1990s please! That's not the same thing and you know it! (j/k. i'll stop now)
- senkora 2y agoFrom the "Early Days" section: > PDP-11s still employed (efficient) 16-bit int most of the time, but could use 32-bit long as needed. The 32-bitters used 32-bit int most of the time, which was more efficient, but could express 16-bit via short. Data structures used to communicate among machines avoided int. Oh, interesting. So "short" meant 16-bit portable integer, "long" meant 32-bit portable integer, and "int" meant fast non-portable integer.
- chasil 2y agoSolaris famously compiles everything in (/usr)/bin as 32-bit. Alas, my SmartOS test system is gone, or I would show you.
- quesera 2y agoIt looks like there's some variability: smartos$ uname -a SunOS smartos 5.11 joyent_20240701T205528Z i86pc i386 i86pc Solaris Core system stuff: smartos$ file /usr/bin/ls /usr/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (Solaris), dynamically linked, interpreter /usr/lib/ld.so.1, not stripped smartos$ file /bin/sh /bin/sh: symbolic link to ksh93 smartos$ file /bin/ksh93 /bin/ksh93: ELF 64-bit LSB executable, x86-64, version 1 (Solaris), dynamically linked, interpreter /usr/lib/amd64/ld.so.1, not stripped And then the pkgsrc stuff: smartos$ which ls /opt/local/bin/ls smartos$ file /opt/local/bin/ls /opt/local/bin/ls: symbolic link to /opt/local/bin/gls smartos$ file /opt/local/bin/gls /opt/local/bin/gls: ELF 64-bit LSB executable, x86-64, version 1 (Solaris), dynamically linked, interpreter /usr/lib/amd64/ld.so.1, not stripped
- yjftsjthsd-h 2y agoThat was my first thought, too:) But is that x32 (amd64 with 32-bit pointers), or full i386 32-bit code+data?
- wang_li 2y ago$ uname -a SunOS bob 5.11 11.4.68.164.2 sun4v sparc sun4v kernel-zone $ pwd /usr/bin $ file * | grep 32-bit | wc 46 1008 8890 $ file * | grep 64-bit | wc 1036 21449 185122 I think Solaris is famous for doing away with static linking. E: A Solaris 10 amd64 box is all 32-bit in /usr/bin.
- ChrisArchitect 2y ago[dupe] More discussion: https://news.ycombinator.com/item?id=41768144 https://news.ycombinator.com/item?id=41768144
- ngcc_hk 2y agoThis is crazy. Like why not baby start to eat spaghetti, rice or noodle. Just to attack people then and said they are silly not to think ahead, totally ignore nearly all have to handle transition due to advance in chip technology. The fact all had to do that meant it is human fact to learn not to ignore. One lesson is to check and not allow i.e. not ignore the address bit, like DEC (but where is DEC now btw). Tbh, look at C. How many features are not allowed but just undefined in that standard. Hence even that I wonder is there some reason we have to accept human fallibility and deal with it. Anyway easy to comment on hindsight. What I think more important is say it cannot be done and hence no way forward but totally new architecture. X86 cannot do 64 bit say … it ended up confusing me why we have amd-64 in an Intel cpu … What we need is like Apple somehow force migration except Apple II, we have from Mac OS … 9 … x … macOS with hardware change … IBM mainframe is still running and the 24 bit is a feature not a bug or mistake from a marketing point of view.