[PATCH] readelf: Remove show_op_index variable
Mark Wielaard
mark@klomp.org
Fri Feb 5 15:46:29 GMT 2021
Hi Timm,
On Tue, 2021-02-02 at 11:23 +0100, Timm Bäder via Elfutils-devel wrote:
> advance_pc() uses show_op_index to save whether the current op_index
> is
> > 0 OR the new op_index is > 0.
>
> The new op index is calculated via
>
> new_op_index = (op_index + op_advance) % max_ops_per_instr;
>
> since all of the variables involved are unsigned,
> new_op_index >= op_index is always true.
>
> So...
>
> if op_index > 0, then new_op_index > 0
> if op_index == 0, then new_op_index >= 0
>
> and if the new_op_index is > 0, then the old one was as well.
>
> In any case, we only need to check the new_op_index, since show_op_index
> used to OR the two comparisons.
>
> In other words:
>
> op_index > 0 | new_op_index > 0 || show_op_index
> ------------------------------------------------
> true true true
> false true true
> true false true xx
> false false false
>
> ... but since the third line (marked with xx) is not possible,
> the table becomes:
>
> op_index > 0 | new_op_index > 0 || show_op_index
> ------------------------------------------------
> true true true
> false true true
> false false false
>
> ... and show_op_index is equal to (new_op_index > 0).
> So, remove the show_op_index variable and simply replace it by comparing
> the new op_index > 0.
Very nice simplification. Thanks for the extensive commit message.
In most cases max_ops_per_instr is actually 1. In which case op_index
will always be zero.
Pushed to trunk.
Thanks,
Mark
More information about the Elfutils-devel
mailing list