4 ms·
I suspect if you were to compare code that uses both the remainder and quotient of a division, you would find a similar trend: the x86 division instructions pro
by userbinator 8y ago
I suspect if you were to compare code that uses both the remainder and quotient of a division, you would find a similar trend: the x86 division instructions produce both, but ARM has only a quotient-generating division instruction, and you have to do another multiplication(!) and subtraction to get the remainder.
That, along with the fact that earlier ARMs didn't even have a divide instruction, is one of the reasons why I'm not at all fan of the "RISC approach" --- division may not have been easy to implement, but microcoding would've been at least as fast as doing the algorithm in software while taking up far less space, and with hardware advances that move operations from microcode into direct execution, existing software that already has those instructions would automatically become faster on newer hardware with no other action needed.
Division hardware almost always will generate the remainder along with the quotient, but ARM would either need to add another instruction (no benefit to existing software, only new software that knows how to use it) or attempt to detect patterns of simpler instructions that are doing the same thing in order to replace them with one "fused uop" (much more difficult to do.)
- acdha 8y agoI wonder how much that has been changing as an increasingly large percentage of software is compiled far more frequently than in the past (JIT, formats like WASM and Apple’s bitcode, toolchains like LLVM becoming widespread, etc.). It seems like at least Apple could ship a new ARM instruction and be relatively confident that most of the important code would be updated to use it on a time-scale which used to seem impossible. Java might be a counter-example but I’m not sure you can separate that from all of the other dubious decisions which happened over the years there.
- pcwalton 8y agoThere is a good reason why nobody implements multiply and divide like x86 did: it's terrible for register allocation. Especially on 32-bit, where register pressure is very high, having division input and output registers hardwired is obnoxious, and it kills a register for the upper half of the product or remainder or quotient that you almost never need. ARM has the correct design. Even Intel admits this: look at the MULX instruction that retrofits the right design onto x86. Earlier versions of ARM didn't have a divide instruction because of die space and the fact that it's rarely needed. Integer division is usually by a constant, so a shift and/or a multiplication suffices. There's no need to microcode a divide instruction either, because the kernel can just trap the #UD and perform the division itself, just like soft float works. (Yeah, it's slow, but software division is always slow.) Modern designs like RISC-V do this properly: expose division as an optional extension so as to scale down to microcontrollers.
- stevekemp 8y agoI wrote a simple compiler for mathematical operations recently, https://github.com/skx/math-compiler/ https://github.com/skx/math-compiler/ and I have to say I really appreciated the ability to get the two halves of the result in one operation. I've just provisioned an ARM server so I can experiment with generating ARM assembly as well as Intel. No doubt I'll have fun learning of the different instructions available - until now I've only ever written assembly for intel and Z80 processors.
- PorterDuff 8y ago"earlier ARMs didn't even have a divide instruction," Hah. That's interesting. I think that the cheaper variants of the AMD 29000 had the same feature. A voice in my head tells me that divides for realtime video transforms used to really be a trip.