panfrost: introduce LDST_ATOMIC property
[mesa.git] / src / panfrost / midgard / midgard_ops.h
1 /* Copyright (c) 2018-2019 Alyssa Rosenzweig (alyssa@rosenzweig.io)
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
22 #ifndef __MIDGARD_OPS
23 #define __MIDGARD_OPS
24
25 #include "helpers.h"
26
27 /* Forward declare */
28
29 extern struct mir_op_props alu_opcode_props[256];
30 extern struct mir_ldst_op_props load_store_opcode_props[256];
31 extern struct mir_tag_props midgard_tag_props[16];
32
33 #define OP_IS_ATOMIC(op) (load_store_opcode_props[op].props & LDST_ATOMIC)
34 #define OP_IS_STORE(op) (load_store_opcode_props[op].props & LDST_STORE)
35 #define OP_HAS_ADDRESS(op) (load_store_opcode_props[op].props & LDST_ADDRESS)
36
37 /* Is this opcode that of an integer (regardless of signedness)? Instruction
38 * names authoritatively determine types */
39
40 static inline bool
41 midgard_is_integer_op(int op)
42 {
43 const char *name = alu_opcode_props[op].name;
44
45 if (!name)
46 return false;
47
48 return (name[0] == 'i') || (name[0] == 'u');
49 }
50
51 /* Does this opcode *write* an integer? Same as is_integer_op, unless it's a
52 * conversion between int<->float in which case we do the opposite */
53
54 static inline bool
55 midgard_is_integer_out_op(int op)
56 {
57 bool is_int = midgard_is_integer_op(op);
58 bool is_conversion = alu_opcode_props[op].props & OP_TYPE_CONVERT;
59
60 return is_int ^ is_conversion;
61 }
62
63 /* Determines effective writemask, taking quirks and expansion into account */
64
65 static inline unsigned
66 effective_writemask(midgard_alu_op op, unsigned existing_mask)
67 {
68 /* Channel count is off-by-one to fit in two-bits (0 channel makes no
69 * sense) */
70
71 unsigned channel_count = GET_CHANNEL_COUNT(alu_opcode_props[op].props);
72
73 /* If there is a fixed channel count, construct the appropriate mask */
74
75 if (channel_count)
76 return (1 << channel_count) - 1;
77
78 return existing_mask;
79 };
80
81 #endif