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
178178extern " C" {
179+ uint8_t crt_fcmp (uint32_t LHS, uint32_t RHS);
179180uint8_t crt_fcmpo (uint32_t LHS, uint32_t RHS);
180181uint8_t crt_fcmpu (uint32_t LHS, uint32_t RHS);
182+ uint8_t crt_dcmp (uint64_t LHS, uint64_t RHS);
181183uint8_t crt_dcmpo (uint64_t LHS, uint64_t RHS);
182184uint8_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+
185202static 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\n RHS %08lX\n OT %c%c-----%c !=\n OG %08b\n UT -%c-----%c !=\n UG %08b\n " ,
229+ " LHS %08lX\n RHS %08lX\n "
230+ " OT %c%c-----%c !=\n OG %08b\n "
231+ " UT -%c-----%c !=\n UG %08b\n "
232+ " CT %c%c------ %c=\n CG %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\n RHS %016llX\n OT %c%c-----%c !=\n OG %08b\n UT -%c-----%c !=\n UG %08b\n " ,
278+ " LHS %016llX\n RHS %016llX\n "
279+ " OT %c%c-----%c !=\n OG %08b\n "
280+ " UT -%c-----%c !=\n UG %08b\n "
281+ " CT %c%c------ %c=\n CG %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-
302336int 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