Home | History | Annotate | Line # | Download | only in sfn
      1 /* -*- mesa-c++  -*-
      2  *
      3  * Copyright (c) 2019 Collabora LTD
      4  *
      5  * Author: Gert Wollny <gert.wollny (at) collabora.com>
      6  *
      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:
     13  *
     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
     16  * Software.
     17  *
     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.
     25  */
     26 
     27 #ifndef SFN_GPRARRAY_H
     28 #define SFN_GPRARRAY_H
     29 
     30 #include "sfn_value.h"
     31 #include <vector>
     32 #include <array>
     33 
     34 namespace r600 {
     35 
     36 class ValuePool;
     37 class ValueMap;
     38 class LiverangeEvaluator;
     39 
     40 class GPRValue : public Value {
     41 public:
     42    GPRValue() = default;
     43    GPRValue(GPRValue&& orig) = default;
     44    GPRValue(const GPRValue& orig) = default;
     45 
     46    GPRValue(uint32_t sel, uint32_t chan, int base_offset);
     47 
     48    GPRValue(uint32_t sel, uint32_t chan);
     49 
     50    GPRValue& operator = (const GPRValue& orig) = default;
     51    GPRValue& operator = (GPRValue&& orig) = default;
     52 
     53    uint32_t sel() const override final;
     54 
     55    void set_as_input(){ m_input = true; }
     56    bool is_input() const {return  m_input; }
     57    void set_keep_alive() { m_keep_alive = true; }
     58    bool keep_alive() const {return  m_keep_alive; }
     59    void set_pin_to_channel() override { m_pin_to_channel = true;}
     60    bool pin_to_channel()  const { return m_pin_to_channel;}
     61 
     62 private:
     63    void do_print(std::ostream& os) const override;
     64    void do_print(std::ostream& os, const PrintFlags& flags) const override;
     65    bool is_equal_to(const Value& other) const override;
     66    uint32_t m_sel;
     67    bool m_base_offset;
     68    bool m_input;
     69    bool m_pin_to_channel;
     70    bool m_keep_alive;
     71 };
     72 
     73 using PGPRValue = std::shared_ptr<GPRValue>;
     74 
     75 class GPRVector : public Value {
     76 public:
     77    using Swizzle = std::array<uint32_t,4>;
     78    using Values = std::array<PValue,4>;
     79    GPRVector() = default;
     80    GPRVector(GPRVector&& orig) = default;
     81    GPRVector(const GPRVector& orig);
     82 
     83    GPRVector(const GPRVector& orig, const std::array<uint8_t, 4>& swizzle);
     84    GPRVector(std::array<PValue,4> elms);
     85    GPRVector(uint32_t sel, std::array<uint32_t,4> swizzle);
     86 
     87    GPRVector& operator = (const GPRVector& orig) = default;
     88    GPRVector& operator = (GPRVector&& orig) = default;
     89 
     90    void swizzle(const Swizzle& swz);
     91 
     92    uint32_t sel() const override final;
     93 
     94    void set_reg_i(int i, PValue reg);
     95 
     96    unsigned chan_i(int i) const {return m_elms[i]->chan();}
     97    PValue reg_i(int i) const {return m_elms[i];}
     98    PValue operator [] (int i) const {return m_elms[i];}
     99    PValue& operator [] (int i) {return m_elms[i];}
    100 
    101    void pin_to_channel(int i);
    102    void pin_all_to_channel();
    103 
    104    PValue x() const {return m_elms[0];}
    105    PValue y() const {return m_elms[1];}
    106    PValue z() const {return m_elms[2];}
    107    PValue w() const {return m_elms[3];}
    108 
    109    Values& values() { return m_elms;}
    110 
    111 private:
    112    void do_print(std::ostream& os) const override;
    113    bool is_equal_to(const Value& other) const override;
    114    void validate() const;
    115 
    116    Values m_elms;
    117    mutable bool m_valid;
    118 };
    119 
    120 
    121 class GPRArray : public Value
    122 {
    123 public:
    124    using Pointer = std::shared_ptr<GPRArray>;
    125 
    126    GPRArray(int base, int size, int comp_mask, int frac);
    127 
    128    uint32_t sel() const override;
    129 
    130    uint32_t mask() const { return m_component_mask; };
    131 
    132    size_t size() const {return m_values.size();}
    133 
    134    PValue get_indirect(unsigned index, PValue indirect, unsigned component);
    135 
    136    void record_read(LiverangeEvaluator& ev, int chan)const;
    137    void record_write(LiverangeEvaluator& ev, int chan)const;
    138 
    139    void collect_registers(ValueMap& output) const;
    140 
    141 private:
    142    void do_print(std::ostream& os) const override;
    143 
    144    bool is_equal_to(const Value& other) const override;
    145 
    146    int m_base_index;
    147    int m_component_mask;
    148    int m_frac;
    149 
    150    std::vector<GPRVector> m_values;
    151 };
    152 
    153 using PGPRArray = GPRArray::Pointer;
    154 
    155 class GPRArrayValue :public Value {
    156 public:
    157    GPRArrayValue(PValue value, GPRArray *array);
    158    GPRArrayValue(PValue value, PValue index, GPRArray *array);
    159 
    160    void record_read(LiverangeEvaluator& ev) const;
    161    void record_write(LiverangeEvaluator& ev) const;
    162 
    163    size_t array_size() const;
    164    uint32_t sel() const override;
    165 
    166    PValue value() {return m_value;}
    167 
    168    void reset_value(PValue new_value);
    169    void reset_addr(PValue new_addr);
    170 
    171    Value::Pointer indirect() const {return m_addr;}
    172 
    173 private:
    174 
    175    void do_print(std::ostream& os) const override;
    176 
    177    bool is_equal_to(const Value& other) const override;
    178 
    179    PValue m_value;
    180    PValue m_addr;
    181    GPRArray *m_array;
    182 };
    183 
    184 inline size_t GPRArrayValue::array_size() const
    185 {
    186    return m_array->size();
    187 }
    188 
    189 inline GPRVector::Swizzle swizzle_from_comps(unsigned ncomp)
    190 {
    191    GPRVector::Swizzle swz = {0,1,2,3};
    192    for (int i = ncomp; i < 4; ++i)
    193       swz[i] = 7;
    194    return swz;
    195 }
    196 
    197 inline GPRVector::Swizzle swizzle_from_mask(unsigned mask)
    198 {
    199    GPRVector::Swizzle swz;
    200    for (int i = 0; i < 4; ++i)
    201       swz[i] =  ((1 << i) & mask) ? i : 7;
    202    return swz;
    203 }
    204 
    205 
    206 }
    207 
    208 #endif // SFN_GPRARRAY_H
    209