Skip to content

Commit e2130e8

Browse files
author
cborntra
committed
Add a testcase for floating point <-> signed conversion that
actually checks the condition code of the conversion instruction (most programs dont do that) git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12859 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent 497919a commit e2130e8

File tree

2 files changed

+148
-1
lines changed

2 files changed

+148
-1
lines changed

none/tests/s390x/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ INSN_TESTS = clc clcle cvb cvd icm lpr tcxb lam_stam xc mvst add sub mul \
88
op_exception fgx stck stckf stcke stfle cksm mvcl clcl troo \
99
trto trot trtt tr tre cij cgij clij clgij crj cgrj clrj clgrj \
1010
cs csg cds cdsg cu21 cu21_1 cu24 cu24_1 cu42 cu12 cu12_1 \
11-
ex_sig ex_clone cu14 cu14_1 cu41
11+
ex_sig ex_clone cu14 cu14_1 cu41 fpconv
1212

1313
check_PROGRAMS = $(INSN_TESTS) \
1414
allexec \

none/tests/s390x/fpconv.c

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/* basic float <-> signed int conversions available since z900 */
2+
#include <float.h>
3+
#include <stdio.h>
4+
#include "opcodes.h"
5+
6+
#define I2F(insn, initial, target,round) \
7+
({ \
8+
register unsigned long source asm("2") = initial; \
9+
register typeof(target) _t asm("f0"); \
10+
asm volatile(insn " 0,2\n\t" :"=f" (_t):"d"(source)); \
11+
_t; \
12+
})
13+
14+
#define F2L(insn, initial, type, round, cc) \
15+
({ \
16+
register type source asm("f0") = initial; \
17+
register unsigned long target asm ("2") = 0; \
18+
asm volatile(insn " 2," #round ",0\n\t" \
19+
"ipm %1\n\t" \
20+
"srl %1,28\n\t" \
21+
:"=d" (target), "=d" (cc) :"f"(source):"cc"); \
22+
target; \
23+
})
24+
25+
26+
#define DO_INSN_I2F32(insn, round) \
27+
({ \
28+
float f32; \
29+
printf(#insn " %f\n", I2F(insn, 0, f32, round)); \
30+
printf(#insn " %f\n", I2F(insn, 1, f32, round)); \
31+
printf(#insn " %f\n", I2F(insn, 0xffffffffUL, f32, round)); \
32+
printf(#insn " %f\n", I2F(insn, 0x80000000UL, f32, round)); \
33+
printf(#insn " %f\n", I2F(insn, 0x7fffffffUL, f32, round)); \
34+
printf(#insn " %f\n", I2F(insn, 0x100000000UL, f32, round)); \
35+
printf(#insn " %f\n", I2F(insn, 0xffffffffffffffffUL, f32, round)); \
36+
printf(#insn " %f\n", I2F(insn, 0x8000000000000000UL, f32, round)); \
37+
printf(#insn " %f\n", I2F(insn, 0x7fffffffffffffffUL, f32, round)); \
38+
})
39+
40+
#define DO_INSN_I2F64(insn, round) \
41+
({ \
42+
double f64; \
43+
printf(#insn " %f\n", I2F(insn, 0, f64, round)); \
44+
printf(#insn " %f\n", I2F(insn, 1, f64, round)); \
45+
printf(#insn " %f\n", I2F(insn, 0xffffffffUL, f64, round)); \
46+
printf(#insn " %f\n", I2F(insn, 0x80000000UL, f64, round)); \
47+
printf(#insn " %f\n", I2F(insn, 0x7fffffffUL, f64, round)); \
48+
printf(#insn " %f\n", I2F(insn, 0x100000000UL, f64, round)); \
49+
printf(#insn " %f\n", I2F(insn, 0xffffffffffffffffUL, f64, round)); \
50+
printf(#insn " %f\n", I2F(insn, 0x8000000000000000UL, f64, round)); \
51+
printf(#insn " %f\n", I2F(insn, 0x7fffffffffffffffUL, f64, round)); \
52+
})
53+
54+
#define DO_INSN_I2F128(insn, round) \
55+
({ \
56+
long double f128; \
57+
printf(#insn " %Lf\n", I2F(insn, 0, f128, round)); \
58+
printf(#insn " %Lf\n", I2F(insn, 1, f128, round)); \
59+
printf(#insn " %Lf\n", I2F(insn, 0xffffffffUL, f128, round)); \
60+
printf(#insn " %Lf\n", I2F(insn, 0x80000000UL, f128, round)); \
61+
printf(#insn " %Lf\n", I2F(insn, 0x7fffffffUL, f128, round)); \
62+
printf(#insn " %Lf\n", I2F(insn, 0x100000000UL, f128, round)); \
63+
printf(#insn " %Lf\n", I2F(insn, 0xffffffffffffffffUL, f128, round)); \
64+
printf(#insn " %Lf\n", I2F(insn, 0x8000000000000000UL, f128, round)); \
65+
printf(#insn " %Lf\n", I2F(insn, 0x7fffffffffffffffUL, f128, round)); \
66+
})
67+
68+
#define DO_INSN_F2L(insn, round, type) \
69+
({ \
70+
int cc; \
71+
printf(#insn " %ld ", F2L(insn, -1.1, type, round, cc)); \
72+
printf("cc=%d\n", cc); \
73+
printf(#insn " %ld ", F2L(insn, 0, type, round, cc)); \
74+
printf("cc=%d\n", cc); \
75+
printf(#insn " %ld ", F2L(insn, 1, type, round, cc)); \
76+
printf("cc=%d\n", cc); \
77+
printf(#insn " %ld ", F2L(insn, 1.4, type, round, cc)); \
78+
printf("cc=%d\n", cc); \
79+
printf(#insn " %ld ", F2L(insn, 1.5, type, round, cc)); \
80+
printf("cc=%d\n", cc); \
81+
printf(#insn " %ld ", F2L(insn, 1.6, type, round, cc)); \
82+
printf("cc=%d\n", cc); \
83+
printf(#insn " %ld ", F2L(insn, 1.6E+4, type, round, cc)); \
84+
printf("cc=%d\n", cc); \
85+
printf(#insn " %ld ", F2L(insn, 1.6E+8, type, round, cc)); \
86+
printf("cc=%d\n", cc); \
87+
printf(#insn " %ld ", F2L(insn, 1.6E+12, type, round, cc)); \
88+
printf("cc=%d\n", cc); \
89+
printf(#insn " %ld ", F2L(insn, 1.6E+20, type, round, cc)); \
90+
printf("cc=%d\n", cc); \
91+
printf(#insn " %ld ", F2L(insn, 1.6E+200, type, round, cc)); \
92+
printf("cc=%d\n", cc); \
93+
printf(#insn " %ld ", F2L(insn, 1.6E+2000L, type, round, cc)); \
94+
printf("cc=%d\n", cc); \
95+
printf(#insn " %ld ", F2L(insn, 1.6E-4, type, round, cc)); \
96+
printf("cc=%d\n", cc); \
97+
printf(#insn " %ld ", F2L(insn, FLT_MIN, type, round, cc)); \
98+
printf("cc=%d\n", cc); \
99+
printf(#insn " %ld ", F2L(insn, FLT_MAX, type, round, cc)); \
100+
printf("cc=%d\n", cc); \
101+
printf(#insn " %ld ", F2L(insn, DBL_MIN, type, round, cc)); \
102+
printf("cc=%d\n", cc); \
103+
printf(#insn " %ld ", F2L(insn, DBL_MAX, type, round, cc)); \
104+
printf("cc=%d\n", cc); \
105+
printf(#insn " %ld ", F2L(insn, LDBL_MIN, type, round, cc)); \
106+
printf("cc=%d\n", cc); \
107+
printf(#insn " %ld ", F2L(insn, LDBL_MAX, type, round, cc)); \
108+
printf("cc=%d\n", cc); \
109+
})
110+
111+
#define DO_I2F(round) \
112+
({ \
113+
DO_INSN_I2F32("cefbr", round); \
114+
DO_INSN_I2F32("cegbr", round); \
115+
DO_INSN_I2F64("cdfbr", round); \
116+
DO_INSN_I2F64("cdgbr", round); \
117+
DO_INSN_I2F128("cxfbr", round); \
118+
DO_INSN_I2F128("cxgbr", round); \
119+
})
120+
121+
#define DO_F2L(round) \
122+
({ \
123+
DO_INSN_F2L("cfebr", round, float); \
124+
DO_INSN_F2L("cgebr", round, float); \
125+
DO_INSN_F2L("cfdbr", round, double); \
126+
DO_INSN_F2L("cgdbr", round, double); \
127+
DO_INSN_F2L("cfxbr", round, long double); \
128+
DO_INSN_F2L("cgxbr", round, long double); \
129+
})
130+
131+
132+
int main()
133+
{
134+
DO_I2F(4);
135+
DO_F2L(4);
136+
137+
DO_I2F(5);
138+
DO_F2L(5);
139+
140+
DO_I2F(6);
141+
DO_F2L(6);
142+
143+
DO_I2F(7);
144+
DO_F2L(7);
145+
146+
return 0;
147+
}

0 commit comments

Comments
 (0)