Lines Matching refs:p
109 #define get_input_data(p, o, b) \ argument
110 be##b##_to_cpu(get_unaligned((__be##b *)((p)->in + (o))))
112 #define init_hashtable_nodes(p, b) do { \ argument
114 hash_init((p)->htable##b); \
115 for (_i = 0; _i < ARRAY_SIZE((p)->node##b); _i++) { \
116 (p)->node##b[_i].index = _i; \
117 (p)->node##b[_i].data = 0; \
118 INIT_HLIST_NODE(&(p)->node##b[_i].node); \
122 #define find_index(p, b, n) ({ \ argument
124 p->index##b[n] = INDEX_NOT_FOUND; \
125 hash_for_each_possible(p->htable##b, _n, node, p->data##b[n]) { \
126 if (p->data##b[n] == _n->data) { \
127 p->index##b[n] = _n->index; \
131 p->index##b[n] >= 0; \
134 #define check_index(p, b, n) \ argument
135 ((p)->index##b[n] == INDEX_NOT_CHECKED \
136 ? find_index(p, b, n) \
137 : (p)->index##b[n] >= 0)
139 #define replace_hash(p, b, i, d) do { \ argument
140 struct sw842_hlist_node##b *_n = &(p)->node##b[(i)+(d)]; \
142 _n->data = (p)->data##b[d]; \
145 (unsigned int)((p)->in - (p)->instart), \
147 hash_add((p)->htable##b, &_n->node, _n->data); \
152 static int add_bits(struct sw842_param *p, u64 d, u8 n);
154 static int __split_add_bits(struct sw842_param *p, u64 d, u8 n, u8 s) in __split_add_bits() argument
161 ret = add_bits(p, d >> s, n - s); in __split_add_bits()
164 return add_bits(p, d & GENMASK_ULL(s - 1, 0), s); in __split_add_bits()
167 static int add_bits(struct sw842_param *p, u64 d, u8 n) in add_bits() argument
169 int b = p->bit, bits = b + n, s = round_up(bits, 8) - bits; in add_bits()
171 u8 *out = p->out; in add_bits()
182 return __split_add_bits(p, d, n, 32); in add_bits()
183 else if (p->olen < 8 && bits > 32 && bits <= 56) in add_bits()
184 return __split_add_bits(p, d, n, 16); in add_bits()
185 else if (p->olen < 4 && bits > 16 && bits <= 24) in add_bits()
186 return __split_add_bits(p, d, n, 8); in add_bits()
188 if (DIV_ROUND_UP(bits, 8) > p->olen) in add_bits()
211 p->bit += n; in add_bits()
213 if (p->bit > 7) { in add_bits()
214 p->out += p->bit / 8; in add_bits()
215 p->olen -= p->bit / 8; in add_bits()
216 p->bit %= 8; in add_bits()
222 static int add_template(struct sw842_param *p, u8 c) in add_template() argument
233 ret = add_bits(p, t[4], OP_BITS); in add_template()
245 ret = add_bits(p, p->index8[0], I8_BITS); in add_template()
247 ret = add_bits(p, p->data8[0], 64); in add_template()
253 ret = add_bits(p, get_input_data(p, 2, 32), 32); in add_template()
257 ret = add_bits(p, p->index4[b >> 2], I4_BITS); in add_template()
259 ret = add_bits(p, p->data4[b >> 2], 32); in add_template()
267 ret = add_bits(p, p->index2[b >> 1], I2_BITS); in add_template()
269 ret = add_bits(p, p->data2[b >> 1], 16); in add_template()
305 static int add_repeat_template(struct sw842_param *p, u8 r) in add_repeat_template() argument
313 ret = add_bits(p, OP_REPEAT, OP_BITS); in add_repeat_template()
317 ret = add_bits(p, r, REPEAT_BITS); in add_repeat_template()
327 static int add_short_data_template(struct sw842_param *p, u8 b) in add_short_data_template() argument
334 ret = add_bits(p, OP_SHORT_DATA, OP_BITS); in add_short_data_template()
338 ret = add_bits(p, b, SHORT_DATA_BITS); in add_short_data_template()
343 ret = add_bits(p, p->in[i], 8); in add_short_data_template()
354 static int add_zeros_template(struct sw842_param *p) in add_zeros_template() argument
356 int ret = add_bits(p, OP_ZEROS, OP_BITS); in add_zeros_template()
367 static int add_end_template(struct sw842_param *p) in add_end_template() argument
369 int ret = add_bits(p, OP_END, OP_BITS); in add_end_template()
380 static bool check_template(struct sw842_param *p, u8 c) in check_template() argument
391 match = check_index(p, 2, b >> 1); in check_template()
393 match = check_index(p, 4, b >> 2); in check_template()
395 match = check_index(p, 8, 0); in check_template()
408 static void get_next_data(struct sw842_param *p) in get_next_data() argument
410 p->data8[0] = get_input_data(p, 0, 64); in get_next_data()
411 p->data4[0] = get_input_data(p, 0, 32); in get_next_data()
412 p->data4[1] = get_input_data(p, 4, 32); in get_next_data()
413 p->data2[0] = get_input_data(p, 0, 16); in get_next_data()
414 p->data2[1] = get_input_data(p, 2, 16); in get_next_data()
415 p->data2[2] = get_input_data(p, 4, 16); in get_next_data()
416 p->data2[3] = get_input_data(p, 6, 16); in get_next_data()
423 static void update_hashtables(struct sw842_param *p) in update_hashtables() argument
425 u64 pos = p->in - p->instart; in update_hashtables()
430 replace_hash(p, 8, n8, 0); in update_hashtables()
431 replace_hash(p, 4, n4, 0); in update_hashtables()
432 replace_hash(p, 4, n4, 1); in update_hashtables()
433 replace_hash(p, 2, n2, 0); in update_hashtables()
434 replace_hash(p, 2, n2, 1); in update_hashtables()
435 replace_hash(p, 2, n2, 2); in update_hashtables()
436 replace_hash(p, 2, n2, 3); in update_hashtables()
442 static int process_next(struct sw842_param *p) in process_next() argument
446 p->index8[0] = INDEX_NOT_CHECKED; in process_next()
447 p->index4[0] = INDEX_NOT_CHECKED; in process_next()
448 p->index4[1] = INDEX_NOT_CHECKED; in process_next()
449 p->index2[0] = INDEX_NOT_CHECKED; in process_next()
450 p->index2[1] = INDEX_NOT_CHECKED; in process_next()
451 p->index2[2] = INDEX_NOT_CHECKED; in process_next()
452 p->index2[3] = INDEX_NOT_CHECKED; in process_next()
456 if (check_template(p, i)) in process_next()
460 ret = add_template(p, i); in process_next()
480 struct sw842_param *p = (struct sw842_param *)wmem; in sw842_compress() local
486 BUILD_BUG_ON(sizeof(*p) > SW842_MEM_COMPRESS); in sw842_compress()
488 init_hashtable_nodes(p, 8); in sw842_compress()
489 init_hashtable_nodes(p, 4); in sw842_compress()
490 init_hashtable_nodes(p, 2); in sw842_compress()
492 p->in = (u8 *)in; in sw842_compress()
493 p->instart = p->in; in sw842_compress()
494 p->ilen = ilen; in sw842_compress()
495 p->out = out; in sw842_compress()
496 p->olen = *olen; in sw842_compress()
497 p->bit = 0; in sw842_compress()
499 total = p->olen; in sw842_compress()
514 last = ~get_unaligned((u64 *)p->in); in sw842_compress()
516 while (p->ilen > 7) { in sw842_compress()
517 next = get_unaligned((u64 *)p->in); in sw842_compress()
522 get_next_data(p); in sw842_compress()
534 ret = add_repeat_template(p, repeat_count); in sw842_compress()
541 ret = add_zeros_template(p); in sw842_compress()
543 ret = process_next(p); in sw842_compress()
550 update_hashtables(p); in sw842_compress()
551 p->in += 8; in sw842_compress()
552 p->ilen -= 8; in sw842_compress()
556 ret = add_repeat_template(p, repeat_count); in sw842_compress()
562 if (p->ilen > 0) { in sw842_compress()
563 ret = add_short_data_template(p, p->ilen); in sw842_compress()
567 p->in += p->ilen; in sw842_compress()
568 p->ilen = 0; in sw842_compress()
571 ret = add_end_template(p); in sw842_compress()
583 ret = add_bits(p, crc, CRC_BITS); in sw842_compress()
587 if (p->bit) { in sw842_compress()
588 p->out++; in sw842_compress()
589 p->olen--; in sw842_compress()
590 p->bit = 0; in sw842_compress()
594 pad = (8 - ((total - p->olen) % 8)) % 8; in sw842_compress()
596 if (pad > p->olen) /* we were so close! */ in sw842_compress()
598 memset(p->out, 0, pad); in sw842_compress()
599 p->out += pad; in sw842_compress()
600 p->olen -= pad; in sw842_compress()
603 if (unlikely((total - p->olen) > UINT_MAX)) in sw842_compress()
606 *olen = total - p->olen; in sw842_compress()