How to determine if memory is aligned?

后端 未结 8 2340
生来不讨喜
生来不讨喜 2020-11-29 18:27

I am new to optimizing code with SSE/SSE2 instructions and until now I have not gotten very far. To my knowledge a common SSE-optimized function would look like this:

<
8条回答
  •  鱼传尺愫
    2020-11-29 18:37

    EDIT: casting to long is a cheap way to protect oneself against the most likely possibility of int and pointers being different sizes nowadays.

    As pointed out in the comments below, there are better solutions if you are willing to include a header...

    A pointer p is aligned on a 16-byte boundary iff ((unsigned long)p & 15) == 0.

提交回复
热议问题