From: Florian Krohm Date: Thu, 6 Sep 2012 03:22:16 +0000 (+0000) Subject: s390: Add a testcase for condition code computation for X-Git-Tag: svn/VALGRIND_3_9_0~700 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32930aaa32c5b007bd9b61cae7c4c7e712fcaec6;p=thirdparty%2Fvalgrind.git s390: Add a testcase for condition code computation for convert-to-fixed. See VEX r2516. Part of fixing bugzilla #306054. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12958 --- diff --git a/none/tests/s390x/Makefile.am b/none/tests/s390x/Makefile.am index 158c08f7e0..da22c4b78a 100644 --- a/none/tests/s390x/Makefile.am +++ b/none/tests/s390x/Makefile.am @@ -8,7 +8,8 @@ INSN_TESTS = clc clcle cvb cvd icm lpr tcxb lam_stam xc mvst add sub mul \ op_exception fgx stck stckf stcke stfle cksm mvcl clcl troo \ trto trot trtt tr tre cij cgij clij clgij crj cgrj clrj clgrj \ cs csg cds cdsg cu21 cu21_1 cu24 cu24_1 cu42 cu12 cu12_1 \ - ex_sig ex_clone cu14 cu14_1 cu41 fpconv ecag fpext fpext_warn + ex_sig ex_clone cu14 cu14_1 cu41 fpconv ecag fpext fpext_warn \ + rounding-1 check_PROGRAMS = $(INSN_TESTS) \ allexec \ diff --git a/none/tests/s390x/rounding-1.c b/none/tests/s390x/rounding-1.c new file mode 100644 index 0000000000..deb8071a37 --- /dev/null +++ b/none/tests/s390x/rounding-1.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include + +/* This testcase is to illustrate that for convert to fixed the condition + code depends on the rounding mode. */ + +const char * +rtext(unsigned round) +{ + switch (round) { + case 0: return "[fpc]"; + case 1: return "[->near/away]"; + /* 2 is invalid */ + case 3: return "[prep short]"; + case 4: return "[->near/even]"; + case 5: return "[->0]"; + case 6: return "[->+inf]"; + case 7: return "[->-inf]"; + } + assert(0); +} + +#define convert_to_int(opcode,src_type,dst_type,dst_fmt,round,value) \ +do { \ + src_type src = value; \ + dst_type dst; \ + unsigned cc; \ + \ + __asm__ volatile (opcode " %[dst]," #round ",%[src]\n\t" \ + "ipm %[cc]\n\t" \ + "srl %[cc],28\n\t" \ + : [dst] "=d"(dst), [cc] "=d"(cc) \ + : [src] "f"(src) \ + : "cc"); \ + \ + printf("%s %-20s %f\t-> %"dst_fmt"\tcc = %u\n", \ + opcode, rtext(round), src, dst, cc); \ +} while (0) + + +#define cfdbr(round,value) \ + convert_to_int("cfdbr",double,int32_t,PRId32,round,value) + +int main(void) +{ + double dval; + + dval = -2147483648.5; // a < MN + + // f64 -> i32 + + cfdbr(4, dval); // round to nearest with ties to even + cfdbr(5, dval); // round to zero + cfdbr(6, dval); // round to +inf + + /* The next invocation needs to give cc=3. It used to give cc=1 when + we were considering the to-be-converted value ONLY */ + cfdbr(7, dval); // round to -inf + + return 0; +} diff --git a/none/tests/s390x/rounding-1.stderr.exp b/none/tests/s390x/rounding-1.stderr.exp new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/none/tests/s390x/rounding-1.stderr.exp @@ -0,0 +1,2 @@ + + diff --git a/none/tests/s390x/rounding-1.stdout.exp b/none/tests/s390x/rounding-1.stdout.exp new file mode 100644 index 0000000000..98c3854a4c --- /dev/null +++ b/none/tests/s390x/rounding-1.stdout.exp @@ -0,0 +1,4 @@ +cfdbr [->near/even] -2147483648.500000 -> -2147483648 cc = 1 +cfdbr [->0] -2147483648.500000 -> -2147483648 cc = 1 +cfdbr [->+inf] -2147483648.500000 -> -2147483648 cc = 1 +cfdbr [->-inf] -2147483648.500000 -> -2147483648 cc = 3 diff --git a/none/tests/s390x/rounding-1.vgtest b/none/tests/s390x/rounding-1.vgtest new file mode 100644 index 0000000000..4c1e45b2bc --- /dev/null +++ b/none/tests/s390x/rounding-1.vgtest @@ -0,0 +1 @@ +prog: rounding-1