summary refs log tree commit diff
path: root/test/fpcnv.ssa
blob: aea67acda33a91d2c5aa8716bb0764330877def9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# floating point casts and conversions

export
function s $fneg(s %f) {
@fneg
	%b0 =w cast %f
	%b1 =w xor 2147483648, %b0
	%rs =s cast %b1
	ret %rs
}

export
function d $ftrunc(d %f) {
@ftrunc
	%l0 =w dtosi %f
	%rt =d swtof %l0
	ret %rt
}

export
function s $wtos(w %w) {
@start
	%rt =s uwtof %w
	ret %rt
}
export
function d $wtod(w %w) {
@start
	%rt =d uwtof %w
	ret %rt
}

export
function s $ltos(l %l) {
@start
	%rt =s ultof %l
	ret %rt
}
export
function d $ltod(l %l) {
@start
	%rt =d ultof %l
	ret %rt
}

export
function w $stow(s %f) {
@start
	%rt =w stoui %f
	ret %rt
}
export
function w $dtow(d %f) {
@start
	%rt =w dtoui %f
	ret %rt
}

export
function l $stol(s %f) {
@start
	%rt =l stoui %f
	ret %rt
}
export
function l $dtol(d %f) {
@start
	%rt =l dtoui %f
	ret %rt
}



# >>> driver
# #include <limits.h>
# 
# extern float fneg(float);
# extern double ftrunc(double);
# 
# extern float wtos(unsigned int);
# extern double wtod(unsigned int);
# extern float ltos(long long unsigned int);
# extern double ltod(long long unsigned int);
# 
# extern unsigned int stow(float);
# extern unsigned int dtow(double);
# extern unsigned long long stol(float);
# extern unsigned long long dtol(double);
# 
# unsigned long long iin[] = { 0, 1, 16, 234987, 427386245, 0x7fff0000,
# 	0xffff0000, 23602938196141, 72259248152500195, 9589010795705032704ull,
# 	0xdcf5fbe299d0148aull, 0xffffffff00000000ull, -1 };
# 
# double fin[] = { 0.17346516197824458, 442.0760005466251, 4342856.879893436,
# 	98547543006.49626, 236003043787688.3, 9.499222733527032e+18,
# 	1.1936266170755652e+19 };
# 
# int main() {
# 	int i;
# 
# 	if (fneg(1.23f) != -1.23f)  return 1;
# 	if (ftrunc(3.1415) != 3.0)  return 2;
# 	if (ftrunc(-1.234) != -1.0) return 3;
# 
# 	for (i=0; i<sizeof(iin)/sizeof(iin[0]); i++) {
# 		if (wtos(iin[i]) != (float) (unsigned int)iin[i])
# 			return 4;
# 		if (wtod(iin[i]) != (double)(unsigned int)iin[i])
# 			return 5;
# 		if (ltos(iin[i]) != (float) iin[i])
# 			return 6;
# 		if (ltod(iin[i]) != (double)iin[i])
# 			return 7;
# 	}
# 	for (i=0; i<sizeof(fin)/sizeof(fin[0]); i++) {
# 		if (stol((float)fin[i]) != (unsigned long long)(float)fin[i])
# 			return 8;
# 		if (dtol(fin[i]) != (unsigned long long)fin[i])
# 			return 9;
# 		if((unsigned long long)fin[i] > UINT_MAX)
# 			continue;
# 		if (stow((float)fin[i]) != (unsigned int)(float)fin[i])
# 			return 10;
# 		if (dtow(fin[i]) != (unsigned int)fin[i])
# 			return 11;
# 	}
# 	return 0;
# }
# <<<