"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/test/test-float.c" (15 Mar 2019, 2729 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test-float.c": 0.09.49_vs_0.09.50.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include <math.h>
   26 
   27 #include "../stress-version.h"
   28 
   29 /* GCC hot attribute */
   30 #if defined(__GNUC__) && NEED_GNUC(4,6,0)
   31 #define HOT     __attribute__ ((hot))
   32 #else
   33 #define HOT
   34 #endif
   35 
   36 /* -O3 attribute support */
   37 #if defined(__GNUC__) && !defined(__clang__) && NEED_GNUC(4,6,0)
   38 #define OPTIMIZE3   __attribute__((optimize("-O3")))
   39 #else
   40 #define OPTIMIZE3
   41 #endif
   42 
   43 /* From stress-cpu.c */
   44 #define float_ops(_type, a, b, c, d, _sin, _cos)        \
   45         do {                                            \
   46                 a = a + b;                              \
   47                 b = a * c;                              \
   48                 c = a - b;                              \
   49                 d = a / b;                              \
   50                 a = c / (_type)0.1923L;                 \
   51                 b = c + a;                              \
   52                 c = b * (_type)3.12L;                   \
   53                 d = d + b + (_type)_sin(a);             \
   54                 a = (b + c) / c;                        \
   55                 b = b * c;                              \
   56                 c = c + (_type)1.0L;                    \
   57                 d = d - (_type)_sin(c);                 \
   58                 a = a * (_type)_cos(b);                 \
   59                 b = b + (_type)_cos(c);                 \
   60                 c = (_type)_sin(a + b) / (_type)2.344L; \
   61                 b = d - (_type)1.0L;                    \
   62         } while (0)
   63 
   64 static FLOAT HOT OPTIMIZE3 test(void)
   65 {
   66     FLOAT a = 0.0, b = 0.0, c = 0.0, d = 0.0;
   67 
   68     float_ops(FLOAT, a, b, c, d, sin, cos);
   69     float_ops(FLOAT, a, b, c, d, sinl, cosl);
   70 
   71     return a + b + c + d;
   72 }
   73 
   74 int main(void)
   75 {
   76     return (int)test();
   77 }