On 2023/04/21 12:08, Tao Liu wrote:
> Just an idea on another optimization,
>
> SEARCHMASK(si->s_parms.s_ulong.value[si->val])
>
> in search_ulong() might be pre-processed somewhere.
> For loops, reducing machine instructions is often effective.
>
Do you mean change the code like the following in search_ulong()?
int value = SEARCHMASK(si->s_parms.s_ulong.value[si->val]);
for (i = 0; i < longcnt; i++, bufptr++, addr += sizeof(long)) {
for (si->val = 0; si->val < si->vcnt; si->val++) {
if (SEARCHMASK(*bufptr) == value)) {
....
}
}
}
In this way, we don't need to recalculate the value every time in the loop.
Yes, this might be good, or the function itself is called many times so
adding a member might be good if it's effective:
struct {
ulong value[MAXARGS];
char *opt_string[MAXARGS];
ulong mask;
+ ulong masked_value[MAXARGS];
} s_ulong;
and in search_ulong(),
int *masked = si->s_parms.s_ulong.masked_value;
...
if (SEARCHMASK(*bufptr) == masked[si->val])
(Ideally, it might be better to reduce member access e.g. si->s_parms...
in the loop, because it may use a few instructions. (or gcc may optimize
it?) objdump can be used to check :)
Thanks,
Kazu