Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 5 | */ |
| 6 | /* |
| 7 | * Test for correctness of composite floating-point comparisons. |
| 8 | * Written by Paolo Bonzini, 26th May 2004. |
| 9 | * This file is originally a part of the GCC testsuite. |
| 10 | */ |
| 11 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 12 | #include <config.h> |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 13 | |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 14 | #include <post.h> |
| 15 | |
Yuri Tikhonov | 7ed66f7 | 2008-12-20 14:54:21 +0300 | [diff] [blame] | 16 | GNU_FPOST_ATTR |
| 17 | |
Tom Rini | 3dd5d4a | 2022-12-04 10:14:17 -0500 | [diff] [blame] | 18 | #if CFG_POST & CFG_SYS_POST_FPU |
Kumar Gala | fe6555b | 2011-01-25 03:00:08 -0600 | [diff] [blame] | 19 | |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 20 | static int failed; |
| 21 | |
| 22 | #define TEST(c) if ((c) != ok) failed++ |
| 23 | #define ORD(a, b) (!__builtin_isunordered ((a), (b))) |
| 24 | #define UNORD(a, b) (__builtin_isunordered ((a), (b))) |
| 25 | #define UNEQ(a, b) (__builtin_isunordered ((a), (b)) || ((a) == (b))) |
| 26 | #define UNLT(a, b) (__builtin_isunordered ((a), (b)) || ((a) < (b))) |
| 27 | #define UNLE(a, b) (__builtin_isunordered ((a), (b)) || ((a) <= (b))) |
| 28 | #define UNGT(a, b) (__builtin_isunordered ((a), (b)) || ((a) > (b))) |
| 29 | #define UNGE(a, b) (__builtin_isunordered ((a), (b)) || ((a) >= (b))) |
| 30 | #define LTGT(a, b) (__builtin_islessgreater ((a), (b))) |
| 31 | |
| 32 | static float pinf; |
| 33 | static float ninf; |
| 34 | static float NaN; |
| 35 | |
| 36 | static void iuneq (float x, float y, int ok) |
| 37 | { |
| 38 | TEST (UNEQ (x, y)); |
| 39 | TEST (!LTGT (x, y)); |
| 40 | TEST (UNLE (x, y) && UNGE (x,y)); |
| 41 | } |
| 42 | |
| 43 | static void ieq (float x, float y, int ok) |
| 44 | { |
| 45 | TEST (ORD (x, y) && UNEQ (x, y)); |
| 46 | } |
| 47 | |
| 48 | static void iltgt (float x, float y, int ok) |
| 49 | { |
| 50 | TEST (!UNEQ (x, y)); /* Not optimizable. */ |
| 51 | TEST (LTGT (x, y)); /* Same, __builtin_islessgreater does not trap. */ |
| 52 | TEST (ORD (x, y) && (UNLT (x, y) || UNGT (x,y))); |
| 53 | } |
| 54 | |
| 55 | static void ine (float x, float y, int ok) |
| 56 | { |
| 57 | TEST (UNLT (x, y) || UNGT (x, y)); |
| 58 | } |
| 59 | |
| 60 | static void iunlt (float x, float y, int ok) |
| 61 | { |
| 62 | TEST (UNLT (x, y)); |
| 63 | TEST (UNORD (x, y) || (x < y)); |
| 64 | } |
| 65 | |
| 66 | static void ilt (float x, float y, int ok) |
| 67 | { |
| 68 | TEST (ORD (x, y) && UNLT (x, y)); /* Not optimized */ |
| 69 | TEST ((x <= y) && (x != y)); |
| 70 | TEST ((x <= y) && (y != x)); |
| 71 | TEST ((x != y) && (x <= y)); /* Not optimized */ |
| 72 | TEST ((y != x) && (x <= y)); /* Not optimized */ |
| 73 | } |
| 74 | |
| 75 | static void iunle (float x, float y, int ok) |
| 76 | { |
| 77 | TEST (UNLE (x, y)); |
| 78 | TEST (UNORD (x, y) || (x <= y)); |
| 79 | } |
| 80 | |
| 81 | static void ile (float x, float y, int ok) |
| 82 | { |
| 83 | TEST (ORD (x, y) && UNLE (x, y)); /* Not optimized */ |
| 84 | TEST ((x < y) || (x == y)); |
| 85 | TEST ((y > x) || (x == y)); |
| 86 | TEST ((x == y) || (x < y)); /* Not optimized */ |
| 87 | TEST ((y == x) || (x < y)); /* Not optimized */ |
| 88 | } |
| 89 | |
| 90 | static void iungt (float x, float y, int ok) |
| 91 | { |
| 92 | TEST (UNGT (x, y)); |
| 93 | TEST (UNORD (x, y) || (x > y)); |
| 94 | } |
| 95 | |
| 96 | static void igt (float x, float y, int ok) |
| 97 | { |
| 98 | TEST (ORD (x, y) && UNGT (x, y)); /* Not optimized */ |
| 99 | TEST ((x >= y) && (x != y)); |
| 100 | TEST ((x >= y) && (y != x)); |
| 101 | TEST ((x != y) && (x >= y)); /* Not optimized */ |
| 102 | TEST ((y != x) && (x >= y)); /* Not optimized */ |
| 103 | } |
| 104 | |
| 105 | static void iunge (float x, float y, int ok) |
| 106 | { |
| 107 | TEST (UNGE (x, y)); |
| 108 | TEST (UNORD (x, y) || (x >= y)); |
| 109 | } |
| 110 | |
| 111 | static void ige (float x, float y, int ok) |
| 112 | { |
| 113 | TEST (ORD (x, y) && UNGE (x, y)); /* Not optimized */ |
| 114 | TEST ((x > y) || (x == y)); |
| 115 | TEST ((y < x) || (x == y)); |
| 116 | TEST ((x == y) || (x > y)); /* Not optimized */ |
| 117 | TEST ((y == x) || (x > y)); /* Not optimized */ |
| 118 | } |
| 119 | |
| 120 | int fpu_post_test_math6 (void) |
| 121 | { |
| 122 | pinf = __builtin_inf (); |
| 123 | ninf = -__builtin_inf (); |
| 124 | NaN = __builtin_nan (""); |
| 125 | |
| 126 | iuneq (ninf, pinf, 0); |
| 127 | iuneq (NaN, NaN, 1); |
| 128 | iuneq (pinf, ninf, 0); |
| 129 | iuneq (1, 4, 0); |
| 130 | iuneq (3, 3, 1); |
| 131 | iuneq (5, 2, 0); |
| 132 | |
| 133 | ieq (1, 4, 0); |
| 134 | ieq (3, 3, 1); |
| 135 | ieq (5, 2, 0); |
| 136 | |
| 137 | iltgt (ninf, pinf, 1); |
| 138 | iltgt (NaN, NaN, 0); |
| 139 | iltgt (pinf, ninf, 1); |
| 140 | iltgt (1, 4, 1); |
| 141 | iltgt (3, 3, 0); |
| 142 | iltgt (5, 2, 1); |
| 143 | |
| 144 | ine (1, 4, 1); |
| 145 | ine (3, 3, 0); |
| 146 | ine (5, 2, 1); |
| 147 | |
| 148 | iunlt (NaN, ninf, 1); |
| 149 | iunlt (pinf, NaN, 1); |
| 150 | iunlt (pinf, ninf, 0); |
| 151 | iunlt (pinf, pinf, 0); |
| 152 | iunlt (ninf, ninf, 0); |
| 153 | iunlt (1, 4, 1); |
| 154 | iunlt (3, 3, 0); |
| 155 | iunlt (5, 2, 0); |
| 156 | |
| 157 | ilt (1, 4, 1); |
| 158 | ilt (3, 3, 0); |
| 159 | ilt (5, 2, 0); |
| 160 | |
| 161 | iunle (NaN, ninf, 1); |
| 162 | iunle (pinf, NaN, 1); |
| 163 | iunle (pinf, ninf, 0); |
| 164 | iunle (pinf, pinf, 1); |
| 165 | iunle (ninf, ninf, 1); |
| 166 | iunle (1, 4, 1); |
| 167 | iunle (3, 3, 1); |
| 168 | iunle (5, 2, 0); |
| 169 | |
| 170 | ile (1, 4, 1); |
| 171 | ile (3, 3, 1); |
| 172 | ile (5, 2, 0); |
| 173 | |
| 174 | iungt (NaN, ninf, 1); |
| 175 | iungt (pinf, NaN, 1); |
| 176 | iungt (pinf, ninf, 1); |
| 177 | iungt (pinf, pinf, 0); |
| 178 | iungt (ninf, ninf, 0); |
| 179 | iungt (1, 4, 0); |
| 180 | iungt (3, 3, 0); |
| 181 | iungt (5, 2, 1); |
| 182 | |
| 183 | igt (1, 4, 0); |
| 184 | igt (3, 3, 0); |
| 185 | igt (5, 2, 1); |
| 186 | |
| 187 | iunge (NaN, ninf, 1); |
| 188 | iunge (pinf, NaN, 1); |
| 189 | iunge (ninf, pinf, 0); |
| 190 | iunge (pinf, pinf, 1); |
| 191 | iunge (ninf, ninf, 1); |
| 192 | iunge (1, 4, 0); |
| 193 | iunge (3, 3, 1); |
| 194 | iunge (5, 2, 1); |
| 195 | |
| 196 | ige (1, 4, 0); |
| 197 | ige (3, 3, 1); |
| 198 | ige (5, 2, 1); |
| 199 | |
| 200 | if (failed) { |
| 201 | post_log ("Error in FPU math6 test\n"); |
| 202 | return -1; |
| 203 | } |
| 204 | return 0; |
| 205 | } |
| 206 | |
Tom Rini | 3dd5d4a | 2022-12-04 10:14:17 -0500 | [diff] [blame] | 207 | #endif /* CFG_POST & CFG_SYS_POST_FPU */ |