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

loads and stores with vectors can read/write more than the vector size #145

Open
sarah-quinones opened this issue Jun 12, 2020 · 2 comments

Comments

@sarah-quinones
Copy link

this function, for example

#define SIMDPP_ARCH_X86_AVX2
#include <simdpp/simd.h>

void sum(double* out, double const* lhs, double const* rhs) {
  using vec_t = simdpp::float64<1>;
  auto l = simdpp::load_u<vec_t>(lhs);
  auto r = simdpp::load_u<vec_t>(rhs);
  simdpp::store_u(out, l + r);
}

will load and write 4 doubles instead of a single one, which may result in an unexpected buffer overflow. is this the intended behavior?

@p12tic
Copy link
Owner

p12tic commented Jun 13, 2020

Indeed, the support for vectors of size smaller than the smallest native size is currently not fully implemented.

@sarah-quinones
Copy link
Author

sarah-quinones commented Jun 14, 2020

it's not just sizes smaller than the smallest native size. for example, the above code generates the correct instructions if we use float64<2>, but not with float64<3> (loads/stores 4 doubles) or even float64<6> (loads/stores 8 doubles).

i think vectors of size N that's a power of 2 and smaller than the smallest native size could be implemented as unaligned std::array<double, N> for example.
as for the ones that are of size N larger than the largest native size, we could implement them like this (assuming the largest size is 4 for example)

struct float64 {
  array<float64<4>, N/4> first;
  array<float64<2>, (N % 4) / 2> second;
  array<float64<1>, N % 2> third;
};

would this be an acceptable way of handling it?

EDIT: on second thought, it'd require slightly more work to handle the cases where the array sizes are 0. but it should still be feasible

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

2 participants