Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit a9aac28

Browse files
William Douglasbryteise
authored andcommitted
Update opt_mask handling to match mixer-tools
mixer-tools populates the optimized mask based on a matrix of values where the mask includes both the optimization of the file on the line but also the combined masks of all matching files. This means a file mask needs to be translaed from the mask to what its actual optimization level is and what other optimizations levels are available to be useful. This change adds 2 new elements to the file struct. The opt_level stores a files optimization level and available_levels stores a bitwise or of the different optimization levels that can be found in the file list for the same file. For instance an AVX2_3 mask indicates the file is AVX2 with both SSE and AVX512 files also available (SSE | AVX2 | AVX512 == 3). Signed-off-by: William Douglas <[email protected]>
1 parent 6eb95df commit a9aac28

File tree

4 files changed

+145
-87
lines changed

4 files changed

+145
-87
lines changed

src/swupd.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,19 @@ struct update_stat {
109109
/* +1 for null termination */
110110
#define SWUPD_HASH_LEN (DIGEST_LEN_SHA256 + 1)
111111

112-
/* Can support 7 different levels */
113-
#define SSE_OPT 0x0
114-
#define V3_OPT 0x1
115-
#define V4_OPT 0x2
116-
117-
#define MAX_OPT(opt) (opt) > 3
112+
/* Any changes here must match mixer, requires format bump */
113+
#define SSE 0
114+
#define AVX2 1 << 0
115+
#define AVX512 1 << 1
116+
117+
#define SSE_0 0x0
118+
#define SSE_1 0x1
119+
#define SSE_2 0x2
120+
#define SSE_3 0x3
121+
#define AVX2_1 0x4
122+
#define AVX2_3 0x5
123+
#define AVX512_2 0x6
124+
#define AVX512_3 0x7
118125

119126
struct file {
120127
char *filename;
@@ -140,6 +147,8 @@ struct file {
140147
unsigned int do_not_update : 1;
141148

142149
unsigned char opt_mask;
150+
unsigned char opt_level;
151+
unsigned char available_levels;
143152

144153
struct file *peer; /* same file in another manifest */
145154
struct header *header;

src/swupd_lib/manifest_parser.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,48 @@
5050
/* Changes to the OPTIMIZED_BITMASKS array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0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0 };
5252

53+
int set_opts(struct file *file, unsigned char mask)
54+
{
55+
file->opt_mask = mask;
56+
switch (file->opt_mask) {
57+
case SSE_0:
58+
file->opt_level = SSE;
59+
file->available_levels = SSE;
60+
break;
61+
case SSE_1:
62+
file->opt_level = SSE;
63+
file->available_levels = SSE | AVX2;
64+
break;
65+
case SSE_2:
66+
file->opt_level = SSE;
67+
file->available_levels = SSE | AVX512;
68+
break;
69+
case SSE_3:
70+
file->opt_level = SSE;
71+
file->available_levels = SSE | AVX2 | AVX512;
72+
break;
73+
case AVX2_1:
74+
file->opt_level = AVX2;
75+
file->available_levels = SSE | AVX2;
76+
break;
77+
case AVX2_3:
78+
file->opt_level = AVX2;
79+
file->available_levels = SSE | AVX2 | AVX512;
80+
break;
81+
case AVX512_2:
82+
file->opt_level = AVX512;
83+
file->available_levels = SSE | AVX512;
84+
break;
85+
case AVX512_3:
86+
file->opt_level = AVX512;
87+
file->available_levels = SSE | AVX2 | AVX512;
88+
break;
89+
default:
90+
return -1;
91+
}
92+
return 0;
93+
}
94+
5395
struct manifest *manifest_parse(const char *component, const char *filename, bool header_only)
5496
{
5597
FILE *infile;
@@ -217,8 +259,11 @@ struct manifest *manifest_parse(const char *component, const char *filename, boo
217259
file->is_experimental = 1;
218260
}
219261

220-
file->opt_mask = OPTIMIZED_BITMASKS[(unsigned char)line[2]];
221-
if (file->opt_mask != SSE_OPT) {
262+
if (set_opts(file, OPTIMIZED_BITMASKS[(unsigned char)line[2]])) {
263+
FREE(file);
264+
continue;
265+
}
266+
if (file->opt_level != SSE) {
222267
FREE(file);
223268
continue;
224269
}

test/unit/data/mom2

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,66 +21,66 @@ X... 0000000000000000000000000000000000000000000000000000000000000004 30 f4
2121
..C. 0000000000000000000000000000000000000000000000000000000000000010 30 f10
2222
..b. 0000000000000000000000000000000000000000000000000000000000000011 30 f11
2323
..s. 0000000000000000000000000000000000000000000000000000000000000012 30 f12
24-
..a. 0000000000000000000000000000000000000000000000000000000000000013 30 f12
25-
..c. 0000000000000000000000000000000000000000000000000000000000000014 30 f12
26-
..d. 0000000000000000000000000000000000000000000000000000000000000015 30 f12
27-
..e. 0000000000000000000000000000000000000000000000000000000000000016 30 f12
28-
..f. 0000000000000000000000000000000000000000000000000000000000000017 30 f12
29-
..g. 0000000000000000000000000000000000000000000000000000000000000018 30 f12
30-
..h. 0000000000000000000000000000000000000000000000000000000000000019 30 f12
31-
..i. 0000000000000000000000000000000000000000000000000000000000000020 30 f12
32-
..j. 0000000000000000000000000000000000000000000000000000000000000021 30 f12
33-
..k. 0000000000000000000000000000000000000000000000000000000000000022 30 f12
34-
..l. 0000000000000000000000000000000000000000000000000000000000000023 30 f12
35-
..m. 0000000000000000000000000000000000000000000000000000000000000024 30 f12
36-
..n. 0000000000000000000000000000000000000000000000000000000000000025 30 f12
37-
..o. 0000000000000000000000000000000000000000000000000000000000000026 30 f12
38-
..p. 0000000000000000000000000000000000000000000000000000000000000027 30 f12
39-
..q. 0000000000000000000000000000000000000000000000000000000000000028 30 f12
40-
..r. 0000000000000000000000000000000000000000000000000000000000000029 30 f12
41-
..t. 0000000000000000000000000000000000000000000000000000000000000030 30 f12
42-
..u. 0000000000000000000000000000000000000000000000000000000000000031 30 f12
43-
..v. 0000000000000000000000000000000000000000000000000000000000000032 30 f12
44-
..w. 0000000000000000000000000000000000000000000000000000000000000033 30 f12
45-
..x. 0000000000000000000000000000000000000000000000000000000000000034 30 f12
46-
..y. 0000000000000000000000000000000000000000000000000000000000000035 30 f12
47-
..z. 0000000000000000000000000000000000000000000000000000000000000036 30 f12
48-
..A. 0000000000000000000000000000000000000000000000000000000000000037 30 f12
49-
..B. 0000000000000000000000000000000000000000000000000000000000000038 30 f12
50-
..D. 0000000000000000000000000000000000000000000000000000000000000039 30 f12
51-
..E. 0000000000000000000000000000000000000000000000000000000000000040 30 f12
52-
..F. 0000000000000000000000000000000000000000000000000000000000000041 30 f12
53-
..G. 0000000000000000000000000000000000000000000000000000000000000042 30 f12
54-
..H. 0000000000000000000000000000000000000000000000000000000000000043 30 f12
55-
..I. 0000000000000000000000000000000000000000000000000000000000000044 30 f12
56-
..J. 0000000000000000000000000000000000000000000000000000000000000045 30 f12
57-
..K. 0000000000000000000000000000000000000000000000000000000000000046 30 f12
58-
..L. 0000000000000000000000000000000000000000000000000000000000000047 30 f12
59-
..M. 0000000000000000000000000000000000000000000000000000000000000048 30 f12
60-
..N. 0000000000000000000000000000000000000000000000000000000000000049 30 f12
61-
..O. 0000000000000000000000000000000000000000000000000000000000000050 30 f12
62-
..P. 0000000000000000000000000000000000000000000000000000000000000051 30 f12
63-
..Q. 0000000000000000000000000000000000000000000000000000000000000052 30 f12
64-
..R. 0000000000000000000000000000000000000000000000000000000000000053 30 f12
65-
..S. 0000000000000000000000000000000000000000000000000000000000000054 30 f12
66-
..T. 0000000000000000000000000000000000000000000000000000000000000055 30 f12
67-
..U. 0000000000000000000000000000000000000000000000000000000000000056 30 f12
68-
..V. 0000000000000000000000000000000000000000000000000000000000000057 30 f12
69-
..W. 0000000000000000000000000000000000000000000000000000000000000058 30 f12
70-
..X. 0000000000000000000000000000000000000000000000000000000000000059 30 f12
71-
..Y. 0000000000000000000000000000000000000000000000000000000000000060 30 f12
72-
..Z. 0000000000000000000000000000000000000000000000000000000000000061 30 f12
73-
..0. 0000000000000000000000000000000000000000000000000000000000000062 30 f12
74-
..1. 0000000000000000000000000000000000000000000000000000000000000063 30 f12
75-
..2. 0000000000000000000000000000000000000000000000000000000000000064 30 f12
76-
..3. 0000000000000000000000000000000000000000000000000000000000000065 30 f12
77-
..4. 0000000000000000000000000000000000000000000000000000000000000066 30 f12
78-
..5. 0000000000000000000000000000000000000000000000000000000000000067 30 f12
79-
..6. 0000000000000000000000000000000000000000000000000000000000000068 30 f12
80-
..7. 0000000000000000000000000000000000000000000000000000000000000069 30 f12
81-
..8. 0000000000000000000000000000000000000000000000000000000000000070 30 f12
82-
..9. 0000000000000000000000000000000000000000000000000000000000000071 30 f12
83-
..!. 0000000000000000000000000000000000000000000000000000000000000072 30 f12
84-
..#. 0000000000000000000000000000000000000000000000000000000000000073 30 f12
85-
..^. 0000000000000000000000000000000000000000000000000000000000000074 30 f12
86-
..*. 0000000000000000000000000000000000000000000000000000000000000075 30 f12
24+
..a. 0000000000000000000000000000000000000000000000000000000000000013 30 f13
25+
..c. 0000000000000000000000000000000000000000000000000000000000000014 30 f14
26+
..d. 0000000000000000000000000000000000000000000000000000000000000015 30 f15
27+
..e. 0000000000000000000000000000000000000000000000000000000000000016 30 f13
28+
..f. 0000000000000000000000000000000000000000000000000000000000000017 30 f15
29+
..g. 0000000000000000000000000000000000000000000000000000000000000018 30 f14
30+
..h. 0000000000000000000000000000000000000000000000000000000000000019 30 f15
31+
..i. 0000000000000000000000000000000000000000000000000000000000000020 30 fxy
32+
..j. 0000000000000000000000000000000000000000000000000000000000000021 30 fxy
33+
..k. 0000000000000000000000000000000000000000000000000000000000000022 30 fxy
34+
..l. 0000000000000000000000000000000000000000000000000000000000000023 30 fxy
35+
..m. 0000000000000000000000000000000000000000000000000000000000000024 30 fxy
36+
..n. 0000000000000000000000000000000000000000000000000000000000000025 30 fxy
37+
..o. 0000000000000000000000000000000000000000000000000000000000000026 30 fxy
38+
..p. 0000000000000000000000000000000000000000000000000000000000000027 30 fxy
39+
..q. 0000000000000000000000000000000000000000000000000000000000000028 30 fxy
40+
..r. 0000000000000000000000000000000000000000000000000000000000000029 30 fxy
41+
..t. 0000000000000000000000000000000000000000000000000000000000000030 30 fxy
42+
..u. 0000000000000000000000000000000000000000000000000000000000000031 30 fxy
43+
..v. 0000000000000000000000000000000000000000000000000000000000000032 30 fxy
44+
..w. 0000000000000000000000000000000000000000000000000000000000000033 30 fxy
45+
..x. 0000000000000000000000000000000000000000000000000000000000000034 30 fxy
46+
..y. 0000000000000000000000000000000000000000000000000000000000000035 30 fxy
47+
..z. 0000000000000000000000000000000000000000000000000000000000000036 30 fxy
48+
..A. 0000000000000000000000000000000000000000000000000000000000000037 30 fxy
49+
..B. 0000000000000000000000000000000000000000000000000000000000000038 30 fxy
50+
..D. 0000000000000000000000000000000000000000000000000000000000000039 30 fxy
51+
..E. 0000000000000000000000000000000000000000000000000000000000000040 30 fxy
52+
..F. 0000000000000000000000000000000000000000000000000000000000000041 30 fxy
53+
..G. 0000000000000000000000000000000000000000000000000000000000000042 30 fxy
54+
..H. 0000000000000000000000000000000000000000000000000000000000000043 30 fxy
55+
..I. 0000000000000000000000000000000000000000000000000000000000000044 30 fxy
56+
..J. 0000000000000000000000000000000000000000000000000000000000000045 30 fxy
57+
..K. 0000000000000000000000000000000000000000000000000000000000000046 30 fxy
58+
..L. 0000000000000000000000000000000000000000000000000000000000000047 30 fxy
59+
..M. 0000000000000000000000000000000000000000000000000000000000000048 30 fxy
60+
..N. 0000000000000000000000000000000000000000000000000000000000000049 30 fxy
61+
..O. 0000000000000000000000000000000000000000000000000000000000000050 30 fxy
62+
..P. 0000000000000000000000000000000000000000000000000000000000000051 30 fxy
63+
..Q. 0000000000000000000000000000000000000000000000000000000000000052 30 fxy
64+
..R. 0000000000000000000000000000000000000000000000000000000000000053 30 fxy
65+
..S. 0000000000000000000000000000000000000000000000000000000000000054 30 fxy
66+
..T. 0000000000000000000000000000000000000000000000000000000000000055 30 fxy
67+
..U. 0000000000000000000000000000000000000000000000000000000000000056 30 fxy
68+
..V. 0000000000000000000000000000000000000000000000000000000000000057 30 fxy
69+
..W. 0000000000000000000000000000000000000000000000000000000000000058 30 fxy
70+
..X. 0000000000000000000000000000000000000000000000000000000000000059 30 fxy
71+
..Y. 0000000000000000000000000000000000000000000000000000000000000060 30 fxy
72+
..Z. 0000000000000000000000000000000000000000000000000000000000000061 30 fxy
73+
..0. 0000000000000000000000000000000000000000000000000000000000000062 30 fxy
74+
..1. 0000000000000000000000000000000000000000000000000000000000000063 30 fxy
75+
..2. 0000000000000000000000000000000000000000000000000000000000000064 30 fxy
76+
..3. 0000000000000000000000000000000000000000000000000000000000000065 30 fxy
77+
..4. 0000000000000000000000000000000000000000000000000000000000000066 30 fxy
78+
..5. 0000000000000000000000000000000000000000000000000000000000000067 30 fxy
79+
..6. 0000000000000000000000000000000000000000000000000000000000000068 30 fxy
80+
..7. 0000000000000000000000000000000000000000000000000000000000000069 30 fxy
81+
..8. 0000000000000000000000000000000000000000000000000000000000000070 30 fxy
82+
..9. 0000000000000000000000000000000000000000000000000000000000000071 30 fxy
83+
..!. 0000000000000000000000000000000000000000000000000000000000000072 30 fxy
84+
..#. 0000000000000000000000000000000000000000000000000000000000000073 30 fxy
85+
..^. 0000000000000000000000000000000000000000000000000000000000000074 30 fxy
86+
..*. 0000000000000000000000000000000000000000000000000000000000000075 30 fxy

test/unit/test_manifest.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "swupd.h"
2424
#include "test_helper.h"
2525

26-
static void validate_file(struct list *files, const char *filename, int version, int hash, int is_dir, int is_file, int is_link, int is_deleted, int is_ghosted, int is_manifest, int is_experimental, int is_exported)
26+
static void validate_file(struct list *files, const char *filename, int version, int hash, int is_dir, int is_file, int is_link, int is_deleted, int is_ghosted, int is_manifest, int is_experimental, int is_exported, unsigned char mask)
2727
{
2828
struct list *list;
2929
char hash_str[SWUPD_HASH_LEN];
@@ -41,6 +41,7 @@ static void validate_file(struct list *files, const char *filename, int version,
4141
check(file->is_manifest == is_manifest);
4242
check(file->is_experimental == is_experimental);
4343
check(file->is_exported == is_exported);
44+
check(file->opt_mask == mask);
4445

4546
check(file->last_change == version);
4647

@@ -90,23 +91,26 @@ static void test_manifest_parse()
9091
// Check if parser can parse all different flags supported for the file list
9192
manifest = manifest_parse_test("test", dir, "data/mom2", false);
9293
check(manifest != NULL);
93-
check(list_len(manifest->files) == 12);
94+
check(list_len(manifest->files) == 15);
9495
check(list_len(manifest->manifests) == 1);
9596

96-
validate_file(manifest->manifests, "m1", 10, 1, 0, 0, 0, 0, 0, 1, 0, 0);
97-
98-
validate_file(manifest->files, "f1", 20, 1, 0, 1, 0, 0, 0, 0, 0, 0);
99-
validate_file(manifest->files, "f2", 30, 2, 1, 0, 0, 0, 0, 0, 0, 0);
100-
validate_file(manifest->files, "f3", 30, 3, 0, 0, 1, 0, 0, 0, 0, 0);
101-
validate_file(manifest->files, "f4", 30, 4, 0, 0, 0, 0, 0, 0, 0, 0);
102-
validate_file(manifest->files, "f5", 30, 5, 0, 0, 0, 1, 0, 0, 0, 0);
103-
validate_file(manifest->files, "f6", 30, 6, 0, 0, 0, 1, 1, 0, 0, 0);
104-
validate_file(manifest->files, "f7", 30, 7, 0, 0, 0, 0, 0, 0, 1, 0);
105-
validate_file(manifest->files, "f8", 30, 8, 0, 0, 0, 0, 0, 0, 0, 0);
106-
validate_file(manifest->files, "f9", 30, 9, 0, 0, 0, 0, 0, 0, 0, 1);
107-
validate_file(manifest->files, "f10", 30, 10, 0, 0, 0, 0, 0, 0, 0, 0);
108-
validate_file(manifest->files, "f11", 30, 11, 0, 0, 0, 0, 0, 0, 0, 0);
109-
validate_file(manifest->files, "f12", 30, 12, 0, 0, 0, 0, 0, 0, 0, 0);
97+
validate_file(manifest->manifests, "m1", 10, 1, 0, 0, 0, 0, 0, 1, 0, 0, SSE_0);
98+
99+
validate_file(manifest->files, "f1", 20, 1, 0, 1, 0, 0, 0, 0, 0, 0, SSE_0);
100+
validate_file(manifest->files, "f2", 30, 2, 1, 0, 0, 0, 0, 0, 0, 0, SSE_0);
101+
validate_file(manifest->files, "f3", 30, 3, 0, 0, 1, 0, 0, 0, 0, 0, SSE_0);
102+
validate_file(manifest->files, "f4", 30, 4, 0, 0, 0, 0, 0, 0, 0, 0, SSE_0);
103+
validate_file(manifest->files, "f5", 30, 5, 0, 0, 0, 1, 0, 0, 0, 0, SSE_0);
104+
validate_file(manifest->files, "f6", 30, 6, 0, 0, 0, 1, 1, 0, 0, 0, SSE_0);
105+
validate_file(manifest->files, "f7", 30, 7, 0, 0, 0, 0, 0, 0, 1, 0, SSE_0);
106+
validate_file(manifest->files, "f8", 30, 8, 0, 0, 0, 0, 0, 0, 0, 0, SSE_0);
107+
validate_file(manifest->files, "f9", 30, 9, 0, 0, 0, 0, 0, 0, 0, 1, SSE_0);
108+
validate_file(manifest->files, "f10", 30, 10, 0, 0, 0, 0, 0, 0, 0, 0, SSE_0);
109+
validate_file(manifest->files, "f11", 30, 11, 0, 0, 0, 0, 0, 0, 0, 0, SSE_0);
110+
validate_file(manifest->files, "f12", 30, 12, 0, 0, 0, 0, 0, 0, 0, 0, SSE_0);
111+
validate_file(manifest->files, "f13", 30, 13, 0, 0, 0, 0, 0, 0, 0, 0, SSE_1);
112+
validate_file(manifest->files, "f14", 30, 14, 0, 0, 0, 0, 0, 0, 0, 0, SSE_2);
113+
validate_file(manifest->files, "f15", 30, 15, 0, 0, 0, 0, 0, 0, 0, 0, SSE_3);
110114

111115
manifest_free(manifest);
112116

0 commit comments

Comments
 (0)