Skip to content

Instantly share code, notes, and snippets.

@tejainece
Created April 27, 2024 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tejainece/7f848f28aa048ea03839c94b14473b90 to your computer and use it in GitHub Desktop.
Save tejainece/7f848f28aa048ea03839c94b14473b90 to your computer and use it in GitHub Desktop.
SIMD trials
//
// Created by tejag on 2024-04-26.
//
#include <cxxabi.h>
#include <experimental/simd>
#include <iostream>
#include <vector>
template <typename T> void printType() {
std::cout << abi::__cxa_demangle(typeid(T).name(), NULL, NULL, NULL);
}
namespace stdx = std::experimental;
int main() {
using toFloat = stdx::rebind_simd_t<float, stdx::fixed_size_simd<uint8_t, 4>>;
std::vector<uint8_t> v = {1, 2, 3, 4};
stdx::fixed_size_simd<uint8_t, 4> a(v.data(), stdx::vector_aligned);
auto fs = stdx::simd_cast<toFloat>(a) + 0.5f;
std::vector<float> out(4);
fs.copy_to(out.data(), stdx::vector_aligned);
for (auto i : out) {
std::cout << i << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment