3 ms·
One major issue that causes C compiler optimizations to be necessary are impedance mismatches between the architecture and the language. bulitin/intrsinsic fun
by aidenn0 7y ago
One major issue that causes C compiler optimizations to be necessary are impedance mismatches between the architecture and the language. bulitin/intrsinsic functions are the "work around" for this, but they tend to be very non-portable (between compilers, and even sometimes between backends on the same compiler).
If you do this in C, most compilers will optimize into a 64-bit rotate:
(n << d)|(n >> (64 - d))
But that requires an optimizer.
Many compiler vendors have an extension that will compile to a rotate instruction, but they tend to differ from one compiler to another.
- akkartik 7y agoAuthor here. You didn't really ask a question, but I thought I'd mention a few things that may be related. 1. Mu isn't intended to be portable. There are no other backends, not even other processor families. Though you still have to put up with other processors within the same family, if it's a new instruction that older processors don't have. So far it just focuses on lowest-common-denominator 32-bit instructions. 2. The whole goal with Mu is to eliminate impedance mismatch with the architecture. It's relatively straightforward to add another instruction at the Mu level called 'rotate', and have it code-generate the appropriate x86 instruction. That seems less convoluted than assuming a fixed language and compiler and expressing a rotation out of 4 binary operators. 3. Finally, there's also the option of writing some functions in the 'machine code' level called SubX. Functions generated by Mu and SubX will freely inter-operate, though SubX functions lack safety guarantees.
- aidenn0 7y agoThanks for the clarifications!