9 print_float(const char *ident
, float x
)
18 printf("%s = %08x = %.17g\n", ident
, u
.i
, x
);
22 print_double(const char *ident
, double x
)
31 printf("%s = %016lx = %.17g\n", ident
, u
.i
, x
);
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 };
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 };
49 for (i
= 0; i
< COUNT
; i
++) {
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
);
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
);