Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;asm lib sse
- public maximum
- public Summ
- public Vpir
- _TEXT segment
- DllMain proc
- mov rax, 2
- ret 12
- DllMain endp
- maximum proc export
- movups xmm0, [rcx]
- movups xmm1, [rdx]
- maxps xmm0, xmm1
- movups [r9], xmm0;
- sub rcx, 16
- add r9, 16
- movups [r9], xmm0;
- ;movups [rax], xmm0
- ret
- maximum endp
- Summ proc export
- movups xmm0, [rcx]
- movups xmm1, [rdx]
- mov rax, 8
- add_loop:
- sub rax, 4
- addps xmm0, xmm1
- sub rcx, 16
- sub rdx, 16
- movups [r9], xmm0
- add r9, 16
- cmp rax, 0
- jnle add_loop
- ;movups [r9], xmm0
- ret
- Summ endp
- Vpir proc export
- movups xmm0, [rcx] ;S
- movups xmm1, [rdx] ;V
- movups xmm2, [r8]; 3
- 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
- Vpir endp
- _TEXT ends
- end
- //client c++
- #include <Windows.h>
- #include <iostream>
- using namespace std;
- typedef float* (WINAPI* Summ)(float*, float*, int, float*);
- typedef float* (WINAPI* Vpd)(float*, float*, float*, float*);
- // v = S * H / 3
- float* Vpiramid(float* square, float* height, float* three, float* res) {
- for (int i = 0; i < 3; i++)
- {
- res[i] = square[i] * height[i] / three[i];
- }
- return res;
- }
- int main()
- {
- HMODULE hModule, hModule1;
- hModule = LoadLibrary(TEXT("asm_sse.dll"));
- if (hModule == NULL) return -1;
- Summ sum = (Summ)GetProcAddress(hModule, "Summ");
- Vpd Vpir = (Vpd)GetProcAddress(hModule, "Vpir");
- 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 norm[] = { 0,0,0,0,0,0,0,0 };
- float result[] = { 2.1, 1.2, 2.3, 4.4, 6.5, 10.6, 2.7, 8.8};
- float notres[] = { 3.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7, 11.8 };
- float n[] = {0, 0, 0, 0, 0, 0, 0, 0};
- /*sum(result, notres, 8, n);
- for (int i = 0; i < 8; i++)
- {
- cout << result[i] << endl;
- }
- cout << "\n\n\n" << endl;*/
- int time_start_1 = clock();
- //Vpir(square, height, three, norm);
- for (int i = 0; i < 100000000; i++)
- {
- Vpir(square, height, three, norm);
- }
- /*for (int i = 0; i < size; i++)
- {
- cout << norm[i] << endl;
- }*/
- 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 < 100000000; i++)
- {
- Vpiramid(square, height, three, norm);
- }
- int time_end_2 = clock();
- cout << "c++ time: " << time_end_2 - time_start_2 << endl;
- FreeLibrary(hModule);
- //FreeLibrary(hModule1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement