Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- time_t start, stop;
- struct wektor
- {
- float l1, l2, l3, l4;
- };
- struct wektor A, B;
- void losowanieLiczb() //uzupelnianie wektora liczbami
- {
- int przedzial1=1000;
- float przedzial2 = 4.12;
- srand(time(NULL));
- A.l1 = rand()%przedzial1/przedzial2;
- A.l2 = rand()%przedzial1/przedzial2;
- A.l3 = rand()%przedzial1/przedzial2;
- A.l4 = rand()%przedzial1/przedzial2;
- B.l1 = rand()%przedzial1/przedzial2;
- B.l2 = rand()%przedzial1/przedzial2;
- B.l3 = rand()%przedzial1/przedzial2;
- B.l4 = rand()%przedzial1/przedzial2;
- }
- float dodawanie(int ile_liczb) //dodawanie
- {
- struct wektor V;
- int q, w;
- float czas;
- float sredni_czas=0;
- for(q=0;q<10;q++){
- losowanieLiczb();
- start=clock();
- for(w=0;w<ile_liczb;w++){
- //losowanieLiczb();
- //start=clock();
- //__asm( "movl $A, %eax\n"
- // "movl $B, %ebx\n"
- // "movups (%eax), %xmm0\n"
- // "movups (%ebx), %xmm1\n"
- // "addps %xmm1, %xmm0\n"
- __asm(
- "movups A, %xmm0\n"
- "movups B, %xmm1\n"
- "addps %xmm0, %xmm1\n"
- "movups %xmm1, A\n"
- );
- //stop=clock();
- //czas= (double)(stop-start)/CLOCKS_PER_SEC;
- //sredni_czas= sredni_czas+czas;
- }
- stop=clock();
- czas= (double)(stop-start)/CLOCKS_PER_SEC;
- sredni_czas= sredni_czas+czas;
- }
- return sredni_czas/10;
- }
- double odejmowanie(int ile_liczb) //odejmowanie
- {
- int q, w;
- double czas;
- double sredni_czas=0;
- for(q=0;q<10;q++){
- losowanieLiczb();
- start=clock();
- for(w=0;w<ile_liczb;w++){
- __asm(
- "movups A, %xmm0\n"
- "movups B, %xmm1\n"
- "subps %xmm0, %xmm1\n"
- "movups %xmm1, A\n"
- );
- }
- stop=clock();
- czas= (double)(stop-start)/CLOCKS_PER_SEC;
- sredni_czas= sredni_czas+czas;
- }
- return sredni_czas/10;
- }
- double mnozenie(int ile_liczb) //mnozenie
- {
- int q, w;
- double czas;
- double sredni_czas=0;
- for(q=0;q<10;q++){
- losowanieLiczb();
- start=clock();
- for(w=0;w<ile_liczb;w++){
- __asm(
- "movups A, %xmm0\n"
- "movups B, %xmm1\n"
- "mulps %xmm0, %xmm1\n"
- "movups %xmm1, A\n"
- );
- }
- stop=clock();
- czas= (double)(stop-start)/CLOCKS_PER_SEC;
- sredni_czas= sredni_czas+czas;
- }
- return sredni_czas/10;
- }
- double dzielenie(int ile_liczb) //dzielenie
- {
- int q, w;
- double czas;
- double sredni_czas=0;
- for(q=0;q<10;q++){
- losowanieLiczb();
- start=clock();
- for(w=0;w<ile_liczb;w++){
- __asm(
- "movups A, %xmm0\n"
- "movups B, %xmm1\n"
- "divps %xmm0, %xmm1\n"
- "movups %xmm1, A\n"
- );
- }
- stop=clock();
- czas= (double)(stop-start)/CLOCKS_PER_SEC;
- sredni_czas= sredni_czas+czas;
- }
- return sredni_czas/10;
- }
- int main()
- {
- dodawanie(2048);
- printf("\nTyp obliczen: SIMD\n");
- printf("Liczba liczb: %i\n", 2048);
- printf("Sredni czas [s]:\n");
- printf("+ %f\n", dodawanie(2048/4));
- printf("- %f\n", odejmowanie(2048/4));
- printf("* %f\n", mnozenie(2048/4));
- printf("/ %f\n", dzielenie(2048/4));
- printf("\nTyp obliczen: SIMD\n");
- printf("Liczba liczb: %i\n", 4096);
- printf("Sredni czas [s]:\n");
- printf("+ %f\n", dodawanie(4096/4));
- printf("- %f\n", odejmowanie(4096/4));
- printf("* %f\n", mnozenie(4096/4));
- printf("/ %f\n", dzielenie(4096/4));
- printf("\nTyp obliczen: SIMD\n");
- printf("Liczba liczb: %i\n", 8196);
- printf("Sredni czas [s]:\n");
- printf("+ %f\n", dodawanie(8192/4));
- printf("- %f\n", odejmowanie(8192/4));
- printf("* %f\n", mnozenie(8192/4));
- printf("/ %f\n", dzielenie(8192/4));
- //printf("ilosc liczb= %i\n", liczba*4);
- //printf("czas dodawania= %f\n", wynik_add);
- //printf("czas odejmowania= %f\n", wynik_sub);
- //printf("czas mnozenia= %f\n", wynik_mul);
- //printf("czas dzielenia= %f\n\n", wynik_div);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement