Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this Out-of-bounds access? #42

Open
torshepherd opened this issue Nov 8, 2023 · 1 comment
Open

Is this Out-of-bounds access? #42

torshepherd opened this issue Nov 8, 2023 · 1 comment

Comments

@torshepherd
Copy link

version / revision Operating System Compiler & Version Compiler Flags CPU
GCC11 Linux GCC11 -mavx2 -mfma -mavx tigerlake

Testcase

namespace stdx = std::experimental;

static auto indexSimd = stdx::native_simd<int>{[](int i){ return i; }};

stdx::native_simd<int> b;
int a[3]{42, 43, 44};
stdx::where(indexSimd < 3, b).copy_from(a, stdx::element_aligned);

Does this access memory out of bounds? I am pretty sure this code would:

b.copy_from(a, stdx::element_aligned);

But I would expect the former to do a maskload such that it doesn't touch the shadow 4th element?

If this is UB, is there any good way to load a partial SIMD from a contiguous region safely? This would be very valuable for iterating over for example a std::vector of length that is not necessarily divisible by the vector block size

Actual Results

Expected Results

@torshepherd
Copy link
Author

Ok according to godbolt+ASAN there is no OOB access. But can I count on that?

https://godbolt.org/z/7vqaM85Kh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant