git subrepo pull (merge) --force deps/lightning
[pcsx_rearmed.git] / deps / lightning / include / lightning / jit_arm.h
CommitLineData
4a71579b 1/*
79bfeef6 2 * Copyright (C) 2012-2023 Free Software Foundation, Inc.
4a71579b
PC
3 *
4 * This file is part of GNU lightning.
5 *
6 * GNU lightning is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * GNU lightning is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
15 *
16 * Authors:
17 * Paulo Cesar Pereira de Andrade
18 */
19
20#ifndef _jit_arm_h
21#define _jit_arm_h
22
23#define JIT_HASH_CONSTS 0
24#define JIT_NUM_OPERANDS 3
25
26/*
27 * Types
28 */
29#define jit_swf_p() (jit_cpu.vfp == 0)
30#define jit_hardfp_p() jit_cpu.abi
31#define jit_ldrt_strt_p() jit_cpu.ldrt_strt
32
33#define JIT_FP _R11
34typedef enum {
35#define jit_r(i) (_R4 + (i))
36#define jit_r_num() 3
37#define jit_v(i) (_R7 + (i))
38#define jit_v_num() 3
39#define jit_f(i) (jit_cpu.abi ? _D8 + ((i)<<1) : _D0 - ((i)<<1))
40#define jit_f_num() 8
41 _R12, /* ip - temporary */
42#define JIT_R0 _R4
43#define JIT_R1 _R5
44#define JIT_R2 _R6
45 _R4, /* r4 - variable */
46 _R5, /* r5 - variable */
47 _R6, /* r6 - variable */
48#define JIT_V0 _R7
49#define JIT_V1 _R8
50#define JIT_V2 _R9
51 _R7, /* r7 - variable */
52 _R8, /* r8 - variable */
53 _R9, /* r9 - variable */
54 _R10, /* sl - stack limit */
55 _R11, /* fp - frame pointer */
56 _R13, /* sp - stack pointer */
57 _R14, /* lr - link register */
58 _R15, /* pc - program counter */
59 _R3, /* r3 - argument/result */
60 _R2, /* r2 - argument/result */
61 _R1, /* r1 - argument/result */
62 _R0, /* r0 - argument/result */
63#define JIT_F0 (jit_hardfp_p() ? _D8 : _D0)
64#define JIT_F1 (jit_hardfp_p() ? _D9 : _D1)
65#define JIT_F2 (jit_hardfp_p() ? _D10 : _D2)
66#define JIT_F3 (jit_hardfp_p() ? _D11 : _D3)
67#define JIT_F4 (jit_hardfp_p() ? _D12 : _D4)
68#define JIT_F5 (jit_hardfp_p() ? _D13 : _D5)
69#define JIT_F6 (jit_hardfp_p() ? _D14 : _D6)
70#define JIT_F7 (jit_hardfp_p() ? _D15 : _D7)
71 _S16, _D8 = _S16, _Q4 = _D8,
72 _S17,
73 _S18, _D9 = _S18,
74 _S19,
75 _S20, _D10 = _S20, _Q5 = _D10,
76 _S21,
77 _S22, _D11 = _S22,
78 _S23,
79 _S24, _D12 = _S24, _Q6 = _D12,
80 _S25,
81 _S26, _D13 = _S26,
82 _S27,
83 _S28, _D14 = _S28, _Q7 = _D14,
84 _S29,
85 _S30, _D15 = _S30,
86 _S31,
87 _S15,
88 _S14, _D7 = _S14,
89 _S13,
90 _S12, _D6 = _S12, _Q3 = _D6,
91 _S11,
92 _S10, _D5 = _S10,
93 _S9,
94 _S8, _D4 = _S8, _Q2 = _D4,
95 _S7,
96 _S6, _D3 = _S6,
97 _S5,
98 _S4, _D2 = _S4, _Q1 = _D2,
99 _S3,
100 _S2, _D1 = _S2,
101 _S1,
102 _S0, _D0 = _S0, _Q0 = _D0,
103 _NOREG,
104#define JIT_NOREG _NOREG
105} jit_reg_t;
106
107typedef struct {
108 jit_uint32_t version : 4;
79bfeef6
PC
109 /* this field originally was only used for the 'e' in armv5te.
110 * it can also be used to force hardware division, if setting
111 * version to 7, telling it is armv7r or better. */
4a71579b
PC
112 jit_uint32_t extend : 1;
113 /* only generate thumb instructions for thumb2 */
114 jit_uint32_t thumb : 1;
115 jit_uint32_t vfp : 3;
116 jit_uint32_t neon : 1;
117 jit_uint32_t abi : 2;
118 /* use strt+offset instead of str.w?
119 * on special cases it causes a SIGILL at least on qemu, probably
120 * due to some memory ordering constraint not being respected, so,
121 * disable by default */
122 jit_uint32_t ldrt_strt : 1;
79bfeef6
PC
123 /* assume functions called never match jit instruction set?
124 * that is libc, gmp, mpfr, etc functions are in thumb mode and jit
125 * is in arm mode, or the reverse, what may cause a crash upon return
126 * of that function if generating jit for a relative jump.
127 */
128 jit_uint32_t exchange : 1;
ba86ff93
PC
129 /* By default assume cannot load unaligned data.
130 * A3.2.1
131 * Unaligned data access
132 * An ARMv7 implementation must support unaligned data accesses by
133 * some load and store instructions, as Table A3-1 shows. Software
134 * can set the SCTLR.A bit to control whether a misaligned access by
135 * one of these instructions causes an Alignment fault Data Abort
136 * exception.
137 * Table A3-1 Alignment requirements of load/store instructions
138 * Result if check fails when
139 * Instructions Alignment check SCTLR.A is 0 SCTLR.A is 1
140 * LDRB, LDREXB,
141 * LDRBT, LDRSB,
142 * LDRSBT, STRB,
143 * STREXB, STRBT,
144 * SWPB, TBB None - -
145 * LDRH, LDRHT,
146 * LDRSH, LDRSHT,
147 * STRH, STRHT,
148 * TBH Halfword Unaligned access Alignment fault
149 * LDREXH, STREXH Halfword Alignment fault Alignment fault
150 * LDR, LDRT,
151 * STR, STRT Word Unaligned access Alignment fault
152 * LDREX, STREX Word Alignment fault Alignment fault
153 * LDREXD, STREXD Doubleword Alignment fault Alignment fault
154 * All forms of
155 * LDM and STM,
156 * LDRD, RFE, SRS,
157 * STRD, SWP Word Alignment fault Alignment fault
158 * LDC, LDC2,
159 * STC, STC2 Word Alignment fault Alignment fault
160 * VLDM, VLDR,
161 * VPOP, VPUSH,
162 * VSTM, VSTR Word Alignment fault Alignment fault
163 * VLD1, VLD2,
164 * VLD3, VLD4,
165 * VST1, VST2,
166 * VST3, VST4,
167 * all with
168 * standard
169 * alignment (a) Element size Unaligned access Alignment fault
170 * VLD1, VLD2,
171 * VLD3, VLD4,
172 * VST1, VST2,
173 * VST3, VST4,
174 * all with
175 * @<align>
176 * specified (a) As specified by Alignment fault Alignment fault
177 * @<align>
178 *
179 * (a) These element and structure load/store instructions are only in
180 * the Advanced SIMD Extension to the ARMv7 ARM and Thumb instruction
181 * sets. ARMv7 does not support the pre-ARMv6 alignment model, so
182 * software cannot use that model with these instructions.
183 */
184 jit_uint32_t unaligned : 1;
185 jit_uint32_t vfp_unaligned : 1;
4a71579b
PC
186} jit_cpu_t;
187
188/*
189 * Initialization
190 */
191extern jit_cpu_t jit_cpu;
192
193#endif /* _jit_arm_h */