hasherezade / tiny_tracer

A Pin Tool for tracing API calls etc
1.25k stars 138 forks source link

using 32bit 'and' mask to get lower 32bit part instead of shifting the value two times #6

Closed 0ffffffffh closed 3 years ago

hasherezade commented 3 years ago

I would normally use a mask, but in this case I decided to use an equivalent notation more for the sake of readablity. In the full fragment:


    if (isEax) {
        result = (Timer << 32) >> 32;
    }
    else {
        result = (Timer) >> 32;
    }

It looks much more clear what intention of this code was - that we are splitting the Timer value on two chunks, 32 bits each. It is like:

    if (isEax) {
        result = (Timer << DELIM) >> DELIM;
    }
    else {
        result = (Timer) >> DELIM;
    }

I don't think it makes much sense to refactor it for using a mask, the performance gain will be minor to none, while the meaning of the code will become less obvious.