arm64 VEX frontend and backend support for Iop_M{Add,Sub}F{32,64}
[valgrind.git] / none / tests / arm64 / fmadd_sub.c
blobdcab22d1bcd67a108e41037c1d1f7df8c9d831f1
1 #include <math.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #define COUNT 5
8 static void
9 print_float(const char *ident, float x)
11 union
13 float f;
14 uint32_t i;
15 } u;
17 u.f = x;
18 printf("%s = %08x = %.17g\n", ident, u.i, x);
21 static void
22 print_double(const char *ident, double x)
24 union
26 double f;
27 uint64_t i;
28 } u;
30 u.f = x;
31 printf("%s = %016lx = %.17g\n", ident, u.i, x);
34 int
35 main(int argc, char **argv)
37 float x[] = { 55, 0.98076171874999996, 0, 1, 0xFFFFFFFF } ;
38 float y[] = { 0.69314718055994529, 1.015625, 0, 1, 0xFFFFFFFF };
39 float z[] = { 38.123094930796988, 1, 0, 1, 0xFFFFFFFF };
40 float dst = -5;
42 double dx[] = { 55, 0.98076171874999996, 0, 1, 0xFFFFFFFF } ;
43 double dy[] = { 0.69314718055994529, 1.015625, 0, 1, 0xFFFFFFFF };
44 double dz[] = { 38.123094930796988, 1, 0, 1, 0xFFFFFFFF };
45 double ddst= -5;
47 int i;
49 for (i = 0; i < COUNT; i++) {
50 //32bit variant
51 asm("fmadd %s0, %s1, %s2, %s3\n;" : "=w"(dst) : "w"(x[i]), "w"(y[i]), "w"(z[i]));
52 printf("FMADD 32bit: dst = z + x * y\n");
53 printf("%f = %f + %f * %f\n", dst, z[i], x[i], y[i]);
54 print_float("dst", dst);
56 // Floating-point negated fused multiply-add
57 asm("fnmadd %s0, %s1, %s2, %s3\n;" : "=w"(dst) : "w"(x[i]), "w"(y[i]), "w"(z[i]));
58 printf("FNMADD 32bit: dst = -z + (-x) * y\n");
59 printf("%f = -%f + (-%f) * %f\n", dst, z[i], x[i], y[i]);
60 print_float("dst", dst);
62 asm("fmsub %s0, %s1, %s2, %s3\n;" : "=w"(dst) : "w"(x[i]), "w"(y[i]), "w"(z[i]));
63 printf("FMSUB 32bit: dst = z + (-x) * y\n");
64 printf("%f = %f + (-%f) * %f\n", dst, z[i], x[i], y[i]);
65 print_float("dst", dst);
67 asm("fnmsub %s0, %s1, %s2, %s3\n;" : "=w"(dst) : "w"(x[i]), "w"(y[i]), "w"(z[i]));
68 printf("FNMSUB 32bit: dst = -z + x * y\n");
69 printf("%f = -%f + %f * %f\n", dst, z[i], x[i], y[i]);
70 print_float("dst", dst);
72 //64bit variant
73 asm("fmadd %d0, %d1, %d2, %d3\n;" : "=w"(ddst) : "w"(dx[i]), "w"(dy[i]), "w"(dz[i]));
74 printf("FMADD 64bit: dst = z + x * y\n");
75 printf("%f = %f + %f * %f\n", ddst, dz[i], dx[i], dy[i]);
76 print_double("dst", ddst);
78 asm("fnmadd %d0, %d1, %d2, %d3\n;" : "=w"(ddst) : "w"(dx[i]), "w"(dy[i]), "w"(dz[i]));
79 printf("FNMADD 64bit: dst = -z + (-x) * y\n");
80 printf("%f = -%f - %f * %f\n", ddst, dz[i], dx[i], dy[i]);
81 print_double("dst", ddst);
83 asm("fmsub %d0, %d1, %d2, %d3\n;" : "=w"(ddst) : "w"(dx[i]), "w"(dy[i]), "w"(dz[i]));
84 printf("FMSUB 64bit: dst = z + (-x) * y\n");
85 printf("%f = %f + (-%f) * %f\n", ddst, dz[i], dx[i], dy[i]);
86 print_double("dst", ddst);
88 asm("fnmsub %d0, %d1, %d2, %d3\n;" : "=w"(ddst) : "w"(dx[i]), "w"(dy[i]), "w"(dz[i]));
89 printf("FNMSUB 64bit: dst = -z + x * y\n");
90 printf("%f = -%f + %f * %f\n", ddst, dz[i], dx[i], dy[i]);
91 print_double("dst", ddst);
93 printf("\n");
96 return 0;