]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/sim-inline.h
This commit was generated by cvs2svn to track changes on a CVS vendor
[thirdparty/binutils-gdb.git] / sim / common / sim-inline.h
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
4 Copyright (C) 1997, Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 */
21
22
23 #ifndef _SIM_INLINE_H_
24 #define _SIM_INLINE_H_
25
26
27 /* INLINE CODE SELECTION:
28
29 GCC -O3 attempts to inline any function or procedure in scope. The
30 options below facilitate fine grained control over what is and what
31 isn't made inline. For instance it can control things down to a
32 specific modules static routines. Doing this allows the compiler
33 to both eliminate the overhead of function calls and (as a
34 consequence) also eliminate further dead code.
35
36 On a CISC (x86) I've found that I can achieve an order of magintude
37 speed improvement (x3-x5). In the case of RISC (sparc) while the
38 performance gain isn't as great it is still significant.
39
40 Each module is controled by the macro <module>_INLINE which can
41 have the values described below
42
43 0 Do not inline any thing for the given module
44
45 The following additional values are `bit fields' and can be
46 combined.
47
48 REVEAL_MODULE:
49
50 Include the C file for the module into the file being compiled
51 but do not make the functions within the module inline.
52
53 While of no apparent benefit, this makes it possible for the
54 included module, when compiled to inline its calls to what
55 would otherwize be external functions.
56
57 INLINE_MODULE:
58
59 Make external functions within the module `inline'. Thus if
60 the module is included into a file being compiled, calls to
61 its funtions can be eliminated. 2 implies 1.
62
63 INLINE_LOCALS:
64
65 Make internal (static) functions within the module `inline'.
66
67 In addition to this, modules have been put into two categories.
68
69 INCLUDED_BY_MODULE
70
71 eg sim-endian.h sim-bits.h
72
73 Because these modules are small and simple and do not have
74 any complex interdendencies they are configured, if
75 <module>_INLINE is so enabled, to inline themselves in all
76 modules that include those files.
77
78 For the default build, this is a real win as all byte
79 conversion and bit manipulation functions are inlined.
80
81 !INCLUDED_BY_MODULE
82
83 Complex modules - the rest
84
85 These are all handled using the files sim-inline.h and
86 sim-inline.c. The main simulator engine includes both of
87 these and hence includes all remaining code.
88
89 The following abreviations are available:
90
91 INCLUDE_MODULE == (REVEAL_MODULE | INLINE_MODULE)
92
93 ALL_INLINE == (REVEAL_MODULE | INLINE_MODULE | INLINE_LOCALS)
94
95 ALL_BY_MODULE = (INCLUDED_BY_MODULE | ALL_INLINE)
96
97 IMPLEMENTATION:
98
99 The inline ability is enabled by prefixing every data / function
100 declaration and definition with one of the following:
101
102
103 INLINE_<module>
104
105 Prefix to any global function that is a candidate for being
106 inline.
107
108 values - `', `static', `static INLINE'
109
110
111 EXTERN_<module>
112
113 Prefix to any global data structures for the module. Global
114 functions that are not to be inlined shall also be prefixed
115 with this.
116
117 values - `', `static', `static'
118
119
120 STATIC_INLINE_<module>
121
122 Prefix to any local (static) function that is a candidate for
123 being made inline.
124
125 values - `static', `static INLINE'
126
127
128 static
129
130 Prefix all local data structures. Local functions that are not
131 to be inlined shall also be prefixed with this.
132
133 values - `static', `static'
134
135 nb: will not work for modules that are being inlined for every
136 use (white lie).
137
138
139 extern
140 #ifndef _SIM_INLINE_C_
141 #endif
142
143 Prefix to any declaration of a global object (function or
144 variable) that should not be inlined and should have only one
145 definition. The #ifndef wrapper goes around the definition
146 propper to ensure that only one copy is generated.
147
148 nb: this will not work when a module is being inlined for every
149 use.
150
151
152 STATIC_<module>
153
154 Replaced by either `static' or `EXTERN_MODULE'.
155
156
157 REALITY CHECK:
158
159 This is not for the faint hearted. I've seen GCC get up to 500mb
160 trying to compile what this can create.
161
162 Some of the modules do not yet implement the WITH_INLINE_STATIC
163 option. Instead they use the macro STATIC_INLINE to control their
164 local function.
165
166 Because of the way that GCC parses __attribute__(), the macro's
167 need to be adjacent to the functioin name rather then at the start
168 of the line vis:
169
170 int STATIC_INLINE_MODULE f(void);
171 void INLINE_MODULE *g(void);
172
173 */
174
175
176 #define REVEAL_MODULE 1
177 #define INLINE_MODULE 2
178 #define INCLUDE_MODULE (INLINE_MODULE | REVEAL_MODULE)
179 #define INLINE_LOCALS 4
180 #define ALL_INLINE 7
181 #define ALL_BY_MODULE (INCLUDED_BY_MODULE | ALL_INLINE)
182
183 #define INCLUDED_BY_MODULE 16
184 #define REGPARM_MODULE 32
185
186
187 /* Default macro to simplify control several of key the inlines */
188
189 #ifndef DEFAULT_INLINE
190 #define DEFAULT_INLINE INLINE_LOCALS
191 #endif
192
193
194
195 /* Your compilers inline prefix */
196
197 #ifndef INLINE
198 #if defined(__GNUC__) && defined(__OPTIMIZE__)
199 #define INLINE __inline__
200 #else
201 #define INLINE /*inline*/
202 #endif
203 #endif
204
205
206
207 /* Your compiler's static prefix */
208
209 #ifndef STATIC_INLINE
210 #define STATIC_INLINE static INLINE
211 #endif
212
213
214
215 /* Your compiler's no-return reserved word */
216
217 #ifndef NORETURN
218 #define NORETURN
219 #endif
220
221
222
223 /* Your compilers's unused reserved word */
224
225 #if !defined (UNUSED)
226 #if (!defined(__GNUC__) \
227 || (__GNUC__ < 2) \
228 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
229 #define UNUSED
230 #else
231 #define UNUSED __attribute__((__unused__))
232 #endif
233 #endif
234
235
236
237
238 /* Your compilers nonstandard function call mechanism prefix */
239
240 #if !defined REGPARM
241 #if defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__))
242 #if (WITH_REGPARM && WITH_STDCALL)
243 #define REGPARM __attribute__((__regparm__(WITH_REGPARM),__stdcall__))
244 #else
245 #if (WITH_REGPARM && !WITH_STDCALL)
246 #define REGPARM __attribute__((__regparm__(WITH_REGPARM)))
247 #else
248 #if (!WITH_REGPARM && WITH_STDCALL)
249 #define REGPARM __attribute__((__stdcall__))
250 #endif
251 #endif
252 #endif
253 #endif
254 #endif
255
256 #if !defined REGPARM
257 #define REGPARM
258 #endif
259
260
261
262 /* sim-bits */
263
264 #if (SIM_BITS_INLINE & REGPARM_MODULE)
265 # define REGPARM_SIM_BITS REGPARM
266 #else
267 # define REGPARM_SIM_BITS
268 #endif
269
270 #if (((SIM_BITS_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
271 && !defined(_SIM_BITS_C_) && (SIM_BITS_INLINE & INCLUDE_MODULE))
272 # if (SIM_BITS_INLINE & INLINE_MODULE)
273 # define INLINE_SIM_BITS(TYPE) static INLINE TYPE UNUSED
274 # define EXTERN_SIM_BITS(TYPE) static TYPE UNUSED REGPARM_SIM_BITS
275 # else
276 # define INLINE_SIM_BITS(TYPE) static TYPE UNUSED REGPARM_SIM_BITS
277 # define EXTERN_SIM_BITS(TYPE) static TYPE UNUSED REGPARM_SIM_BITS
278 # endif
279 #else
280 # define INLINE_SIM_BITS(TYPE) TYPE REGPARM_SIM_BITS
281 # define EXTERN_SIM_BITS(TYPE) TYPE REGPARM_SIM_BITS
282 #endif
283
284 #if (SIM_BITS_INLINE & INLINE_LOCALS)
285 # define STATIC_INLINE_SIM_BITS(TYPE) static INLINE TYPE
286 #else
287 # define STATIC_INLINE_SIM_BITS(TYPE) static TYPE REGPARM_SIM_BITS
288 #endif
289
290
291
292 /* sim-core */
293
294 #if (SIM_CORE_INLINE & REGPARM_MODULE)
295 # define REGPARM_SIM_CORE REGPARM
296 #else
297 # define REGPARM_SIM_CORE
298 #endif
299
300 #if (((SIM_CORE_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
301 && !defined(_SIM_CORE_C_) && (SIM_CORE_INLINE & INCLUDE_MODULE))
302 # if (SIM_CORE_INLINE & INLINE_MODULE)
303 # define INLINE_SIM_CORE(TYPE) static INLINE TYPE UNUSED
304 # define EXTERN_SIM_CORE(TYPE) static TYPE UNUSED REGPARM_SIM_CORE
305 #else
306 # define INLINE_SIM_CORE(TYPE) static TYPE UNUSED REGPARM_SIM_CORE
307 # define EXTERN_SIM_CORE(TYPE) static TYPE UNUSED REGPARM_SIM_CORE
308 #endif
309 #else
310 # define INLINE_SIM_CORE(TYPE) TYPE REGPARM_SIM_CORE
311 # define EXTERN_SIM_CORE(TYPE) TYPE REGPARM_SIM_CORE
312 #endif
313
314 #if (SIM_CORE_INLINE & INLINE_LOCALS)
315 # define STATIC_INLINE_SIM_CORE(TYPE) static INLINE TYPE
316 #else
317 # define STATIC_INLINE_SIM_CORE(TYPE) static TYPE REGPARM_SIM_CORE
318 #endif
319
320
321
322 /* sim-endian */
323
324 #if (SIM_ENDIAN_INLINE & REGPARM_MODULE)
325 # define REGPARM_SIM_ENDIAN REGPARM
326 #else
327 # define REGPARM_SIM_ENDIAN
328 #endif
329
330 #if (((SIM_ENDIAN_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
331 && !defined(_SIM_ENDIAN_C_) && (SIM_ENDIAN_INLINE & INCLUDE_MODULE))
332 # if (SIM_ENDIAN_INLINE & INLINE_MODULE)
333 # define INLINE_SIM_ENDIAN(TYPE) static INLINE TYPE UNUSED
334 # define EXTERN_SIM_ENDIAN(TYPE) static TYPE UNUSED REGPARM_SIM_ENDIAN
335 # else
336 # define INLINE_SIM_ENDIAN(TYPE) static TYPE UNUSED REGPARM_SIM_ENDIAN
337 # define EXTERN_SIM_ENDIAN(TYPE) static TYPE UNUSED REGPARM_SIM_ENDIAN
338 # endif
339 #else
340 # define INLINE_SIM_ENDIAN(TYPE) TYPE REGPARM_SIM_ENDIAN
341 # define EXTERN_SIM_ENDIAN(TYPE) TYPE REGPARM_SIM_ENDIAN
342 #endif
343
344 #if (SIM_ENDIAN_INLINE & INLINE_LOCALS)
345 # define STATIC_INLINE_SIM_ENDIAN(TYPE) static INLINE TYPE
346 #else
347 # define STATIC_INLINE_SIM_ENDIAN(TYPE) static TYPE REGPARM_SIM_ENDIAN
348 #endif
349
350
351
352 /* sim-events */
353
354 #if (SIM_EVENTS_INLINE & REGPARM_MODULE)
355 # define REGPARM_SIM_EVENTS REGPARM
356 #else
357 # define REGPARM_SIM_EVENTS
358 #endif
359
360 #if (((SIM_EVENTS_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
361 && !defined(_SIM_EVENTS_C_) && (SIM_EVENTS_INLINE & INCLUDE_MODULE))
362 # if (SIM_EVENTS_INLINE & INLINE_MODULE)
363 # define INLINE_SIM_EVENTS(TYPE) static INLINE TYPE UNUSED
364 # define EXTERN_SIM_EVENTS(TYPE) static TYPE UNUSED REGPARM_SIM_EVENTS
365 # else
366 # define INLINE_SIM_EVENTS(TYPE) static TYPE UNUSED REGPARM_SIM_EVENTS
367 # define EXTERN_SIM_EVENTS(TYPE) static TYPE UNUSED REGPARM_SIM_EVENTS
368 # endif
369 #else
370 # define INLINE_SIM_EVENTS(TYPE) TYPE REGPARM_SIM_EVENTS
371 # define EXTERN_SIM_EVENTS(TYPE) TYPE REGPARM_SIM_EVENTS
372 #endif
373
374 #if (SIM_EVENTS_INLINE & INLINE_LOCALS)
375 # define STATIC_INLINE_SIM_EVENTS(TYPE) static INLINE TYPE
376 #else
377 # define STATIC_INLINE_SIM_EVENTS(TYPE) static TYPE REGPARM_SIM_EVENTS
378 #endif
379
380
381
382 /* sim-fpu */
383
384 #if (SIM_FPU_INLINE & REGPARM_MODULE)
385 # define REGPARM_SIM_FPU REGPARM
386 #else
387 # define REGPARM_SIM_FPU
388 #endif
389
390 #if (((SIM_FPU_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
391 && !defined(_SIM_FPU_C_) && (SIM_FPU_INLINE & INCLUDE_MODULE))
392 # if (SIM_FPU_INLINE & INLINE_MODULE)
393 # define INLINE_SIM_FPU(TYPE) static INLINE TYPE UNUSED
394 # define EXTERN_SIM_FPU(TYPE) static TYPE UNUSED REGPARM_SIM_FPU
395 # else
396 # define INLINE_SIM_FPU(TYPE) static TYPE UNUSED REGPARM_SIM_FPU
397 # define EXTERN_SIM_FPU(TYPE) static TYPE UNUSED REGPARM_SIM_FPU
398 # endif
399 #else
400 # define INLINE_SIM_FPU(TYPE) TYPE REGPARM_SIM_FPU
401 # define EXTERN_SIM_FPU(TYPE) TYPE REGPARM_SIM_FPU
402 #endif
403
404 #if (SIM_FPU_INLINE & INLINE_LOCALS)
405 # define STATIC_INLINE_SIM_FPU(TYPE) static INLINE TYPE
406 #else
407 # define STATIC_INLINE_SIM_FPU(TYPE) static TYPE REGPARM_SIM_FPU
408 #endif
409
410
411
412 /* sim-types */
413
414 #if (SIM_TYPES_INLINE & REGPARM_MODULE)
415 # define REGPARM_SIM_TYPES REGPARM
416 #else
417 # define REGPARM_SIM_TYPES
418 #endif
419
420 #if (((SIM_TYPES_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
421 && !defined(_SIM_TYPES_C_) && (SIM_TYPES_INLINE & INCLUDE_MODULE))
422 # if (SIM_TYPES_INLINE & INLINE_MODULE)
423 # define INLINE_SIM_TYPES(TYPE) static INLINE TYPE UNUSED
424 # define EXTERN_SIM_TYPES(TYPE) static TYPE UNUSED REGPARM_SIM_TYPES
425 # else
426 # define INLINE_SIM_TYPES(TYPE) static TYPE UNUSED REGPARM_SIM_TYPES
427 # define EXTERN_SIM_TYPES(TYPE) static TYPE UNUSED REGPARM_SIM_TYPES
428 # endif
429 #else
430 # define INLINE_SIM_TYPES(TYPE) TYPE REGPARM_SIM_TYPES
431 # define EXTERN_SIM_TYPES(TYPE) TYPE REGPARM_SIM_TYPES
432 #endif
433
434 #if (SIM_TYPES_INLINE & INLINE_LOCALS)
435 # define STATIC_INLINE_SIM_TYPES(TYPE) static INLINE TYPE
436 #else
437 # define STATIC_INLINE_SIM_TYPES(TYPE) static TYPE REGPARM_SIM_TYPES
438 #endif
439
440
441
442 /* icache */
443
444 #if (ICACHE_INLINE & REGPARM_MODULE)
445 # define REGPARM_ICACHE REGPARM
446 #else
447 # define REGPARM_ICACHE
448 #endif
449
450 #if (((ICACHE_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
451 && !defined(_ICACHE_C_) && (ICACHE_INLINE & INCLUDE_MODULE))
452 # if (ICACHE_INLINE & INLINE_MODULE)
453 # define INLINE_ICACHE(TYPE) static INLINE TYPE UNUSED
454 # define EXTERN_ICACHE(TYPE) static TYPE UNUSED REGPARM_ICACHE
455 #else
456 # define INLINE_ICACHE(TYPE) static TYPE UNUSED REGPARM_ICACHE
457 # define EXTERN_ICACHE(TYPE) static TYPE UNUSED REGPARM_ICACHE
458 #endif
459 #else
460 # define INLINE_ICACHE(TYPE) TYPE REGPARM_ICACHE
461 # define EXTERN_ICACHE(TYPE) TYPE REGPARM_ICACHE
462 #endif
463
464 #if (ICACHE_INLINE & INLINE_LOCALS)
465 # define STATIC_INLINE_ICACHE(TYPE) static INLINE TYPE
466 #else
467 # define STATIC_INLINE_ICACHE(TYPE) static TYPE REGPARM_ICACHE
468 #endif
469
470
471
472 /* idecode */
473
474 #if (IDECODE_INLINE & REGPARM_MODULE)
475 # define REGPARM_IDECODE REGPARM
476 #else
477 # define REGPARM_IDECODE
478 #endif
479
480 #if (((IDECODE_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
481 && !defined(_IDECODE_C_) && (IDECODE_INLINE & INCLUDE_MODULE))
482 # if (IDECODE_INLINE & INLINE_MODULE)
483 # define INLINE_IDECODE(TYPE) static INLINE TYPE UNUSED
484 # define EXTERN_IDECODE(TYPE) static TYPE UNUSED REGPARM_IDECODE
485 #else
486 # define INLINE_IDECODE(TYPE) static TYPE UNUSED REGPARM_IDECODE
487 # define EXTERN_IDECODE(TYPE) static TYPE UNUSED REGPARM_IDECODE
488 #endif
489 #else
490 # define INLINE_IDECODE(TYPE) TYPE REGPARM_IDECODE
491 # define EXTERN_IDECODE(TYPE) TYPE REGPARM_IDECODE
492 #endif
493
494 #if (IDECODE_INLINE & INLINE_LOCALS)
495 # define STATIC_INLINE_IDECODE(TYPE) static INLINE TYPE
496 #else
497 # define STATIC_INLINE_IDECODE(TYPE) static TYPE REGPARM_IDECODE
498 #endif
499
500
501
502 /* semantics */
503
504 #if (SEMANTICS_INLINE & REGPARM_MODULE)
505 # define REGPARM_SEMANTICS REGPARM
506 #else
507 # define REGPARM_SEMANTICS
508 #endif
509
510 #if (((SEMANTICS_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
511 && !defined(_SEMANTICS_C_) && (SEMANTICS_INLINE & INCLUDE_MODULE))
512 # if (SEMANTICS_INLINE & INLINE_MODULE)
513 # define INLINE_SEMANTICS(TYPE) static INLINE TYPE UNUSED
514 # define EXTERN_SEMANTICS(TYPE) static TYPE UNUSED REGPARM_SEMANTICS
515 #else
516 # define INLINE_SEMANTICS(TYPE) static TYPE UNUSED REGPARM_SEMANTICS
517 # define EXTERN_SEMANTICS(TYPE) static TYPE UNUSED REGPARM_SEMANTICS
518 #endif
519 #else
520 # define INLINE_SEMANTICS(TYPE) TYPE REGPARM_SEMANTICS
521 # define EXTERN_SEMANTICS(TYPE) TYPE REGPARM_SEMANTICS
522 #endif
523
524 #if (SEMANTICS_INLINE & INLINE_LOCALS)
525 # define STATIC_INLINE_SEMANTICS(TYPE) static INLINE TYPE
526 #else
527 # define STATIC_INLINE_SEMANTICS(TYPE) static TYPE REGPARM_SEMANTICS
528 #endif
529
530
531
532 /* support */
533
534 #if (SUPPORT_INLINE & REGPARM_MODULE)
535 # define REGPARM_SUPPORT REGPARM
536 #else
537 # define REGPARM_SUPPORT
538 #endif
539
540 #if (((SUPPORT_INLINE & INCLUDED_BY_MODULE) || defined(_SIM_INLINE_C_)) \
541 && !defined(_SUPPORT_C_) && (SUPPORT_INLINE & INCLUDE_MODULE))
542 # if (SUPPORT_INLINE & INLINE_MODULE)
543 # define INLINE_SUPPORT(TYPE) static INLINE TYPE UNUSED
544 # define EXTERN_SUPPORT(TYPE) static TYPE UNUSED REGPARM_SUPPORT
545 #else
546 # define INLINE_SUPPORT(TYPE) static TYPE UNUSED REGPARM_SUPPORT
547 # define EXTERN_SUPPORT(TYPE) static TYPE UNUSED REGPARM_SUPPORT
548 #endif
549 #else
550 # define INLINE_SUPPORT(TYPE) TYPE REGPARM_SUPPORT
551 # define EXTERN_SUPPORT(TYPE) TYPE REGPARM_SUPPORT
552 #endif
553
554 #if (SUPPORT_INLINE & INLINE_LOCALS)
555 # define STATIC_INLINE_SUPPORT(TYPE) static INLINE TYPE
556 #else
557 # define STATIC_INLINE_SUPPORT(TYPE) static TYPE REGPARM_SUPPORT
558 #endif
559
560
561
562 #endif