gnu: Add intel-xed.
[jackhill/guix/guix.git] / gnu / packages / patches / intel-xed-fix-nondeterminism.patch
1 This patch removes sources of build non-determinism in the upstream sources.
2
3 In particular, many of the compiled sources are generated with Python code,
4 which in turn uses dictionaries to index the output C functions. However,
5 iterators over Python dictionaries have no guaranteed order, thus resulting in
6 the C functions being output in a random order between builds.
7
8 The patch below fixes this by forcing an order during output in several key
9 places. Note, however, that future updates may uncover new such places that
10 just happen to be non-problematic at the time of this patch. If you are
11 reading this due to finding such issues, feel free to contact me at
12 elaexuotee@wilsonb.com for help.
13
14 diff --git a/pysrc/ild_codegen.py b/pysrc/ild_codegen.py
15 index 628ec45..a9bff79 100755
16 --- a/pysrc/ild_codegen.py
17 +++ b/pysrc/ild_codegen.py
18 @@ -188,14 +188,14 @@ def gen_l2_func_list(agi, target_nt_dict, arg_nt_dict,
19 ild_t_member):
20 """generate L2 functions"""
21 l2_func_list = []
22 - for (nt_name,array) in target_nt_dict.items():
23 + for (nt_name,array) in sorted(target_nt_dict.items()):
24 target_opname = array.get_target_opname()
25 if array.is_const_lookup_fun():
26 fo = gen_const_l2_function(agi, nt_name,
27 target_opname, ild_t_member)
28 l2_func_list.append(fo)
29 else:
30 - for arg_nt_seq,arg_arr in arg_nt_dict.items():
31 + for arg_nt_seq,arg_arr in sorted(arg_nt_dict.items()):
32 fo = gen_scalable_l2_function(agi, nt_name,
33 target_opname, ild_t_member, arg_arr, list(arg_nt_seq))
34 l2_func_list.append(fo)
35 diff --git a/pysrc/ild_disp.py b/pysrc/ild_disp.py
36 index 942c036..cf80e29 100755
37 --- a/pysrc/ild_disp.py
38 +++ b/pysrc/ild_disp.py
39 @@ -350,7 +350,8 @@ def work(agi, united_lookup, disp_nts, brdisp_nts, ild_gendir,
40 disp_dict = _gen_l3_array_dict(agi, disp_nts, _disp_token)
41
42
43 - nt_arr_list = list(brdisp_dict.values()) + list(disp_dict.values())
44 + nt_arr_list = ([v for (k,v) in sorted(brdisp_dict.items())] +
45 + [v for (k,v) in sorted(disp_dict.items())])
46 #create function that calls all initialization functions
47 init_f = ild_nt.gen_init_function(nt_arr_list, 'xed_ild_disp_l3_init')
48
49 @@ -367,7 +368,7 @@ def work(agi, united_lookup, disp_nts, brdisp_nts, ild_gendir,
50 l2_functions = []
51 eosz_op = ild_eosz.get_target_opname()
52 easz_op = ild_easz.get_target_opname()
53 - for nt_name,array in list(disp_dict.items()) + list(brdisp_dict.items()):
54 + for nt_name,array in sorted(disp_dict.items()) + sorted(brdisp_dict.items()):
55 #Some DISP NTs depend on EOSZ, others on EASZ, we need to know
56 #that when we generate L2 functions
57 if eosz_op in array.get_arg_names():
58 diff --git a/pysrc/ild_easz.py b/pysrc/ild_easz.py
59 index 02cd691..c53b9f2 100755
60 --- a/pysrc/ild_easz.py
61 +++ b/pysrc/ild_easz.py
62 @@ -165,9 +165,10 @@ def work(agi, united_lookup, easz_nts, ild_gendir, debug):
63 return
64 nt_seq_arrays[tuple(nt_seq)] = array
65 #init function calls all single init functions for the created tables
66 - init_f = ild_nt.gen_init_function(list(nt_seq_arrays.values()),
67 + nt_seq_values = [v for (k,v) in sorted(nt_seq_arrays.items())]
68 + init_f = ild_nt.gen_init_function(nt_seq_values,
69 'xed_ild_easz_init')
70 - ild_nt.dump_lu_arrays(agi, list(nt_seq_arrays.values()), _easz_c_fn,
71 + ild_nt.dump_lu_arrays(agi, nt_seq_values, _easz_c_fn,
72 mbuild.join('include-private', _easz_header_fn),
73 init_f)
74 getter_fos = []
75 diff --git a/pysrc/ild_eosz.py b/pysrc/ild_eosz.py
76 index 6643bc3..89d2d89 100755
77 --- a/pysrc/ild_eosz.py
78 +++ b/pysrc/ild_eosz.py
79 @@ -200,10 +200,11 @@ def work(agi, united_lookup, eosz_nts, ild_gendir, debug):
80 return None
81 nt_seq_arrays[tuple(nt_seq)] = array
82 #init function calls all single init functions for the created tables
83 - init_f = ild_nt.gen_init_function(list(nt_seq_arrays.values()),
84 + nt_seq_values = [v for (k,v) in sorted(nt_seq_arrays.items())]
85 + init_f = ild_nt.gen_init_function(nt_seq_values,
86 'xed_ild_eosz_init')
87 #dump init and lookup functions for EOSZ sequences
88 - ild_nt.dump_lu_arrays(agi, list(nt_seq_arrays.values()), _eosz_c_fn,
89 + ild_nt.dump_lu_arrays(agi, nt_seq_values, _eosz_c_fn,
90 mbuild.join('include-private', _eosz_header_fn),
91 init_f)
92 #generate EOSZ getter functions - they get xed_decoded_inst_t*
93 diff --git a/pysrc/ild_imm.py b/pysrc/ild_imm.py
94 index 51c413c..0530bae 100755
95 --- a/pysrc/ild_imm.py
96 +++ b/pysrc/ild_imm.py
97 @@ -322,12 +322,14 @@ def work(agi, united_lookup, imm_nts, ild_gendir, eosz_dict,
98 level='l3')
99 nt_dict[nt_name] = array
100
101 + nt_dict_values = [v for (k,v) in sorted(nt_dict.items())]
102 +
103 #create function that calls all initialization functions for L3
104 - init_f = ild_nt.gen_init_function(list(nt_dict.values()),
105 + init_f = ild_nt.gen_init_function(nt_dict_values,
106 'xed_ild_imm_l3_init')
107
108 #dump L3 functions
109 - ild_nt.dump_lu_arrays(agi, list(nt_dict.values()), _l3_c_fn,
110 + ild_nt.dump_lu_arrays(agi, nt_dict_values, _l3_c_fn,
111 mbuild.join('include-private',_l3_header_fn),
112 init_f)
113