Lines Matching full:p

109 #define get_input_data(p, o, b)						\
110 be##b##_to_cpu(get_unaligned((__be##b *)((p)->in + (o))))
112 #define init_hashtable_nodes(p, b) do { \
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) ({ \
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) \
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 { \
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)
161 ret = add_bits(p, d >> s, n - s);
164 return add_bits(p, d & GENMASK_ULL(s - 1, 0), s);
167 static int add_bits(struct sw842_param *p, u64 d, u8 n)
169 int b = p->bit, bits = b + n, s = round_up(bits, 8) - bits;
171 u8 *out = p->out;
178 /* split this up if writing to > 8 bytes (i.e. n == 64 && p->bit > 0),
182 return __split_add_bits(p, d, n, 32);
183 else if (p->olen < 8 && bits > 32 && bits <= 56)
184 return __split_add_bits(p, d, n, 16);
185 else if (p->olen < 4 && bits > 16 && bits <= 24)
186 return __split_add_bits(p, d, n, 8);
188 if (DIV_ROUND_UP(bits, 8) > p->olen)
211 p->bit += n;
213 if (p->bit > 7) {
214 p->out += p->bit / 8;
215 p->olen -= p->bit / 8;
216 p->bit %= 8;
222 static int add_template(struct sw842_param *p, u8 c)
233 ret = add_bits(p, t[4], OP_BITS);
245 ret = add_bits(p, p->index8[0], I8_BITS);
247 ret = add_bits(p, p->data8[0], 64);
253 ret = add_bits(p, get_input_data(p, 2, 32), 32);
257 ret = add_bits(p, p->index4[b >> 2], I4_BITS);
259 ret = add_bits(p, p->data4[b >> 2], 32);
267 ret = add_bits(p, p->index2[b >> 1], I2_BITS);
269 ret = add_bits(p, p->data2[b >> 1], 16);
305 static int add_repeat_template(struct sw842_param *p, u8 r)
313 ret = add_bits(p, OP_REPEAT, OP_BITS);
317 ret = add_bits(p, r, REPEAT_BITS);
327 static int add_short_data_template(struct sw842_param *p, u8 b)
334 ret = add_bits(p, OP_SHORT_DATA, OP_BITS);
338 ret = add_bits(p, b, SHORT_DATA_BITS);
343 ret = add_bits(p, p->in[i], 8);
354 static int add_zeros_template(struct sw842_param *p)
356 int ret = add_bits(p, OP_ZEROS, OP_BITS);
367 static int add_end_template(struct sw842_param *p)
369 int ret = add_bits(p, OP_END, OP_BITS);
380 static bool check_template(struct sw842_param *p, u8 c)
391 match = check_index(p, 2, b >> 1);
393 match = check_index(p, 4, b >> 2);
395 match = check_index(p, 8, 0);
408 static void get_next_data(struct sw842_param *p)
410 p->data8[0] = get_input_data(p, 0, 64);
411 p->data4[0] = get_input_data(p, 0, 32);
412 p->data4[1] = get_input_data(p, 4, 32);
413 p->data2[0] = get_input_data(p, 0, 16);
414 p->data2[1] = get_input_data(p, 2, 16);
415 p->data2[2] = get_input_data(p, 4, 16);
416 p->data2[3] = get_input_data(p, 6, 16);
423 static void update_hashtables(struct sw842_param *p)
425 u64 pos = p->in - p->instart;
430 replace_hash(p, 8, n8, 0);
431 replace_hash(p, 4, n4, 0);
432 replace_hash(p, 4, n4, 1);
433 replace_hash(p, 2, n2, 0);
434 replace_hash(p, 2, n2, 1);
435 replace_hash(p, 2, n2, 2);
436 replace_hash(p, 2, n2, 3);
440 * the p->dataN fields must already be set for the current 8 byte block
442 static int process_next(struct sw842_param *p)
446 p->index8[0] = INDEX_NOT_CHECKED;
447 p->index4[0] = INDEX_NOT_CHECKED;
448 p->index4[1] = INDEX_NOT_CHECKED;
449 p->index2[0] = INDEX_NOT_CHECKED;
450 p->index2[1] = INDEX_NOT_CHECKED;
451 p->index2[2] = INDEX_NOT_CHECKED;
452 p->index2[3] = INDEX_NOT_CHECKED;
456 if (check_template(p, i))
460 ret = add_template(p, i);
480 struct sw842_param *p = (struct sw842_param *)wmem;
486 BUILD_BUG_ON(sizeof(*p) > SW842_MEM_COMPRESS);
488 init_hashtable_nodes(p, 8);
489 init_hashtable_nodes(p, 4);
490 init_hashtable_nodes(p, 2);
492 p->in = (u8 *)in;
493 p->instart = p->in;
494 p->ilen = ilen;
495 p->out = out;
496 p->olen = *olen;
497 p->bit = 0;
499 total = p->olen;
514 last = ~get_unaligned((u64 *)p->in);
516 while (p->ilen > 7) {
517 next = get_unaligned((u64 *)p->in);
522 get_next_data(p);
534 ret = add_repeat_template(p, repeat_count);
543 ret = add_zeros_template(p);
545 ret = process_next(p);
552 update_hashtables(p);
553 p->in += 8;
554 p->ilen -= 8;
558 ret = add_repeat_template(p, repeat_count);
564 if (p->ilen > 0) {
565 ret = add_short_data_template(p, p->ilen);
569 p->in += p->ilen;
570 p->ilen = 0;
573 ret = add_end_template(p);
585 ret = add_bits(p, crc, CRC_BITS);
589 if (p->bit) {
590 p->out++;
591 p->olen--;
592 p->bit = 0;
596 pad = (8 - ((total - p->olen) % 8)) % 8;
598 if (pad > p->olen) /* we were so close! */
600 memset(p->out, 0, pad);
601 p->out += pad;
602 p->olen -= pad;
605 if (unlikely((total - p->olen) > UINT_MAX))
608 *olen = total - p->olen;