How to write the same value to sequential locations in x86

I need to do the following code very efficiently with an x86 internal machine. Can anyone suggest a solution?

uint64_t array[8];
array[0] = SOME_VALUE;
array[1] = SOME_VALUE;
array[2] = SOME_VALUE;
array[3] = SOME_VALUE;
array[4] = SOME_VALUE;
array[5] = SOME_VALUE;
array[6] = SOME_VALUE;
array[7] = SOME_VALUE;

      

Since the same value is written to sequential locations, if the eigenvector / SSE can do this efficiently, I would like to try this.

+3


source to share


2 answers


While I don't know the vector / SSE instructions, I have found that sometimes looking at the generated code shows that the compiler knows the optimal machine code, and you will find that it is already generating what you were hoping for.It is worth looking at the generated code.



0


source


Use memset

. glibc will take care of the optimization for you. If you think you can do better, you should submit the patch to the mailing list.



Also, "command speed" is hardly a bottleneck here. This is probably the memory bandwidth. Unfortunately, there is no magic bullet to reduce it other than "reading and writing less memory".

0


source







All Articles