| 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* |
| 3 | * Copyright (C) 2022 Paul Cercueil <paul@crapouillou.net> |
| 4 | */ |
| 5 | |
| 6 | #ifndef __LIGHTREC_CONSTPROP_H__ |
| 7 | #define __LIGHTREC_CONSTPROP_H__ |
| 8 | |
| 9 | #include "lightrec.h" |
| 10 | |
| 11 | #define LIGHTREC_CONSTPROP_INITIALIZER { { 0, 0xffffffff, 0 }, } |
| 12 | |
| 13 | struct block; |
| 14 | |
| 15 | struct constprop_data { |
| 16 | u32 value; |
| 17 | u32 known; |
| 18 | u32 sign; |
| 19 | }; |
| 20 | |
| 21 | static inline _Bool is_known(const struct constprop_data *v, u8 reg) |
| 22 | { |
| 23 | return v[reg].known == 0xffffffff; |
| 24 | } |
| 25 | |
| 26 | static inline _Bool bits_are_known_zero(const struct constprop_data *v, |
| 27 | u8 reg, u32 mask) |
| 28 | { |
| 29 | return !(~v[reg].known & mask) && !(v[reg].value & mask); |
| 30 | } |
| 31 | |
| 32 | static inline _Bool is_known_zero(const struct constprop_data *v, u8 reg) |
| 33 | { |
| 34 | return bits_are_known_zero(v, reg, 0xffffffff); |
| 35 | } |
| 36 | |
| 37 | void lightrec_consts_propagate(const struct block *block, |
| 38 | unsigned int idx, |
| 39 | struct constprop_data *v); |
| 40 | |
| 41 | enum psx_map |
| 42 | lightrec_get_constprop_map(const struct lightrec_state *state, |
| 43 | const struct constprop_data *v, u8 reg, s16 imm); |
| 44 | |
| 45 | #endif /* __LIGHTREC_CONSTPROP_H__ */ |