是否可以强制 GCC 在没有内联汇编的情况下输出我给它的精确按位指令?
Is it possible to force GCC to output the exact bitwise instructions I give it without inline assembly?
我编写的代码如下所示:
char* xor_and_print(byte arr[], size_t buffSize, byte key)
{
size_t i;
for(i = 0; i < buffSize; i++)
{
printf("%c", (arr[i] & ~key) | (key & ~arr[i]));
}
putchar('\n');
}
这是一个分解为更多指令的异或运算。我正在使用 gcc-6.3.0。即使我使用 -O0
标志进行编译,gcc 也会在反汇编中将其转换为一条 xor
指令。是否可以用标志强制它编写那些特定的 asm 指令,或者我必须使用内联汇编语言?
使用volatile
应该避免这种优化:
for(i = 0; i < buffSize; i++)
{
byte volatile b = arr[i];
printf("%c", (b & ~key) | (key & ~b));
}
但对于更高的优化级别,它也会保持未优化状态。
我编写的代码如下所示:
char* xor_and_print(byte arr[], size_t buffSize, byte key)
{
size_t i;
for(i = 0; i < buffSize; i++)
{
printf("%c", (arr[i] & ~key) | (key & ~arr[i]));
}
putchar('\n');
}
这是一个分解为更多指令的异或运算。我正在使用 gcc-6.3.0。即使我使用 -O0
标志进行编译,gcc 也会在反汇编中将其转换为一条 xor
指令。是否可以用标志强制它编写那些特定的 asm 指令,或者我必须使用内联汇编语言?
使用volatile
应该避免这种优化:
for(i = 0; i < buffSize; i++)
{
byte volatile b = arr[i];
printf("%c", (b & ~key) | (key & ~b));
}
但对于更高的优化级别,它也会保持未优化状态。