summaryrefslogtreecommitdiffstats
path: root/tests/tcg
diff options
context:
space:
mode:
authorJoseph Myers2020-05-14 01:49:27 +0200
committerPaolo Bonzini2020-06-10 18:10:24 +0200
commit80b4008c805ebcfd4c0d302ac31c1689e34571e0 (patch)
tree1b9d77a23eb27cbd12dd9f1b8fe201b2c9486e33 /tests/tcg
parenthw/elf_ops: Do not ignore write failures when loading ELF (diff)
downloadqemu-80b4008c805ebcfd4c0d302ac31c1689e34571e0.tar.gz
qemu-80b4008c805ebcfd4c0d302ac31c1689e34571e0.tar.xz
qemu-80b4008c805ebcfd4c0d302ac31c1689e34571e0.zip
target/i386: fix floating-point load-constant rounding
The implementations of the fldl2t, fldl2e, fldpi, fldlg2 and fldln2 instructions load fixed constants independent of the rounding mode. Fix them to load a value correctly rounded for the current rounding mode (but always rounded to 64-bit precision independent of the precision control, and without setting "inexact") as specified. Signed-off-by: Joseph Myers <joseph@codesourcery.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <alpine.DEB.2.21.2005132348310.11687@digraph.polyomino.org.uk> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/tcg')
-rw-r--r--tests/tcg/i386/test-i386-fldcst.c199
1 files changed, 199 insertions, 0 deletions
diff --git a/tests/tcg/i386/test-i386-fldcst.c b/tests/tcg/i386/test-i386-fldcst.c
new file mode 100644
index 0000000000..e635432ccf
--- /dev/null
+++ b/tests/tcg/i386/test-i386-fldcst.c
@@ -0,0 +1,199 @@
+/* Test instructions loading floating-point constants. */
+
+#include <stdint.h>
+#include <stdio.h>
+
+volatile long double ld_res;
+
+int main(void)
+{
+ short cw;
+ int ret = 0;
+
+ /* Round to nearest. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x000;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldl2t" : "=t" (ld_res));
+ if (ld_res != 0x3.5269e12f346e2bf8p+0L) {
+ printf("FAIL: fldl2t N\n");
+ ret = 1;
+ }
+ /* Round downward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x400;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldl2t" : "=t" (ld_res));
+ if (ld_res != 0x3.5269e12f346e2bf8p+0L) {
+ printf("FAIL: fldl2t D\n");
+ ret = 1;
+ }
+ /* Round toward zero. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0xc00;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldl2t" : "=t" (ld_res));
+ if (ld_res != 0x3.5269e12f346e2bf8p+0L) {
+ printf("FAIL: fldl2t Z\n");
+ ret = 1;
+ }
+ /* Round upward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x800;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldl2t" : "=t" (ld_res));
+ if (ld_res != 0x3.5269e12f346e2bfcp+0L) {
+ printf("FAIL: fldl2t U\n");
+ ret = 1;
+ }
+
+ /* Round to nearest. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x000;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldl2e" : "=t" (ld_res));
+ if (ld_res != 0x1.71547652b82fe178p+0L) {
+ printf("FAIL: fldl2e N\n");
+ ret = 1;
+ }
+ /* Round downward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x400;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldl2e" : "=t" (ld_res));
+ if (ld_res != 0x1.71547652b82fe176p+0L) {
+ printf("FAIL: fldl2e D\n");
+ ret = 1;
+ }
+ /* Round toward zero. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0xc00;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldl2e" : "=t" (ld_res));
+ if (ld_res != 0x1.71547652b82fe176p+0L) {
+ printf("FAIL: fldl2e Z\n");
+ ret = 1;
+ }
+ /* Round upward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x800;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldl2e" : "=t" (ld_res));
+ if (ld_res != 0x1.71547652b82fe178p+0L) {
+ printf("FAIL: fldl2e U\n");
+ ret = 1;
+ }
+
+ /* Round to nearest. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x000;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldpi" : "=t" (ld_res));
+ if (ld_res != 0x3.243f6a8885a308d4p+0L) {
+ printf("FAIL: fldpi N\n");
+ ret = 1;
+ }
+ /* Round downward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x400;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldpi" : "=t" (ld_res));
+ if (ld_res != 0x3.243f6a8885a308dp+0L) {
+ printf("FAIL: fldpi D\n");
+ ret = 1;
+ }
+ /* Round toward zero. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0xc00;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldpi" : "=t" (ld_res));
+ if (ld_res != 0x3.243f6a8885a308dp+0L) {
+ printf("FAIL: fldpi Z\n");
+ ret = 1;
+ }
+ /* Round upward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x800;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldpi" : "=t" (ld_res));
+ if (ld_res != 0x3.243f6a8885a308d4p+0L) {
+ printf("FAIL: fldpi U\n");
+ ret = 1;
+ }
+
+ /* Round to nearest. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x000;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldlg2" : "=t" (ld_res));
+ if (ld_res != 0x4.d104d427de7fbcc8p-4L) {
+ printf("FAIL: fldlg2 N\n");
+ ret = 1;
+ }
+ /* Round downward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x400;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldlg2" : "=t" (ld_res));
+ if (ld_res != 0x4.d104d427de7fbccp-4L) {
+ printf("FAIL: fldlg2 D\n");
+ ret = 1;
+ }
+ /* Round toward zero. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0xc00;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldlg2" : "=t" (ld_res));
+ if (ld_res != 0x4.d104d427de7fbccp-4L) {
+ printf("FAIL: fldlg2 Z\n");
+ ret = 1;
+ }
+ /* Round upward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x800;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldlg2" : "=t" (ld_res));
+ if (ld_res != 0x4.d104d427de7fbcc8p-4L) {
+ printf("FAIL: fldlg2 U\n");
+ ret = 1;
+ }
+
+ /* Round to nearest. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x000;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldln2" : "=t" (ld_res));
+ if (ld_res != 0xb.17217f7d1cf79acp-4L) {
+ printf("FAIL: fldln2 N\n");
+ ret = 1;
+ }
+ /* Round downward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x400;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldln2" : "=t" (ld_res));
+ if (ld_res != 0xb.17217f7d1cf79abp-4L) {
+ printf("FAIL: fldln2 D\n");
+ ret = 1;
+ }
+ /* Round toward zero. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0xc00;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldln2" : "=t" (ld_res));
+ if (ld_res != 0xb.17217f7d1cf79abp-4L) {
+ printf("FAIL: fldln2 Z\n");
+ ret = 1;
+ }
+ /* Round upward. */
+ __asm__ volatile ("fnstcw %0" : "=m" (cw));
+ cw = (cw & ~0xc00) | 0x800;
+ __asm__ volatile ("fldcw %0" : : "m" (cw));
+ __asm__ volatile ("fldln2" : "=t" (ld_res));
+ if (ld_res != 0xb.17217f7d1cf79acp-4L) {
+ printf("FAIL: fldln2 U\n");
+ ret = 1;
+ }
+
+ return ret;
+}