Coverage Report

Created: 2025-06-15 00:57

/src/cmp_tool/lib/common/cmp_cal_up_model.h
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * @file   cmp_cal_up_model.h
3
 * @author Dominik Loidolt (dominik.loidolt@univie.ac.at)
4
 * @date   2023
5
 *
6
 * @copyright GPLv2
7
 * This program is free software; you can redistribute it and/or modify it
8
 * under the terms and conditions of the GNU General Public License,
9
 * version 2, as published by the Free Software Foundation.
10
 *
11
 * This program is distributed in the hope it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14
 * more details.
15
 *
16
 * @brief functions to calculate the updated (new) model
17
 */
18
19
#ifndef CMP_CAL_UP_MODEL_H
20
#define CMP_CAL_UP_MODEL_H
21
22
#include <stdint.h>
23
24
25
/* the maximal model values used in the update equation for the new model */
26
50.9k
#define MAX_MODEL_VALUE 16U
27
28
29
/**
30
 * @brief method for lossy rounding
31
 * @note This function is implemented as a macro for the sake of performance
32
 *
33
 * @param value the value to round
34
 * @param round rounding parameter
35
 *
36
 * @return rounded value
37
 */
38
39
264k
#define round_fwd(value, round) ((uint32_t)(value) >> (round))
40
41
42
/**
43
 * @brief inverse method for lossy rounding
44
 * @note This function is implemented as a macro for the sake of performance
45
 *
46
 * @param value the value to round back
47
 * @param round rounding parameter
48
 *
49
 * @return back rounded value
50
 */
51
52
21.1k
#define round_inv(value, round) ((uint32_t)(value) << (round))
53
54
55
/**
56
 * @brief implementation of the model update equation
57
 * @note check before that model_value is not greater than MAX_MODEL_VALUE
58
 *
59
 * @warning: Do not use this macro with types larger than uint32_t
60
 *
61
 * @param data    data to process
62
 * @param model   (current) model of the data to process
63
 * @param model_value model weighting parameter
64
 * @param round   routing parameter
65
 *
66
 * @returns (new) updated model
67
 */
68
69
#define cmp_up_model(data, model, model_value, round)             \
70
19.8k
  __extension__                     \
71
19.8k
  ({                        \
72
19.8k
    uint32_t __ret;                   \
73
19.8k
    switch (sizeof(data)) {                 \
74
1.49k
    case sizeof(uint8_t):                 \
75
6.45k
    case sizeof(uint16_t):                  \
76
6.45k
      __ret = cmp_up_model16(data, model, model_value, round);      \
77
6.45k
      break;                   \
78
13.4k
    case sizeof(uint32_t):                  \
79
13.4k
      __ret = cmp_up_model32(data, model, model_value, round);      \
80
13.4k
      break;                   \
81
19.8k
    }                     \
82
19.8k
    (__typeof__(data))__ret;                \
83
19.8k
  })
84
85
86
/* fast calculation  for data size smaller that uint32_t  */
87
static __inline uint16_t cmp_up_model16(uint32_t data, uint32_t model,
88
              unsigned int model_value, unsigned int round)
89
6.45k
{
90
  /* round and round back input because for decompression the accurate
91
   * data values are not available
92
   */
93
6.45k
  uint32_t const weighted_data = round_inv(round_fwd(data, round), round)
94
6.45k
    * (MAX_MODEL_VALUE - model_value);
95
6.45k
  uint32_t const weighted_model = model * model_value;
96
97
  /* truncation is intended */
98
6.45k
  return (uint16_t)((weighted_model + weighted_data) / MAX_MODEL_VALUE);
99
6.45k
}
cmp_icu.c:cmp_up_model16
Line
Count
Source
89
6.45k
{
90
  /* round and round back input because for decompression the accurate
91
   * data values are not available
92
   */
93
6.45k
  uint32_t const weighted_data = round_inv(round_fwd(data, round), round)
94
6.45k
    * (MAX_MODEL_VALUE - model_value);
95
6.45k
  uint32_t const weighted_model = model * model_value;
96
97
  /* truncation is intended */
98
6.45k
  return (uint16_t)((weighted_model + weighted_data) / MAX_MODEL_VALUE);
99
6.45k
}
Unexecuted instantiation: cmp_support.c:cmp_up_model16
100
101
102
/* slow calculation for uint32_t data size */
103
static __inline uint32_t cmp_up_model32(uint32_t data, uint32_t model,
104
              unsigned int model_value, unsigned int round)
105
14.7k
{
106
  /* round and round back input because for decompression the accurate
107
   * data values are not available
108
   * cast to uint64_t to prevent overflow in the multiplication
109
   */
110
14.7k
  uint64_t const weighted_data = (uint64_t)round_inv(round_fwd(data, round), round)
111
14.7k
    * (MAX_MODEL_VALUE - model_value);
112
14.7k
  uint64_t const weighted_model = (uint64_t)model * model_value;
113
114
  /* truncation is intended */
115
14.7k
  return (uint32_t)((weighted_model + weighted_data) / MAX_MODEL_VALUE);
116
14.7k
}
cmp_icu.c:cmp_up_model32
Line
Count
Source
105
14.7k
{
106
  /* round and round back input because for decompression the accurate
107
   * data values are not available
108
   * cast to uint64_t to prevent overflow in the multiplication
109
   */
110
14.7k
  uint64_t const weighted_data = (uint64_t)round_inv(round_fwd(data, round), round)
111
14.7k
    * (MAX_MODEL_VALUE - model_value);
112
14.7k
  uint64_t const weighted_model = (uint64_t)model * model_value;
113
114
  /* truncation is intended */
115
14.7k
  return (uint32_t)((weighted_model + weighted_data) / MAX_MODEL_VALUE);
116
14.7k
}
Unexecuted instantiation: cmp_support.c:cmp_up_model32
117
118
#endif /* CMP_CAL_UP_MODEL */