blitz  Version 1.0.2
simdtypes.h
Go to the documentation of this file.
1 #ifndef BZ_SIMDTYPES_H
2 #define BZ_SIMDTYPES_H
3 
4 #include <blitz/blitz.h>
5 #include <stdint.h>
6 
7 namespace blitz {
8 
9 template<class T,int N> class TinyVector;
10 
14 template<size_t I, size_t L> struct _bz_meta_bitwidth {
15  static const size_t width = _bz_meta_bitwidth<(I>>1), L+1>::width;
16 };
17 
18 template<size_t L> struct _bz_meta_bitwidth<0,L> {
19  static const size_t width = L;
20 };
21 
22 
31 template<typename T> class simdTypes {
32 public:
35  static const size_t byteWidth =
36  BZ_SIMD_WIDTH>sizeof(T) ? BZ_SIMD_WIDTH : sizeof(T);
37 
39  static const size_t vecWidth =
40  BZ_SIMD_WIDTH>sizeof(T) ? BZ_SIMD_WIDTH/sizeof(T) : 1;
41 
44 
46  static inline bool isVectorAligned(const T* restrict pointer)
47  { return (uintptr_t)((void*)pointer) % BZ_SIMD_WIDTH == 0; }
48 
52  static inline diffType offsetToAlignment(const T* restrict pointer) {
53  const uintptr_t m = (uintptr_t)((void*)pointer) & (byteWidth-1);
54  return m ? (byteWidth - m)/sizeof(T) : 0;
55 }
56 
59  static inline size_t paddedLength(size_t length) {
60  return (length & (vecWidth-1)) ?
61  (length & ~(vecWidth-1)) + vecWidth : length;
62  };
63 };
64 
66 template <typename T>
67 inline bool isVectorAligned(const T* restrict pointer) {
68  return simdTypes<T>::isVectorAligned(pointer); }
69 
70 
71 }
72 
73 #endif
_bz_global blitz::IndexPlaceholder< 4 > m
Definition: indexexpr.h:260
Helper class that defines the width of the simd instructions for a given type.
Definition: simdtypes.h:31
TinyVector< T, vecWidth > vecType
TinyVector type of T that fills the simd width.
Definition: simdtypes.h:43
static diffType offsetToAlignment(const T *restrict pointer)
Return number of elements from pointer to next simd width boundary.
Definition: simdtypes.h:52
static bool isVectorAligned(const T *restrict pointer)
Test if a pointer to T is simd aligned.
Definition: simdtypes.h:46
Definition: array-impl.h:66
ptrdiff_t diffType
Definition: blitz.h:111
static size_t paddedLength(size_t length)
Return a length which has been padded to next larger even SIMD width.
Definition: simdtypes.h:59
static const size_t byteWidth
SIMD width of type in bytes (sizeof(T) if simd width does not fit a T)
Definition: simdtypes.h:35
This metaprogram returns the number of bits necessary to fit the specified number.
Definition: simdtypes.h:14
#define BZ_SIMD_WIDTH
Definition: bzconfig.h:387
static const size_t vecWidth
SIMD width of types in number of elements.
Definition: simdtypes.h:39
#define restrict
Definition: compiler.h:95
static const size_t width
Definition: simdtypes.h:15
The TinyVector class is a one-dimensional, fixed length vector that implements the blitz expression t...
Definition: et-forward.h:14
bool isVectorAligned(const T *restrict pointer)
General function just forwards to the simdTypes class.
Definition: simdtypes.h:67