From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 3/6] kconfig: add comments to expression transformations
Date: Sun, 8 Sep 2024 21:43:18 +0900 [thread overview]
Message-ID: <20240908124352.1828890-3-masahiroy@kernel.org> (raw)
In-Reply-To: <20240908124352.1828890-1-masahiroy@kernel.org>
Provide explanations for complex transformations.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/expr.c | 43 ++++++++++++++++++++++++++++++++++++------
1 file changed, 37 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index d5dc682f7dc6..e83fe0c3d62f 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -442,6 +442,7 @@ static struct expr *expr_join_or(struct expr *e1, struct expr *e2)
}
}
if (sym1->type == S_BOOLEAN) {
+ // a || !a -> y
if ((e1->type == E_NOT && e1->left.expr->type == E_SYMBOL && e2->type == E_SYMBOL) ||
(e2->type == E_NOT && e2->left.expr->type == E_SYMBOL && e1->type == E_SYMBOL))
return expr_alloc_symbol(&symbol_yes);
@@ -647,6 +648,30 @@ struct expr *expr_eliminate_dups(struct expr *e)
* Performs various simplifications involving logical operators and
* comparisons.
*
+ * For bool type:
+ * A=n -> !A
+ * A=m -> n
+ * A=y -> A
+ * A!=n -> A
+ * A!=m -> y
+ * A!=y -> !A
+ *
+ * For any type:
+ * !!A -> A
+ * !(A=B) -> A!=B
+ * !(A!=B) -> A=B
+ * !(A<=B) -> A>B
+ * !(A>=B) -> A<B
+ * !(A<B) -> A>=B
+ * !(A>B) -> A<=B
+ * !(A || B) -> !A && !B
+ * !(A && B) -> !A || !B
+ *
+ * For constant:
+ * !y -> n
+ * !m -> m
+ * !n -> y
+ *
* Allocates and returns a new expression.
*/
struct expr *expr_transform(struct expr *e)
@@ -674,12 +699,14 @@ struct expr *expr_transform(struct expr *e)
if (e->left.sym->type != S_BOOLEAN)
break;
if (e->right.sym == &symbol_no) {
+ // A=n -> !A
e->type = E_NOT;
e->left.expr = expr_alloc_symbol(e->left.sym);
e->right.sym = NULL;
break;
}
if (e->right.sym == &symbol_mod) {
+ // A=m -> n
printf("boolean symbol %s tested for 'm'? test forced to 'n'\n", e->left.sym->name);
e->type = E_SYMBOL;
e->left.sym = &symbol_no;
@@ -687,6 +714,7 @@ struct expr *expr_transform(struct expr *e)
break;
}
if (e->right.sym == &symbol_yes) {
+ // A=y -> A
e->type = E_SYMBOL;
e->right.sym = NULL;
break;
@@ -696,11 +724,13 @@ struct expr *expr_transform(struct expr *e)
if (e->left.sym->type != S_BOOLEAN)
break;
if (e->right.sym == &symbol_no) {
+ // A!=n -> A
e->type = E_SYMBOL;
e->right.sym = NULL;
break;
}
if (e->right.sym == &symbol_mod) {
+ // A!=m -> y
printf("boolean symbol %s tested for 'm'? test forced to 'y'\n", e->left.sym->name);
e->type = E_SYMBOL;
e->left.sym = &symbol_yes;
@@ -708,6 +738,7 @@ struct expr *expr_transform(struct expr *e)
break;
}
if (e->right.sym == &symbol_yes) {
+ // A!=y -> !A
e->type = E_NOT;
e->left.expr = expr_alloc_symbol(e->left.sym);
e->right.sym = NULL;
@@ -717,7 +748,7 @@ struct expr *expr_transform(struct expr *e)
case E_NOT:
switch (e->left.expr->type) {
case E_NOT:
- // !!a -> a
+ // !!A -> A
tmp = e->left.expr->left.expr;
free(e->left.expr);
free(e);
@@ -726,7 +757,7 @@ struct expr *expr_transform(struct expr *e)
break;
case E_EQUAL:
case E_UNEQUAL:
- // !a='x' -> a!='x'
+ // !(A=B) -> A!=B
tmp = e->left.expr;
free(e);
e = tmp;
@@ -734,7 +765,7 @@ struct expr *expr_transform(struct expr *e)
break;
case E_LEQ:
case E_GEQ:
- // !a<='x' -> a>'x'
+ // !(A<=B) -> A>B
tmp = e->left.expr;
free(e);
e = tmp;
@@ -742,14 +773,14 @@ struct expr *expr_transform(struct expr *e)
break;
case E_LTH:
case E_GTH:
- // !a<'x' -> a>='x'
+ // !(A<B) -> A>=B
tmp = e->left.expr;
free(e);
e = tmp;
e->type = e->type == E_LTH ? E_GEQ : E_LEQ;
break;
case E_OR:
- // !(a || b) -> !a && !b
+ // !(A || B) -> !A && !B
tmp = e->left.expr;
e->type = E_AND;
e->right.expr = expr_alloc_one(E_NOT, tmp->right.expr);
@@ -758,7 +789,7 @@ struct expr *expr_transform(struct expr *e)
e = expr_transform(e);
break;
case E_AND:
- // !(a && b) -> !a || !b
+ // !(A && B) -> !A || !B
tmp = e->left.expr;
e->type = E_OR;
e->right.expr = expr_alloc_one(E_NOT, tmp->right.expr);
--
2.43.0
next prev parent reply other threads:[~2024-09-08 12:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-08 12:43 [PATCH 1/6] scripts: move hash function from scripts/kconfig/ to scripts/include/ Masahiro Yamada
2024-09-08 12:43 ` [PATCH 2/6] kconfig: change some expr_*() functions to bool Masahiro Yamada
2024-09-08 12:43 ` Masahiro Yamada [this message]
2024-09-08 12:43 ` [PATCH 4/6] kconfig: refactor expr_eliminate_dups() Masahiro Yamada
2024-09-08 12:43 ` [PATCH 5/6] kconfig: use hash table to reuse expressions Masahiro Yamada
2024-09-08 12:43 ` [PATCH 6/6] kconfig: cache expression values Masahiro Yamada
2024-09-30 13:30 ` Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240908124352.1828890-3-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox