Skip to content

Commit 5d5d392

Browse files
committed
added tests for fcmp/dcmp
1 parent 581e953 commit 5d5d392

2 files changed

Lines changed: 94 additions & 22 deletions

File tree

test/floating_point/compare/src/cmp_test.s

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
.section .text
44

5+
.global _crt_fcmp
6+
.type _crt_fcmp, @function
7+
_crt_fcmp:
8+
ld iy, 0
9+
add iy, sp
10+
ld hl, (iy + 3)
11+
ld e, (iy + 6)
12+
ld bc, (iy + 9)
13+
ld a, (iy + 12)
14+
call __fpcmp
15+
push af
16+
pop hl
17+
ld a, l
18+
ret
19+
.extern __fpcmp
20+
521
.global _crt_fcmpo
622
.type _crt_fcmpo, @function
723
_crt_fcmpo:
@@ -34,6 +50,28 @@ _crt_fcmpu:
3450
ret
3551
.extern __fpcmpu
3652

53+
.global _crt_dcmp
54+
.type _crt_dcmp, @function
55+
_crt_dcmp:
56+
ld iy, 0
57+
add iy, sp
58+
ld hl, (iy + 18)
59+
push hl
60+
ld hl, (iy + 15)
61+
push hl
62+
ld hl, (iy + 12)
63+
push hl
64+
ld bc, (iy + 9)
65+
ld de, (iy + 6)
66+
ld hl, (iy + 3)
67+
call __dcmp
68+
push af
69+
pop hl
70+
ld a, l
71+
ld sp, iy
72+
ret
73+
.extern __dcmp
74+
3775
.global _crt_dcmpo
3876
.type _crt_dcmpo, @function
3977
_crt_dcmpo:

test/floating_point/compare/src/main.cpp

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//------------------------------------------------------------------------------
1616

1717
// define to 0 or 1
18-
#define DEBUG_DIAGNOSTICS 0
18+
#define DEBUG_DIAGNOSTICS 1
1919

2020
//------------------------------------------------------------------------------
2121
// Tables
@@ -176,12 +176,29 @@ static inline uint64_t f64_to_u64(long double x) {
176176
//------------------------------------------------------------------------------
177177

178178
extern "C" {
179+
uint8_t crt_fcmp(uint32_t LHS, uint32_t RHS);
179180
uint8_t crt_fcmpo(uint32_t LHS, uint32_t RHS);
180181
uint8_t crt_fcmpu(uint32_t LHS, uint32_t RHS);
182+
uint8_t crt_dcmp(uint64_t LHS, uint64_t RHS);
181183
uint8_t crt_dcmpo(uint64_t LHS, uint64_t RHS);
182184
uint8_t crt_dcmpu(uint64_t LHS, uint64_t RHS);
183185
}
184186

187+
static constexpr bool EQ_O = true;
188+
static constexpr bool NEQ_U = false;
189+
190+
static constexpr bool LT_O = true;
191+
static constexpr bool NLT_U = false;
192+
193+
static constexpr bool NGE_U = true;
194+
static constexpr bool GE_O = false;
195+
196+
static constexpr bool NLG_U = true;
197+
static constexpr bool LG_O = false;
198+
199+
static constexpr bool ORDER = true;
200+
static constexpr bool UNORD = false;
201+
185202
static bool test_fcmp(
186203
uint32_t LHS, uint32_t RHS,
187204
bool truth_o_zero,
@@ -190,25 +207,41 @@ static bool test_fcmp(
190207
bool truth_u_zero,
191208
bool truth_u_carry
192209
) {
210+
uint8_t cmpc = crt_fcmp(LHS, RHS);
193211
uint8_t cmpo = crt_fcmpo(LHS, RHS);
194212
uint8_t cmpu = crt_fcmpu(LHS, RHS);
213+
bool ordered = (truth_u_carry == ORDER);
214+
bool truth_c_zero = truth_o_zero;
215+
bool truth_c_sign = truth_o_sign;
216+
bool cmpc_fail = (ordered && (
217+
(((cmpc & (1 << 6)) != 0) != truth_c_zero ) ||
218+
(((cmpc & (1 << 7)) != 0) != truth_c_sign )
219+
));
195220
if (
196221
(((cmpo & (1 << 6)) != 0) != truth_o_zero ) ||
197222
(((cmpo & (1 << 0)) != 0) != truth_o_carry) ||
198223
(((cmpo & (1 << 7)) != 0) != truth_o_sign ) ||
199224
(((cmpu & (1 << 6)) != 0) != truth_u_zero ) ||
200-
(((cmpu & (1 << 0)) != 0) != truth_u_carry)
225+
(((cmpu & (1 << 0)) != 0) != truth_u_carry) ||
226+
cmpc_fail
201227
) {
202228
test_printf(
203-
"LHS %08lX\nRHS %08lX\nOT %c%c-----%c !=\nOG %08b\nUT -%c-----%c !=\nUG %08b\n",
229+
"LHS %08lX\nRHS %08lX\n"
230+
"OT %c%c-----%c !=\nOG %08b\n"
231+
"UT -%c-----%c !=\nUG %08b\n"
232+
"CT %c%c------ %c=\nCG %08b\n",
204233
LHS, RHS,
205234
truth_o_sign ? '1' : '0',
206235
truth_o_zero ? '1' : '0',
207236
truth_o_carry ? '1' : '0',
208237
cmpo,
209238
truth_u_zero ? '1' : '0',
210239
truth_u_carry ? '1' : '0',
211-
cmpu
240+
cmpu,
241+
!ordered ? '?' : (truth_c_sign ? '1' : '0'),
242+
!ordered ? '?' : (truth_c_zero ? '1' : '0'),
243+
!ordered ? '?' : '!',
244+
cmpc
212245
);
213246
return false;
214247
}
@@ -223,25 +256,41 @@ static bool test_dcmp(
223256
bool truth_u_zero,
224257
bool truth_u_carry
225258
) {
259+
uint8_t cmpc = crt_dcmp(LHS, RHS);
226260
uint8_t cmpo = crt_dcmpo(LHS, RHS);
227261
uint8_t cmpu = crt_dcmpu(LHS, RHS);
262+
bool ordered = (truth_u_carry == ORDER);
263+
bool truth_c_zero = truth_o_zero;
264+
bool truth_c_sign = truth_o_sign;
265+
bool cmpc_fail = (ordered && (
266+
(((cmpc & (1 << 6)) != 0) != truth_c_zero ) ||
267+
(((cmpc & (1 << 7)) != 0) != truth_c_sign )
268+
));
228269
if (
229270
(((cmpo & (1 << 6)) != 0) != truth_o_zero ) ||
230271
(((cmpo & (1 << 0)) != 0) != truth_o_carry) ||
231272
(((cmpo & (1 << 7)) != 0) != truth_o_sign ) ||
232273
(((cmpu & (1 << 6)) != 0) != truth_u_zero ) ||
233-
(((cmpu & (1 << 0)) != 0) != truth_u_carry)
274+
(((cmpu & (1 << 0)) != 0) != truth_u_carry) ||
275+
cmpc_fail
234276
) {
235277
test_printf(
236-
"LHS %016llX\nRHS %016llX\nOT %c%c-----%c !=\nOG %08b\nUT -%c-----%c !=\nUG %08b\n",
278+
"LHS %016llX\nRHS %016llX\n"
279+
"OT %c%c-----%c !=\nOG %08b\n"
280+
"UT -%c-----%c !=\nUG %08b\n"
281+
"CT %c%c------ %c=\nCG %08b\n",
237282
LHS, RHS,
238283
truth_o_sign ? '1' : '0',
239284
truth_o_zero ? '1' : '0',
240285
truth_o_carry ? '1' : '0',
241286
cmpo,
242287
truth_u_zero ? '1' : '0',
243288
truth_u_carry ? '1' : '0',
244-
cmpu
289+
cmpu,
290+
!ordered ? '?' : (truth_c_sign ? '1' : '0'),
291+
!ordered ? '?' : (truth_c_zero ? '1' : '0'),
292+
!ordered ? '?' : '!',
293+
cmpc
245294
);
246295
return false;
247296
}
@@ -284,21 +333,6 @@ static bool test_dcmp(
284333
);
285334
}
286335

287-
static constexpr bool EQ_O = true;
288-
static constexpr bool NEQ_U = false;
289-
290-
static constexpr bool LT_O = true;
291-
static constexpr bool NLT_U = false;
292-
293-
static constexpr bool NGE_U = true;
294-
static constexpr bool GE_O = false;
295-
296-
static constexpr bool NLG_U = true;
297-
static constexpr bool LG_O = false;
298-
299-
static constexpr bool ORDER = true;
300-
static constexpr bool UNORD = false;
301-
302336
int fcmp_basic_test(void) {
303337
// test signed zero
304338
C(test_fcmp(+0.0f, +0.0f, EQ_O, NLT_U, GE_O, NLG_U, ORDER));

0 commit comments

Comments
 (0)