1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
4 Copyright (C) 1997, Free Software Foundation, Inc.
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.
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.
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.
23 #ifndef _SIM_INLINE_H_
24 #define _SIM_INLINE_H_
27 /* INLINE CODE SELECTION:
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.
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.
40 Each module is controled by the macro <module>_INLINE which can
41 have the values described below
43 0 Do not inline any thing for the given module
45 The following additional values are `bit fields' and can be
50 Include the C file for the module into the file being compiled
51 but do not make the functions within the module inline.
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.
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.
65 Make internal (static) functions within the module `inline'.
67 In addition to this, modules have been put into two categories.
71 eg sim-endian.h sim-bits.h
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.
78 For the default build, this is a real win as all byte
79 conversion and bit manipulation functions are inlined.
83 Complex modules - the rest
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.
89 The following abreviations are available:
91 INCLUDE_MODULE == (REVEAL_MODULE | INLINE_MODULE)
93 ALL_INLINE == (REVEAL_MODULE | INLINE_MODULE | INLINE_LOCALS)
95 ALL_BY_MODULE = (INCLUDED_BY_MODULE | ALL_INLINE)
99 The inline ability is enabled by prefixing every data / function
100 declaration and definition with one of the following:
105 Prefix to any global function that is a candidate for being
108 values - `', `static', `static INLINE'
113 Prefix to any global data structures for the module. Global
114 functions that are not to be inlined shall also be prefixed
117 values - `', `static', `static'
120 STATIC_INLINE_<module>
122 Prefix to any local (static) function that is a candidate for
125 values - `static', `static INLINE'
130 Prefix all local data structures. Local functions that are not
131 to be inlined shall also be prefixed with this.
133 values - `static', `static'
135 nb: will not work for modules that are being inlined for every
140 #ifndef _SIM_INLINE_C_
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.
148 nb: this will not work when a module is being inlined for every
154 Replaced by either `static' or `EXTERN_MODULE'.
159 This is not for the faint hearted. I've seen GCC get up to 500mb
160 trying to compile what this can create.
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
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
170 int STATIC_INLINE_MODULE f(void);
171 void INLINE_MODULE *g(void);
176 #define REVEAL_MODULE 1
177 #define INLINE_MODULE 2
178 #define INCLUDE_MODULE (INLINE_MODULE | REVEAL_MODULE)
179 #define INLINE_LOCALS 4
181 #define ALL_BY_MODULE (INCLUDED_BY_MODULE | ALL_INLINE)
183 #define INCLUDED_BY_MODULE 16
184 #define REGPARM_MODULE 32
187 /* Default macro to simplify control several of key the inlines */
189 #ifndef DEFAULT_INLINE
190 #define DEFAULT_INLINE INLINE_LOCALS
195 /* Your compilers inline prefix */
198 #if defined(__GNUC__) && defined(__OPTIMIZE__)
199 #define INLINE __inline__
201 #define INLINE /*inline*/
207 /* Your compiler's static prefix */
209 #ifndef STATIC_INLINE
210 #define STATIC_INLINE static INLINE
215 /* Your compiler's no-return reserved word */
223 /* Your compilers's unused reserved word */
225 #if !defined (UNUSED)
226 #if (!defined(__GNUC__) \
228 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
231 #define UNUSED __attribute__((__unused__))
238 /* Your compilers nonstandard function call mechanism prefix */
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__))
245 #if (WITH_REGPARM && !WITH_STDCALL)
246 #define REGPARM __attribute__((__regparm__(WITH_REGPARM)))
248 #if (!WITH_REGPARM && WITH_STDCALL)
249 #define REGPARM __attribute__((__stdcall__))
264 #if (SIM_BITS_INLINE & REGPARM_MODULE)
265 # define REGPARM_SIM_BITS REGPARM
267 # define REGPARM_SIM_BITS
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
276 # define INLINE_SIM_BITS(TYPE) static TYPE UNUSED REGPARM_SIM_BITS
277 # define EXTERN_SIM_BITS(TYPE) static TYPE UNUSED REGPARM_SIM_BITS
280 # define INLINE_SIM_BITS(TYPE) TYPE REGPARM_SIM_BITS
281 # define EXTERN_SIM_BITS(TYPE) TYPE REGPARM_SIM_BITS
284 #if (SIM_BITS_INLINE & INLINE_LOCALS)
285 # define STATIC_INLINE_SIM_BITS(TYPE) static INLINE TYPE
287 # define STATIC_INLINE_SIM_BITS(TYPE) static TYPE REGPARM_SIM_BITS
294 #if (SIM_CORE_INLINE & REGPARM_MODULE)
295 # define REGPARM_SIM_CORE REGPARM
297 # define REGPARM_SIM_CORE
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
306 # define INLINE_SIM_CORE(TYPE) static TYPE UNUSED REGPARM_SIM_CORE
307 # define EXTERN_SIM_CORE(TYPE) static TYPE UNUSED REGPARM_SIM_CORE
310 # define INLINE_SIM_CORE(TYPE) TYPE REGPARM_SIM_CORE
311 # define EXTERN_SIM_CORE(TYPE) TYPE REGPARM_SIM_CORE
314 #if (SIM_CORE_INLINE & INLINE_LOCALS)
315 # define STATIC_INLINE_SIM_CORE(TYPE) static INLINE TYPE
317 # define STATIC_INLINE_SIM_CORE(TYPE) static TYPE REGPARM_SIM_CORE
324 #if (SIM_ENDIAN_INLINE & REGPARM_MODULE)
325 # define REGPARM_SIM_ENDIAN REGPARM
327 # define REGPARM_SIM_ENDIAN
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
336 # define INLINE_SIM_ENDIAN(TYPE) static TYPE UNUSED REGPARM_SIM_ENDIAN
337 # define EXTERN_SIM_ENDIAN(TYPE) static TYPE UNUSED REGPARM_SIM_ENDIAN
340 # define INLINE_SIM_ENDIAN(TYPE) TYPE REGPARM_SIM_ENDIAN
341 # define EXTERN_SIM_ENDIAN(TYPE) TYPE REGPARM_SIM_ENDIAN
344 #if (SIM_ENDIAN_INLINE & INLINE_LOCALS)
345 # define STATIC_INLINE_SIM_ENDIAN(TYPE) static INLINE TYPE
347 # define STATIC_INLINE_SIM_ENDIAN(TYPE) static TYPE REGPARM_SIM_ENDIAN
354 #if (SIM_EVENTS_INLINE & REGPARM_MODULE)
355 # define REGPARM_SIM_EVENTS REGPARM
357 # define REGPARM_SIM_EVENTS
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
366 # define INLINE_SIM_EVENTS(TYPE) static TYPE UNUSED REGPARM_SIM_EVENTS
367 # define EXTERN_SIM_EVENTS(TYPE) static TYPE UNUSED REGPARM_SIM_EVENTS
370 # define INLINE_SIM_EVENTS(TYPE) TYPE REGPARM_SIM_EVENTS
371 # define EXTERN_SIM_EVENTS(TYPE) TYPE REGPARM_SIM_EVENTS
374 #if (SIM_EVENTS_INLINE & INLINE_LOCALS)
375 # define STATIC_INLINE_SIM_EVENTS(TYPE) static INLINE TYPE
377 # define STATIC_INLINE_SIM_EVENTS(TYPE) static TYPE REGPARM_SIM_EVENTS
384 #if (SIM_FPU_INLINE & REGPARM_MODULE)
385 # define REGPARM_SIM_FPU REGPARM
387 # define REGPARM_SIM_FPU
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
396 # define INLINE_SIM_FPU(TYPE) static TYPE UNUSED REGPARM_SIM_FPU
397 # define EXTERN_SIM_FPU(TYPE) static TYPE UNUSED REGPARM_SIM_FPU
400 # define INLINE_SIM_FPU(TYPE) TYPE REGPARM_SIM_FPU
401 # define EXTERN_SIM_FPU(TYPE) TYPE REGPARM_SIM_FPU
404 #if (SIM_FPU_INLINE & INLINE_LOCALS)
405 # define STATIC_INLINE_SIM_FPU(TYPE) static INLINE TYPE
407 # define STATIC_INLINE_SIM_FPU(TYPE) static TYPE REGPARM_SIM_FPU
414 #if (SIM_TYPES_INLINE & REGPARM_MODULE)
415 # define REGPARM_SIM_TYPES REGPARM
417 # define REGPARM_SIM_TYPES
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
426 # define INLINE_SIM_TYPES(TYPE) static TYPE UNUSED REGPARM_SIM_TYPES
427 # define EXTERN_SIM_TYPES(TYPE) static TYPE UNUSED REGPARM_SIM_TYPES
430 # define INLINE_SIM_TYPES(TYPE) TYPE REGPARM_SIM_TYPES
431 # define EXTERN_SIM_TYPES(TYPE) TYPE REGPARM_SIM_TYPES
434 #if (SIM_TYPES_INLINE & INLINE_LOCALS)
435 # define STATIC_INLINE_SIM_TYPES(TYPE) static INLINE TYPE
437 # define STATIC_INLINE_SIM_TYPES(TYPE) static TYPE REGPARM_SIM_TYPES
444 #if (ICACHE_INLINE & REGPARM_MODULE)
445 # define REGPARM_ICACHE REGPARM
447 # define REGPARM_ICACHE
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
456 # define INLINE_ICACHE(TYPE) static TYPE UNUSED REGPARM_ICACHE
457 # define EXTERN_ICACHE(TYPE) static TYPE UNUSED REGPARM_ICACHE
460 # define INLINE_ICACHE(TYPE) TYPE REGPARM_ICACHE
461 # define EXTERN_ICACHE(TYPE) TYPE REGPARM_ICACHE
464 #if (ICACHE_INLINE & INLINE_LOCALS)
465 # define STATIC_INLINE_ICACHE(TYPE) static INLINE TYPE
467 # define STATIC_INLINE_ICACHE(TYPE) static TYPE REGPARM_ICACHE
474 #if (IDECODE_INLINE & REGPARM_MODULE)
475 # define REGPARM_IDECODE REGPARM
477 # define REGPARM_IDECODE
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
486 # define INLINE_IDECODE(TYPE) static TYPE UNUSED REGPARM_IDECODE
487 # define EXTERN_IDECODE(TYPE) static TYPE UNUSED REGPARM_IDECODE
490 # define INLINE_IDECODE(TYPE) TYPE REGPARM_IDECODE
491 # define EXTERN_IDECODE(TYPE) TYPE REGPARM_IDECODE
494 #if (IDECODE_INLINE & INLINE_LOCALS)
495 # define STATIC_INLINE_IDECODE(TYPE) static INLINE TYPE
497 # define STATIC_INLINE_IDECODE(TYPE) static TYPE REGPARM_IDECODE
504 #if (SEMANTICS_INLINE & REGPARM_MODULE)
505 # define REGPARM_SEMANTICS REGPARM
507 # define REGPARM_SEMANTICS
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
516 # define INLINE_SEMANTICS(TYPE) static TYPE UNUSED REGPARM_SEMANTICS
517 # define EXTERN_SEMANTICS(TYPE) static TYPE UNUSED REGPARM_SEMANTICS
520 # define INLINE_SEMANTICS(TYPE) TYPE REGPARM_SEMANTICS
521 # define EXTERN_SEMANTICS(TYPE) TYPE REGPARM_SEMANTICS
524 #if (SEMANTICS_INLINE & INLINE_LOCALS)
525 # define STATIC_INLINE_SEMANTICS(TYPE) static INLINE TYPE
527 # define STATIC_INLINE_SEMANTICS(TYPE) static TYPE REGPARM_SEMANTICS
534 #if (SUPPORT_INLINE & REGPARM_MODULE)
535 # define REGPARM_SUPPORT REGPARM
537 # define REGPARM_SUPPORT
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
546 # define INLINE_SUPPORT(TYPE) static TYPE UNUSED REGPARM_SUPPORT
547 # define EXTERN_SUPPORT(TYPE) static TYPE UNUSED REGPARM_SUPPORT
550 # define INLINE_SUPPORT(TYPE) TYPE REGPARM_SUPPORT
551 # define EXTERN_SUPPORT(TYPE) TYPE REGPARM_SUPPORT
554 #if (SUPPORT_INLINE & INLINE_LOCALS)
555 # define STATIC_INLINE_SUPPORT(TYPE) static INLINE TYPE
557 # define STATIC_INLINE_SUPPORT(TYPE) static TYPE REGPARM_SUPPORT