source: proto/lz4d/sequential_pablo_kernel.py @ 5539

Last change on this file since 5539 was 5539, checked in by xwa163, 22 months ago

lz4d_prototype: add prototype for sequential_pablo_kernel, modify lz4d prototype to use sequential_pablo_kernel

File size: 3.3 KB
Line 
1import sequential_pablo
2from bitwise_op_helper import *
3
4class SequentialPabloKernel:
5
6    def __init__(self, input_buffers, output_buffers):
7        self._input_buffers = input_buffers
8        self._output_buffers = output_buffers
9        self._buffer_cursor = {}
10
11    def init_buffer_cursor(self, buffer_keys):
12        for key in buffer_keys:
13            self._buffer_cursor[key] = 0
14
15    # Similar to generateDo(Segment/Block/MultiBlock)Method, need to be implement by subclass
16    def process(self):
17        pass
18
19    '''
20    Helper Method
21    '''
22    def modify_input_bitstream(self, input_name, offset_cursor_name, value):
23        self._input_buffers[input_name] = bit_set_value(self._input_buffers[input_name], value, self.get_cursor_value(offset_cursor_name))
24
25    def get_cursor_value(self, cursor_name):
26        return self._buffer_cursor[cursor_name]
27
28    def memcpy(self, source_ptr, source_offset, dst_ptr, dst_offset, length):
29        dst_ptr[dst_offset : dst_offset + length] = source_ptr[source_offset : source_offset + length]
30
31    def mark_output_bitstream_one(self, output_name, startIndex, endIndex):
32        self._output_buffers[output_name] |= sequential_pablo.generate_bit_one_mask(startIndex, endIndex)
33
34    '''
35    Operations with cursor movement
36    '''
37    def advance_cursor(self, cursor_name, num):
38        self._buffer_cursor[cursor_name] += num
39
40    def advance_cursor_until_pos(self, cursor_name, pos):
41        assert self._buffer_cursor[cursor_name] < pos # cursor can only be advanced
42        self._buffer_cursor[cursor_name] = pos
43
44    def advance_cursor_until_next_one(self, cursor_name, marker_name):
45        cursor_pos = self._buffer_cursor[cursor_name]
46        marker = self._input_buffers[marker_name]
47        cursor_pos = sequential_pablo.position_of_next_one(marker, cursor_pos)
48        self._buffer_cursor[cursor_name] = cursor_pos
49
50    def advance_cursor_until_next_zero(self, cursor_name, marker_name):
51        cursor_pos = self._buffer_cursor[cursor_name]
52        marker = self._input_buffers[marker_name]
53        cursor_pos = sequential_pablo.position_of_next_zero(marker, cursor_pos)
54        self._buffer_cursor[cursor_name] = cursor_pos
55
56    # source_cursor and dst_cursor will both move forward
57    def memcpy_2_cursors_until_next_zero(self, source_ptr, source_cursor_name, dst_ptr, dst_cursor_name, source_marker_name):
58        source_cursor = self._buffer_cursor[source_cursor_name]
59        dst_cursor = self._buffer_cursor[dst_cursor_name]
60
61        distance = sequential_pablo.count_forward_one(self._input_buffers[source_marker_name], source_cursor)
62        dst_ptr[dst_cursor : dst_cursor + distance] = source_ptr[source_cursor : source_cursor + distance]
63
64        self._buffer_cursor[source_cursor_name] += distance
65        self._buffer_cursor[dst_cursor_name] += distance
66
67    def memcpy_dst_cursor_until_next_zero(self, source_ptr, source_offset, dst_ptr, dst_cursor_name, dst_marker):
68        output_pos = self.get_cursor_value(dst_cursor_name)
69
70        match_end_mark_pos = sequential_pablo.position_of_next_zero(self._input_buffers[dst_marker], output_pos)
71        distance = match_end_mark_pos - output_pos
72
73        # Match Copy
74        for i in range(distance):
75            dst_ptr[output_pos + i] = source_ptr[source_offset + i]
76
77        output_pos += distance
78
79        self._buffer_cursor[dst_cursor_name] += distance
Note: See TracBrowser for help on using the repository browser.