Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Код проекта С++
- #include <Windows.h>
- #include <iostream>
- using namespace std;
- float* Func_formula(float* square, float* height, float* three, float* res) {
- for (int i = 0; i < 8; i++)
- {
- res[i] = square[i] * height[i] / three[i];
- }
- return res;
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- HMODULE hModule;
- hModule = LoadLibrary(TEXT("D:/librarias/EVM/Lr4/Project1/x64/Debug/Project1.dll"));
- typedef void (*form)(float* square, float* height, float* three, float* res_sse);
- form formula = (form)GetProcAddress(hModule, "formula");
- int size = 8;
- float square[] = { 3.5, 2.2, 1.6, 2.2, 8.1, 4.1, 9.4, 10.2 };
- float height[] = { 6.2, 7.6, 9.1, 2.2, 8.1, 4.1, 9.4, 10.2 };
- float three[] = { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 };
- float res_sse[] = { 0,0,0,0,0,0,0,0 };
- float res_func[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
- int time_start_1 = clock();
- for (int i = 0; i < 10000000; i++)
- {
- formula(square, height, three, res_sse);
- }
- int time_end_1 = clock();
- cout << "asm time: " << time_end_1 - time_start_1 << endl;
- int time_start_2 = clock();
- for (int i = 0; i < 10000000; i++)
- {
- Func_formula(square, height, three, res_func);
- }
- int time_end_2 = clock();
- cout << "c++ time: " << time_end_2 - time_start_2 << endl;
- double Min, Max, Mid = 0.0, Current;
- Max = abs((res_sse[0] - res_func[0]) / res_func[0]);
- Min = Max;
- for (int i = 0; i < size; i++)
- {
- Current = abs((res_sse[i] - res_func[i]) / res_func[i]);
- Mid += Current;
- if (res_sse[i] - res_func[i] > Max) {
- Max = res_sse[i] - res_func[i];
- }
- if (Current < Min)
- Min = Current;
- }
- Mid = Mid / (1.0 * 8);
- cout << " Минимальная ошибка : " << Min << "\n";
- cout << "Максимальная ошибка : " << Max << "\n";
- cout << " Средняя ошибка : " << Mid << "\n";
- float max_func, max_sse, max_res = 0;
- int qq = 0;
- for (int i = 0; i < size; i++) {
- if (res_sse[i] - res_func[i] > max_res){
- max_res = res_sse[i] - res_func[i];
- max_sse = res_sse[i];
- max_func = res_func[i];
- qq = i;
- }
- }
- cout << max_res << " " << max_sse << " " << max_func << " " << qq;
- FreeLibrary(hModule);
- }
- ////////////////////////////////////////////////////////
- Код ассемблера
- public formula
- _TEXT segment
- DllMain proc
- mov rax, 2
- ret 12
- DllMain endp
- formula proc export
- movups xmm0, [rcx]
- movups xmm1, [rdx]
- movups xmm2, [r8]
- mov rax, 8
- loop2:
- sub rax, 4
- mulps xmm0, xmm1
- divps xmm0, xmm2
- sub rcx, 16
- sub rdx, 16
- movups [r9], xmm0
- add r9, 16
- cmp rax, 0
- jnle loop2
- ret
- formula endp
- _TEXT ends
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement