source: proto/lz4d/deposit_compressed_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: 2.3 KB
Line 
1from sequential_pablo_kernel import SequentialPabloKernel
2import sequential_pablo
3
4class DepositCompressedKernel(SequentialPabloKernel):
5
6    def __init__(self, input_buffers, output_buffers):
7        SequentialPabloKernel.__init__(self, input_buffers, output_buffers)
8
9    def process(self):
10        self.init_buffer_cursor(['extract', 'deposit'])
11
12        file_content = self._input_buffers['file_content']
13        block_data = self._input_buffers['block_data']
14        outputStrBuffer = self._output_buffers['outputStrBuffer']
15
16        # Outer loop will iterate throught all of the compressed block
17        # while (compressed_start_marker):
18        for (isCompressed, block_start_pos, block_end_pos) in block_data:
19            if not isCompressed:
20                # There will be much fewer uncompressed block than compressed block
21                self.advance_cursor('deposit', block_end_pos - block_start_pos)
22
23            self.advance_cursor_until_pos('extract', block_start_pos)
24            self.advance_cursor_until_next_one('deposit', 'd_marker')
25
26            # Position of first e1 bit
27            self.advance_cursor_until_next_one('extract', 'e1_marker')
28
29            self.advance_cursor('extract', 1)
30            self.memcpy_2_cursors_until_next_zero(file_content, 'extract', outputStrBuffer, 'deposit', 'e1_marker')
31
32            while self.get_cursor_value('extract') < block_end_pos:
33                offset_pos = self.get_cursor_value('extract')
34                match_offset = ord(file_content[offset_pos]) + (ord(file_content[offset_pos + 1]) << 8)
35                match_copy_pos = self.get_cursor_value('deposit') - match_offset
36
37                self.memcpy_dst_cursor_until_next_zero(outputStrBuffer, match_copy_pos, outputStrBuffer, 'deposit', 'm0_marker')
38
39                output_cursor = self.get_cursor_value('deposit')
40                self.memcpy(outputStrBuffer, output_cursor - match_offset, outputStrBuffer, output_cursor, 1)
41                self.advance_cursor('deposit', 1)
42
43                #  /* next token */
44                self.advance_cursor_until_next_one('extract', 'e1_marker')
45                self.advance_cursor('extract', 1)
46                self.memcpy_2_cursors_until_next_zero(file_content, 'extract', outputStrBuffer, 'deposit',
47                                                      'e1_marker')
48
Note: See TracBrowser for help on using the repository browser.