9 ms·
Remember how we used to have machines with a 7 bit byte? And everything was written to handle either 6, 7, or 8 bit bytes? And now we've settled on all machi
by londons_explore 6y ago
Remember how we used to have machines with a 7 bit byte? And everything was written to handle either 6, 7, or 8 bit bytes?
And now we've settled on all machines being 8 bit bytes, and programmers no longer have to worry about such details?
Is it time to do the same for big endian machines? Is it time to accept that all machines that matter are little endian, and the extra effort keeping everything portable to big endian is no longer worth the mental effort?
- bumbada 6y agoWhat happens is that all machines that matter are little endian but network works always in Big Endian.
- londons_explore 6y agoWe'll have to keep it as a quirk of history... A bit like the electron has a negative charge...
- PixelOfDeath 6y agoThey hat a 50/50 chance at getting the technical electricity direction right... and the fucked it up!
- bombcar 6y agoIsn’t big endian a bit more natural considered on a bit level? The bits start from highest to lowest on a serial connection.
- ben509 6y agoBig-endian is natural when you're comparing numbers, which is probably why people represent numbers in a big-endian fashion. Little-endian is natural with casts because the address doesn't change, and it's the order in which addition takes place.
- kangalioo 6y agoI feel like big endian is more _intuitive_ because that's what our number notation has evolved to be. But more _natural_ is little endian because, well, it's just more straightforward to have the digits' magnitude be in ascending order (2^0, 2^1, 2^2, 2^3...) instead of putting it in reverse. Plus you encounter less roadblocks in practice with little endian (e.g. address changes with casts) which is often a sign of good natural design
- CydeWeys 6y agoI'm curious how you're defining "natural", and if you think ISO-8601 is the reverse of "natural" too. All human number systems I've ever seen write numbers out as big Endian (yes, even Roman numerals), so I'm really struggling to see how that wouldn't be considered natural.
- ByteJockey 6y agoIt seems like it would be a more natural for representing the number when communicating with a human. But that's not what we're doing here, so it's not entirely relevant.
- bombcar 6y agoCounting out change is little endian - usually you start cents then dollars. I wonder if we went big endian “by mistake” with Arabic numerals given that Arabic is written right to left. Some ancient texts have “four and twenty” which is little endian. We also add commas to large numbers to help with a human processing problem - you have to get to the end of the number to know what the first digit represents and then count backwards (groups of three help).
- a1369209993 6y ago> The bits start from highest to lowest on a serial connection. This is only true on a big endian serial connection (that is, one that, tautologically, sends the most-significant bit first). Offhand, I think most serial protocols are big endian, but by that logic, most CPUs are little endian, so that doesn't really help. The thing that's actually useful about big endian is not that it's natural (as kangalioo points out, that's little endian) or that it's how humans write numbers (by that logic crap like BCD or decimal floats is a good idea), but that big endian preserves lexicographic order of fixed-width integers.
- pabs3 6y agoIBM is going to be pretty annoyed when your code doesn't work on their mainframes.
- jart 6y agoIn my experience IBM does the right thing and sends patches rather than asking us to fix their problems for them, and I respect them for that reason, even if it's a tiny burden to review those changes. However endianness isn't just about supporting IBM. Modern compilers will literally break your code if you alias memory using a type wider than char. It's illegal per the standard. In the past compilers would simply not care and say, oh the architecture permits unaligned reads so we'll just let you do that. Not anymore. Modern GCC and Clang force your code to conform to the abstract standard definition rather than the local architecture definition. It's also worth noting that people think x86 architecture permits unaligned reads but that's not entirely true. For example, you can't do unaligned read-ahead on C strings, because in extremely rare cases you might cross a page boundary that isn't defined and trigger a segfault.
- froh 6y agoyes IBM provided asm for s390 hton ntoh, and "all we had to do" for mainframe Linux was patch x86 only packages to use hton ntoh when they persisted binary data. for the kernel IBM did it on their own, contributing mainline, for userland suse did it, grabbing some patches from japanese turbolinux, and then red hat grabbed the patches from turbo and suse, and together we got them mainline lol. and PPC then just piggybacked on top of that effort.
- account42 6y ago> It's also worth noting that people think x86 architecture permits unaligned reads but that's not entirely true. For example, you can't do unaligned read-ahead on C strings, because in extremely rare cases you might cross a page boundary that isn't defined and trigger a segfault. But that's not a problem with an unaligned read but rather that you are reading more than you are allowed to. And in C even an aligned readahead is UB. A better example might be SSE instructions which do have aligned variants that trap on unaligned pointers.
- genmon 6y agoThat reminds me of a project to interface with vending machines. (We built a bookshop in a vending machine that would tweet whenever it sold an item, with automated stock management.) Vending machines have an internal protocol a little like I2C. We created a custom peripheral to bridge the machine to the web, based on a Raspberry Pi. The protocol was defined by Coca Cola Japan in 1975 (in order to have optionality in their supply chain). It's still in use today. But because it was designed in Japan, with a need for wide characters, it assumes 9 bit bytes. We couldn't find any way to get a Raspberry Pi to speak 9 bit bytes. The eventual solution was a custom shield that would read the bits, and reserialise to 8 bit bytes for the Pi to understand. And vice versa. 9 bit bytes. I grew up knowing that bytes had variable length, bit this was the first time I encountered it in the wild. This was 2015.
- raverbashing 6y agoWell you could bit bang and the 9 bits wouldn't be an issue. (Even if you had a tiny PIC microcontroler just to do that) This is best solvable the closer to the device in question and in the simplest way possible.
- ghoward 6y agoSorry, dumb question: what is bit banging?
- gspr 6y agoThe practice of using software to literally toggle (or read) individual pins with the correct software-controlled timing in order to communicate with some hardware. To transmit a bit pattern 10010010 over a single pin channel, for example, you'd literally set the pin high, sleep for a some predetermined amount of time, set it low, sleep, set it low, sleep, set it high, etc.
- thristian 6y agoIn order to exchange data over a serial connection, the ones and zeroes have to be sent with exact timing, so the receiver can reliably tell where one bit ends and the next begins. Because of this, the hardware that's doing the communication can't do anything else at the same time. And since the actual mechanics of the process are simple and straightforward, most computers with a serial connection have special serial-interface hardware (a Universal Asynchronous Receiver/Transmitter, or UART) to take care of it - the CPU gives the UART some data, then returns to more productive pursuits while the UART works away. But sometimes you can't use a UART: maybe you're working on a tiny embedded computer without one, or maybe you need to speak a weird 9-bit protocol a standard UART doesn't understand. In that case, you can make the CPU pump the serial line directly. It's inefficient (there's probably more interesting work the CPU could be doing) and it can be difficult to make the CPU pause for exactly the right amount of time (CPUs are normally designed to run as fast or as efficiently as possible, nothing in between), but it's possible and sometimes it's all you've got. That's bit-banging.
- DonHopkins 6y agoWe used to have machines with arbitrarily sized bytes, and 36 bit words! http://pdp10.nocrew.org/docs/instruction-set/Byte.html http://pdp10.nocrew.org/docs/instruction-set/Byte.html >In the PDP-10 a "byte" is some number of contiguous bits within one word. A byte pointer is a quantity (which occupies a whole word) which describes the location of a byte. There are three parts to the description of a byte: the word (i.e., address) in which the byte occurs, the position of the byte within the word, and the length of the byte. >A byte pointer has the following format: 000000 000011 1 1 1111 112222222222333333 012345 678901 2 3 4567 890123456789012345 _________________________________________ | | | | | | | | POS | SIZE |U|I| X | Y | |______|______|_|_|____|__________________| >POS is the byte position: the number of bits from the right end of the byte to the right end of the word. SIZE is the byte size in bits. >The U field is ignored by the byte instructions. >The I, X and Y fields are used, just as in an instruction, to compute an effective address which specifies the location of the word containing the byte. "If you're not playing with 36 bits, you're not playing with a full DEC!" -DIGEX (Doug Humphrey) http://otc.umd.edu/staff/humphrey http://otc.umd.edu/staff/humphrey
- deleted 6y ago[deleted]
- einpoklum 6y ago> Is it time to accept that all machines that matter are little endian. Well, no, because it's not the case. SPARC is big-endian, and a bunch of IBM processors. ARM processors are mostly bi-endian. > Is it time to do the same for big endian machines? No. Not just because of their prevalence, but because there isn't a compelling reason why everything should be little- endian.
- gnufx 6y agoMachines that matter to who? Maintainers of packages for OSes that support s390x (RHEL/Fedora, SUSE, Debian), Arduino AVR users, AIX users, embedded systems people with, say, Coldfire or some DSP? I don't know to what extent portable code is relevant to embedded systems, but I guess they care about cryptography libraries, for instance. (I know it's bi- in principle, but SPARC is still even in the Top500.)