* src/vm/jit/codegen-common.cpp (codegen_emit): New generic version of the
[cacao.git] / src / vm / jit / optimizing / profile.h
1 /* src/vm/jit/optimizing/profile.h - runtime profiling
2
3    Copyright (C) 1996-2005, 2006, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _PROFILE_H
27 #define _PROFILE_H
28
29 #include "config.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #include "vm/types.h"
36
37 #include "vm/global.h"
38
39
40 /* CPU cycle counting macros **************************************************/
41
42 #if defined(ENABLE_PROFILING) && defined(__X86_64__)
43
44 #define PROFILE_CYCLE_START \
45     do { \
46         if (JITDATA_HAS_FLAG_INSTRUMENT(jd)) { \
47             M_PUSH(RAX); \
48             M_PUSH(RDX); \
49             \
50             M_MOV_IMM(code, REG_ITMP3); \
51             M_RDTSC; \
52             M_ISUB_MEMBASE(RAX, REG_ITMP3, OFFSET(codeinfo, cycles)); \
53             M_ISBB_MEMBASE(RDX, REG_ITMP3, OFFSET(codeinfo, cycles) + 4); \
54             \
55             M_POP(RDX); \
56             M_POP(RAX); \
57         } \
58     } while (0)
59
60 #define PROFILE_CYCLE_STOP \
61     do { \
62         if (JITDATA_HAS_FLAG_INSTRUMENT(jd)) { \
63             M_PUSH(RAX); \
64             M_PUSH(RDX); \
65             \
66             M_MOV_IMM(code, REG_ITMP3); \
67             M_RDTSC; \
68             M_IADD_MEMBASE(RAX, REG_ITMP3, OFFSET(codeinfo, cycles)); \
69             M_IADC_MEMBASE(RDX, REG_ITMP3, OFFSET(codeinfo, cycles) + 4); \
70             \
71             M_POP(RDX); \
72             M_POP(RAX); \
73         } \
74     } while (0)
75
76 #else
77
78 #define PROFILE_CYCLE_START
79 #define PROFILE_CYCLE_STOP
80
81 #endif
82
83
84 /* function prototypes ********************************************************/
85
86 bool profile_init(void);
87 bool profile_start_thread(void);
88
89 #if !defined(NDEBUG)
90 void profile_printstats(void);
91 #endif
92
93 #ifdef __cplusplus
94 }
95 #endif
96
97 #endif /* _PROFILE_H */
98
99
100 /*
101  * These are local overrides for various environment variables in Emacs.
102  * Please do not remove this and leave it at the end of the file, where
103  * Emacs will automagically detect them.
104  * ---------------------------------------------------------------------
105  * Local variables:
106  * mode: c
107  * indent-tabs-mode: t
108  * c-basic-offset: 4
109  * tab-width: 4
110  * End:
111  */