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

adicionado atividade2 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions Atividade2/avx1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Exemplo de código AVX utilizando Intel instrinsics e gcc built-in functions
Compile usando:
gcc avx.c -o avx -mavx -O3
http://www.songho.ca/misc/sse/sse.html
https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/X86-Built-in-Functions.html#X86-Built-in-Functions
https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Vector-Extensions.html#Vector-Extensions
https://software.intel.com/sites/landingpage/IntrinsicsGuide/
https://msdn.microsoft.com/en-us/library/26td21ds.aspx
AVX
https://software.intel.com/en-us/articles/introduction-to-intel-advanced-vector-extensions/
*/

#include <stdio.h>

#include <immintrin.h> // AVX


#define VECTOR_SIZE 64

typedef float v8sf __attribute__ ((vector_size(sizeof(float)*VECTOR_SIZE)));



void add_intel_intrinsics(float *y, float *w)
{
__m256 vy = _mm256_load_ps (y);
__m256 vw = _mm256_load_ps (w);


}



int main (int argc, char *argv[])
{
float *y = (float*)_mm_malloc (sizeof(float) * VECTOR_SIZE, 32); //aloca um vetor de 32 bytes (256 bits) alinhado em endereços múltiplos de 16 bytes.
float *w = (float*)_mm_malloc (sizeof(float) * VECTOR_SIZE, 32);



int i = 0;

for (i = 0; i < VECTOR_SIZE; ++i) {
y[i] = i;
w[i] = i;
}


__m256 d = {10, 10, 10, 10, 10, 10, 10, 10}; // mascara que vai modificar o vetor



for (i = 0; i < VECTOR_SIZE - 7; i+=8) { //divide o vetor em pedaços de tamanho 8, para modificar cada pedaço separadamente
__m256 vy = _mm256_load_ps(&y[i]); // y= imagem
__m256 vw = vy * d; // resultado = imagem * mascara
_mm256_store_ps(&w[i],vw);
}

for (i = 0; i < VECTOR_SIZE; i++) { //divide o vetor em pedaços de tamanho 8, para modificar cada pedaço separadamente
printf("%f\n", w[i]);
}

return 0;
}