Branch
Hash :
7b089321
Author :
Date :
2025-01-01T09:24:36
maint: run 'make update-copyright'
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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
/* Benchmarks for totalorder*().
Copyright (C) 2023-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "bench.h"
#include "infinity.h"
#include "macros.h"
#include "minus-zero.h"
#include "signed-nan.h"
#include "signed-snan.h"
int volatile tmp;
#define FINITE_VALUES \
{ -1e37 }, \
{ -1 }, \
{ -1e-5 }, \
{ 0 }, \
{ 1e-5 }, \
{ 0.5772156649015328606 }, \
{ 0.6931471805599453094 }, \
{ 0.8346268416740731863 }, \
{ 0.91596559417721901505 }, \
{ 1 }, \
{ 1.2020569031595942854 }, \
{ 1.6066951524152917638 }, \
{ 1.6180339887498948482 }, \
{ 1.6449340668482264365 }, \
{ 2.6220575542921198105 }, \
{ 2.7182818284590452354 }, \
{ 3.1415926535897932385 }, \
{ 4.66920160910299067185 }, \
{ 262537412640768743.99999999999925007 }, \
{ 1e37 }
static void
do_float_test (char test, int repeat)
{
printf ("Test %c\n", test);
memory_float data[] =
{
#if HAVE_SNANF
memory_negative_SNaNf (),
memory_positive_SNaNf (),
#endif
{ negative_NaNf () },
{ positive_NaNf () },
{ -Infinityf () },
{ Infinityf () },
{ minus_zerof },
FINITE_VALUES
};
int n = sizeof (data) / sizeof (data[0]);
struct timings_state ts;
timing_start (&ts);
int count;
for (count = 0; count < repeat; count++)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
tmp = totalorderf (&data[i].value, &data[j].value);
}
timing_end (&ts);
timing_output (&ts);
printf ("\n");
}
static void
do_double_test (char test, int repeat)
{
printf ("Test %c\n", test);
memory_double data[] =
{
#if HAVE_SNAND
memory_negative_SNaNd (),
memory_positive_SNaNd (),
#endif
{ negative_NaNd () },
{ positive_NaNd () },
{ -Infinityd () },
{ Infinityd () },
{ minus_zerod },
FINITE_VALUES
};
int n = sizeof (data) / sizeof (data[0]);
struct timings_state ts;
timing_start (&ts);
int count;
for (count = 0; count < repeat; count++)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
tmp = totalorder (&data[i].value, &data[j].value);
}
timing_end (&ts);
timing_output (&ts);
printf ("\n");
}
static void
do_long_double_test (char test, int repeat)
{
printf ("Test %c\n", test);
memory_long_double data[] =
{
#if HAVE_SNANL
memory_negative_SNaNl (),
memory_positive_SNaNl (),
#endif
{ negative_NaNl () },
{ positive_NaNl () },
{ -Infinityl () },
{ Infinityl () },
{ minus_zerol },
FINITE_VALUES
};
int n = sizeof (data) / sizeof (data[0]);
struct timings_state ts;
timing_start (&ts);
int count;
for (count = 0; count < repeat; count++)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
tmp = totalorderl (&data[i].value, &data[j].value);
}
timing_end (&ts);
timing_output (&ts);
printf ("\n");
}
/* Performs some or all of the following tests:
f - float
d - double
l - long double
Pass the tests to be performed as first argument. */
int
main (int argc, char *argv[])
{
if (argc != 3)
{
fprintf (stderr, "Usage: %s TESTS REPETITIONS\n", argv[0]);
fprintf (stderr, "Example: %s fdl 1000000\n", argv[0]);
exit (1);
}
const char *tests = argv[1];
int repeat = atoi (argv[2]);
/* Execute each test. */
size_t i;
for (i = 0; i < strlen (tests); i++)
{
char test = tests[i];
switch (test)
{
case 'f':
do_float_test (test, repeat);
break;
case 'd':
do_double_test (test, repeat);
break;
case 'l':
do_long_double_test (test, repeat);
break;
default:
/* Ignore. */
;
}
}
return 0;
}