source: trunk/lib/byte_util.hpp @ 1889

Last change on this file since 1889 was 1871, checked in by ksherdy, 7 years ago

Added conditional.

File size: 672 bytes
Line 
1#ifndef BYTE_UTIL_HPP
2#define BYTE_UTIL_HPP
3
4#include "bitblock.hpp"
5#include <cassert>
6#include <iostream>
7using namespace std;
8
9/* WARNING - Buffer pointer cast to integer type. Pad bytes as necessary. */
10
11template<class T, uint32_t SF>
12static IDISA_ALWAYS_INLINE T slice(const uint8_t * buffer, const uint32_t pos, const uint32_t lgth);
13
14template<class T, uint32_t SF>
15static IDISA_ALWAYS_INLINE T slice(const uint8_t * buffer, const uint32_t pos, const uint32_t lgth) {
16
17    T shift = *((T *)(buffer+pos));
18
19    if(lgth != sizeof(T)) {
20
21        const T ZERO  = 0;
22        T mask = ~(~ZERO << (lgth * SF));
23        return shift & mask;
24
25    }
26
27    return shift;
28}
29
30#endif // BYTE_UTIL_HPP
31
Note: See TracBrowser for help on using the repository browser.