Aligned types and passing arguments by value

前端 未结 2 1704
日久生厌
日久生厌 2021-02-04 11:48

Passing aligned types or structures with aligned types by value doesn\'t work with some implementations. This breaks STL containers, because some of the methods (such as resize)

相关标签:
2条回答
  • 2021-02-04 12:22

    I think the only safe way to do this in general is to pass by reference. Some platforms (e.g. Xbox 360) support passing vector arguments in registers, but I don't think this is possible on x86.

    For the std::vector case, you'll need to make sure that the memory allocated is aligned to 16 bytes; otherwise you'll get crashes when you try to perform most operations on unaligned vectors.

    If you're supporting multiple platforms, a safe plan is to use a typedef e.g.

    typedef const MyVector& MyVectorParameter;
    

    You can then change the typedef on platforms that support vector pass-by-value.

    0 讨论(0)
  • 2021-02-04 12:29

    the oftenly used resize() function is causing all the alignment and perhaps you can try to specialise vector template for __m128 ?

    0 讨论(0)
提交回复
热议问题