From patchwork Fri Jan 30 18:51:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haixia Shi X-Patchwork-Id: 5752381 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5A9E0BF440 for ; Fri, 30 Jan 2015 18:51:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7FD1D2026F for ; Fri, 30 Jan 2015 18:51:22 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9D71A2025B for ; Fri, 30 Jan 2015 18:51:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7AB836E860; Fri, 30 Jan 2015 10:51:20 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ie0-f178.google.com (mail-ie0-f178.google.com [209.85.223.178]) by gabe.freedesktop.org (Postfix) with ESMTP id 200616E860 for ; Fri, 30 Jan 2015 10:51:19 -0800 (PST) Received: by mail-ie0-f178.google.com with SMTP id rp18so5361473iec.9 for ; Fri, 30 Jan 2015 10:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+aJ62s8hdS0S4nX+SomYTOfkmipPOQxMPO19buPoaqg=; b=lqP0BIt9SzE5a9vlWIpgJTlHUo4JEFcvhfSp+H4JJi9hgeUz7MwIi5XYfmPLpwrIsX etFdprrkOdFexmUV+87PGjFYXvimiPnHpuVOBOz79n2eREEhqSy49NgFXmg5DuORGJ1l wZ+zVFvMeB47H/ix5cx95umbPPno7Icur61hk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+aJ62s8hdS0S4nX+SomYTOfkmipPOQxMPO19buPoaqg=; b=EDwoz+2H4IlW60THclKlXW0mNNubHWkff+2aPcJTPuC3bKOCGgzql1Gey7gCCmJXe9 i9DrIZj3SA+pSN9mFNtYzYik6MoCSODkOEYSLH8ajpiN2U1jFyBQtuyDwJND2vOt3tYF 6R5hxtz0v6CpyEdWNEcbYfQtbGi9v5ELscApDbT3PtMynf9sxMPlX42QI0/kRxqLWPJF phUSyTMAwJK8+8qLlvt4SOGvr2x9KV8opzsKQXKMHWvi/2m2fT1K1qJ+i1I+fZhn9VyB 621iw1FiXrjGs7WMd6QOmtw/pxXg6y1b/u3kpP0MwI9UitY5+OJxYrtEJWyH8WroGg5Y qbdg== X-Gm-Message-State: ALoCoQnJmSj7s3wfDMl890D3Q8Z1InCC/WDrab3EViCl2Ogw8Gpqakgy17jQ9YietX3KdwcdCnV5 X-Received: by 10.43.52.197 with SMTP id vn5mr7470765icb.64.1422643878697; Fri, 30 Jan 2015 10:51:18 -0800 (PST) Received: from localhost ([2620:0:1000:1600:4c85:5ef9:b599:2f24]) by mx.google.com with ESMTPSA id b1sm1549891ioe.12.2015.01.30.10.51.17 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 30 Jan 2015 10:51:18 -0800 (PST) From: Haixia Shi To: dri-devel Subject: [PATCH 1/2] drm/udl: optimize udl_compress_hline16 (v2) Date: Fri, 30 Jan 2015 10:51:14 -0800 Message-Id: <1422643875-24678-1-git-send-email-hshi@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: References: Cc: Haixia Shi X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The run-length encoding algorithm should compare 16-bit encoded pixel values instead of comparing raw pixel values. It allows pixels with similar but different colors to be encoded as repeat pixels, and thus potentially save USB bandwidth. Signed-off-by: Haixia Shi Reviewed-by: Daniel Kurtz Tested-by: Haixia Shi --- drivers/gpu/drm/udl/udl_transfer.c | 39 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/udl/udl_transfer.c b/drivers/gpu/drm/udl/udl_transfer.c index f343db7..917dcb9 100644 --- a/drivers/gpu/drm/udl/udl_transfer.c +++ b/drivers/gpu/drm/udl/udl_transfer.c @@ -82,12 +82,14 @@ static inline u16 pixel32_to_be16(const uint32_t pixel) ((pixel >> 8) & 0xf800)); } -static bool pixel_repeats(const void *pixel, const uint32_t repeat, int bpp) +static inline u16 get_pixel_val16(const uint8_t *pixel, int bpp) { + u16 pixel_val16 = 0; if (bpp == 2) - return *(const uint16_t *)pixel == repeat; - else - return *(const uint32_t *)pixel == repeat; + pixel_val16 = *(const uint16_t *)pixel; + else if (bpp == 4) + pixel_val16 = pixel32_to_be16(*(const uint32_t *)pixel); + return pixel_val16; } /* @@ -134,6 +136,7 @@ static void udl_compress_hline16( uint8_t *cmd_pixels_count_byte = NULL; const u8 *raw_pixel_start = NULL; const u8 *cmd_pixel_start, *cmd_pixel_end = NULL; + uint16_t pixel_val16; prefetchw((void *) cmd); /* pull in one cache line at least */ @@ -154,33 +157,29 @@ static void udl_compress_hline16( (int)(cmd_buffer_end - cmd) / 2))) * bpp; prefetch_range((void *) pixel, (cmd_pixel_end - pixel) * bpp); + pixel_val16 = get_pixel_val16(pixel, bpp); while (pixel < cmd_pixel_end) { const u8 *const start = pixel; - u32 repeating_pixel; - - if (bpp == 2) { - repeating_pixel = *(uint16_t *)pixel; - *(uint16_t *)cmd = cpu_to_be16(repeating_pixel); - } else { - repeating_pixel = *(uint32_t *)pixel; - *(uint16_t *)cmd = cpu_to_be16(pixel32_to_be16(repeating_pixel)); - } + const uint16_t repeating_pixel_val16 = pixel_val16; + + *(uint16_t *)cmd = cpu_to_be16(pixel_val16); cmd += 2; pixel += bpp; - if (unlikely((pixel < cmd_pixel_end) && - (pixel_repeats(pixel, repeating_pixel, bpp)))) { + while (pixel < cmd_pixel_end) { + pixel_val16 = get_pixel_val16(pixel, bpp); + if (pixel_val16 != repeating_pixel_val16) + break; + pixel += bpp; + } + + if (unlikely(pixel > start + bpp)) { /* go back and fill in raw pixel count */ *raw_pixels_count_byte = (((start - raw_pixel_start) / bpp) + 1) & 0xFF; - while ((pixel < cmd_pixel_end) && - (pixel_repeats(pixel, repeating_pixel, bpp))) { - pixel += bpp; - } - /* immediately after raw data is repeat byte */ *cmd++ = (((pixel - start) / bpp) - 1) & 0xFF;