3 * Copyright (c) 2018 Collabora LTD
5 * Author: Gert Wollny <gert.wollny@collabora.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include "sfn_alu_defines.h"
42 using Pointer
=std::shared_ptr
<Value
>;
45 PrintFlags():index_mode(0),
49 PrintFlags(int im
, int f
):index_mode(im
),
55 static const int is_rel
= 1;
56 static const int has_abs
= 2;
57 static const int has_neg
= 4;
58 static const int literal_is_float
= 8;
59 static const int index_ar
= 16;
60 static const int index_loopidx
= 32;
74 static const char *component_names
;
76 using LiteralFlags
=std::bitset
<4>;
85 virtual uint32_t sel() const = 0;
86 uint32_t chan() const {return m_chan
;}
88 void set_chan(uint32_t chan
);
89 void print(std::ostream
& os
, const PrintFlags
& flags
) const;
91 void print(std::ostream
& os
) const;
93 bool operator < (const Value
& lhs
) const;
95 static Value::Pointer zero
;
96 static Value::Pointer one_f
;
97 static Value::Pointer zero_dot_5
;
98 static Value::Pointer one_i
;
101 Value(Type type
, uint32_t chan
);
104 virtual void do_print(std::ostream
& os
) const = 0;
105 virtual void do_print(std::ostream
& os
, const PrintFlags
& flags
) const;
107 virtual bool is_equal_to(const Value
& other
) const = 0;
112 friend bool operator == (const Value
& lhs
, const Value
& rhs
);
116 inline std::ostream
& operator << (std::ostream
& os
, const Value
& v
)
123 inline bool operator == (const Value
& lhs
, const Value
& rhs
)
125 if (lhs
.type() == rhs
.type())
126 return lhs
.is_equal_to(rhs
);
130 inline bool operator != (const Value
& lhs
, const Value
& rhs
)
132 return !(lhs
== rhs
);
135 using PValue
=Value::Pointer
;
138 inline bool operator () (PValue lhs
, PValue rhs
) const {
143 using ValueSet
= std::set
<PValue
, value_less
>;
146 class LiteralValue
: public Value
{
148 LiteralValue(float value
, uint32_t chan
= 0);
149 LiteralValue(uint32_t value
, uint32_t chan
= 0);
150 LiteralValue(int value
, uint32_t chan
= 0);
151 uint32_t sel() const override final
;
152 uint32_t value() const;
153 float value_float() const;
155 void do_print(std::ostream
& os
) const override
;
156 void do_print(std::ostream
& os
, const PrintFlags
& flags
) const override
;
157 bool is_equal_to(const Value
& other
) const override
;
164 class SpecialValue
: public Value
{
166 SpecialValue(Type type
, int value
, int chan
);
167 uint32_t sel() const override final
;
169 void do_print(std::ostream
& os
) const override
;
170 AluInlineConstants m_value
;
173 class InlineConstValue
: public SpecialValue
{
175 InlineConstValue(int value
, int chan
);
176 bool is_equal_to(const Value
& other
) const override
;
179 AluInlineConstants m_value
;
182 class UniformValue
: public Value
{
184 UniformValue(uint32_t sel
, uint32_t chan
, uint32_t kcache_bank
= 0);
185 UniformValue(uint32_t sel
, uint32_t chan
, PValue addr
);
186 uint32_t sel() const override
;
187 uint32_t kcache_bank() const;
189 void do_print(std::ostream
& os
) const override
;
190 bool is_equal_to(const Value
& other
) const override
;
193 uint32_t m_kcache_bank
;