source: trunk/lib/buffer.hpp @ 2288

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

Reverted previous del.

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// TODO - Unbake macro buffer constants.
28
29#define ALLOC_STATIC_ALIGNED_BYTE_BUFFER_WITH_COPYBACK(copyback_ptr, base_ptr) \
30    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[BUFFER_SIZE/sizeof(BitBlock)]; \
31    assert_bitblock_align((void*)aligned_##base_ptr);\
32    copyback_ptr = (uint8_t *)aligned_##base_ptr; \
33    memset(copyback_ptr,0,COPYBACK_SIZE); \
34    base_ptr = &copyback_ptr[COPYBACK_SIZE]; \
35
36#define ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER_WITH_COPYBACK(copyback_ptr, base_ptr) \
37    ATTRIBUTE_SIMD_ALIGN BitBlock aligned_##base_ptr[BUFFER_SIZE/sizeof(BitBlock)/8]; \
38    assert_bitblock_align((void*)aligned_##base_ptr);\
39    copyback_ptr = (BitBlock *) aligned_##base_ptr; \
40    memset(copyback_ptr,0,COPYBACK_SIZE/8); \
41    base_ptr = &copyback_ptr[COPYBACK_BLOCKS]; \
42
43#define COPY_BACK_BYTE_BUFFER(copyback_ptr, base_ptr) \
44do {    void * dest = copyback_ptr;\
45    void * src = (uint8_t *)base_ptr + (SEGMENT_SIZE - COPYBACK_SIZE);\
46    assert_bitblock_align(src);\
47    assert_bitblock_align(dest);\
48    memmove(dest, src, COPYBACK_SIZE);\
49} while(0)
50
51#define COPY_BACK_BITBLOCK_BUFFER(copyback_ptr, base_ptr) \
52do {    void * dest = copyback_ptr;\
53    void * src = (uint8_t *)base_ptr + ((SEGMENT_SIZE - COPYBACK_SIZE)/8);\
54    assert_bitblock_align(src);\
55    assert_bitblock_align(dest);\
56    memmove(dest, src, COPYBACK_SIZE/8);\
57} while(0)
58
59#endif // BUFFER_HPP
Note: See TracBrowser for help on using the repository browser.