Advertisement
TukieEz

Untitled

Apr 19th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. Код проекта С++
  2.  
  3.  
  4. #include <Windows.h>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. float* Func_formula(float* square, float* height, float* three, float* res) {
  9. for (int i = 0; i < 8; i++)
  10. {
  11. res[i] = square[i] * height[i] / three[i];
  12. }
  13. return res;
  14. }
  15.  
  16. int main()
  17. {
  18. SetConsoleCP(1251);
  19. SetConsoleOutputCP(1251);
  20. HMODULE hModule;
  21. hModule = LoadLibrary(TEXT("D:/librarias/EVM/Lr4/Project1/x64/Debug/Project1.dll"));
  22. typedef void (*form)(float* square, float* height, float* three, float* res_sse);
  23. form formula = (form)GetProcAddress(hModule, "formula");
  24. int size = 8;
  25. float square[] = { 3.5, 2.2, 1.6, 2.2, 8.1, 4.1, 9.4, 10.2 };
  26. float height[] = { 6.2, 7.6, 9.1, 2.2, 8.1, 4.1, 9.4, 10.2 };
  27. float three[] = { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 };
  28. float res_sse[] = { 0,0,0,0,0,0,0,0 };
  29. float res_func[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  30.  
  31.  
  32. int time_start_1 = clock();
  33. for (int i = 0; i < 10000000; i++)
  34. {
  35. formula(square, height, three, res_sse);
  36. }
  37.  
  38. int time_end_1 = clock();
  39. cout << "asm time: " << time_end_1 - time_start_1 << endl;
  40.  
  41.  
  42. int time_start_2 = clock();
  43. for (int i = 0; i < 10000000; i++)
  44. {
  45. Func_formula(square, height, three, res_func);
  46. }
  47. int time_end_2 = clock();
  48. cout << "c++ time: " << time_end_2 - time_start_2 << endl;
  49.  
  50.  
  51.  
  52.  
  53. double Min, Max, Mid = 0.0, Current;
  54. Max = abs((res_sse[0] - res_func[0]) / res_func[0]);
  55. Min = Max;
  56. for (int i = 0; i < size; i++)
  57. {
  58. Current = abs((res_sse[i] - res_func[i]) / res_func[i]);
  59. Mid += Current;
  60. if (res_sse[i] - res_func[i] > Max) {
  61. Max = res_sse[i] - res_func[i];
  62. }
  63. if (Current < Min)
  64. Min = Current;
  65. }
  66. Mid = Mid / (1.0 * 8);
  67. cout << " Минимальная ошибка : " << Min << "\n";
  68. cout << "Максимальная ошибка : " << Max << "\n";
  69. cout << " Средняя ошибка : " << Mid << "\n";
  70. float max_func, max_sse, max_res = 0;
  71. int qq = 0;
  72. for (int i = 0; i < size; i++) {
  73. if (res_sse[i] - res_func[i] > max_res){
  74. max_res = res_sse[i] - res_func[i];
  75. max_sse = res_sse[i];
  76. max_func = res_func[i];
  77. qq = i;
  78. }
  79. }
  80. cout << max_res << " " << max_sse << " " << max_func << " " << qq;
  81. FreeLibrary(hModule);
  82. }
  83.  
  84.  
  85. ////////////////////////////////////////////////////////
  86.  
  87. Код ассемблера
  88.  
  89. public formula
  90.  
  91. _TEXT segment
  92.  
  93.  
  94. DllMain proc
  95.  
  96. mov rax, 2
  97. ret 12
  98. DllMain endp
  99.  
  100.  
  101.  
  102. formula proc export
  103.  
  104. movups xmm0, [rcx]
  105. movups xmm1, [rdx]
  106. movups xmm2, [r8]
  107.  
  108.  
  109. mov rax, 8
  110.  
  111. loop2:
  112. sub rax, 4
  113. mulps xmm0, xmm1
  114. divps xmm0, xmm2
  115.  
  116.  
  117. sub rcx, 16
  118. sub rdx, 16
  119.  
  120. movups [r9], xmm0
  121. add r9, 16
  122.  
  123. cmp rax, 0
  124. jnle loop2
  125.  
  126. ret
  127. formula endp
  128.  
  129.  
  130. _TEXT ends
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement