annotate packages/kernel/current/tests/fptest.c @ 782:a9ff9f7e3010

* tests/fptest.c: Make all variables static to avoid any risk of collisions with symbols defined elsewhere in eCos.
author jlarmour
date Mon, 03 Mar 2003 05:15:52 +0000
parents 74589c7c236e
children 92cf4ff674de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
1 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
2 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
3 // fptest.cxx
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
4 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
5 // Basic FPU test
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
6 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
7 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
8 //####ECOSGPLCOPYRIGHTBEGIN####
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
9 // -------------------------------------------
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
11 // Copyright (C) 2003 Nick Garnett
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
12 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
14 // the terms of the GNU General Public License as published by the Free
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later version.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
16 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
20 // for more details.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
21 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
22 // You should have received a copy of the GNU General Public License along
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
25 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
26 // As a special exception, if other files instantiate templates or use macros
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
27 // or inline functions from this file, or you compile this file and link it
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
28 // with other works to produce a work based on this file, this file does not
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
29 // by itself cause the resulting work to be covered by the GNU General Public
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
30 // License. However the source code for this file must still be made available
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
31 // in accordance with section (3) of the GNU General Public License.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
32 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
33 // This exception does not invalidate any other reasons why a work based on
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
34 // this file might be covered by the GNU General Public License.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
35 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
36 // -------------------------------------------
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
37 //####ECOSGPLCOPYRIGHTEND####
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
38 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
39 //#####DESCRIPTIONBEGIN####
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
40 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
41 // Author(s): nickg@calivar.com
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
42 // Contributors: nickg@calivar.com
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
43 // Date: 2003-01-27
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
44 // Description: Simple FPU test. This is not very sophisticated as far
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
45 // as checking FPU performance or accuracy. It is more
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
46 // concerned with checking that several threads doing FP
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
47 // operations do not interfere with eachother's use of the
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
48 // FPU.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
49 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
50 //####DESCRIPTIONEND####
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
51 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
52
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
53 #include <pkgconf/kernel.h>
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
54 #include <pkgconf/hal.h>
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
55
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
56 #include <cyg/hal/hal_arch.h>
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
57
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
58 #include <cyg/kernel/kapi.h>
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
59
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
60 #include <cyg/infra/testcase.h>
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
61 #include <cyg/infra/diag.h>
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
62
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
63 //#include <cyg/kernel/test/stackmon.h>
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
64 //#include CYGHWR_MEMORY_LAYOUT_H
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
65
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
66 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
67
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
68 #if defined(CYGFUN_KERNEL_API_C) && \
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
69 defined(CYGSEM_KERNEL_SCHED_MLQUEUE) && \
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
70 (CYGNUM_KERNEL_SCHED_PRIORITIES > 12)
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
71
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
72 //==========================================================================
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
73 // Base priority for all threads.
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
74
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
75 #define BASE_PRI 5
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
76
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
77 //==========================================================================
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
78 // Runtime
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
79 //
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
80 // This is the number of ticks that the program will run for. 3000
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
81 // ticks is equal to 30 seconds in the default configuration. For
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
82 // simulators we reduce the run time to 3 simulated seconds.
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
83
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
84 #define RUN_TICKS 3000
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
85 #define RUN_TICKS_SIM 300
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
86
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
87 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
88 // Thread parameters
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
89
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
90 #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_MINIMUM)
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
91
782
a9ff9f7e3010 * tests/fptest.c: Make all variables static to avoid any risk
jlarmour
parents: 760
diff changeset
92 static cyg_uint8 stacks[3][STACK_SIZE];
a9ff9f7e3010 * tests/fptest.c: Make all variables static to avoid any risk
jlarmour
parents: 760
diff changeset
93 static cyg_handle_t thread[3];
a9ff9f7e3010 * tests/fptest.c: Make all variables static to avoid any risk
jlarmour
parents: 760
diff changeset
94 static cyg_thread thread_struct[3];
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
95
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
96 //==========================================================================
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
97 // Alarm parameters.
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
98
782
a9ff9f7e3010 * tests/fptest.c: Make all variables static to avoid any risk
jlarmour
parents: 760
diff changeset
99 static cyg_alarm alarm_struct;
a9ff9f7e3010 * tests/fptest.c: Make all variables static to avoid any risk
jlarmour
parents: 760
diff changeset
100 static cyg_handle_t alarm;
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
101
782
a9ff9f7e3010 * tests/fptest.c: Make all variables static to avoid any risk
jlarmour
parents: 760
diff changeset
102 static cyg_count8 cur_thread = 0;
a9ff9f7e3010 * tests/fptest.c: Make all variables static to avoid any risk
jlarmour
parents: 760
diff changeset
103 static cyg_count32 alarm_ticks = 0;
a9ff9f7e3010 * tests/fptest.c: Make all variables static to avoid any risk
jlarmour
parents: 760
diff changeset
104 static cyg_count32 run_ticks = RUN_TICKS;
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
105
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
106 //==========================================================================
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
107
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
108 static int errors = 0;
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
109
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
110 //==========================================================================
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
111 // Random number generator. Ripped out of the C library.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
112
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
113 static int rand( unsigned int *seed )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
114 {
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
115 // This is the code supplied in Knuth Vol 2 section 3.6 p.185 bottom
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
116
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
117 #define RAND_MAX 0x7fffffff
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
118 #define MM 2147483647 // a Mersenne prime
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
119 #define AA 48271 // this does well in the spectral test
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
120 #define QQ 44488 // (long)(MM/AA)
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
121 #define RR 3399 // MM % AA; it is important that RR<QQ
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
122
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
123 *seed = AA*(*seed % QQ) - RR*(unsigned int)(*seed/QQ);
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
124 if (*seed < 0)
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
125 *seed += MM;
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
126
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
127 return (int)( *seed & RAND_MAX );
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
128 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
129
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
130 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
131 // Test calculation.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
132 //
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
133 // Generates an array of random FP values and then repeatedly applies
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
134 // a calculation to them and checks that the same result is reached
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
135 // each time. The calculation, in the macro CALC, is intended to make
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
136 // maximum use of the FPU registers. However, the i386 compiler
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
137 // doesn't let this expression get very complex before it starts
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
138 // spilling values out to memory.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
139
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
140 static void do_test( double *values,
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
141 int count,
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
142 int loops,
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
143 int test,
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
144 const char *name)
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
145 {
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
146 unsigned int i, j;
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
147 // volatiles necessary to force
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
148 // values to 64 bits for comparison
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
149 volatile double sum = 1.0;
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
150 volatile double last_sum;
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
151 unsigned int seed;
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
152
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
153 #define V(__i) (values[(__i)%count])
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
154 #define CALC ((V(i-1)*V(i+1))*(V(i-2)*V(i+2))*(V(i-3)*sum))
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
155
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
156 seed = ((unsigned int)&i)*count;
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
157
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
158 // Set up an array of values...
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
159 for( i = 0; i < count; i++ )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
160 values[i] = (double)rand( &seed )/(double)0x7fffffff;
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
161
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
162 // Now calculate something from them...
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
163 for( i = 0; i < count; i++ )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
164 sum += CALC;
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
165 last_sum = sum;
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
166
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
167 // Now recalculate the sum in a loop and look for errors
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
168 for( j = 0; j < loops ; j++ )
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
169 {
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
170 sum = 1.0;
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
171 for( i = 0; i < count; i++ )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
172 sum += CALC;
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
173
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
174 if( sum != last_sum )
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
175 {
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
176 errors++;
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
177 diag_printf("%s: Sum mismatch! %d sum=[%08x:%08x] last_sum=[%08x:%08x]\n",
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
178 name,j,
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
179 ((cyg_uint32 *)&sum)[0],((cyg_uint32 *)&sum)[1],
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
180 ((cyg_uint32 *)&last_sum)[0],((cyg_uint32 *)&last_sum)[1]
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
181 );
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
182 }
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
183
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
184 #if 0
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
185 if( ((j*count)%1000000) == 0 )
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
186 diag_printf("INFO:<%s: %2d calculations done>\n",name,j*count);
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
187 #endif
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
188 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
189
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
190 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
191
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
192 //==========================================================================
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
193 // Alarm handler
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
194 //
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
195 // This is called every tick. It lowers the priority of the currently
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
196 // running thread and raises the priority of the next. Thus we
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
197 // implement a form of timelslicing between the threads at one tick
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
198 // granularity.
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
199
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
200 static void alarm_fn(cyg_handle_t alarm, cyg_addrword_t data)
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
201 {
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
202 alarm_ticks++;
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
203
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
204 if( alarm_ticks >= run_ticks )
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
205 {
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
206 if( errors )
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
207 CYG_TEST_FAIL("Errors detected");
760
74589c7c236e * tests/fptest.c (alarm_fn): Added CYG_TEST_PASS() call to keep
nickg
parents: 648
diff changeset
208 else
74589c7c236e * tests/fptest.c (alarm_fn): Added CYG_TEST_PASS() call to keep
nickg
parents: 648
diff changeset
209 CYG_TEST_PASS("OK");
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
210
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
211 CYG_TEST_FINISH("FP Test done");
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
212 }
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
213 else
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
214 {
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
215 cyg_thread_set_priority( thread[cur_thread], BASE_PRI );
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
216
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
217 cur_thread = (cur_thread+1)%3;
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
218
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
219 cyg_thread_set_priority( thread[cur_thread], BASE_PRI-1 );
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
220 }
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
221 }
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
222
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
223
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
224 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
225
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
226 #define FP1_COUNT 1000
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
227
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
228 static double fpt1_values[FP1_COUNT];
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
229
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
230 void fptest1( CYG_ADDRWORD id )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
231 {
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
232 while(1)
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
233 do_test( fpt1_values, FP1_COUNT, 2000000000, id, "fptest1" );
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
234 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
235
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
236 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
237
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
238 #define FP2_COUNT 10000
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
239
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
240 static double fpt2_values[FP2_COUNT];
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
241
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
242 void fptest2( CYG_ADDRWORD id )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
243 {
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
244 while(1)
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
245 do_test( fpt2_values, FP2_COUNT, 2000000000, id, "fptest2" );
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
246 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
247
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
248 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
249
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
250 #define FP3_COUNT 100
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
251
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
252 static double fpt3_values[FP3_COUNT];
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
253
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
254 void fptest3( CYG_ADDRWORD id )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
255 {
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
256 while(1)
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
257 do_test( fpt3_values, FP3_COUNT, 2000000000, id, "fptest3" );
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
258 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
259
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
260 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
261
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
262 void fptest_main( void )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
263 {
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
264
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
265 CYG_TEST_INIT();
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
266
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
267 if( cyg_test_is_simulator )
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
268 {
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
269 run_ticks = RUN_TICKS_SIM;
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
270 }
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
271
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
272 CYG_TEST_INFO("Run fptest in cyg_start");
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
273 do_test( fpt3_values, FP3_COUNT, 1000, 0, "start" );
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
274 CYG_TEST_INFO( "cyg_start run done");
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
275
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
276 cyg_thread_create( BASE_PRI-1,
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
277 fptest1,
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
278 0,
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
279 "fptest1",
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
280 &stacks[0][0],
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
281 STACK_SIZE,
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
282 &thread[0],
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
283 &thread_struct[0]);
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
284
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
285 cyg_thread_resume( thread[0] );
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
286
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
287 cyg_thread_create( BASE_PRI,
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
288 fptest2,
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
289 1,
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
290 "fptest2",
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
291 &stacks[1][0],
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
292 STACK_SIZE,
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
293 &thread[1],
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
294 &thread_struct[1]);
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
295
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
296 cyg_thread_resume( thread[1] );
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
297
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
298 cyg_thread_create( BASE_PRI,
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
299 fptest3,
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
300 2,
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
301 "fptest3",
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
302 &stacks[2][0],
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
303 STACK_SIZE,
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
304 &thread[2],
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
305 &thread_struct[2]);
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
306
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
307 cyg_thread_resume( thread[2] );
648
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
308
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
309 cyg_alarm_create( cyg_real_time_clock(),
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
310 alarm_fn,
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
311 0,
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
312 &alarm,
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
313 &alarm_struct );
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
314
0c5540a10fcc * tests/fptest.c: Changed to run for a constant time rather than a
nickg
parents: 552
diff changeset
315 cyg_alarm_initialize( alarm, cyg_current_time()+1, 1 );
552
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
316
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
317 cyg_scheduler_start();
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
318
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
319 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
320
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
321 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
322
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
323 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
324 externC void
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
325 cyg_hal_invoke_constructors();
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
326 #endif
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
327
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
328 externC void
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
329 cyg_start( void )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
330 {
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
331 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
332 cyg_hal_invoke_constructors();
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
333 #endif
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
334 fptest_main();
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
335 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
336
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
337 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
338
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
339 #else // CYGFUN_KERNEL_API_C...
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
340
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
341 externC void
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
342 cyg_start( void )
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
343 {
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
344 CYG_TEST_INIT();
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
345 CYG_TEST_NA("FP test requires:\n"
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
346 "CYGFUN_KERNEL_API_C && \n"
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
347 "CYGSEM_KERNEL_SCHED_MLQUEUE && \n"
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
348 "(CYGNUM_KERNEL_SCHED_PRIORITIES > 12)\n");
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
349 }
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
350
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
351 #endif // CYGFUN_KERNEL_API_C, etc.
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
352
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
353 //==========================================================================
fddb77989fbb * cdl/kernel.cdl:
nickg
parents:
diff changeset
354 // EOF fptest.cxx