File: altivec-3.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (80 lines) | stat: -rw-r--r-- 1,673 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* { dg-do run { target { powerpc*-*-* && vmx_hw } } } */
/* { dg-do compile { target { powerpc*-*-* && { ! vmx_hw } } } } */
/* { dg-require-effective-target powerpc_altivec_ok } */
/* { dg-options "-maltivec" } */

extern void exit (int);
extern void abort (void);

typedef int int4 __attribute__ ((vector_size (16)));
typedef float float4 __attribute__ ((vector_size (16)));

int4 a1 = (int4) { 100, 200, 300, 400 };
int4 a2 = (int4) { 500, 600, 700, 800 };

float4 f1 = (float4) { 1.0, 2.0, 3.0, 4.0 };  
float4 f2 = (float4) { 5.0, 6.0, 7.0, 8.0 };

int i3[4] __attribute__((aligned(16)));
int j3[4] __attribute__((aligned(16)));
float h3[4] __attribute__((aligned(16)));
float g3[4] __attribute__((aligned(16)));

#define vec_store(dst, src) \
  __builtin_vec_st (src, 0, (__typeof__ (src) *) dst)

#define vec_add_int4(x, y) \
  __builtin_altivec_vaddsws (x, y)

#define vec_add_float4(x, y) \
  __builtin_altivec_vaddfp (x, y)

#define my_abs(x) (x > 0.0F ? x : -x)

void
compare_int4 (int *a, int *b)
{
  int i;

  for (i = 0; i < 4; ++i)
    if (a[i] != b[i])
      abort ();
}

void
compare_float4 (float *a, float *b)
{
  int i;

  for (i = 0; i < 4; ++i)
    if (my_abs(a[i] - b[i]) >= 1.0e-6)
      abort ();
}

void
main1 ()
{
  int loc1 = 600, loc2 = 800;
  int4 a3 = (int4) { loc1, loc2, 1000, 1200 };
  int4 itmp;
  double locf = 12.0;
  float4 f3 = (float4) { 6.0, 8.0, 10.0, 12.0 };
  float4 ftmp;

  vec_store (i3, a3);
  itmp = vec_add_int4 (a1, a2);
  vec_store (j3, itmp);
  compare_int4 (i3, j3);

  vec_store (g3, f3);
  ftmp = vec_add_float4 (f1, f2);
  vec_store (h3, ftmp);
  compare_float4 (g3, h3);
}

int
main ()
{
  main1 ();
  exit (0);
}