source: trunk/lib/buffer.hpp @ 2159

Last change on this file since 2159 was 2159, checked in by ksherdy, 7 years ago
File size: 2.9 KB
RevLine 
[2151]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//
[2156]12#define PADDING_BLOCKS 1
[2151]13#define PADDING_SIZE (BLOCK_SIZE * PADDING_BLOCKS)
[2156]14#define COPYBACK_BLOCKS 0
[2151]15#define COPYBACK_SIZE (BLOCK_SIZE * COPYBACK_BLOCKS)
[2156]16#define SEGMENT_BLOCKS  12
[2151]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///////////////////////////////////////////////////////////////////////////
[2156]31
32#define ALLOC_STATIC_ALIGNED_BYTE_BUFFER(base_ptr, buffer_size) \
33    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[buffer_size/sizeof(BitBlock)]; \
[2151]34    assert_bitblock_align((void*)aligned_##base_ptr);\
[2156]35    base_ptr = (uint8_t *)&aligned_##base_ptr[0];\
[2151]36
[2156]37#define ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER(base_ptr, buffer_size) \
38    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[buffer_size/sizeof(BitBlock)/8]; \
[2151]39    assert_bitblock_align((void*)aligned_##base_ptr);\
40    base_ptr = &aligned_##base_ptr[0];\
41
[2159]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)]; \
[2151]44    assert_bitblock_align((void*)aligned_##base_ptr);\
45    copyback_ptr = (uint8_t *)aligned_##base_ptr; \
[2159]46    memset(copyback_ptr,0,COPYBACK_SIZE); \
47    base_ptr = &copyback_ptr[COPYBACK_SIZE]; \
[2151]48
[2159]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]; \
[2151]51    assert_bitblock_align((void*)aligned_##base_ptr);\
52    copyback_ptr = (BitBlock *) aligned_##base_ptr; \
[2159]53    memset(copyback_ptr,0,COPYBACK_SIZE/8); \
54    base_ptr = &copyback_ptr[COPYBACK_BLOCKS]; \
[2151]55
[2159]56#define COPY_BACK_BYTE_BUFFER(copyback_ptr, base_ptr) \
[2151]57do {    void * dest = copyback_ptr;\
[2159]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);\
[2151]62} while(0)
63
[2159]64#define COPY_BACK_BITBLOCK_BUFFER(copyback_ptr, base_ptr) \
[2151]65do {    void * dest = copyback_ptr;\
[2159]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);\
[2151]70} while(0)
71
72#endif // BUFFER_HPP
Note: See TracBrowser for help on using the repository browser.