Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / include / tcg / tcg-cond.h
blob5cadbd6ff2cd31cb4cd4f1c70ee100b1dade1fa2
1 /*
2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #ifndef TCG_COND_H
26 #define TCG_COND_H
29 * Conditions. Note that these are laid out for easy manipulation by
30 * the functions below:
31 * bit 0 is used for inverting;
32 * bit 1 is used for conditions that need swapping (signed/unsigned).
33 * bit 2 is used with bit 1 for swapping.
34 * bit 3 is used for unsigned conditions.
36 typedef enum {
37 /* non-signed */
38 TCG_COND_NEVER = 0 | 0 | 0 | 0,
39 TCG_COND_ALWAYS = 0 | 0 | 0 | 1,
41 /* equality */
42 TCG_COND_EQ = 8 | 0 | 0 | 0,
43 TCG_COND_NE = 8 | 0 | 0 | 1,
45 /* "test" i.e. and then compare vs 0 */
46 TCG_COND_TSTEQ = 8 | 4 | 0 | 0,
47 TCG_COND_TSTNE = 8 | 4 | 0 | 1,
49 /* signed */
50 TCG_COND_LT = 0 | 0 | 2 | 0,
51 TCG_COND_GE = 0 | 0 | 2 | 1,
52 TCG_COND_GT = 0 | 4 | 2 | 0,
53 TCG_COND_LE = 0 | 4 | 2 | 1,
55 /* unsigned */
56 TCG_COND_LTU = 8 | 0 | 2 | 0,
57 TCG_COND_GEU = 8 | 0 | 2 | 1,
58 TCG_COND_GTU = 8 | 4 | 2 | 0,
59 TCG_COND_LEU = 8 | 4 | 2 | 1,
60 } TCGCond;
62 /* Invert the sense of the comparison. */
63 static inline TCGCond tcg_invert_cond(TCGCond c)
65 return (TCGCond)(c ^ 1);
68 /* Swap the operands in a comparison. */
69 static inline TCGCond tcg_swap_cond(TCGCond c)
71 return (TCGCond)(c ^ ((c & 2) << 1));
74 /* Must a comparison be considered signed? */
75 static inline bool is_signed_cond(TCGCond c)
77 return (c & (8 | 2)) == 2;
80 /* Must a comparison be considered unsigned? */
81 static inline bool is_unsigned_cond(TCGCond c)
83 return (c & (8 | 2)) == (8 | 2);
86 /* Must a comparison be considered a test? */
87 static inline bool is_tst_cond(TCGCond c)
89 return (c | 1) == TCG_COND_TSTNE;
92 /* Create an "unsigned" version of a "signed" comparison. */
93 static inline TCGCond tcg_unsigned_cond(TCGCond c)
95 return is_signed_cond(c) ? (TCGCond)(c + 8) : c;
98 /* Create a "signed" version of an "unsigned" comparison. */
99 static inline TCGCond tcg_signed_cond(TCGCond c)
101 return is_unsigned_cond(c) ? (TCGCond)(c - 8) : c;
104 /* Create the eq/ne version of a tsteq/tstne comparison. */
105 static inline TCGCond tcg_tst_eqne_cond(TCGCond c)
107 return is_tst_cond(c) ? (TCGCond)(c - 4) : c;
110 /* Create the lt/ge version of a tstne/tsteq comparison of the sign. */
111 static inline TCGCond tcg_tst_ltge_cond(TCGCond c)
113 return is_tst_cond(c) ? (TCGCond)(c ^ 0xf) : c;
117 * Create a "high" version of a double-word comparison.
118 * This removes equality from a LTE or GTE comparison.
120 static inline TCGCond tcg_high_cond(TCGCond c)
122 switch (c) {
123 case TCG_COND_GE:
124 case TCG_COND_LE:
125 case TCG_COND_GEU:
126 case TCG_COND_LEU:
127 return (TCGCond)(c ^ (4 | 1));
128 default:
129 return c;
133 #endif /* TCG_COND_H */