source: trunk/lib/buffer.hpp @ 2168

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

Removed buffer constantsfrom header.

File size: 2.3 KB
Line 
1#ifndef BUFFER_HPP
2#define BUFFER_HPP
3#include "bitblock.hpp"
4
5///////////////////////////////////////////////////////////////////////////
6//
7// Statically Allocated Parallel Data Buffer Management
8//
9// Parallel data buffers with optional copyback/padding segments.
10//
11// |COPYBACK BLOCKS|WORKING SEGMENT BLOCKS|PADDING BLOCKS|
12//
13// WARNING: Statically allocated bitblock arrays must remain in scope.
14//
15///////////////////////////////////////////////////////////////////////////
16
17#define ALLOC_STATIC_ALIGNED_BYTE_BUFFER(base_ptr, buffer_size) \
18    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[buffer_size/sizeof(BitBlock)]; \
19    assert_bitblock_align((void*)aligned_##base_ptr);\
20    base_ptr = (uint8_t *)&aligned_##base_ptr[0];\
21
22#define ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER(base_ptr, buffer_size) \
23    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[buffer_size/sizeof(BitBlock)/8]; \
24    assert_bitblock_align((void*)aligned_##base_ptr);\
25    base_ptr = &aligned_##base_ptr[0];\
26
27#define ALLOC_STATIC_ALIGNED_BYTE_BUFFER_WITH_COPYBACK(copyback_ptr, base_ptr) \
28    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[BUFFER_SIZE/sizeof(BitBlock)]; \
29    assert_bitblock_align((void*)aligned_##base_ptr);\
30    copyback_ptr = (uint8_t *)aligned_##base_ptr; \
31    memset(copyback_ptr,0,COPYBACK_SIZE); \
32    base_ptr = &copyback_ptr[COPYBACK_SIZE]; \
33
34#define ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER_WITH_COPYBACK(copyback_ptr, base_ptr) \
35    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[BUFFER_SIZE/sizeof(BitBlock)/8]; \
36    assert_bitblock_align((void*)aligned_##base_ptr);\
37    copyback_ptr = (BitBlock *) aligned_##base_ptr; \
38    memset(copyback_ptr,0,COPYBACK_SIZE/8); \
39    base_ptr = &copyback_ptr[COPYBACK_BLOCKS]; \
40
41#define COPY_BACK_BYTE_BUFFER(copyback_ptr, base_ptr) \
42do {    void * dest = copyback_ptr;\
43    void * src = (uint8_t *)base_ptr + (SEGMENT_SIZE - COPYBACK_SIZE);\
44    assert_bitblock_align(src);\
45    assert_bitblock_align(dest);\
46    memmove(dest, src, COPYBACK_SIZE);\
47} while(0)
48
49#define COPY_BACK_BITBLOCK_BUFFER(copyback_ptr, base_ptr) \
50do {    void * dest = copyback_ptr;\
51    void * src = (uint8_t *)base_ptr + ((SEGMENT_SIZE - COPYBACK_SIZE)/8);\
52    assert_bitblock_align(src);\
53    assert_bitblock_align(dest);\
54    memmove(dest, src, COPYBACK_SIZE/8);\
55} while(0)
56
57#endif // BUFFER_HPP
Note: See TracBrowser for help on using the repository browser.