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