4 ms·
Article is very light on details, and contains zero citations, and only a single result of a single benchmark the guy ran, with no details of how it was run. It
by dmitrygr 8y ago
Article is very light on details, and contains zero citations, and only a single result of a single benchmark the guy ran, with no details of how it was run. It follows up by stating his theory as to why this happens as a fact (again with no citations). Author does not even offer us a clue as to what ARM core is used. The claim is:
> The difference is that the computation
> of the most significant bits of a
> 64-bit product on an ARM processor
> requires a separate and expensive
> instruction.
I see no proof of this anywhere in the ARMv8 spec. You get the lower 64 bits of result using MUL and higher 64 bits using UMULH. Neither of those is that expensive.
Looking at [1] we can see that MUL has throughput of 1 and latency of 3, UMULH has 1/4 and 6, but as long as you do not issue another multiply just after your UMULH, this 1/4 throughput is easily hidden, since only the multiplier is busy, the rest of the CPU can go on. So unless your entire loop is under 6 cycles, or you simply have no instructions to schedule that do not need a multiply within the next 3 of UMULH, it shouldn't matter. Given those large constants that need to be loaded, they will each need 4 instrs (mov+movk+movk+movk), there are plenty of instrs to schedule after UMULH. Either OP's compiler messed up, or something entirely different is going on.
If, the author was using a weaker in-order core, say Cortex-A55, still more performance is expected than appears demonstrated. There [2] the low part is calculated in 2 or 3 cycles, the high in 4. But comparing an ARM in-order little core to a modern OoO x86 is just not fair.
EDIT: Indeed, looking [3] at what gcc produces for this code is sad. For example, why it is bothering synthesizing 0x1b03738712fad5c9 before issuing the first UMULH is unclear, but it IS stupid.
EDIT2: on skylake [4] MUL has a latency of 3, so faster than on ARM but not by that much. I'd guess the constant loading on arm using 4 instructions per constant hurts more than UMULH
EDIT3: in comments on original site, author said the ARM chip being used is a "Skylark" by "Ampere Computing" [5]. Given that I cannot find any info on that microarchitecture, I cannot say more about why it might be slow.
[1] Cortex®-A72 Software Optimization Guide: https://static.docs.arm.com/uan0016/a/cortex_a72_software_optimization_guide_external.pdf https://static.docs.arm.com/uan0016/a/cortex_a72_software_op...
[2] Cortex®-A55 Software Optimization Guide: https://static.docs.arm.com/epm128372/20/arm_cortex_a55_software_optimization_guide_v2.pdf https://static.docs.arm.com/epm128372/20/arm_cortex_a55_soft...
[3] Godbolt for this code: https://godbolt.org/z/UeOo6C https://godbolt.org/z/UeOo6C
[4] Lists of instruction latencies, throughputs and micro operation breakdowns for Intel, AMD and VIA CPUs: https://www.agner.org/optimize/instruction_tables.pdf https://www.agner.org/optimize/instruction_tables.pdf
[5] Skylark - Microarchitectures - AppliedMicro: https://en.wikichip.org/wiki/apm/microarchitectures/skylark https://en.wikichip.org/wiki/apm/microarchitectures/skylark
- tntn 8y ago>> separate and expensive instruction. > I see no proof of this anywhere. Huh. I see proof in your comment. > UMULH separate? Check. > UMULH has 1/4 and 6 expensive (relative to MUL)? Check.
- dmitrygr 8y agonot enough to explain the perf discrepancy. as i explained, both of these values 1/4 and 6 are hideable with proper instruction scheduling. at best author proved that arm gcc sucks at instruction scheduling, which is not news to anyone
- tntn 8y agoThen quote the claim that you are objecting to, not the statement of fact (which is what you have currently quoted).
- dmitrygr 8y agoobjection was to the implied claim that this is the cause for the slowdown. It is implied by the sentence structure and the preceding paragraph. I've expanded the quote to make it clearer. Thanks
- naniwaduni 8y agoA generation of programmers was indoctrinated to believe they couldn't beat the compiler. It is definitely surprisingly to find a popular compiler generating low-hanging fruit. For many use-cases, if code can't be written to get the compiler in use to generate that sequence of instructions, it might as well not exist.
- BeeOnRope 8y agoI mean 1/4 isn't hideable with "proper instruction scheduling" if you are doing a multiplication-heavy benchmark. No amount of scheduling gymnastics is going to get you more than 1 MULH per 4 cycles. Since the wyhash function needs 2 64x64->128 multiplication, you'll need two high and two low muls on ARM, so this is pretty much a dense multiplication benchmark. No amount of scheduling can save you. Still by my calculation that should only put the ARM chip at a 5x disadvantage in multiplication throughput, but it was nearly 18x slower. Frequency difference probably explains some of that, but not all.