demoii16_2.cpp
上传用户:husern
上传日期:2018-01-20
资源大小:42486k
文件大小:2k
源码类别:

游戏

开发平台:

Visual C++

  1. // DEMOII16_2.CPP - Hello world SIMD demo
  2. // I N C L U D E S ///////////////////////////////////////////////////////////
  3. #define WIN32_LEAN_AND_MEAN  
  4. #include <windows.h>   // include important windows stuff
  5. #include <windowsx.h> 
  6. #include <stdio.h>
  7. #include <math.h> 
  8. #include <xmmintrin.h> // <-- this is needed for SIMD support (SSE I)
  9. // MAIN //////////////////////////////////////////////////////////////////
  10. void main()
  11. {
  12. // print out os/processor support 
  13. if (IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE))
  14.    printf("nMMX Available.n");
  15. else
  16.    printf("nMMX NOT Available.n");
  17. if (IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE))
  18.    printf("nXMMI Available.n");
  19. else
  20.    {
  21.    printf("nXMMI NOT Available.n");
  22.    return;
  23.    } // end if
  24. // define 3 SIMD packed values, remember always must be 16byte aligned
  25. __declspec(align(16)) static float x[4] = {1,2,3,4};
  26. __declspec(align(16)) static float y[4] = {5,6,7,8};
  27. __declspec(align(16)) static float z[4] = {0,0,0,0};
  28. __m128 m0, m1, m2;
  29. // lets do a little SIMD to add X and Y and store the results in Z
  30. _asm
  31.    {
  32.    lea esi, x
  33.    movaps xmm0, [esi]  // move the value of x into XMM0
  34.    addps  xmm0, y  // add the value of y to XMM0
  35.    movaps z, xmm0  // store the results from XMM0 into z   
  36.    } // end asm
  37. // print the results
  38. printf("n x[%f,%f,%f,%f]", x[0], x[1], x[2], x[3]);
  39. printf("n+y[%f,%f,%f,%f]", y[0], y[1], y[2], y[3]);
  40. printf("n_______________________________________");
  41. printf("n=z[%f,%f,%f,%f]nn",  z[0], z[1], z[2], z[3]);
  42. } // end main