[igt-dev] [PATCH i-g-t 06/20] tests/psr: Optimize check for green frame.

Katarzyna Dec katarzyna.dec at intel.com
Fri Apr 13 10:59:24 UTC 2018


On Tue, Apr 10, 2018 at 07:37:18PM -0700, Dhinakaran Pandiyan wrote:
> Eliminate three memcpy's and four sscanf's.
> 
> Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan at intel.com>
Reviewed-by: Katarzyna Dec <katarzyna.dec at intel.com> 
> ---
>  tests/kms_psr_sink_crc.c | 30 +++++-------------------------
>  1 file changed, 5 insertions(+), 25 deletions(-)
> 
> diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c
> index af63e689..94134b7d 100644
> --- a/tests/kms_psr_sink_crc.c
> +++ b/tests/kms_psr_sink_crc.c
> @@ -241,34 +241,14 @@ static void get_sink_crc(data_t *data, char *crc)
>  
>  static bool is_green(char *crc)
>  {
> -	char color_mask[5] = "FFFF\0";
> -	char rs[5], gs[5], bs[5];
> -	unsigned int rh, gh, bh, mask;
> -	int ret;
> -
> +	const char *mask = "0000FFFF0000";
> +	uint32_t *p = (uint32_t *)crc, *mask_p = (uint32_t *)mask;
>  	if (igt_interactive_debug)
>  		return false;
>  
> -	sscanf(color_mask, "%4x", &mask);
> -
> -	memcpy(rs, &crc[0], 4);
> -	rs[4] = '\0';
> -	ret = sscanf(rs, "%4x", &rh);
> -	igt_require(ret > 0);
> -
> -	memcpy(gs, &crc[4], 4);
> -	gs[4] = '\0';
> -	ret = sscanf(gs, "%4x", &gh);
> -	igt_require(ret > 0);
> -
> -	memcpy(bs, &crc[8], 4);
> -	bs[4] = '\0';
> -	ret = sscanf(bs, "%4x", &bh);
> -	igt_require(ret > 0);
> -
> -	return ((rh & mask) == 0 &&
> -		(gh & mask) != 0 &&
> -		(bh & mask) == 0);
> +	/* Check R and B components are 0 and G is non-zero */
> +	return *p == *mask_p && *(p + 2) == *(mask_p + 2) &&
> +	       (*(p + 1) & *(mask_p + 1)) != 0;
>  }
>  
>  static void assert_or_manual(bool condition, const char *expected)
> -- 
> 2.14.1
> 
> _______________________________________________
> 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