Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Utilities/cmliblzma/liblzma/simple/ia64.c
Line
Count
Source
1
// SPDX-License-Identifier: 0BSD
2
3
///////////////////////////////////////////////////////////////////////////////
4
//
5
/// \file       ia64.c
6
/// \brief      Filter for IA64 (Itanium) binaries
7
///
8
//  Authors:    Igor Pavlov
9
//              Lasse Collin
10
//
11
///////////////////////////////////////////////////////////////////////////////
12
13
#include "simple_private.h"
14
15
16
static size_t
17
ia64_code(void *simple lzma_attribute((__unused__)),
18
    uint32_t now_pos, bool is_encoder,
19
    uint8_t *buffer, size_t size)
20
2.21k
{
21
2.21k
  static const uint32_t BRANCH_TABLE[32] = {
22
2.21k
    0, 0, 0, 0, 0, 0, 0, 0,
23
2.21k
    0, 0, 0, 0, 0, 0, 0, 0,
24
2.21k
    4, 4, 6, 6, 0, 0, 7, 7,
25
2.21k
    4, 4, 0, 0, 4, 4, 0, 0
26
2.21k
  };
27
28
2.21k
  size_t i;
29
449k
  for (i = 0; i + 16 <= size; i += 16) {
30
446k
    const uint32_t instr_template = buffer[i] & 0x1F;
31
446k
    const uint32_t mask = BRANCH_TABLE[instr_template];
32
446k
    uint32_t bit_pos = 5;
33
34
1.78M
    for (size_t slot = 0; slot < 3; ++slot, bit_pos += 41) {
35
1.34M
      if (((mask >> slot) & 1) == 0)
36
1.29M
        continue;
37
38
41.5k
      const size_t byte_pos = (bit_pos >> 3);
39
41.5k
      const uint32_t bit_res = bit_pos & 0x7;
40
41.5k
      uint64_t instruction = 0;
41
42
290k
      for (size_t j = 0; j < 6; ++j)
43
249k
        instruction += (uint64_t)(
44
249k
            buffer[i + j + byte_pos])
45
249k
            << (8 * j);
46
47
41.5k
      uint64_t inst_norm = instruction >> bit_res;
48
49
41.5k
      if (((inst_norm >> 37) & 0xF) == 0x5
50
5.42k
          && ((inst_norm >> 9) & 0x7) == 0
51
          /* &&  (inst_norm & 0x3F)== 0 */
52
41.5k
          ) {
53
1.99k
        uint32_t src = (uint32_t)(
54
1.99k
            (inst_norm >> 13) & 0xFFFFF);
55
1.99k
        src |= ((inst_norm >> 36) & 1) << 20;
56
57
1.99k
        src <<= 4;
58
59
1.99k
        uint32_t dest;
60
1.99k
        if (is_encoder)
61
0
          dest = now_pos + (uint32_t)(i) + src;
62
1.99k
        else
63
1.99k
          dest = src - (now_pos + (uint32_t)(i));
64
65
1.99k
        dest >>= 4;
66
67
1.99k
        inst_norm &= ~((uint64_t)(0x8FFFFF) << 13);
68
1.99k
        inst_norm |= (uint64_t)(dest & 0xFFFFF) << 13;
69
1.99k
        inst_norm |= (uint64_t)(dest & 0x100000)
70
1.99k
            << (36 - 20);
71
72
1.99k
        instruction &= (1U << bit_res) - 1;
73
1.99k
        instruction |= (inst_norm << bit_res);
74
75
13.9k
        for (size_t j = 0; j < 6; j++)
76
11.9k
          buffer[i + j + byte_pos] = (uint8_t)(
77
11.9k
              instruction
78
11.9k
              >> (8 * j));
79
1.99k
      }
80
41.5k
    }
81
446k
  }
82
83
2.21k
  return i;
84
2.21k
}
85
86
87
static lzma_ret
88
ia64_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
89
    const lzma_filter_info *filters, bool is_encoder)
90
832
{
91
832
  return lzma_simple_coder_init(next, allocator, filters,
92
832
      &ia64_code, 0, 16, 16, is_encoder);
93
832
}
94
95
96
#ifdef HAVE_ENCODER_IA64
97
extern lzma_ret
98
lzma_simple_ia64_encoder_init(lzma_next_coder *next,
99
    const lzma_allocator *allocator,
100
    const lzma_filter_info *filters)
101
0
{
102
0
  return ia64_coder_init(next, allocator, filters, true);
103
0
}
104
#endif
105
106
107
#ifdef HAVE_DECODER_IA64
108
extern lzma_ret
109
lzma_simple_ia64_decoder_init(lzma_next_coder *next,
110
    const lzma_allocator *allocator,
111
    const lzma_filter_info *filters)
112
832
{
113
  return ia64_coder_init(next, allocator, filters, false);
114
832
}
115
#endif