source: trunk/symbol_table/src/buffer.hpp @ 2140

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

Fixed template.

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