aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/builtins-powerpc.c
blob: 55809106f807099a6eb093a1a75b63c10f3869ef (plain)
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
/* PowerPC-specific builtins */

#include <stdio.h>
#include <math.h>

char * check_relative_error(double exact, double actual, double precision)
{
  double relative_error = (actual - exact) / exact;
  return fabs(relative_error) <= precision ? "OK" : "ERROR";
}

unsigned int x = 0x12345678;
unsigned int y = 0xDEADBEEF;
double a = 3.14159;
double b = 2.718;
double c = 1.414;
unsigned short s = 0x1234;

int main(int argc, char ** argv)
{
  unsigned z;

  printf("mulhw(%x, %x) = %x\n", x, y, __builtin_mulhw(x, y));
  printf("mulhwu(%x, %x) = %x\n", x, y, __builtin_mulhwu(x, y));

  printf("fmadd(%f, %f, %f) = %f\n", a, b, c, __builtin_fmadd(a, b, c));
  printf("fmsub(%f, %f, %f) = %f\n", a, b, c, __builtin_fmsub(a, b, c));
  printf("frsqrte(%f) = %s\n",
         a, check_relative_error(1.0 / sqrt(a), __builtin_frsqrte(a), 1./32.));
  printf("fres(%f) = %s\n",
         a, check_relative_error(1.0 / a, __builtin_fres(a), 1./256.));
  printf("fsel(%f, %f, %f) = %f\n", a, b, c, __builtin_fsel(a, b, c));
  printf("fsel(%f, %f, %f) = %f\n", -a, b, c, __builtin_fsel(-a, b, c));
  printf("fcti(%f) = %d\n", a, __builtin_fcti(a));
  printf("fcti(%f) = %d\n", b, __builtin_fcti(b));
  printf("fcti(%f) = %d\n", c, __builtin_fcti(c));
  __builtin_eieio();
  __builtin_sync();
  __builtin_isync();
  printf("isel(%d, %d, %d) = %d\n", 0, x, y, __builtin_isel(0, x, y));
  printf("isel(%d, %d, %d) = %d\n", 42, x, y, __builtin_isel(42, x, y));
  printf ("read_16_rev = %x\n", __builtin_read16_reversed(&s));
  printf ("read_32_rev = %x\n", __builtin_read32_reversed(&y));
  __builtin_write16_reversed(&s, 0x789A);
  printf ("after write_16_rev: %x\n", s);
  __builtin_write32_reversed(&y, 0x12345678);
  printf ("after write_32_rev: %x\n", y);
  y = 0;
  __builtin_write32_reversed(&y, 0x12345678);
  printf ("CSE write_32_rev: %s\n", y == 0x78563412 ? "ok" : "ERROR");
  /* Make sure that ignoring the result of a builtin
     doesn't cause an internal error */
  (void) __builtin_bswap(x);
  (void) __builtin_fsqrt(a);
  return 0;
}