Lines Matching +full:4 +full:- +full:temp

1 // SPDX-License-Identifier: 0BSD
7 * Igor Pavlov <https://7-zip.org/>
21 BCJ_X86 = 4, /* x86 or x86-64 */
38 /* True if we are operating in single-call mode. */
65 * needs to be big enough to hold Alignment + 2 * Look-ahead:
67 * Type Alignment Look-ahead
68 * x86 1 4
69 * PowerPC 4 0
70 * IA-64 16 0
71 * ARM 4 0
72 * ARM-Thumb 2 2
73 * SPARC 4 0
76 } temp; member
97 size_t prev_pos = (size_t)-1; in bcj_x86()
98 uint32_t prev_mask = s->x86_prev_mask; in bcj_x86()
104 if (size <= 4) in bcj_x86()
107 size -= 4; in bcj_x86()
112 prev_pos = i - prev_pos; in bcj_x86()
116 prev_mask = (prev_mask << (prev_pos - 1)) & 7; in bcj_x86()
118 b = buf[i + 4 - mask_to_bit_num[prev_mask]]; in bcj_x86()
130 if (bcj_x86_test_msbyte(buf[i + 4])) { in bcj_x86()
133 dest = src - (s->pos + (uint32_t)i + 5); in bcj_x86()
138 b = (uint8_t)(dest >> (24 - j)); in bcj_x86()
142 src = dest ^ (((uint32_t)1 << (32 - j)) - 1); in bcj_x86()
146 dest |= (uint32_t)0 - (dest & 0x01000000); in bcj_x86()
148 i += 4; in bcj_x86()
154 prev_pos = i - prev_pos; in bcj_x86()
155 s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 1); in bcj_x86()
168 for (i = 0; i < size; i += 4) { in bcj_powerpc()
172 instr -= s->pos + (uint32_t)i; in bcj_powerpc()
189 4, 4, 6, 6, 0, 0, 7, 7, in bcj_ia64()
190 4, 4, 0, 0, 4, 4, 0, 0 in bcj_ia64()
203 /* Instruction slot (0, 1, or 2) in the 128-bit instruction word */ in bcj_ia64()
219 /* 41-bit instruction stored somewhere in the lowest 48 bits */ in bcj_ia64()
246 addr <<= 4; in bcj_ia64()
247 addr -= s->pos + (uint32_t)i; in bcj_ia64()
248 addr >>= 4; in bcj_ia64()
253 << (36 - 20); in bcj_ia64()
255 instr &= (1 << bit_res) - 1; in bcj_ia64()
277 for (i = 0; i < size; i += 4) { in bcj_arm()
282 addr -= s->pos + (uint32_t)i + 8; in bcj_arm()
300 if (size < 4) in bcj_armthumb()
303 size -= 4; in bcj_armthumb()
313 addr -= s->pos + (uint32_t)i + 4; in bcj_armthumb()
335 for (i = 0; i < size; i += 4) { in bcj_sparc()
339 instr -= s->pos + (uint32_t)i; in bcj_sparc()
341 instr = ((uint32_t)0x40000000 - (instr & 0x400000)) in bcj_sparc()
360 for (i = 0; i < size; i += 4) { in bcj_arm64()
365 addr = instr - ((s->pos + (uint32_t)i) >> 2); in bcj_arm64()
373 /* Only convert values in the range +/-512 MiB. */ in bcj_arm64()
377 addr -= (s->pos + (uint32_t)i) >> 12; in bcj_arm64()
382 instr |= (0U - (addr & 0x020000)) & 0xE00000; in bcj_arm64()
407 size -= 8; in bcj_riscv()
422 addr -= s->pos + (uint32_t)i; in bcj_riscv()
429 | ((addr << 4) & 0xE0)); in bcj_riscv()
431 buf[i + 3] = (uint8_t)(((addr >> 4) & 0x7F) in bcj_riscv()
434 i += 4 - 2; in bcj_riscv()
444 instr2 = get_unaligned_le32(buf + i + 4); in bcj_riscv()
446 if (((instr << 8) ^ (instr2 - 3)) & 0xF8003) { in bcj_riscv()
447 i += 6 - 2; in bcj_riscv()
459 if ((uint32_t)((instr - 0x3117) << 18) in bcj_riscv()
461 i += 4 - 2; in bcj_riscv()
465 addr = get_unaligned_be32(buf + i + 4); in bcj_riscv()
466 addr -= s->pos + (uint32_t)i; in bcj_riscv()
475 put_unaligned_le32(instr2, buf + i + 4); in bcj_riscv()
477 i += 8 - 2; in bcj_riscv()
486 * Apply the selected BCJ filter. Update *pos and s->pos to match the amount
499 size -= *pos; in bcj_apply()
501 switch (s->type) { in bcj_apply()
549 s->pos += filtered; in bcj_apply()
553 * Flush pending filtered data from temp to the output buffer.
555 * data to the beginning of temp.
561 copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos); in bcj_flush()
562 memcpy(b->out + b->out_pos, s->temp.buf, copy_size); in bcj_flush()
563 b->out_pos += copy_size; in bcj_flush()
565 s->temp.filtered -= copy_size; in bcj_flush()
566 s->temp.size -= copy_size; in bcj_flush()
567 memmove(s->temp.buf, s->temp.buf + copy_size, s->temp.size); in bcj_flush()
572 * data in chunks of 1-16 bytes. To hide this issue, this function does
585 if (s->temp.filtered > 0) { in xz_dec_bcj_run()
587 if (s->temp.filtered > 0) in xz_dec_bcj_run()
590 if (s->ret == XZ_STREAM_END) in xz_dec_bcj_run()
596 * temp, copy the unfiltered data from temp to the output buffer in xz_dec_bcj_run()
600 * to temp and rewind the output buffer position accordingly. in xz_dec_bcj_run()
602 * This needs to be always run when temp.size == 0 to handle a special in xz_dec_bcj_run()
606 if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) { in xz_dec_bcj_run()
607 out_start = b->out_pos; in xz_dec_bcj_run()
608 memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size); in xz_dec_bcj_run()
609 b->out_pos += s->temp.size; in xz_dec_bcj_run()
611 s->ret = xz_dec_lzma2_run(lzma2, b); in xz_dec_bcj_run()
612 if (s->ret != XZ_STREAM_END in xz_dec_bcj_run()
613 && (s->ret != XZ_OK || s->single_call)) in xz_dec_bcj_run()
614 return s->ret; in xz_dec_bcj_run()
616 bcj_apply(s, b->out, &out_start, b->out_pos); in xz_dec_bcj_run()
623 if (s->ret == XZ_STREAM_END) in xz_dec_bcj_run()
626 s->temp.size = b->out_pos - out_start; in xz_dec_bcj_run()
627 b->out_pos -= s->temp.size; in xz_dec_bcj_run()
628 memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size); in xz_dec_bcj_run()
633 * to try decoding more data to temp. in xz_dec_bcj_run()
635 if (b->out_pos + s->temp.size < b->out_size) in xz_dec_bcj_run()
640 * We have unfiltered data in temp. If the output buffer isn't full in xz_dec_bcj_run()
641 * yet, try to fill the temp buffer by decoding more data from the in xz_dec_bcj_run()
642 * next filter. Apply the BCJ filter on temp. Then we hopefully can in xz_dec_bcj_run()
643 * fill the actual output buffer by copying filtered data from temp. in xz_dec_bcj_run()
644 * A mix of filtered and unfiltered data may be left in temp; it will in xz_dec_bcj_run()
647 if (b->out_pos < b->out_size) { in xz_dec_bcj_run()
648 /* Make b->out{,_pos,_size} temporarily point to s->temp. */ in xz_dec_bcj_run()
649 s->out = b->out; in xz_dec_bcj_run()
650 s->out_pos = b->out_pos; in xz_dec_bcj_run()
651 s->out_size = b->out_size; in xz_dec_bcj_run()
652 b->out = s->temp.buf; in xz_dec_bcj_run()
653 b->out_pos = s->temp.size; in xz_dec_bcj_run()
654 b->out_size = sizeof(s->temp.buf); in xz_dec_bcj_run()
656 s->ret = xz_dec_lzma2_run(lzma2, b); in xz_dec_bcj_run()
658 s->temp.size = b->out_pos; in xz_dec_bcj_run()
659 b->out = s->out; in xz_dec_bcj_run()
660 b->out_pos = s->out_pos; in xz_dec_bcj_run()
661 b->out_size = s->out_size; in xz_dec_bcj_run()
663 if (s->ret != XZ_OK && s->ret != XZ_STREAM_END) in xz_dec_bcj_run()
664 return s->ret; in xz_dec_bcj_run()
666 bcj_apply(s, s->temp.buf, &s->temp.filtered, s->temp.size); in xz_dec_bcj_run()
673 if (s->ret == XZ_STREAM_END) in xz_dec_bcj_run()
674 s->temp.filtered = s->temp.size; in xz_dec_bcj_run()
677 if (s->temp.filtered > 0) in xz_dec_bcj_run()
681 return s->ret; in xz_dec_bcj_run()
688 s->single_call = single_call; in xz_dec_bcj_create()
727 s->type = id; in xz_dec_bcj_reset()
728 s->ret = XZ_OK; in xz_dec_bcj_reset()
729 s->pos = 0; in xz_dec_bcj_reset()
730 s->x86_prev_mask = 0; in xz_dec_bcj_reset()
731 s->temp.filtered = 0; in xz_dec_bcj_reset()
732 s->temp.size = 0; in xz_dec_bcj_reset()