[Beignet] [PATCH 1/7] add helper functions in ir::Constant and ir::ConstantSet
Lu, Guanqun
guanqun.lu at intel.com
Thu Apr 25 00:10:24 PDT 2013
> -----Original Message-----
> From: beignet-bounces+guanqun.lu=intel.com at lists.freedesktop.org
> [mailto:beignet-bounces+guanqun.lu=intel.com at lists.freedesktop.org] On
> Behalf Of Homer Hsing
> Sent: Thursday, April 25, 2013 2:21 PM
> To: beignet at lists.freedesktop.org
> Cc: Xing, Homer
> Subject: [Beignet] [PATCH 1/7] add helper functions in ir::Constant and
> ir::ConstantSet
>
> 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 | 42
> ++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 40 insertions(+), 2 deletions(-)
>
> diff --git a/backend/src/ir/constant.hpp b/backend/src/ir/constant.hpp index
> 3a23dc2..c7a7af7 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,38 @@ 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) {
> + size_t i = 0;
> + for (auto c : constants) {
> + if (c.getName() == name)
> + return constants[i];
> + i ++;
> + }
what the point of using 'i' here? I dont' think it's necessary.
> + GBE_ASSERT(false);
> + return *(Constant *)nullptr;
returning the nullptr's reference, seems a bit weird for me...
> + }
> + /*! 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() {}
If there's nothing to do in the constructor, we can just leave them undefined. The compiler would automatically create one for us. the same with the destructor.
> + ConstantSet(const ConstantSet& other) : data(other.data),
> constants(other.constants) {}
> + ~ConstantSet() {}
ditto.
> + 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