Advertisement
Teammasik

laba_5_EVM

Apr 4th, 2023
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. ;asm lib sse
  2. public maximum
  3. public Summ
  4. public Vpir
  5.  
  6. _TEXT segment
  7.  
  8.  
  9. DllMain proc
  10.  
  11. mov rax, 2
  12. ret 12
  13. DllMain endp
  14.  
  15.  
  16. maximum proc export
  17.  
  18.  
  19. movups xmm0, [rcx]
  20. movups xmm1, [rdx]
  21. maxps xmm0, xmm1
  22.  
  23. movups [r9], xmm0;
  24. sub rcx, 16
  25. add r9, 16
  26. movups [r9], xmm0;
  27. ;movups [rax], xmm0
  28.  
  29. ret
  30. maximum endp
  31.  
  32.  
  33. Summ proc export
  34. movups xmm0, [rcx]
  35. movups xmm1, [rdx]
  36. mov rax, 8
  37.  
  38. add_loop:
  39. sub rax, 4
  40. addps xmm0, xmm1
  41. sub rcx, 16
  42. sub rdx, 16
  43. movups [r9], xmm0
  44. add r9, 16
  45.  
  46. cmp rax, 0
  47. jnle add_loop
  48. ;movups [r9], xmm0
  49. ret
  50. Summ endp
  51.  
  52. Vpir proc export
  53.  
  54. movups xmm0, [rcx] ;S
  55. movups xmm1, [rdx] ;V
  56. movups xmm2, [r8]; 3
  57.  
  58.  
  59. mov rax, 8
  60.  
  61. loop2:
  62. sub rax, 4
  63. mulps xmm0, xmm1
  64. divps xmm0, xmm2
  65.  
  66.  
  67. sub rcx, 16
  68. sub rdx, 16
  69.  
  70. movups [r9], xmm0
  71. add r9, 16
  72.  
  73. cmp rax, 0
  74. jnle loop2
  75.  
  76. ret
  77. Vpir endp
  78.  
  79.  
  80. _TEXT ends
  81. end
  82.  
  83.  
  84. //client c++
  85. #include <Windows.h>
  86. #include <iostream>
  87. using namespace std;
  88.  
  89. typedef float* (WINAPI* Summ)(float*, float*, int, float*);
  90. typedef float* (WINAPI* Vpd)(float*, float*, float*, float*);
  91.  
  92. // v = S * H / 3
  93. float* Vpiramid(float* square, float* height, float* three, float* res) {
  94. for (int i = 0; i < 3; i++)
  95. {
  96. res[i] = square[i] * height[i] / three[i];
  97. }
  98. return res;
  99. }
  100.  
  101. int main()
  102. {
  103.  
  104. HMODULE hModule, hModule1;
  105. hModule = LoadLibrary(TEXT("asm_sse.dll"));
  106. if (hModule == NULL) return -1;
  107.  
  108. Summ sum = (Summ)GetProcAddress(hModule, "Summ");
  109.  
  110. Vpd Vpir = (Vpd)GetProcAddress(hModule, "Vpir");
  111.  
  112. int size = 8;
  113. float square[] = { 3.5, 2.2, 1.6, 2.2, 8.1, 4.1, 9.4, 10.2};
  114. float height[] = { 6.2, 7.6, 9.1, 2.2, 8.1, 4.1, 9.4, 10.2 };
  115. float three[] = { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 };
  116. float norm[] = { 0,0,0,0,0,0,0,0 };
  117.  
  118.  
  119.  
  120. float result[] = { 2.1, 1.2, 2.3, 4.4, 6.5, 10.6, 2.7, 8.8};
  121. float notres[] = { 3.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7, 11.8 };
  122. float n[] = {0, 0, 0, 0, 0, 0, 0, 0};
  123.  
  124. /*sum(result, notres, 8, n);
  125. for (int i = 0; i < 8; i++)
  126. {
  127. cout << result[i] << endl;
  128. }
  129. cout << "\n\n\n" << endl;*/
  130.  
  131. int time_start_1 = clock();
  132. //Vpir(square, height, three, norm);
  133. for (int i = 0; i < 100000000; i++)
  134. {
  135. Vpir(square, height, three, norm);
  136. }
  137. /*for (int i = 0; i < size; i++)
  138. {
  139. cout << norm[i] << endl;
  140. }*/
  141.  
  142. int time_end_1 = clock();
  143. cout << "asm time: " << time_end_1 - time_start_1 << endl;
  144.  
  145.  
  146. int time_start_2 = clock();
  147. for (int i = 0; i < 100000000; i++)
  148. {
  149. Vpiramid(square, height, three, norm);
  150. }
  151. int time_end_2 = clock();
  152. cout << "c++ time: " << time_end_2 - time_start_2 << endl;
  153.  
  154. FreeLibrary(hModule);
  155. //FreeLibrary(hModule1);
  156. }
  157.  
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement