qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC PATCH v4 1/6] coccinelle: add a script to optimize


From: Eric Blake
Subject: Re: [Qemu-devel] [RFC PATCH v4 1/6] coccinelle: add a script to optimize tcg op using tcg_gen_extract()
Date: Mon, 15 May 2017 09:04:53 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0

On 05/12/2017 06:38 PM, Philippe Mathieu-Daudé wrote:
> If you have coccinelle installed you can apply this script using:
> 
>     $ spatch \
>         --macro-file scripts/cocci-macro-file.h \
>         --dir target --in-place
> 
> You can also use directly Peter Senna Tschudin docker image (easier):
> 
>     $ docker run -v `pwd`:`pwd` -w `pwd` petersenna/coccinelle \
>         --sp-file scripts/coccinelle/tcg_gen_extract.cocci \
>         --macro-file scripts/cocci-macro-file.h \
>         --dir target --in-place
> 
> Then verified that no manual touchups are required.
> 
> The following thread was helpful while writing this script:
> 
>     https://github.com/coccinelle/coccinelle/issues/86
> 
> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
> ---
>  scripts/coccinelle/tcg_gen_extract.cocci | 103 
> +++++++++++++++++++++++++++++++
>  1 file changed, 103 insertions(+)
>  create mode 100644 scripts/coccinelle/tcg_gen_extract.cocci

It's still not obvious to me whether we want this script in the tree (as
something we plan to rerun regularly to check for regressions), or just
in the commit message (useful for the one-time location of spots to
optimize, but something we don't anticipate repeating).


> +@@
> +import sys
> +fd = sys.stderr
> +def debug(msg="", trailer="\n"):
> +    fd.write("[DBG] " + msg + trailer)
> +def low_bits_count(value):
> +    bits_count = 0
> +    while (value & (1 << bits_count)):
> +        bits_count += 1

Surely python has a faster method than this (after all, we have ctz and
friends in C code)?  But my python is limited enough that I don't know
of one off-hand.

> +    return bits_count
> +def Mn(order): # Mersenne number
> +    return (1 << order) - 1

Correct name...


> +else:
> +    debug("candidate at %s:%s" % (shr_p[0].file, shr_p[0].line))
> +    try: # only eval integer, no #define like 'SR_M' (cpp did this, else 
> some headers are missing).
> +        msk_v = long(msk_s.strip("UL"), 0)
> +        msk_b = low_bits_count(msk_v)
> +        if msk_b == 0:
> +            debug("  value: 0x%x low_bits: %d" % (msk_v, msk_b))
> +        else:
> +            debug("  value: 0x%x low_bits: %d [Mersenne prime: 0x%x]" % 
> (msk_v, msk_b, Mn(msk_b)))

...but this name is still wrong.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]