Please enter what you're looking for to continue your search
 

vec_abs
ADD TO COMPARE ADDED TO COMPARE

 IBM Power 9 64-bit (64 bits)/ VSX  View official documentation
Purpose:

Returns a vector output that contains the absolute values of the contents of the vector a.

The value of each element of output is the absolute value of the corresponding element of a. For integer vectors, the arithmetic is modular.

Result:

A 128-bit vector of 16 x 8-bit/8 x 16-bit/4 x 32-bit/2 x 64-bit signed integers, or 4 x 32-bit single-precision/2 x 64-bit double-precision floating-point numbers that hold the absolute values of the input elements.

Prototypes

Assembly Instruction:
vspltisw
Usage:
vector signed int result = vec_abs( vector signed int a )
Example:
#include <altivec.h>
#include <stdio.h>
int main() {
 vector signed int  a = {
  -1, 2, -3, 4
 };
 vector signed int d = vec_abs(a);
 int result_data[4];
 vec_st(d,  0, result_data);
 for (int i = 0; i < 4; ++i) {
   printf("%d ", result_data[i]);
  }
  printf("\n");

  return  0;
 }
Assembly Instruction:
vspltisw
Usage:
vector float result = vec_abs( vector float a )
Example:
#include <altivec.h>
#include <stdio.h>
int main() {
 vector float a = {
  -1.0f, 2.0f, -3.0f, 4.0f
 };
 vector float result = vec_abs(a);
 float result_data[4];
 vec_st(result, 0, result_data);
 for (int i = 0; i < 4; ++i) {
   printf("%f ", result_data[i]);
  }
  printf("\n");

  return 0;
 }
Assembly Instruction:
vspltisw
Usage:
vector signed char result = vec_abs( vector signed char a )
Example:
#include <altivec.h>
#include <stdio.h>
int main() {
 vector signed char a = {
  -1, 2, -3, 4, -5, 6, -7, 8,        -9, 10, -11, 12, -13, 14, -15, 16
 };
 vector signed char d = vec_abs(a);
 signed char result_data[16];
 vec_st(d, 0, result_data);
 for (int i = 0; i < 16; i++) {
   printf("%d ", result_data[i]);
  }
  printf("\n");

  return 0;
 }
Assembly Instruction:
vspltisw
Usage:
vector double result = vec_abs( vector double a )
Example:
#include <altivec.h>
#include <stdio.h>
int main() {
 vector double a = {
  -1.0, 2.0, -3.0, 4.0
 };
 vector double d = vec_abs(a);
 double result_data[4];
 vec_st(d, 0, result_data);
 for (int i = 0; i < 4; i++) {
   printf("%f ", result_data[i]);
  }
  printf("\n");

  return 0;
 }
Assembly Instruction:
vspltisw
Usage:
vector signed int result = vec_abs( vector signed int a )
Example:
#include <altivec.h>
#include <stdio.h>
int main() {
 vector signed int a = {
  -1, 2, -3, 4
 };
 vector signed int d = vec_abs(a);
 int result_data[4];
 vec_st(d, 0, result_data);
 for (int i = 0; i < 4; ++i) {
   printf("%d ", result_data[i]);
  }
  printf("\n");

  return 0;
 }
Assembly Instruction:
vspltisw
Usage:
vector signed short result = vec_abs( vector signed short a )
Example:
#include <altivec.h>
#include <stdio.h>
int main() {
 vector signed short a = {
  -10, 20, -30, 40, -50, 60, -70, 80
 };
 vector signed short d = vec_abs(a);
 signed short result_data[8];
 vec_st(d, 0, result_data);
 for (int i = 0; i < 8; ++i) {
   printf("%d ", result_data[i]);
  }
  printf("\n");

  return 0;
 }
SIMD Intrinsics Summary
SIMD Engines: 6
C Intrinsics: 10444
NEON: 4353
AVX2: 405
AVX512: 4717
SSE4.2: 598
VSX: 192
IBM-Z: 179