Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tarefa 1,2 aprendi a manda esse negocio #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions ex2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdio.h>

#include <immintrin.h>

void crepusculo(float *imgin, float *imgout, __m256 intens)
{
__m256 vimgin = _mm256_load_ps (imgin);
__m256 vimgout = _mm256_add_ps (vimgin, intens);
_mm256_store_ps(imgout, vimgout);

/* Equivalente Assembly
** mov eax, a
** mov edx, b
** mov ecx, c
** movaps xmm0, XMMWORD PTR [eax]
** addps xmm0, XMMWORD PTR [edx]
** movaps XMMWORD PTR [ecx], xmm0
*/
}

int main (int argc, char *argv[])
{

__m256 intens = _mm256_set1_ps(50);

float *imgin = (float*)_mm_malloc (sizeof(float) *96, 32); //aloca um vetor de 32 bytes (256 bits) alinhado em endereços múltiplos de 16 bytes.
float *imgout = (float*)_mm_malloc (sizeof(float) *96, 32);

int i = 0;

for (i = 0; i < 96; ++i) {
imgin[i] = i;
}

for (i = 0; i <= 96 - 8; i+=8) {
crepusculo(&imgin[i], &imgout[i], intens);
}

printf("Vai da certo");

for (i = 0; i < 96; ++i) {
printf("%f\n",imgout[i]);
}

}
49 changes: 49 additions & 0 deletions ex3.1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <immintrin.h> // AVX MUITO LOCO - novo Hero da Marvel
#define MAX 50000

void produtoEscalar(int imgIn[], int mult[], int result[], int n)
{
int i, j;
for (i = 0; i < n; i++){
for(j=0;j<3;j++){
result[i] += imgIn[i]*mult[j];
}
}
}


int main()
{
int i = 0;
srand(time(NULL));
int imgIn[MAX];
int result[MAX];
int mult[3] = {1,2,3};

for(i=0;i<MAX;i++){
result[i] = 0;
}

for(i=0;i<MAX;i++){
imgIn[i] = rand() % 10;
}


clock_t tic = clock();

for(i=0;i<50;i++){

produtoEscalar(imgIn, mult, result, MAX);

}

clock_t toc = clock();

printf("Elapsed: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);

return 0;
}
39 changes: 39 additions & 0 deletions ex3.2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <immintrin.h> // AVX MUITO LOCO - novo Hero da Marvel
#define MAX 50000

int main(){

float *imgIn = (float*)_mm_malloc (sizeof(float) * MAX, 32);
float *imgOut = (float*)_mm_malloc (sizeof(float) * MAX, 32);
float *mult = (float*)_mm_malloc (sizeof(float) * 8, 32);
mult[0] = 1;
mult[1] = 2;
mult[2] = 3;
int i = 0, j = 0, k = 0;

for (i = 0; i < MAX; i++) {
imgOut[i] = 0;
}

__m256 vImgIn = _mm256_load_ps(imgIn);
__m256 vImgOut = _mm256_load_ps(imgOut);
__m256 vmult = _mm256_load_ps(mult);

clock_t tic = clock();

for(k = 0;k<50;k++){
for(i=0;i<=MAX-8;i+=8){
for(j=0;j<3;j++){
vImgOut += _mm256_mul_ps(vImgIn, vmult);
}
}
}
clock_t toc = clock();

printf("\n\n Essa bagaca demorou: %f fuking segundos\n", (double)(toc - tic) / CLOCKS_PER_SEC);

}