/[svn]/libgig/trunk/src/helper.h
ViewVC logotype

Diff of /libgig/trunk/src/helper.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2911 by schoenebeck, Mon Dec 29 16:25:51 2014 UTC revision 2912 by schoenebeck, Tue May 17 14:30:10 2016 UTC
# Line 53  inline long Abs(long val) { Line 53  inline long Abs(long val) {
53      return (val > 0) ? val : -val;      return (val > 0) ? val : -val;
54  }  }
55    
56    inline void swapBytes_16(void* Word) {
57        uint8_t byteCache = *((uint8_t*) Word);
58        *((uint8_t*) Word)     = *((uint8_t*) Word + 1);
59        *((uint8_t*) Word + 1) = byteCache;
60    }
61    
62    inline void swapBytes_32(void* Word) {
63        uint8_t byteCache = *((uint8_t*) Word);
64        *((uint8_t*) Word)     = *((uint8_t*) Word + 3);
65        *((uint8_t*) Word + 3) = byteCache;
66        byteCache = *((uint8_t*) Word + 1);
67        *((uint8_t*) Word + 1) = *((uint8_t*) Word + 2);
68        *((uint8_t*) Word + 2) = byteCache;
69    }
70    
71    inline void swapBytes_64(void* Word) {
72        uint8_t byteCache = ((uint8_t*)Word)[0];
73        ((uint8_t*)Word)[0] = ((uint8_t*)Word)[7];
74        ((uint8_t*)Word)[7] = byteCache;
75        byteCache = ((uint8_t*)Word)[1];
76        ((uint8_t*)Word)[1] = ((uint8_t*)Word)[6];
77        ((uint8_t*)Word)[6] = byteCache;
78        byteCache = ((uint8_t*)Word)[2];
79        ((uint8_t*)Word)[2] = ((uint8_t*)Word)[5];
80        ((uint8_t*)Word)[5] = byteCache;
81        byteCache = ((uint8_t*)Word)[3];
82        ((uint8_t*)Word)[3] = ((uint8_t*)Word)[4];
83        ((uint8_t*)Word)[4] = byteCache;
84    }
85    
86    inline void swapBytes(void* Word, uint64_t WordSize) {
87        uint8_t byteCache;
88        uint64_t lo = 0, hi = WordSize - 1;
89        for (; lo < hi; hi--, lo++) {
90            byteCache = *((uint8_t*) Word + lo);
91            *((uint8_t*) Word + lo) = *((uint8_t*) Word + hi);
92            *((uint8_t*) Word + hi) = byteCache;
93        }
94    }
95    
96  /**  /**
97   * Stores a 16 bit integer in memory using little-endian format.   * Stores a 16 bit integer in memory using little-endian format.
98   *   *
# Line 78  inline void store32(uint8_t* pData, uint Line 118  inline void store32(uint8_t* pData, uint
118  }  }
119    
120  /**  /**
121     * Loads a 32 bit integer in memory using little-endian format.
122     *
123     * @param pData - memory pointer
124     * @returns 32 bit data word
125     */
126    inline uint32_t load32(uint8_t* pData) {
127        return uint32_t(pData[0])       |
128               uint32_t(pData[1]) << 8  |
129               uint32_t(pData[2]) << 16 |
130               uint32_t(pData[3]) << 24;
131    }
132    
133    /**
134   * Swaps the order of the data words in the given memory area   * Swaps the order of the data words in the given memory area
135   * with a granularity given by \a WordSize.   * with a granularity given by \a WordSize.
136   *   *

Legend:
Removed from v.2911  
changed lines
  Added in v.2912

  ViewVC Help
Powered by ViewVC