Message ID | 20170510200535.13268-2-f4bug@amsat.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 05/10/2017 03:05 PM, Philippe Mathieu-Daudé wrote: > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > scripts/coccinelle/tcg_gen_extract.cocci | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > create mode 100644 scripts/coccinelle/tcg_gen_extract.cocci > > diff --git a/scripts/coccinelle/tcg_gen_extract.cocci b/scripts/coccinelle/tcg_gen_extract.cocci > new file mode 100644 > index 0000000000..4080f97cc7 > --- /dev/null > +++ b/scripts/coccinelle/tcg_gen_extract.cocci > @@ -0,0 +1,26 @@ > +// optimize TCG using extract op > +// > +// Copyright: (C) 2017 Philippe Mathieu-Daudé. GPLv2. Unless you provide a strong reason to the contrary, new files should be GPLv2+ rather than GPLv2-only.
On 05/10/2017 01:05 PM, Philippe Mathieu-Daudé wrote: > +-tcg_gen_shri_tl(ret, arg, ofs); > +-tcg_gen_andi_tl(ret, ret, len); > ++tcg_gen_extract_tl(ret, arg, ofs, len); You can't simply copy the and mask to the extract length. You need to verify it's all low bits and convert that to a count of the low bits. E.g. 0xff -> 8. r~
On 05/10/2017 05:12 PM, Eric Blake wrote: > On 05/10/2017 03:05 PM, Philippe Mathieu-Daudé wrote: >> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> >> --- >> scripts/coccinelle/tcg_gen_extract.cocci | 26 ++++++++++++++++++++++++++ >> 1 file changed, 26 insertions(+) >> create mode 100644 scripts/coccinelle/tcg_gen_extract.cocci >> >> diff --git a/scripts/coccinelle/tcg_gen_extract.cocci b/scripts/coccinelle/tcg_gen_extract.cocci >> new file mode 100644 >> index 0000000000..4080f97cc7 >> --- /dev/null >> +++ b/scripts/coccinelle/tcg_gen_extract.cocci >> @@ -0,0 +1,26 @@ >> +// optimize TCG using extract op >> +// >> +// Copyright: (C) 2017 Philippe Mathieu-Daudé. GPLv2. > > Unless you provide a strong reason to the contrary, new files should be > GPLv2+ rather than GPLv2-only. Ok sorry! Wrong copy/paste mostly. While here, I was unsure how to add this file in MAINTAINERS for get_maintainer.pl since it works on many target/ directories. Stefan just merged one of your script you added under the "QObject" section, it makes sens. But does it make sens to add this one in the "Common Code" section of "Tiny Code Generator (TCG)"? I don't think it is useful, it will only bother Richard Henderson. Maybe we should add a "Coccinelle" entry with peoples willing to review/help those scripts... What do you think? Regards, Phil.
On 05/10/2017 03:19 PM, Richard Henderson wrote: > On 05/10/2017 01:05 PM, Philippe Mathieu-Daudé wrote: >> +-tcg_gen_shri_tl(ret, arg, ofs); >> +-tcg_gen_andi_tl(ret, ret, len); >> ++tcg_gen_extract_tl(ret, arg, ofs, len); > > You can't simply copy the and mask to the extract length. > > You need to verify it's all low bits and convert that to a count of the > low bits. E.g. 0xff -> 8. Coccinelle may still be able to do that, but it becomes a little less obvious (and I'm not the expert to consult on what that would look like).
On 05/10/2017 05:19 PM, Richard Henderson wrote: > On 05/10/2017 01:05 PM, Philippe Mathieu-Daudé wrote: >> +-tcg_gen_shri_tl(ret, arg, ofs); >> +-tcg_gen_andi_tl(ret, ret, len); >> ++tcg_gen_extract_tl(ret, arg, ofs, len); > > You can't simply copy the and mask to the extract length. > > You need to verify it's all low bits and convert that to a count of the > low bits. E.g. 0xff -> 8. Hey Richard, this pattern can be applied as long as len << ofs does not overflow target_long, regardless of low bits count, right? Phil.
diff --git a/scripts/coccinelle/tcg_gen_extract.cocci b/scripts/coccinelle/tcg_gen_extract.cocci new file mode 100644 index 0000000000..4080f97cc7 --- /dev/null +++ b/scripts/coccinelle/tcg_gen_extract.cocci @@ -0,0 +1,26 @@ +// optimize TCG using extract op +// +// Copyright: (C) 2017 Philippe Mathieu-Daudé. GPLv2. +// Confidence: High +// Options: --macro-file scripts/cocci-macro-file.h +@@ +identifier ret, arg; +constant ofs, len; +@@ +( +// from Nikunj A Dadhania comment: +// http://lists.nongnu.org/archive/html/qemu-devel/2017-02/msg05211.html +-tcg_gen_shri_tl(ret, arg, ofs); +-tcg_gen_andi_tl(ret, ret, len); ++tcg_gen_extract_tl(ret, arg, ofs, len); +| +// from Aurelien Jarno comment: +// http://lists.nongnu.org/archive/html/qemu-devel/2017-05/msg01466.html +-tcg_gen_shri_i32(ret, arg, ofs); +-tcg_gen_andi_i32(ret, ret, len); ++tcg_gen_extract_i32(ret, arg, ofs, len); +| +-tcg_gen_shri_i64(ret, arg, ofs); +-tcg_gen_andi_i64(ret, ret, len); ++tcg_gen_extract_i64(ret, arg, ofs, len); +)
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> --- scripts/coccinelle/tcg_gen_extract.cocci | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 scripts/coccinelle/tcg_gen_extract.cocci