echosse.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright Oliver Kowalke 2009.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <cstddef>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <iostream>
  9. #include <emmintrin.h>
  10. #include <boost/context/fiber.hpp>
  11. namespace ctx = boost::context;
  12. void echoSSE( int i) {
  13. __m128i xmm;
  14. xmm = _mm_set_epi32( i, i + 1, i + 2, i + 3);
  15. uint32_t v32[4];
  16. memcpy( & v32, & xmm, 16);
  17. std::cout << v32[0];
  18. std::cout << v32[1];
  19. std::cout << v32[2];
  20. std::cout << v32[3];
  21. }
  22. int main( int argc, char * argv[]) {
  23. int i = 0;
  24. ctx::fiber f{
  25. [&i](ctx::fiber && f) {
  26. for (;;) {
  27. std::cout << i;
  28. echoSSE( i);
  29. std::cout << " ";
  30. f = std::move( f).resume();
  31. }
  32. return std::move( f);
  33. }};
  34. for (; i < 11; ++i) {
  35. f = std::move( f).resume();
  36. }
  37. std::cout << "\nmain: done" << std::endl;
  38. return EXIT_SUCCESS;
  39. }