3 ms·
This... should not even be a hard thing.
by flamedoge 10y ago
This... should not even be a hard thing.
- DannyBee 10y agoThe dynamic dispatch is not a hard thing. For C, in fact, you get "whatever", and that's even legal. For C++, the problem is templates, etc, are linkonce, and you can't choose which it's going to pick (ie the problem described in the article). You also can get screwed by inlining, etc. Function multi-versioning alone does not solve this well, you really need a way to make the ABI part of the template arguments or something to do it well. There are other issues.
- brucedawson 10y agoDynamic dispatch is not a hard thing. And in fact the article treats dynamic dispatch as being too simple to be worthy of discussion. The article is about the subtle problems that can happen after you have dynamically dispatched. How do you think that compilers and linkers should handle the problems of non-inlined inline functions in the face of /arch:AVX? Saying that it should not even be a hard thing doesn't help much.
- flamedoge 10y agoThe way the author is using it to generate both AVX and non-AVX code is such a hack that I find it hard to believe it even worked. It is literally a ticking time bomb that depends on compiler's inliner heuristics to trigger. Compilers and linkers should be able to generate and optimize different code paths -- it shouldn't have to take hacking and tinkering with tools to do something. To make it sound worse, that something isn't even guaranteed to be safe even with hacky build. Literally the only two things it takes to do this are a conditional check based on CPUID result and CodeGen support for generating multiple Arch paths. If you have those two, multi-version function is very likely to work with safety. Edit: oh, you are the author. I hope you weren't offended. I meant none.
- alfalfasprout 10y agoLike others have said it's not a "hard thing" per se. It's that few implementations actually work correctly in most of the edge cases. Manual dispatch is, of course, doable. Agner Fog's optimization guide has a pretty decent walkthrough of writing your own dispatcher and even he has to go through a bunch of caveats.