[igt-dev] [PATCH i-g-t v4 1/3] lib/igt_aux: Add function to swap int64 in array

Antonio Argenziano antonio.argenziano at intel.com
Fri Jan 26 16:50:04 UTC 2018



On 25/01/18 03:35, Jani Nikula wrote:
> On Thu, 25 Jan 2018, Ville Syrjälä <ville.syrjala at linux.intel.com> wrote:
>> On Wed, Jan 24, 2018 at 05:00:01PM -0800, Antonio Argenziano wrote:
>>> Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>
>>> Cc: Chris Wilson <chris at chris-wilson.co.uk>
>>> Cc: Michal Winiarski <michal.winiarski at intel.com>
>>> ---
>>>   lib/igt_aux.c | 19 +++++++++++++++++++
>>>   lib/igt_aux.h |  1 +
>>>   2 files changed, 20 insertions(+)
>>>
>>> diff --git a/lib/igt_aux.c b/lib/igt_aux.c
>>> index 8ca0b60d..8012d8ae 100644
>>> --- a/lib/igt_aux.c
>>> +++ b/lib/igt_aux.c
>>> @@ -577,6 +577,25 @@ void igt_exchange_int(void *array, unsigned i, unsigned j)
>>>   	int_arr[j] = tmp;
>>>   }
>>>   
>>> +/**
>>> + * igt_exchange_int64:
>>> + * @array: pointer to the array of int64_t
>>> + * @i: first position
>>> + * @j: second position
>>> + *
>>> + * Exchanges the two values at array indices @i and @j. Useful as an exchange
>>> + * function for igt_permute_array().
>>> + */
>>> +void igt_exchange_int64(void *array, unsigned i, unsigned j)
>>> +{
>>> +	int64_t *int_arr, tmp;
>>
>> Why void* when you really mean int64_t*?
>>
>>> +	int_arr = array;
>>> +
>>> +	tmp = int_arr[i];
>>> +	int_arr[i] = int_arr[j];
>>> +	int_arr[j] = tmp;
>>
>> igt_swap()
> 
> 
> All of the igt_exchange_whatever functions could be replaced with a
> single macro that does typeof on the array parameter.

Basically that would be igt_swap(). You would have to replace the 
permute interface to make it not take a void pointer but a generic array.

I tried the following:

#define igt_permute_array(array, size) do { \
	int _i; \
	typeof(array) _array; \
	_array = array; \
  \
	for (_i = size - 1; _i > 0; _i--) { \
		/* yes, not perfectly uniform, who cares */ \
		long _l = hars_petruska_f54_1_random_unsafe() % (_i +1); \
		if (_i != _l) \
			igt_swap(_array[_i], _array[_l]); \
	} \
} while (0)

The problem I had is that typeof() doesn't seems to play nice with 
arrays but wants a pointer type.
So it would be a pervasive change and I would prefer to make it into a 
separate patchset.

Thanks,
Antonio

> 
> BR,
> Jani.
> 
>>
>>> +}
>>> +
>>>   /**
>>>    * igt_permute_array:
>>>    * @array: pointer to array
>>> diff --git a/lib/igt_aux.h b/lib/igt_aux.h
>>> index 02e70126..60d4de71 100644
>>> --- a/lib/igt_aux.h
>>> +++ b/lib/igt_aux.h
>>> @@ -117,6 +117,7 @@ bool __igt_sigiter_continue(struct __igt_sigiter *iter, bool interrupt);
>>>   	for (struct timespec t__={}; igt_nsec_elapsed(&t__)>>20 < (t); )
>>>   
>>>   void igt_exchange_int(void *array, unsigned i, unsigned j);
>>> +void igt_exchange_int64(void *array, unsigned i, unsigned j);
>>>   void igt_permute_array(void *array, unsigned size,
>>>   			   void (*exchange_func)(void *array,
>>>   						 unsigned i,
>>> -- 
>>> 2.14.2
>>>
>>> _______________________________________________
>>> igt-dev mailing list
>>> igt-dev at lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/igt-dev
> 


More information about the igt-dev mailing list