source: trunk/lib/buffer.hpp @ 2152

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

Statically allocated buffer management. Application wide at present. May refactor routines to include size parameters.

File size: 2.8 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 0
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  2
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#define ALLOC_STATIC_ALIGNED_BYTE_BUFFER(base_ptr) \
32    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[BUFFER_SIZE/sizeof(BitBlock)]; \
33    assert_bitblock_align((void*)aligned_##base_ptr);\
34    base_ptr = &aligned_##base_ptr[0];\
35
36#define ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER(base_ptr) \
37    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[BUFFER_SIZE/sizeof(BitBlock)/8]; \
38    assert_bitblock_align((void*)aligned_##base_ptr);\
39    base_ptr = &aligned_##base_ptr[0];\
40
41#define ALLOC_STATIC_ALIGNED_BYTE_BUFFER_WITH_COPYBACK(copyback_ptr, base_ptr) \
42    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[BUFFER_SIZE/sizeof(BitBlock)]; \
43    assert_bitblock_align((void*)aligned_##base_ptr);\
44    copyback_ptr = (uint8_t *)aligned_##base_ptr; \
45    memset(copyback_ptr,0,COPYBACK_SIZE); \
46    base_ptr = &copyback_ptr[COPYBACK_SIZE]; \
47
48#define ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER_WITH_COPYBACK(copyback_ptr, base_ptr) \
49    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[BUFFER_SIZE/sizeof(BitBlock)/8]; \
50    assert_bitblock_align((void*)aligned_##base_ptr);\
51    copyback_ptr = (BitBlock *) aligned_##base_ptr; \
52    memset(copyback_ptr,0,COPYBACK_SIZE/8); \
53    base_ptr = &copyback_ptr[COPYBACK_BLOCKS]; \
54
55#define COPY_BACK_BYTE_BUFFER(copyback_ptr, base_ptr) \
56do {    void * dest = copyback_ptr;\
57    void * src = (uint8_t *)base_ptr + (SEGMENT_SIZE - COPYBACK_SIZE);\
58        assert_bitblock_align(src);\
59        assert_bitblock_align(dest);\
60        memmove(dest, src, COPYBACK_SIZE);\
61} while(0)
62
63#define COPY_BACK_BITBLOCK_BUFFER(copyback_ptr, base_ptr) \
64do {    void * dest = copyback_ptr;\
65    void * src = (uint8_t *)base_ptr + ((SEGMENT_SIZE - COPYBACK_SIZE)/8);\
66        assert_bitblock_align(src);\
67        assert_bitblock_align(dest);\
68        memmove(dest, src, COPYBACK_SIZE/8);\
69} while(0)
70
71#endif // BUFFER_HPP
Note: See TracBrowser for help on using the repository browser.