1 /* 2 * Copyright (c) 2017, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef CMRTLIB_LINUX_SHARE_CM_COMMON_H_ 24 #define CMRTLIB_LINUX_SHARE_CM_COMMON_H_ 25 26 #include "cm_include.h" 27 28 #ifndef __SURFACE_SAMPLER_INDEX_DEFINED__ 29 #define __SURFACE_SAMPLER_INDEX_DEFINED__ 30 31 class SurfaceIndex 32 { 33 public: SurfaceIndex()34 CM_NOINLINE SurfaceIndex() { m_index = 0; m_extraByte = '0'; }; SurfaceIndex(const SurfaceIndex & src)35 CM_NOINLINE SurfaceIndex(const SurfaceIndex& src) { m_index = src.m_index; m_extraByte = '0'; }; SurfaceIndex(const unsigned int & n)36 CM_NOINLINE SurfaceIndex(const unsigned int& n) { m_index = n; m_extraByte = '0'; }; 37 CM_NOINLINE SurfaceIndex& operator = (const unsigned int& n) { this->m_index = n; return *this; }; 38 CM_NOINLINE SurfaceIndex& operator + (const unsigned int& n) { this->m_index += n; return *this; }; get_data(void)39 virtual unsigned int get_data(void) { return m_index; }; 40 41 private: 42 unsigned int m_index; 43 /* 44 * Do not delete this line: 45 * SurfaceIndex is commonly used as CM kernel function's parameter. 46 * It has virutal table and has copy constructor, so GNU calling convetion will pass the object's pointer to kernel function. 47 * This is different from MSVC, which always copies the entire object transferred on the callee's stack. 48 * 49 * Depending on the special object size after adding below "extra_byte", 50 * SetKernelArg and SetThreadArg can recognize this object and follow GNU's convention to construct kernel function's stack. 51 */ 52 unsigned char m_extraByte; 53 }; 54 55 class SamplerIndex 56 { 57 public: SamplerIndex()58 CM_NOINLINE SamplerIndex() { m_index = 0; m_extraByte = '0'; }; SamplerIndex(SamplerIndex & src)59 CM_NOINLINE SamplerIndex(SamplerIndex& src) { m_index = src.get_data(); m_extraByte = '0'; }; SamplerIndex(const unsigned int & n)60 CM_NOINLINE SamplerIndex(const unsigned int& n) { m_index = n; m_extraByte = '0'; }; 61 CM_NOINLINE SamplerIndex& operator = (const unsigned int& n) { this->m_index = n; return *this; }; get_data(void)62 virtual unsigned int get_data(void) { return m_index; }; 63 64 private: 65 unsigned int m_index; 66 /* 67 * Do not delete this line: 68 * Same reason as SurfaceIndex. 69 */ 70 unsigned char m_extraByte; 71 }; 72 73 #endif /* __SURFACE_SAMPLER_INDEX_DEFINED__ */ 74 75 #ifndef __VME_INDEX_DEFINED__ 76 #define __VME_INDEX_DEFINED__ 77 78 class VmeIndex 79 80 { 81 public: VmeIndex()82 CM_NOINLINE VmeIndex () { m_index = 0; m_extraByte = '0'; }; VmeIndex(VmeIndex & src)83 CM_NOINLINE VmeIndex (VmeIndex& src) { m_index = src.get_data(); m_extraByte = '0'; }; VmeIndex(const unsigned int & n)84 CM_NOINLINE VmeIndex (const unsigned int& n) { m_index = n; m_extraByte = '0'; }; 85 CM_NOINLINE VmeIndex & operator = (const unsigned int& n) { this->m_index = n; return *this; }; get_data(void)86 virtual unsigned int get_data(void) { return m_index; }; 87 private: 88 unsigned int m_index; 89 /* 90 * Do not delete this line: 91 * Same reason as SurfaceIndex. 92 */ 93 unsigned char m_extraByte; 94 }; 95 96 #endif /* __VME_INDEX_DEFINED__ */ 97 98 #endif // #ifndef CMRTLIB_LINUX_SHARE_CM_COMMON_H_ 99