Please advise on dealing with compiler issue
I am adding code to the sparc64 kernel that would require reading/writing one of the new registers on M7 processor, namely MCDPER. There are three ways I know of to do this:
1. __asm__ __volatile__("rd %%mcdper, %0\n\t": "=r" (tmp)) - This is the best way to do it but the support for %%mcdper is available in binutils 2.26 and newer only. Compiling the kernel with older binutils will cause build failure.
2. __asm__ __volatile__("rd %%asr14, %0\n\t": "=r" (tmp)) - This should work independent of binutils version but it does not due to two bugs in assembler that have been fixed recently but not in a released version yet - <https://sourceware.org/ml/binutils/2016-03/msg00302.html>,
<https://sourceware.org/ml/binutils/2016-03/msg00303.html>.
3. .byte 0x83,0x43,0x80,0x00 - This is byte coded equivalent of "rd %asr14, %g1". This works independent of binutils version but is ugly and requires pre-assigning a register to read MCDPER into, which does not help compiler with optimization.
Of the three options, only option 3 can work without requiring everyone compiling kernel to update to latest binutils.
Please advise on best way to proceed.
Thanks,
Khalid
From: Khalid Aziz <[email protected]>
Date: Wed, 20 Apr 2016 09:08:02 -0600
Quoted 4 lines
3. .byte 0x83,0x43,0x80,0x00 - This is byte coded equivalent of "rd %asr14, %g1". This works independent of binutils version but is ugly and requires pre-assigning a register to read MCDPER into, which does not help compiler with optimization.
The register read is so expensive relative to executing other instructions, that I don't think compiler optimizations are a valid consideration at all.
This is the only valid option given the constraints, and you should use ".word xxxxx" just like we do for other similar hard coded instruction sequences.
Thanks.