From 01fe72d9fcbddd32af0527d7be40e21c7f92d1b0 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Wed, 4 Dec 2024 15:21:20 -0700 Subject: [PATCH 1/4] added type coercion for bit-shifting expressions --- auxil/gen-zam | 2 +- src/Expr.cc | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/auxil/gen-zam b/auxil/gen-zam index 3c17f9797e..0f32b4a05a 160000 --- a/auxil/gen-zam +++ b/auxil/gen-zam @@ -1 +1 @@ -Subproject commit 3c17f9797ebab5157d7b08265540cd7f4de15d1f +Subproject commit 0f32b4a05a7e1772d1a0a9b366ebd7a815e1af39 diff --git a/src/Expr.cc b/src/Expr.cc index 878002d598..cd1c98ebd3 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -1860,8 +1860,11 @@ BitExpr::BitExpr(ExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2) if ( IsIntegral(bt1) && bt2 == TYPE_COUNT ) { if ( is_vector(op1) || is_vector(op2) ) SetType(make_intrusive(base_type(bt1))); - else + else { SetType(base_type(bt1)); + if ( bt1 != bt2 ) + op2 = make_intrusive(op2, bt1); + } } else if ( IsIntegral(bt1) && bt2 == TYPE_INT ) From 7d25835ca883b9fbf6477885a6b4149e03e1df05 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Wed, 4 Dec 2024 15:24:11 -0700 Subject: [PATCH 2/4] expanded ZAM operations for bit-shifting to allow for int/count shift values --- src/script_opt/ZAM/OPs/binary-exprs.op | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/script_opt/ZAM/OPs/binary-exprs.op b/src/script_opt/ZAM/OPs/binary-exprs.op index 17d90f9979..9b5643d746 100644 --- a/src/script_opt/ZAM/OPs/binary-exprs.op +++ b/src/script_opt/ZAM/OPs/binary-exprs.op @@ -37,15 +37,19 @@ binary-expr-op Mask # Signal that this expression only has mixed-type evaluation. op-type X explicit-result-type -eval-mixed A I auto mask = static_cast($2); - auto a = $1->AsAddr(); - if ( a.GetFamily() == IPv4 && mask > 32 ) - ERROR(util::fmt("bad IPv4 subnet prefix length: %" PRIu32, mask)); - if ( a.GetFamily() == IPv6 && mask > 128 ) - ERROR(util::fmt("bad IPv6 subnet prefix length: %" PRIu32, mask)); - auto v = make_intrusive(a, mask); - Unref($$.AsSubNet()); - $$.AsSubNetRef() = v.release(); +eval-mixed A I DoMask($$, $1, static_cast($2)) +eval-mixed A U DoMask($$, $1, $2) + +macro DoMask(lhs, op1, op2) + auto mask = static_cast(op2); + auto a = op1->AsAddr(); + if ( a.GetFamily() == IPv4 && mask > 32 ) + ERROR(util::fmt("bad IPv4 subnet prefix length: %" PRIu32, mask)); + if ( a.GetFamily() == IPv6 && mask > 128 ) + ERROR(util::fmt("bad IPv6 subnet prefix length: %" PRIu32, mask)); + auto v = make_intrusive(a, mask); + Unref(lhs.AsSubNet()); + lhs.AsSubNetRef() = v.release(); binary-expr-op Mod op-type I U From f300fb6cf068fb2001e6d72e7536b25acb7b4868 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Wed, 4 Dec 2024 15:25:31 -0700 Subject: [PATCH 3/4] ZAM support for pattern equality/inequality operations --- src/script_opt/ZAM/OPs/rel-exprs.op | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/script_opt/ZAM/OPs/rel-exprs.op b/src/script_opt/ZAM/OPs/rel-exprs.op index fd74886fb9..92c35b7ce6 100644 --- a/src/script_opt/ZAM/OPs/rel-exprs.op +++ b/src/script_opt/ZAM/OPs/rel-exprs.op @@ -17,7 +17,7 @@ eval-type T $1->IsSubsetOf(*$2) eval-type A $1->AsAddr() < $2->AsAddr() || $1->AsAddr() == $2->AsAddr() rel-expr-op EQ -op-type I U D S T A N F +op-type I U D S T A N F P vector eval $1 == $2 eval-type S Bstr_cmp($1->AsString(), $2->AsString()) == 0 @@ -25,6 +25,7 @@ eval-type T $1->EqualTo(*$2) eval-type A $1->AsAddr() == $2->AsAddr() eval-type N $1->AsSubNet() == $2->AsSubNet() eval-type F $1->GetName() == $2->GetName() +eval-type P strcmp($1->Get()->PatternText(), $2->Get()->PatternText()) == 0 eval-mixed P S $1->MatchExactly($2->AsString()) rel-expr-op NE From 678db505fbf7ca77ec30d50cca998a41676e795d Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Wed, 4 Dec 2024 15:26:13 -0700 Subject: [PATCH 4/4] update of BTest that tracks number of (and validates) ZAM operations --- testing/btest/Baseline.zam/opt.validate-ZAM/output | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/btest/Baseline.zam/opt.validate-ZAM/output b/testing/btest/Baseline.zam/opt.validate-ZAM/output index 10a684fd93..1707dacb53 100644 --- a/testing/btest/Baseline.zam/opt.validate-ZAM/output +++ b/testing/btest/Baseline.zam/opt.validate-ZAM/output @@ -1,2 +1,2 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -1232 valid, 1853 tested, 425 skipped +1245 valid, 1883 tested, 437 skipped