15 ms·
Generating small code can be desirable - the uOP$ is a lot smaller than the I$ For example, compilers aren't very good at spotting overflows, so you can end up
by mhh__ 6y ago
Generating small code can be desirable - the uOP$ is a lot smaller than the I$
For example, compilers aren't very good at spotting overflows, so you can end up with a 150 instruction SIMD monster for the factorial function when pentium pro code could've been faster for the ints that matter.
All this x86 weirdness is partly why the schedulers compilers actually use are quite detached from the textbooks - GCC builds a FSM to model the decoder for example, as that's where a lot of the bottleneck will be for a CISC ISA like X86
- dragontamer 6y agouOPs are proprietary and undocumented: potentially changing between architectures even from the same company. So it's hard to generalize. But it's my understanding that uOPs are constant sized. Having a variable length uOP seems counterproductive. If something is so complex that it won't fit in one uOP, then it's probably preferable to encode it as two separate uOPs. We can get an idea of what is multiple uOPs by looking at the pipelines and latency charts. But even then: multiplication is likely one uOP despite taking multiple clock ticks of latency. So it's not exactly a precise science...
- gpderetta 6y agoThe number of uops for each instruction is well documented. IIRC uops can take more than one solt in the uop cache if they need to encode large constants, so they are technically variable length.
- mhh__ 6y agoWe know - and your compiler knows - exactly how many uOps are generated and which ports they execute on them - just not what they really do. Intel's performance counters can be fairly elucidating as to what your computer is doing - but - finding one you actually want can often mean scrolling through a list of thousands. My point is that small code is useful - unrolling a twice nested loop can kill performance if you aren't careful.
- tom_mellior 6y agoCould you explain how one would get a SIMD monster for a factorial function?
- nwallin 6y agohttps://godbolt.org/z/61xGW7 https://godbolt.org/z/61xGW7 Basically, the compiler isn't smart enough to realize that the loop in the factorial function couldn't possibly execute more than a few iterations before returning. Basically, it tries to do this: int a = 1; int b = 2; int c = 3; int d = 4; for (int i = 5; i < x; i += 4) { a *= i; b *= i + 1; c *= i + 2; d *= i + 3; } // handwave a bunch of crap about edge cases return a * b * c * d;
- mhh__ 6y agonwallin has provided an example. I think I've lost the results now, but when benchmarked it's basically neck and neck between size and speed but similar speed for less code is almost always a good thing in this case.