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 virtual void set_pin_to_channel() { assert(0 && "Only GPRs can be pinned to a channel ");}
90 void print(std::ostream
& os
, const PrintFlags
& flags
) const;
92 void print(std::ostream
& os
) const;
94 bool operator < (const Value
& lhs
) const;
96 static Value::Pointer zero
;
97 static Value::Pointer one_f
;
98 static Value::Pointer zero_dot_5
;
99 static Value::Pointer one_i
;
102 Value(Type type
, uint32_t chan
);
105 virtual void do_print(std::ostream
& os
) const = 0;
106 virtual void do_print(std::ostream
& os
, const PrintFlags
& flags
) const;
108 virtual bool is_equal_to(const Value
& other
) const = 0;
113 friend bool operator == (const Value
& lhs
, const Value
& rhs
);
117 inline std::ostream
& operator << (std::ostream
& os
, const Value
& v
)
124 inline bool operator == (const Value
& lhs
, const Value
& rhs
)
126 if (lhs
.type() == rhs
.type())
127 return lhs
.is_equal_to(rhs
);
131 inline bool operator != (const Value
& lhs
, const Value
& rhs
)
133 return !(lhs
== rhs
);
136 using PValue
=Value::Pointer
;
139 inline bool operator () (PValue lhs
, PValue rhs
) const {
144 using ValueSet
= std::set
<PValue
, value_less
>;
147 class LiteralValue
: public Value
{
149 LiteralValue(float value
, uint32_t chan
= 0);
150 LiteralValue(uint32_t value
, uint32_t chan
= 0);
151 LiteralValue(int value
, uint32_t chan
= 0);
152 uint32_t sel() const override final
;
153 uint32_t value() const;
154 float value_float() const;
156 void do_print(std::ostream
& os
) const override
;
157 void do_print(std::ostream
& os
, const PrintFlags
& flags
) const override
;
158 bool is_equal_to(const Value
& other
) const override
;
165 class SpecialValue
: public Value
{
167 SpecialValue(Type type
, int value
, int chan
);
168 uint32_t sel() const override final
;
170 void do_print(std::ostream
& os
) const override
;
171 AluInlineConstants m_value
;
174 class InlineConstValue
: public SpecialValue
{
176 InlineConstValue(int value
, int chan
);
177 bool is_equal_to(const Value
& other
) const override
;
180 AluInlineConstants m_value
;
183 class UniformValue
: public Value
{
185 UniformValue(uint32_t sel
, uint32_t chan
, uint32_t kcache_bank
= 0);
186 UniformValue(uint32_t sel
, uint32_t chan
, PValue addr
);
187 uint32_t sel() const override
;
188 uint32_t kcache_bank() const;
190 void do_print(std::ostream
& os
) const override
;
191 bool is_equal_to(const Value
& other
) const override
;
194 uint32_t m_kcache_bank
;