Search
 
SCRIPT & CODE EXAMPLE
 

C

absolute value of intel intrinsic

#include <stdio.h>
#include <stdlib.h>
#include <intrin.h>

 void vectorAbs(double *x, double *y, unsigned int N);
 int main()
 {
     double x[] = { -1, -2, -3, -4, -5, -6 };
     double y[] = { 2, 2, 2, 2, 2, 2 };
     double *pX = x, *pY = y;

     vectorAbs(pX, pY, 6);
 }

__m128d abs_sample1 (__m128d val)
    {
    return _mm_castsi128_pd (_mm_srli_epi64 (_mm_slli_epi64 (_mm_castpd_si128 (val), 1), 1));
    }

__m128d abs_sample2 (__m128d val)
    {
    const __m128d mask = _mm_castsi128_pd (_mm_set1_epi64x (0x7FFFFFFFFFFFFFFF));
    return _mm_and_pd (mask, val);
    }

 void vectorAbs(double *x, double *y, unsigned int N)
 {
     __m128d xVar;
     __m128d yVar;

     printf("
Square of x : 
");
     for (int i = 0; i < N; i += 2)
     {
       xVar = _mm_loadu_pd(&x[i]);  // load *x[i] to xVar 

       yVar = abs_sample1(xVar); // abs of x
       _mm_storeu_pd(&y[i], yVar); // store yVar to y[i]
       printf("%lf, %lf, ", y[i], y[i + 1]);
     }
     system("pause");

}
Comment

PREVIOUS NEXT
Code Example
C :: unpack and repack deb package 
C :: open with overwrite c 
C :: chevront de vlavier 
C :: increment and decrement operator 
C :: pointer arithmetic on Arrray in c 
C :: c check if character is upper case 
C :: Happy birthday in C 
C :: c list 
C :: prime numbers 
C :: c check if character is a digit or alphabet 
C :: nested while loop in c 
C :: fifo in c 
C :: c program for assignment operator 
C :: realloc in c 
C :: north austin weather 
C :: localStorage.setItem multpile arra 
C :: 4 byte alignment c code 
C :: arduino vscode upload choosing sketch 
C :: semicolong after for() loop stackoverflow 
C :: how to find folders from a c program 
C :: Unix socket I/O primitives 
C :: table de hachage en c 
C :: c math.h sqrt 
C :: brew autoremove 
C :: WARNING: QA Issue: rdepends on 
C :: unia c 
C :: C Create union variables 
C :: resize vm boot disk with empty space 
C :: can we use special characters in switch case in c 
C :: split string at space C 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =