xref: /openbmc/qemu/target/hexagon/idef-parser/macros.h.inc (revision a53b931645183bd0c15dd19ae0708fc3c81ecf1d)
1*b8daa5fcSPhilippe Mathieu-Daudé/*
2*b8daa5fcSPhilippe Mathieu-Daudé *  Copyright(c) 2019-2022 rev.ng Labs Srl. All Rights Reserved.
3*b8daa5fcSPhilippe Mathieu-Daudé *
4*b8daa5fcSPhilippe Mathieu-Daudé *  This program is free software; you can redistribute it and/or modify
5*b8daa5fcSPhilippe Mathieu-Daudé *  it under the terms of the GNU General Public License as published by
6*b8daa5fcSPhilippe Mathieu-Daudé *  the Free Software Foundation; either version 2 of the License, or
7*b8daa5fcSPhilippe Mathieu-Daudé *  (at your option) any later version.
8*b8daa5fcSPhilippe Mathieu-Daudé *
9*b8daa5fcSPhilippe Mathieu-Daudé *  This program is distributed in the hope that it will be useful,
10*b8daa5fcSPhilippe Mathieu-Daudé *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11*b8daa5fcSPhilippe Mathieu-Daudé *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*b8daa5fcSPhilippe Mathieu-Daudé *  GNU General Public License for more details.
13*b8daa5fcSPhilippe Mathieu-Daudé *
14*b8daa5fcSPhilippe Mathieu-Daudé *  You should have received a copy of the GNU General Public License
15*b8daa5fcSPhilippe Mathieu-Daudé *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16*b8daa5fcSPhilippe Mathieu-Daudé */
17*b8daa5fcSPhilippe Mathieu-Daudé
18*b8daa5fcSPhilippe Mathieu-Daudé/* Copy rules */
19*b8daa5fcSPhilippe Mathieu-Daudé#define fLSBOLD(VAL) (fGETBIT(0, VAL))
20*b8daa5fcSPhilippe Mathieu-Daudé#define fSATH(VAL) fSATN(16, VAL)
21*b8daa5fcSPhilippe Mathieu-Daudé#define fSATUH(VAL) fSATUN(16, VAL)
22*b8daa5fcSPhilippe Mathieu-Daudé#define fVSATH(VAL) fVSATN(16, VAL)
23*b8daa5fcSPhilippe Mathieu-Daudé#define fVSATUH(VAL) fVSATUN(16, VAL)
24*b8daa5fcSPhilippe Mathieu-Daudé#define fSATUB(VAL) fSATUN(8, VAL)
25*b8daa5fcSPhilippe Mathieu-Daudé#define fSATB(VAL) fSATN(8, VAL)
26*b8daa5fcSPhilippe Mathieu-Daudé#define fVSATUB(VAL) fVSATUN(8, VAL)
27*b8daa5fcSPhilippe Mathieu-Daudé#define fVSATB(VAL) fVSATN(8, VAL)
28*b8daa5fcSPhilippe Mathieu-Daudé#define fCALL(A) fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);
29*b8daa5fcSPhilippe Mathieu-Daudé#define fCALLR(A) fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);
30*b8daa5fcSPhilippe Mathieu-Daudé#define fCAST2_8s(A) fSXTN(16, 64, A)
31*b8daa5fcSPhilippe Mathieu-Daudé#define fCAST2_8u(A) fZXTN(16, 64, A)
32*b8daa5fcSPhilippe Mathieu-Daudé#define fVSATW(A) fVSATN(32, fCAST8_8s(A))
33*b8daa5fcSPhilippe Mathieu-Daudé#define fSATW(A) fSATN(32, fCAST8_8s(A))
34*b8daa5fcSPhilippe Mathieu-Daudé#define fVSAT(A) fVSATN(32, A)
35*b8daa5fcSPhilippe Mathieu-Daudé#define fSAT(A) fSATN(32, A)
36*b8daa5fcSPhilippe Mathieu-Daudé
37*b8daa5fcSPhilippe Mathieu-Daudé/* Ease parsing */
38*b8daa5fcSPhilippe Mathieu-Daudé#define f8BITSOF(VAL) ((VAL) ? 0xff : 0x00)
39*b8daa5fcSPhilippe Mathieu-Daudé#define fREAD_GP() (Constant_extended ? (0) : GP)
40*b8daa5fcSPhilippe Mathieu-Daudé#define fCLIP(DST, SRC, U) (DST = fMIN((1 << U) - 1, fMAX(SRC, -(1 << U))))
41*b8daa5fcSPhilippe Mathieu-Daudé#define fBIDIR_ASHIFTL(SRC, SHAMT, REGSTYPE)                            \
42*b8daa5fcSPhilippe Mathieu-Daudé    ((SHAMT > 0) ?                                                      \
43*b8daa5fcSPhilippe Mathieu-Daudé     (fCAST##REGSTYPE##s(SRC) << SHAMT) :                               \
44*b8daa5fcSPhilippe Mathieu-Daudé     (fCAST##REGSTYPE##s(SRC) >> -SHAMT))
45*b8daa5fcSPhilippe Mathieu-Daudé
46*b8daa5fcSPhilippe Mathieu-Daudé#define fBIDIR_LSHIFTL(SRC, SHAMT, REGSTYPE)    \
47*b8daa5fcSPhilippe Mathieu-Daudé    ((SHAMT > 0) ?                              \
48*b8daa5fcSPhilippe Mathieu-Daudé     (fCAST##REGSTYPE##u(SRC) << SHAMT) :       \
49*b8daa5fcSPhilippe Mathieu-Daudé     (fCAST##REGSTYPE##u(SRC) >>> -SHAMT))
50*b8daa5fcSPhilippe Mathieu-Daudé
51*b8daa5fcSPhilippe Mathieu-Daudé#define fBIDIR_ASHIFTR(SRC, SHAMT, REGSTYPE)    \
52*b8daa5fcSPhilippe Mathieu-Daudé    ((SHAMT > 0) ?                              \
53*b8daa5fcSPhilippe Mathieu-Daudé     (fCAST##REGSTYPE##s(SRC) >> SHAMT) :       \
54*b8daa5fcSPhilippe Mathieu-Daudé     (fCAST##REGSTYPE##s(SRC) << -SHAMT))
55*b8daa5fcSPhilippe Mathieu-Daudé
56*b8daa5fcSPhilippe Mathieu-Daudé#define fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE) \
57*b8daa5fcSPhilippe Mathieu-Daudé    (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) << ((-(SHAMT)) - 1)) << 1)  \
58*b8daa5fcSPhilippe Mathieu-Daudé                   : (fCAST##REGSTYPE(SRC) >> (SHAMT)))
59*b8daa5fcSPhilippe Mathieu-Daudé
60*b8daa5fcSPhilippe Mathieu-Daudé#define fBIDIR_LSHIFTR(SRC, SHAMT, REGSTYPE)                            \
61*b8daa5fcSPhilippe Mathieu-Daudé    fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE##u)
62*b8daa5fcSPhilippe Mathieu-Daudé
63*b8daa5fcSPhilippe Mathieu-Daudé#define fSATVALN(N, VAL)                                                \
64*b8daa5fcSPhilippe Mathieu-Daudé    fSET_OVERFLOW(                                                      \
65*b8daa5fcSPhilippe Mathieu-Daudé        ((VAL) < 0) ? (-(1LL << ((N) - 1))) : ((1LL << ((N) - 1)) - 1)  \
66*b8daa5fcSPhilippe Mathieu-Daudé    )
67*b8daa5fcSPhilippe Mathieu-Daudé
68*b8daa5fcSPhilippe Mathieu-Daudé#define fSAT_ORIG_SHL(A, ORIG_REG)                                      \
69*b8daa5fcSPhilippe Mathieu-Daudé    (((fCAST4s((fSAT(A)) ^ (fCAST4s(ORIG_REG)))) < 0)                   \
70*b8daa5fcSPhilippe Mathieu-Daudé        ? fSATVALN(32, (fCAST4s(ORIG_REG)))                             \
71*b8daa5fcSPhilippe Mathieu-Daudé        : ((((ORIG_REG) > 0) && ((A) == 0)) ? fSATVALN(32, (ORIG_REG))  \
72*b8daa5fcSPhilippe Mathieu-Daudé                                            : fSAT(A)))
73*b8daa5fcSPhilippe Mathieu-Daudé
74*b8daa5fcSPhilippe Mathieu-Daudé#define fBIDIR_ASHIFTR_SAT(SRC, SHAMT, REGSTYPE)                        \
75*b8daa5fcSPhilippe Mathieu-Daudé    (((SHAMT) < 0) ? fSAT_ORIG_SHL((fCAST##REGSTYPE##s(SRC)             \
76*b8daa5fcSPhilippe Mathieu-Daudé                        << ((-(SHAMT)) - 1)) << 1, (SRC))               \
77*b8daa5fcSPhilippe Mathieu-Daudé                   : (fCAST##REGSTYPE##s(SRC) >> (SHAMT)))
78*b8daa5fcSPhilippe Mathieu-Daudé
79*b8daa5fcSPhilippe Mathieu-Daudé#define fBIDIR_ASHIFTL_SAT(SRC, SHAMT, REGSTYPE)                        \
80*b8daa5fcSPhilippe Mathieu-Daudé    (((SHAMT) < 0)                                                      \
81*b8daa5fcSPhilippe Mathieu-Daudé     ? ((fCAST##REGSTYPE##s(SRC) >> ((-(SHAMT)) - 1)) >> 1)             \
82*b8daa5fcSPhilippe Mathieu-Daudé     : fSAT_ORIG_SHL(fCAST##REGSTYPE##s(SRC) << (SHAMT), (SRC)))
83*b8daa5fcSPhilippe Mathieu-Daudé
84*b8daa5fcSPhilippe Mathieu-Daudé#define fEXTRACTU_BIDIR(INREG, WIDTH, OFFSET)                           \
85*b8daa5fcSPhilippe Mathieu-Daudé    (fZXTN(WIDTH, 32, fBIDIR_LSHIFTR((INREG), (OFFSET), 4_8)))
86*b8daa5fcSPhilippe Mathieu-Daudé
87*b8daa5fcSPhilippe Mathieu-Daudé/* Least significant bit operations */
88*b8daa5fcSPhilippe Mathieu-Daudé#define fLSBNEW0 fLSBNEW(P0N)
89*b8daa5fcSPhilippe Mathieu-Daudé#define fLSBNEW1 fLSBNEW(P1N)
90*b8daa5fcSPhilippe Mathieu-Daudé#define fLSBOLDNOT(VAL) fGETBIT(0, ~VAL)
91*b8daa5fcSPhilippe Mathieu-Daudé#define fLSBNEWNOT(PRED) (fLSBNEW(~PRED))
92*b8daa5fcSPhilippe Mathieu-Daudé#define fLSBNEW0NOT fLSBNEW(~P0N)
93*b8daa5fcSPhilippe Mathieu-Daudé#define fLSBNEW1NOT fLSBNEW(~P1N)
94*b8daa5fcSPhilippe Mathieu-Daudé
95*b8daa5fcSPhilippe Mathieu-Daudé/* Assignments */
96*b8daa5fcSPhilippe Mathieu-Daudé#define fPCALIGN(IMM) (IMM = IMM & ~3)
97*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_LR(A) (LR = A)
98*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_FP(A) (FP = A)
99*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_SP(A) (SP = A)
100*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_LOOP_REGS0(START, COUNT) SA0 = START; (LC0 = COUNT)
101*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_LOOP_REGS1(START, COUNT) SA1 = START; (LC1 = COUNT)
102*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_LC1(VAL) (LC1 = VAL)
103*b8daa5fcSPhilippe Mathieu-Daudé#define fSET_LPCFG(VAL) (USR.LPCFG = VAL)
104*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_P0(VAL) P0 = VAL;
105*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_P1(VAL) P1 = VAL;
106*b8daa5fcSPhilippe Mathieu-Daudé#define fWRITE_P3(VAL) P3 = VAL;
107*b8daa5fcSPhilippe Mathieu-Daudé#define fEA_RI(REG, IMM) (EA = REG + IMM)
108*b8daa5fcSPhilippe Mathieu-Daudé#define fEA_RRs(REG, REG2, SCALE) (EA = REG + (REG2 << SCALE))
109*b8daa5fcSPhilippe Mathieu-Daudé#define fEA_IRs(IMM, REG, SCALE) (EA = IMM + (REG << SCALE))
110*b8daa5fcSPhilippe Mathieu-Daudé#define fEA_IMM(IMM) (EA = IMM)
111*b8daa5fcSPhilippe Mathieu-Daudé#define fEA_REG(REG) (EA = REG)
112*b8daa5fcSPhilippe Mathieu-Daudé#define fEA_BREVR(REG) (EA = fbrev(REG))
113*b8daa5fcSPhilippe Mathieu-Daudé#define fEA_GPI(IMM) (EA = fREAD_GP() + IMM)
114*b8daa5fcSPhilippe Mathieu-Daudé#define fPM_I(REG, IMM) (REG = REG + IMM)
115*b8daa5fcSPhilippe Mathieu-Daudé#define fPM_M(REG, MVAL) (REG = REG + MVAL)
116*b8daa5fcSPhilippe Mathieu-Daudé
117*b8daa5fcSPhilippe Mathieu-Daudé/* Unary operators */
118*b8daa5fcSPhilippe Mathieu-Daudé#define fROUND(A) (A + 0x8000)
119*b8daa5fcSPhilippe Mathieu-Daudé
120*b8daa5fcSPhilippe Mathieu-Daudé/* Binary operators */
121*b8daa5fcSPhilippe Mathieu-Daudé#define fSCALE(N, A) (A << N)
122*b8daa5fcSPhilippe Mathieu-Daudé#define fASHIFTR(SRC, SHAMT, REGSTYPE) (fCAST##REGSTYPE##s(SRC) >> SHAMT)
123*b8daa5fcSPhilippe Mathieu-Daudé#define fLSHIFTR(SRC, SHAMT, REGSTYPE) (SRC >>> SHAMT)
124*b8daa5fcSPhilippe Mathieu-Daudé#define fROTL(SRC, SHAMT, REGSTYPE) fROTL(SRC, SHAMT)
125*b8daa5fcSPhilippe Mathieu-Daudé#define fASHIFTL(SRC, SHAMT, REGSTYPE) (fCAST##REGSTYPE##s(SRC) << SHAMT)
126*b8daa5fcSPhilippe Mathieu-Daudé
127*b8daa5fcSPhilippe Mathieu-Daudé/* Include fHIDE macros which hide type declarations */
128*b8daa5fcSPhilippe Mathieu-Daudé#define fHIDE(A) A
129*b8daa5fcSPhilippe Mathieu-Daudé
130*b8daa5fcSPhilippe Mathieu-Daudé/* Purge non-relevant parts */
131*b8daa5fcSPhilippe Mathieu-Daudé#define fBRANCH_SPECULATE_STALL(A, B, C, D, E)
132