summaryrefslogtreecommitdiffstats
path: root/src/isa-l/igzip/aarch64/encode_df.S
blob: 6dddddf0ae3b0ec5f019e5e8de92b010916c4769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**********************************************************************
  Copyright(c) 2019 Arm Corporation All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the
      distribution.
    * Neither the name of Arm Corporation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/

	.arch armv8-a+crc
	.text
	.align	2
#include "lz0a_const_aarch64.h"
#include "data_struct_aarch64.h"
#include "huffman_aarch64.h"
#include "bitbuf2_aarch64.h"
#include "stdmac_aarch64.h"

/*
declare Macros
*/

.macro	declare_generic_reg name:req,reg:req,default:req
	\name		.req	\default\reg
	w_\name		.req	w\reg
	x_\name		.req	x\reg
.endm

	.global	encode_deflate_icf_aarch64
	.type	encode_deflate_icf_aarch64, %function

/*
	struct deflate_icf *encode_deflate_icf_base(struct deflate_icf *next_in,
				struct deflate_icf *end_in, struct BitBuf2 *bb,
				struct hufftables_icf *hufftables)

*/

	// parameters
	declare_generic_reg	next_in,		0,x
	declare_generic_reg	end_in,			1,x
	declare_generic_reg	bb,			2,x
	declare_generic_reg	hufftables,		3,x

	// local variable
	declare_generic_reg	bb_out_end,		4,x
	declare_generic_reg	bb_bit_count,		5,w
	declare_generic_reg	dist_extra,		6,x
	declare_generic_reg	dist_lit_table,		7,x
	declare_generic_reg	code_and_extra,		8,x
	declare_generic_reg	bb_out_buf,		9,x
	declare_generic_reg	bb_bits,		10,x
	declare_generic_reg	d_length,		11,x
	declare_generic_reg	l_length,		12,x
	declare_generic_reg	d_extra_bit_count,	13,x

	declare_generic_reg	code_sum,		4,x
	declare_generic_reg	count_sum,		7,x

	declare_generic_reg	tmp0,			14,x
	declare_generic_reg	tmp1,			15,x

// bit buffer offset
.equ	offset_m_bits, 0
.equ	offset_m_bit_count, 8
.equ	offset_m_out_buf, 16
.equ	offset_m_out_end, 24

encode_deflate_icf_aarch64:
	cmp	next_in, end_in
	bcs	.done

	ldp	bb_out_buf, bb_out_end, [bb, offset_m_out_buf]
	cmp	bb_out_end, bb_out_buf
	bcc	.done

	ldr	bb_bit_count, [bb, offset_m_bit_count]
	ldr	bb_bits, [bb, offset_m_bits]
	b	.loop_start

	.align 3
.loop:
	ldr	bb_out_end, [bb, offset_m_out_end]
	cmp	bb_out_end, bb_out_buf
	bcc	.done

.loop_start:
	ldrh	w_code_and_extra, [next_in]
	add	next_in, next_in, 4
	ldr	w_dist_lit_table, [next_in, -4]
	and	code_and_extra, code_and_extra, 1023

	ldrh	w_dist_extra, [next_in, -2]
	add	code_and_extra, code_and_extra, 31
	ubfx	x_dist_lit_table, x_dist_lit_table, 10, 9
	add	x_tmp0, hufftables, code_and_extra, lsl 2
	ubfx	x_dist_extra, x_dist_extra, 3, 13
	lsl	x_dist_lit_table, x_dist_lit_table, 2

	ldr	w_code_and_extra, [hufftables, code_and_extra, lsl 2]
	add	x_d_extra_bit_count, hufftables, x_dist_lit_table
	ldrb	w_l_length, [x_tmp0, 3]
	and	code_and_extra, code_and_extra, 0xffffff
	ldrh	w_code_sum, [hufftables, x_dist_lit_table]
	ldrb	w_d_length, [x_d_extra_bit_count, 3]
	add	w_l_length, w_l_length, bb_bit_count
	ldrb	w_d_extra_bit_count, [x_d_extra_bit_count, 2]

	lsl	x_tmp0, code_and_extra, x_bb_bit_count
	add	bb_bit_count, w_d_length, w_l_length
	lsl	x_code_sum, x_code_sum, x_l_length
	orr	x_code_sum, x_code_sum, x_tmp0
	add	w_count_sum, w_d_extra_bit_count, bb_bit_count
	lsl	x_bb_bit_count, x_dist_extra, x_bb_bit_count

	orr	x_bb_bit_count, x_bb_bit_count, bb_bits
	orr	x_tmp0, x_code_sum, x_bb_bit_count         // me->m_bits => x_tmp0
	str	x_tmp0, [bb, offset_m_bits]                // me->m_bits => x_tmp0
	str	w_count_sum, [bb, offset_m_bit_count]

	str	x_tmp0, [bb_out_buf]                       // me->m_bits => x_tmp0
	ldr	bb_bit_count, [bb, offset_m_bit_count]
	ldr	bb_bits, [bb, offset_m_bits]
	and	w_tmp0, bb_bit_count, -8                   // bits => w_tmp0
	ldr	bb_out_buf, [bb, offset_m_out_buf]
	lsr	w_tmp1, bb_bit_count, 3                    // bits/8 => w_tmp1
	lsr	bb_bits, bb_bits, x_tmp0                   // bits => x_tmp0
	sub	bb_bit_count, bb_bit_count, w_tmp0         // bits => w_tmp0
	add	bb_out_buf, bb_out_buf, x_tmp1             // bits/8 => x_tmp1
	str	bb_bits, [bb,offset_m_bits]
	str	bb_bit_count, [bb, offset_m_bit_count]
	str	bb_out_buf, [bb, offset_m_out_buf]

	cmp	end_in, next_in
	bhi	.loop

.done:
	ret
	.size	encode_deflate_icf_aarch64, .-encode_deflate_icf_aarch64