Skip to content

Commit 1f248ca

Browse files
Fixes to matching, Poly/ML 5.9.2
1 parent d78c039 commit 1f248ca

File tree

8 files changed

+126
-9
lines changed

8 files changed

+126
-9
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
polyml: ['5.7.1', '5.9.1']
18+
polyml: ['5.7.1', '5.9.2']
1919
hol4: ['718b3aa']
2020

2121
env:

INSTALL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ First, navigate to the directory where you want to put the source code of Poly/M
3434

3535
sudo apt-get install build-essential git
3636

37-
2. Install Poly/ML 5.9.1
37+
2. Install Poly/ML 5.9.2
3838

3939
git clone https://github.com/polyml/polyml.git
4040
cd polyml
41-
git checkout v5.9.1
41+
git checkout v5.9.2
4242
./configure --prefix=/usr
4343
make
4444
sudo make install
@@ -124,4 +124,4 @@ The same tools used to edit HOL4 theories and run the HOL4 REPL can also be used
124124

125125
The `scripts` directory contains installation scripts. These may be run when installing HOL4P4 e.g. on a fresh virtual machine by
126126

127-
scripts/install.sh
127+
scripts/install.sh

hol/cake_sem/p4_cake_archScript.sml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ val (FOLDL_MATCH''_def, FOLDL_MATCH_alt''_def) =
606606
(Define
607607
‘(FOLDL_MATCH'' w_l res [] = res) /\
608608
(FOLDL_MATCH'' (w_l:(word64 # word64) list) (res_act:identifier # e' list, res_prio_opt:num option) (((s_l,prio),v)::t) =
609-
if match_all_e_alt'' s_l w_l
609+
if match_all'' (ZIP(w_l, s_l))
610610
then
611611
(* TODO: Largest priority wins (like for P4Runtime API) is hard-coded *)
612612
case res_prio_opt of
@@ -620,7 +620,7 @@ val (FOLDL_MATCH''_def, FOLDL_MATCH_alt''_def) =
620620
Define
621621
‘(FOLDL_MATCH_alt'' w_l res acc [] = res) /\
622622
(FOLDL_MATCH_alt'' w_l (res_act, res_prio_opt:num option) acc (((s_l,prio),v)::t) =
623-
if match_all_e_alt'' s_l w_l
623+
if match_all'' (ZIP(w_l, s_l))
624624
then
625625
(* TODO: Smallest priority wins (like for TDI) is hard-coded,
626626
* other than priority zero. *)

hol/cake_sem/p4_cake_arch_ebpfProgScript.sml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ val _ =
8989
if matching_optimization
9090
then
9191
let
92+
(*
9293
val _ = translate match_all_e_alt''_def;
94+
*)
9395
val _ = translate FOLDL_MATCH''_def;
9496
val _ = translate e_list_to_word64s_list_def;
9597
val _ = translate ebpf_apply_table_f''_def;

hol/cake_sem/p4_cake_arch_v1modelProgScript.sml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ val _ =
4949
if matching_optimization
5050
then
5151
let
52+
(*
5253
val _ = translate match_all_e_alt''_def;
54+
*)
5355
val _ = translate FOLDL_MATCH_alt''_def;
5456
val _ = translate FOLDL_MATCH''_def;
5557
val _ = translate e_list_to_word64s_list_def;

hol/cake_sem/p4_cake_auxLib.sml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ val identifier = “:word64”;
2121
val matching_optimization = true;
2222

2323
(* This controls whether optimized I/O (byte instead of bit lists) will be used *)
24-
val io_optimization = false;
24+
val io_optimization = true;
2525

2626
(* This should hold all the named strings in core P4, and currently the additional ones for
2727
* new architectures *)

hol/cake_sem/p4_cake_exec_semScript.sml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,9 @@ val (e_list_to_word64s_list_def,
12821282
p4_match_range''_def,
12831283
match''_def,
12841284
match_all''_def,
1285+
(*
12851286
match_all_e_alt''_def,
1287+
*)
12861288
match_all_first''_def,
12871289
match_all_first_def
12881290
) =
@@ -1350,8 +1352,10 @@ Define
13501352
if match'' w s
13511353
then match_all'' t
13521354
else F)’,
1355+
(*
13531356
Define
13541357
‘match_all_e_alt'' s_l w_l = match_all'' (ZIP(w_l, s_l))’,
1358+
*)
13551359
Define
13561360
‘(match_all_first'' i w_list ([]:(s' list # identifier) list) = NONE) /\
13571361
(match_all_first'' i w_list (h::t) =
@@ -1371,7 +1375,9 @@ else
13711375
Define ‘p4_match_range'' = T’,
13721376
Define ‘match'' = T’,
13731377
Define ‘match_all'' = T’,
1378+
(*
13741379
Define ‘match_all_e_alt'' = T’,
1380+
*)
13751381
Define ‘match_all_first'' = T’,
13761382
Define ‘match_all_first = T’
13771383
)

hol/cake_sem/programs/cake_vss_v1modelScript.sml

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,113 @@ open p4_cake_exec_semProgTheory;
1818
open p4_cake_transformLib p4_cake_auxLib;
1919
open p4_cake_arch_v1modelProgTheory;
2020

21+
(*
22+
open realLib;
23+
24+
realLib.prefer_real;
25+
26+
map (fn (a,b) => (a, (Real.fromInt b) / 3.0))
27+
28+
[
29+
(1, 5696),
30+
(2, 4736),
31+
(3, 4928),
32+
(4, 5056),
33+
(5, 4288),
34+
(6, 4608),
35+
(7, 4480)
36+
]
37+
38+
*)
39+
40+
(*********************)
41+
42+
fun get_keys [] = []
43+
| get_keys (h::t) =
44+
let
45+
val matching = fst $ dest_pair h
46+
val (s_list_tm, prio) = dest_pair matching
47+
val s_list = fst $ dest_list $ s_list_tm
48+
in
49+
if length s_list = 1
50+
then
51+
let
52+
val s = el 1 s_list
53+
in
54+
if is_s_sing s
55+
then
56+
let
57+
val (bool_list_tm, width_tm) = dest_pair $ dest_v_bit $ dest_s_sing s
58+
val value = int_of_term $ rhs $ concl $ EVAL “v2n ^bool_list_tm”
59+
val width = int_of_term width_tm
60+
in
61+
((value, width), int_of_term prio)::(get_keys t)
62+
end
63+
else raise Fail "get_keys only supports s_sing"
64+
end
65+
else raise Fail "get_keys only supports single matching keys (got multiple entries)"
66+
end
67+
;
68+
69+
(* Populate a table with singleton keys, outside of existing entries.
70+
* Used for creating dummy entries for benchmarking table matching *)
71+
(* TODO: How to best handle priority? Best make new entries the prioritized ones... *)
72+
fun populate_table' tbl rand_gen n_additional_entries =
73+
let
74+
val (name, entries) = dest_pair tbl
75+
val entries_list_tm = p4_coreLib.dest_tbl_regular entries
76+
val entries_list = fst $ dest_list $ entries_list_tm
77+
val (keys, prios) = unzip $ get_keys entries_list
78+
(* TODO: Hack. Warn if widths disagree. *)
79+
val width = el 1 $ map snd keys
80+
81+
val max_prio = fst $ mlibUseful.max (fn (a,b) => Int.compare (a, b)) prios
82+
83+
fun get_rand_range width rand_gen existing_keys =
84+
let
85+
val range_value1 = Random.range (0, (funpow width (fn a => a*2) 1)) rand_gen;
86+
val range_value2 = Random.range (0, (funpow width (fn a => a*2) 1)) rand_gen;
87+
val (lo, hi) =
88+
if range_value1 < range_value2
89+
then (range_value1, range_value2)
90+
else (range_value2, range_value1)
91+
val lo' = rhs $ concl $ EVAL $ “(fixwidth ^(numSyntax.term_of_int width) $ n2v ^(numSyntax.term_of_int lo), ^(numSyntax.term_of_int width))”
92+
val hi' = rhs $ concl $ EVAL $ “(fixwidth ^(numSyntax.term_of_int width) $ n2v ^(numSyntax.term_of_int hi), ^(numSyntax.term_of_int width))”
93+
in
94+
if not $ exists (fn a => a >= lo) existing_keys
95+
then
96+
mk_s_range (lo', hi')
97+
else get_rand_range width rand_gen existing_keys
98+
end
99+
;
100+
101+
(* TODO: Chance for doubles now very low *)
102+
fun add_entries existing_keys width rand_gen 0 = []
103+
| add_entries existing_keys width rand_gen n_additional_entries =
104+
let
105+
val new_entry = get_rand_range width rand_gen existing_keys
106+
in
107+
new_entry::(add_entries existing_keys width rand_gen (n_additional_entries-1))
108+
end
109+
;
110+
111+
(* TODO: Take action as an argument *)
112+
val action =
113+
“("NoAction",
114+
[e_v (v_bool T); e_v (v_bool T)])”
115+
val new_entries = add_entries (map fst keys) width rand_gen n_additional_entries
116+
val new_entries' = map (fn a => mk_pair (mk_list ([a], “:s”), term_of_int (max_prio+1))) new_entries
117+
val new_entries_tm = mk_list (map (fn a => mk_pair (a, action)) new_entries', “:(s list # num) # string # e list”)
118+
119+
val entries_list_tm' = rhs $ concl $ EVAL “^new_entries_tm ++ ^entries_list_tm”
120+
121+
in
122+
mk_pair (name, p4_coreLib.mk_tbl_regular entries_list_tm')
123+
end
124+
;
125+
126+
(*********************)
127+
21128
val _ = translation_extends "p4_cake_arch_v1modelProg";
22129

23130
val ipv4_match_tbl =
@@ -95,9 +202,9 @@ val smac_tbl =
95202

96203
val rand_gen = Random.newgen ();
97204

98-
val n_additional_entries = 10;
205+
val n_additional_entries = 1000;
99206

100-
val dmac_tbl' = populate_table dmac_tbl rand_gen n_additional_entries;
207+
val dmac_tbl' = populate_table' dmac_tbl rand_gen n_additional_entries;
101208

102209
val vss_v1model_actx = “([arch_block_inp;
103210
arch_block_pbl "TopParser"

0 commit comments

Comments
 (0)