Debian Codegraph @

src/northbridge/intel/haswell/native_raminit/ranges.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <types.h>
4
5 #include "ranges.h"
6
7 void linear_record_pass(
8 struct linear_train_data *const data,
9 const bool pass,
10 const int32_t value,
11 const int32_t start,
12 const int32_t step)
13 {
14 /* If this is the first time, initialize all values */
15 if (value == start) {
16 /*
17 * If value passed, create a zero-length region for the current value,
18 * which may be extended as long as the successive values are passing.
19 *
20 * Otherwise, create a zero-length range for the preceding value. This
21 * range cannot be extended by other passing values, which is desired.
22 */
23 data->current.start = start - (pass ? 0 : step);
24 data->current.end = data->current.start;
25 data->largest = data->current;
26 } else if (pass) {
27 /* If this pass is not contiguous, it belongs to a new region */
28 if (data->current.end != (value - step))
29 data->current.start = value;
30
31 /* Update end of current region */
32 data->current.end = value;
33
34 /* Update largest region */
35 if (range_width(data->current) > range_width(data->largest))
36 data->largest = data->current;
37 }
38 }
39
40 void phase_record_pass(
41 struct phase_train_data *const data,
42 const bool pass,
43 const int32_t value,
44 const int32_t start,
45 const int32_t step)
46 {
47 /* If this is the first time, initialize all values */
48 if (value == start) {
49 /*
50 * If value passed, create a zero-length region for the current value,
51 * which may be extended as long as the successive values are passing.
52 *
53 * Otherwise, create a zero-length range for the preceding value. This
54 * range cannot be extended by other passing values, which is desired.
55 */
56 data->current.start = start - (pass ? 0 : step);
57 data->current.end = data->current.start;
58 data->largest = data->current;
59 data->initial = data->current;
60 return;
61 }
62 if (!pass)
63 return;
64
65 /* Update initial region */
66 if (data->initial.end == (value - step))
67 data->initial.end = value;
68
69 /* If this pass is not contiguous, it belongs to a new region */
70 if (data->current.end != (value - step))
71 data->current.start = value;
72
73 /* Update end of current region */
74 data->current.end = value;
75
76 /* Update largest region */
77 if (range_width(data->current) > range_width(data->largest))
78 data->largest = data->current;
79 }
80
81 void phase_append_initial_to_current(
82 struct phase_train_data *const data,
83 const int32_t start,
84 const int32_t step)
85 {
86 /* If initial region is valid and does not overlap, append it */
87 if (data->initial.start == start && data->initial.end != data->current.end)
88 data->current.end += step + range_width(data->initial);
89
90 /* Update largest region */
91 if (range_width(data->current) > range_width(data->largest))
92 data->largest = data->current;
93 }
94
95 void phase_append_current_to_initial(
96 struct phase_train_data *const data,
97 const int32_t start,
98 const int32_t step)
99 {
100 /* If initial region is valid and does not overlap, append it */
101 if (data->initial.start == start && data->initial.end != data->current.end) {
102 data->initial.start -= (step + range_width(data->current));
103 data->current = data->initial;
104 }
105
106 /* Update largest region */
107 if (range_width(data->current) > range_width(data->largest))
108 data->largest = data->current;
109 }