source: trunk/lib/buffer.hpp @ 2165

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

Add buffer.hpp

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