[Intel-gfx] [PATCH 13/13] drm/i915: Use binary search when looking for shadowed registers

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Fri Sep 30 10:01:20 UTC 2016


On 30/09/2016 08:54, Joonas Lahtinen wrote:
> On to, 2016-09-29 at 16:35 +0100, Tvrtko Ursulin wrote:
>> +static int mmio_reg_cmp(const void *key, const void *elt)
> + {
> <SNIP>
>> +	if (offset < i915_mmio_reg_offset(*reg))
>> +		return -1;
>> +	else if (offset > i915_mmio_reg_offset(*reg))
>> +		return 1;
>> +	else
>> +		return 0;
> I was about to suggest return a - b; but then realized it might
> overflow. After a bit of searching, that is done in
> regcache_default_cmp though. So not sure if it's a bug in there or did
> I miss something. This is safe way at least.
>
>>   static bool is_gen8_shadowed(u32 offset)
>>   {
>>> -	int i;
>>> -	for (i = 0; i < ARRAY_SIZE(gen8_shadowed_regs); i++)
>>> -		if (offset == gen8_shadowed_regs[i].reg)
>>> -			return true;
>>> +	i915_reg_t *reg;
>>   
>>> -	return false;
>> +	reg = bsearch((void *)(unsigned long)offset,
> (unsigned long) is not required, as we don't have sign bits to extend.

Gcc warns if I omit that.
>
>> +		      (const void *)gen8_shadowed_regs,
>> +		      ARRAY_SIZE(gen8_shadowed_regs),
>> +		      sizeof(i915_reg_t),
>> +		      mmio_reg_cmp);
>> +
>> +	return reg ? true : false;
> As I previously learnt, no need to explicitly convert bool types
> anymore, so this can just be return bsearch(...);
>
> With the last two fixed,

I've done this one.

> Reviewed-by: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>

Thanks!

Tvrtko



More information about the Intel-gfx mailing list