How to force C code to use a specific Intel instruction?

Viewed 114

I am calculating Entropy for a specific array of bytes. since I must calculate log2 of some numbers.

Here is part of the code

for (i = 0; i < ENTROPY_ARRAY_SIZE; i++) {
        if (entropy[i] == 0)
            continue;
        double p = (double)entropy[i] / data_len;
        H -= p * log2(p);
    }

We know that Intel supports two assembly instructions FYL2X and FYL2XP1 to perform the log2 operation faster. The problem is that even when I activated GCC optimization for compilation, the log2 assembly code is not based on Intel's specific instructions. Is there a way to force GCC to use specified instructions for this part of the code? (I checked and the CPU supports these instructions.)

0 Answers
Related