[Beignet] [PATCH 1/7] add helper functions in ir::Constant and ir::ConstantSet

Zhigang Gong zhigang.gong at linux.intel.com
Sat Apr 27 03:33:52 PDT 2013


This version LGTM. Could you write a little bit more in your commit log
to explain why you need to do that? This is the first commit of a new
feature, so if you can write a little bit more about what you will do
and how do you want to implement it, that will be more helpful for other
people to understand the patchset.

The new feature is to support global constant array, and current limitation is
that it only support float/int type of global constant array. Right?

On Sat, Apr 27, 2013 at 10:12:10AM +0800, Homer Hsing wrote:
> Version 3.
> Deleted empty destructor of ConstantSet.
> Updated ConstantSet::getConstant()
> 
> And I am afraid I cannot delete the empty constructor of ConstantSet.
> That will break the constructor of ir::Unit. See unit.cpp, line 30.
> 
> add ir::Constant.reg field
> add helper functions in ir::ConstantSet to get specified ir::Constant
> and binary packed constant array
> 
> Signed-off-by: Homer Hsing <homer.xing at intel.com>
> ---
>  backend/src/ir/constant.hpp | 39 +++++++++++++++++++++++++++++++++++++--
>  1 file changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/backend/src/ir/constant.hpp b/backend/src/ir/constant.hpp
> index 3a23dc2..0717391 100644
> --- a/backend/src/ir/constant.hpp
> +++ b/backend/src/ir/constant.hpp
> @@ -36,25 +36,31 @@ namespace ir {
>    public:
>      /*! Build a constant description */
>      INLINE Constant(const std::string &name, uint32_t size, uint32_t alignment, uint32_t offset) :
> -      name(name), size(size), alignment(alignment), offset(offset) {}
> +      name(name), size(size), alignment(alignment), offset(offset), reg(0) {}
>      /*! Copy constructor */
>      INLINE Constant(const Constant &other) :
> -      name(other.name), size(other.size), alignment(other.alignment), offset(other.offset) {}
> +      name(other.name), size(other.size), alignment(other.alignment), offset(other.offset), reg(other.reg) {}
>      /*! Copy operator */
>      INLINE Constant& operator= (const Constant &other) {
>        this->name = other.name;
>        this->size = other.size;
>        this->alignment = other.alignment;
>        this->offset = other.offset;
> +      this->reg = other.reg;
>        return *this;
>      }
>      /*! Nothing happens here */
>      INLINE ~Constant(void) {}
> +    const std::string& getName(void) const { return name; }
> +    uint32_t getOffset(void) const { return offset; }
> +    uint16_t getReg(void) const { return reg; }
> +    void setReg(uint16_t reg) { this->reg = reg; }
>    private:
>      std::string name; //!< Optional name of the constant
>      uint32_t size;      //!< Size of the constant
>      uint32_t alignment; //!< Alignment required for each constant
>      uint32_t offset;    //!< Offset of the constant in the data segment
> +    uint16_t reg; //!< Virtual register number
>      GBE_CLASS(Constant);
>    };
>  
> @@ -66,6 +72,35 @@ namespace ir {
>    public:
>      /*! Append a new constant in the constant set */
>      void append(const char*, const std::string&, uint32_t size, uint32_t alignment);
> +    /*! Number of constants */
> +    size_t getConstantNum(void) const { return constants.size(); }
> +    /*! Get a special constant */
> +    Constant& getConstant(size_t i) { return constants[i]; }
> +    /*! Get a special constant */
> +    Constant& getConstant(const std::string & name) {
> +      for (auto & c : constants) {
> +        if (c.getName() == name)
> +          return c;
> +      }
> +      GBE_ASSERT(false);
> +      return *(Constant *)nullptr;
> +    }
> +    /*! Number of bytes of serialized constant data */
> +    size_t getDataSize(void) const { return data.size(); }
> +    /*! Store serialized constant data into an array */
> +    void getData(char *mem) const {
> +      for (size_t i = 0; i < data.size(); i ++)
> +        mem[i] = data[i];
> +    }
> +    ConstantSet() {}
> +    ConstantSet(const ConstantSet& other) : data(other.data), constants(other.constants) {}
> +    ConstantSet & operator = (const ConstantSet& other) {
> +      if (&other != this) {
> +        data = other.data;
> +        constants = other.constants;
> +      }
> +      return *this;
> +    }
>    private:
>      vector<char> data;         //!< The constant data serialized in one array
>      vector<Constant> constants;//!< Each constant description
> -- 
> 1.8.1.2
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list