git subrepo clone https://github.com/pcercuei/lightrec.git deps/lightrec
[pcsx_rearmed.git] / deps / lightrec / regcache.h
1 /*
2  * Copyright (C) 2014 Paul Cercueil <paul@crapouillou.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  */
14
15 #ifndef __REGCACHE_H__
16 #define __REGCACHE_H__
17
18 #include "lightrec-private.h"
19
20 #define NUM_REGS (JIT_V_NUM - 2)
21 #define NUM_TEMPS (JIT_R_NUM)
22 #define LIGHTREC_REG_STATE (JIT_V(JIT_V_NUM - 1))
23 #define LIGHTREC_REG_CYCLE (JIT_V(JIT_V_NUM - 2))
24
25 #define REG_LO 32
26 #define REG_HI 33
27
28 struct register_value {
29         _Bool known;
30         u32 value;
31 };
32
33 struct native_register;
34 struct regcache;
35
36 u8 lightrec_alloc_reg(struct regcache *cache, jit_state_t *_jit, u8 jit_reg);
37 u8 lightrec_alloc_reg_temp(struct regcache *cache, jit_state_t *_jit);
38 u8 lightrec_alloc_reg_out(struct regcache *cache, jit_state_t *_jit, u8 reg);
39 u8 lightrec_alloc_reg_in(struct regcache *cache, jit_state_t *_jit, u8 reg);
40 u8 lightrec_alloc_reg_out_ext(struct regcache *cache,
41                               jit_state_t *_jit, u8 reg);
42 u8 lightrec_alloc_reg_in_ext(struct regcache *cache, jit_state_t *_jit, u8 reg);
43
44 u8 lightrec_request_reg_in(struct regcache *cache, jit_state_t *_jit,
45                            u8 reg, u8 jit_reg);
46
47 void lightrec_regcache_reset(struct regcache *cache);
48
49 void lightrec_lock_reg(struct regcache *cache, jit_state_t *_jit, u8 jit_reg);
50 void lightrec_free_reg(struct regcache *cache, u8 jit_reg);
51 void lightrec_free_regs(struct regcache *cache);
52 void lightrec_clean_reg(struct regcache *cache, jit_state_t *_jit, u8 jit_reg);
53 void lightrec_clean_regs(struct regcache *cache, jit_state_t *_jit);
54 void lightrec_unload_reg(struct regcache *cache, jit_state_t *_jit, u8 jit_reg);
55 void lightrec_storeback_regs(struct regcache *cache, jit_state_t *_jit);
56
57 void lightrec_clean_reg_if_loaded(struct regcache *cache, jit_state_t *_jit,
58                                   u8 reg, _Bool unload);
59
60 u8 lightrec_alloc_reg_in_address(struct regcache *cache,
61                 jit_state_t *_jit, u8 reg, s16 offset);
62
63 struct native_register * lightrec_regcache_enter_branch(struct regcache *cache);
64 void lightrec_regcache_leave_branch(struct regcache *cache,
65                         struct native_register *regs);
66
67 struct regcache * lightrec_regcache_init(struct lightrec_state *state);
68 void lightrec_free_regcache(struct regcache *cache);
69
70 const char * lightrec_reg_name(u8 reg);
71
72 void lightrec_regcache_mark_live(struct regcache *cache, jit_state_t *_jit);
73
74 #endif /* __REGCACHE_H__ */