uboot/post/lib_ppc/fpu/compare-fp-1.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2007
   3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   4 *
   5 * See file CREDITS for list of people who contributed to this
   6 * project.
   7 *
   8 * This program is free software; you can redistribute it and/or
   9 * modify it under the terms of the GNU General Public License as
  10 * published by the Free Software Foundation; either version 2 of
  11 * the License, or (at your option) any later version.
  12 *
  13 * This program is distributed in the hope that it will be useful,
  14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16 * GNU General Public License for more details.
  17 *
  18 * You should have received a copy of the GNU General Public License
  19 * along with this program; if not, write to the Free Software
  20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 * MA 02111-1307 USA
  22 */
  23/*
  24 * Test for correctness of composite floating-point comparisons.
  25 * Written by Paolo Bonzini, 26th May 2004.
  26 * This file is originally a part of the GCC testsuite.
  27 */
  28
  29#include <common.h>
  30
  31#include <post.h>
  32
  33#if CONFIG_POST & CONFIG_SYS_POST_FPU
  34
  35static int failed;
  36
  37#define TEST(c) if ((c) != ok) failed++
  38#define ORD(a, b) (!__builtin_isunordered ((a), (b)))
  39#define UNORD(a, b) (__builtin_isunordered ((a), (b)))
  40#define UNEQ(a, b) (__builtin_isunordered ((a), (b)) || ((a) == (b)))
  41#define UNLT(a, b) (__builtin_isunordered ((a), (b)) || ((a) < (b)))
  42#define UNLE(a, b) (__builtin_isunordered ((a), (b)) || ((a) <= (b)))
  43#define UNGT(a, b) (__builtin_isunordered ((a), (b)) || ((a) > (b)))
  44#define UNGE(a, b) (__builtin_isunordered ((a), (b)) || ((a) >= (b)))
  45#define LTGT(a, b) (__builtin_islessgreater ((a), (b)))
  46
  47static float pinf;
  48static float ninf;
  49static float NaN;
  50
  51static void iuneq (float x, float y, int ok)
  52{
  53        TEST (UNEQ (x, y));
  54        TEST (!LTGT (x, y));
  55        TEST (UNLE (x, y) && UNGE (x,y));
  56}
  57
  58static void ieq (float x, float y, int ok)
  59{
  60        TEST (ORD (x, y) && UNEQ (x, y));
  61}
  62
  63static void iltgt (float x, float y, int ok)
  64{
  65        TEST (!UNEQ (x, y)); /* Not optimizable. */
  66        TEST (LTGT (x, y)); /* Same, __builtin_islessgreater does not trap. */
  67        TEST (ORD (x, y) && (UNLT (x, y) || UNGT (x,y)));
  68}
  69
  70static void ine (float x, float y, int ok)
  71{
  72        TEST (UNLT (x, y) || UNGT (x, y));
  73}
  74
  75static void iunlt (float x, float y, int ok)
  76{
  77        TEST (UNLT (x, y));
  78        TEST (UNORD (x, y) || (x < y));
  79}
  80
  81static void ilt (float x, float y, int ok)
  82{
  83        TEST (ORD (x, y) && UNLT (x, y)); /* Not optimized */
  84        TEST ((x <= y) && (x != y));
  85        TEST ((x <= y) && (y != x));
  86        TEST ((x != y) && (x <= y)); /* Not optimized */
  87        TEST ((y != x) && (x <= y)); /* Not optimized */
  88}
  89
  90static void iunle (float x, float y, int ok)
  91{
  92        TEST (UNLE (x, y));
  93        TEST (UNORD (x, y) || (x <= y));
  94}
  95
  96static void ile (float x, float y, int ok)
  97{
  98        TEST (ORD (x, y) && UNLE (x, y)); /* Not optimized */
  99        TEST ((x < y) || (x == y));
 100        TEST ((y > x) || (x == y));
 101        TEST ((x == y) || (x < y)); /* Not optimized */
 102        TEST ((y == x) || (x < y)); /* Not optimized */
 103}
 104
 105static void iungt (float x, float y, int ok)
 106{
 107        TEST (UNGT (x, y));
 108        TEST (UNORD (x, y) || (x > y));
 109}
 110
 111static void igt (float x, float y, int ok)
 112{
 113        TEST (ORD (x, y) && UNGT (x, y)); /* Not optimized */
 114        TEST ((x >= y) && (x != y));
 115        TEST ((x >= y) && (y != x));
 116        TEST ((x != y) && (x >= y)); /* Not optimized */
 117        TEST ((y != x) && (x >= y)); /* Not optimized */
 118}
 119
 120static void iunge (float x, float y, int ok)
 121{
 122        TEST (UNGE (x, y));
 123        TEST (UNORD (x, y) || (x >= y));
 124}
 125
 126static void ige (float x, float y, int ok)
 127{
 128        TEST (ORD (x, y) && UNGE (x, y)); /* Not optimized */
 129        TEST ((x > y) || (x == y));
 130        TEST ((y < x) || (x == y));
 131        TEST ((x == y) || (x > y)); /* Not optimized */
 132        TEST ((y == x) || (x > y)); /* Not optimized */
 133}
 134
 135int fpu_post_test_math6 (void)
 136{
 137        pinf = __builtin_inf ();
 138        ninf = -__builtin_inf ();
 139        NaN = __builtin_nan ("");
 140
 141        iuneq (ninf, pinf, 0);
 142        iuneq (NaN, NaN, 1);
 143        iuneq (pinf, ninf, 0);
 144        iuneq (1, 4, 0);
 145        iuneq (3, 3, 1);
 146        iuneq (5, 2, 0);
 147
 148        ieq (1, 4, 0);
 149        ieq (3, 3, 1);
 150        ieq (5, 2, 0);
 151
 152        iltgt (ninf, pinf, 1);
 153        iltgt (NaN, NaN, 0);
 154        iltgt (pinf, ninf, 1);
 155        iltgt (1, 4, 1);
 156        iltgt (3, 3, 0);
 157        iltgt (5, 2, 1);
 158
 159        ine (1, 4, 1);
 160        ine (3, 3, 0);
 161        ine (5, 2, 1);
 162
 163        iunlt (NaN, ninf, 1);
 164        iunlt (pinf, NaN, 1);
 165        iunlt (pinf, ninf, 0);
 166        iunlt (pinf, pinf, 0);
 167        iunlt (ninf, ninf, 0);
 168        iunlt (1, 4, 1);
 169        iunlt (3, 3, 0);
 170        iunlt (5, 2, 0);
 171
 172        ilt (1, 4, 1);
 173        ilt (3, 3, 0);
 174        ilt (5, 2, 0);
 175
 176        iunle (NaN, ninf, 1);
 177        iunle (pinf, NaN, 1);
 178        iunle (pinf, ninf, 0);
 179        iunle (pinf, pinf, 1);
 180        iunle (ninf, ninf, 1);
 181        iunle (1, 4, 1);
 182        iunle (3, 3, 1);
 183        iunle (5, 2, 0);
 184
 185        ile (1, 4, 1);
 186        ile (3, 3, 1);
 187        ile (5, 2, 0);
 188
 189        iungt (NaN, ninf, 1);
 190        iungt (pinf, NaN, 1);
 191        iungt (pinf, ninf, 1);
 192        iungt (pinf, pinf, 0);
 193        iungt (ninf, ninf, 0);
 194        iungt (1, 4, 0);
 195        iungt (3, 3, 0);
 196        iungt (5, 2, 1);
 197
 198        igt (1, 4, 0);
 199        igt (3, 3, 0);
 200        igt (5, 2, 1);
 201
 202        iunge (NaN, ninf, 1);
 203        iunge (pinf, NaN, 1);
 204        iunge (ninf, pinf, 0);
 205        iunge (pinf, pinf, 1);
 206        iunge (ninf, ninf, 1);
 207        iunge (1, 4, 0);
 208        iunge (3, 3, 1);
 209        iunge (5, 2, 1);
 210
 211        ige (1, 4, 0);
 212        ige (3, 3, 1);
 213        ige (5, 2, 1);
 214
 215        if (failed) {
 216                post_log ("Error in FPU math6 test\n");
 217                return -1;
 218        }
 219        return 0;
 220}
 221
 222#endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */
 223