4 ms·
I don’t have much knowledge on the low-level intricacies of CPUs, could someone please answer a question of mine? There is an older, famous post titled somethi
by kaba0 6y ago
I don’t have much knowledge on the low-level intricacies of CPUs, could someone please answer a question of mine?
There is an older, famous post titled something like “C is not a low-level language”, and relatedly one that assembly itself is not all that low-level today.
I do now almost nothing about the state of today’s CPUs, only that they are extensively complex with long pipelines and that branch prediction is a thing. Also, several layers of caches. x86 on top is almost only an API which frees the hardware engineers from backward compatibility, since these intricacies are programmed by microcodes that are not really accessible to general software.
My question is, wouldn’t a “dumber” processor be better with a more expressive “API”, with instructions like prefetch, some form of parallelism (so that pipelines can be created with machine code and not just heuristics), since it is probably easier and better to branch predict in software than in hardware? In a way current processors sort of JIT compile assembly to some hardware-native form, but if those hardware-level tools were accessible to software, software could do much much better optimizations and bugs could be patched.
- ori_b 6y agoDo you really want to write the code for this as a programmer?
- kaba0 6y agoNot me, but a compiler backend would perhaps have better “materials” for optimization this way. There is no reason for existing higher level code to not be transformable to this “microcode”
- ori_b 6y agoA compiler backend would have to do it statically, and would not be able to do it based on the workload that's being run. The argument to expose this sort of control would be because domain knowledge would allow higher level domain knowledge to be used to tune the prefetching manually.
- kaba0 6y agoThere are JIT compiled languages as well, that could potentially utilize it
- glhaynes 6y agoI'm no expert on such things but your proposal sounds similar (or at least maybe adjacent to) VLIW in the sense of pushing a lot of the smarts to the compiler. It seems to have had some isolated successes but not nearly as much as it was hyped to in the 1990s. https://en.wikipedia.org/wiki/Very_long_instruction_word https://en.wikipedia.org/wiki/Very_long_instruction_word
- bluGill 6y ago> My question is, wouldn’t a “dumber” processor be better with a more expressive “API”, with instructions like prefetch, some form of parallelism (so that pipelines can be created with machine code and not just heuristics), since it is probably easier and better to branch predict in software than in hardware? No. I'll list the reasons I know, but a real hardware designer will know even more. There are many different ways to design hardware. The right thing to prefetch changes with different implementations. Unless you think everyone is going to ship source code?
- kaba0 6y agoNot necessarily source code, but some intermediate representation (even perhaps x86, and then going through a software compiler that converts it to this lower level language in hardware, inserting cache fetches where necessary. But probably a higher level representation, for example JVM byte code could be better optimised)
- qwertycrackers 6y agoThis is kinda what motivated Intel's Itanium architecture. You should look into that to see why what you're proposing makes sense, but hasn't gotten traction.
- ThrowawayR2 6y ago> "...instructions like prefetch..." Things like that already exist, e.g. for x86: https://c9x.me/x86/html/file_module_x86_id_252.html https://c9x.me/x86/html/file_module_x86_id_252.html > "...some form of parallelism (so that pipelines can be created with machine code and not just heuristics)..." Not sure exactly what is meant by this. Either the answer is the hardware already automatically maximizes parallelization (https://en.wikipedia.org/wiki/Superscalar_processor https://en.wikipedia.org/wiki/Superscalar_processor) or the answer is that there's no way to physically rewire a chip on the fly. > "...since it is probably easier and better to branch predict in software than in hardware..." Been tried, doesn't seem to have been that successful IIRC. A cursory Google shows that x86 had (and dropped) branch hint prefixes for instructions and the Cell's SPUs had branch hint instructions as well. Various languages also allow exposing branch prediction hints to the compiler, e.g.: https://en.cppreference.com/w/cpp/language/attributes/likely https://en.cppreference.com/w/cpp/language/attributes/likely