From patchwork Fri Jan 30 18:49:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haixia Shi X-Patchwork-Id: 5752361 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 6344CBF440 for ; Fri, 30 Jan 2015 18:49:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 88BB920274 for ; Fri, 30 Jan 2015 18:49:17 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id A1F662026F for ; Fri, 30 Jan 2015 18:49:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DC63D6E85D; Fri, 30 Jan 2015 10:49:15 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ig0-f182.google.com (mail-ig0-f182.google.com [209.85.213.182]) by gabe.freedesktop.org (Postfix) with ESMTP id AAEC76E85D for ; Fri, 30 Jan 2015 10:49:14 -0800 (PST) Received: by mail-ig0-f182.google.com with SMTP id r10so4917513igi.3 for ; Fri, 30 Jan 2015 10:49:14 -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=QGIKRkmTIIJ/VKmJQIo+dbznbYCX4m5gVaxy5bktsuIWPosqp/VMfBlJ32zY3oy5N+ WwNcTdW12X8a/FeOZergAark+/saR23SuQIOB7w9teJFFHDRRMjvotH1ics6ytByUkzc v2tBIslPEhcZG3zusa+2QgylCHZWFOt3VoO/w= 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=VfvqfkWIA7FD0JEgWoBT9AbK0IJac+sQm60G3eYVfysXVbMqfDaL7mq/y54cVCt8cf 0A0Rct5Yn9rwHJGB4IB6aPNuKW9bBZYLnIn+k5OO0ztebRwwWR44cNVl5jo6T0mnBghJ ausF+7T+D3VDUf0ysEOcea3BJRYxdXPAE14yv31QgDaN+qearfpjhVm79I49JsaCJ7rl pSkyvrt7NaJdBEOQbYW6VLestmJsIK++ociag8dLLHBHlINg+5WBrC6I4s0wc7PtyRz7 0wbq1iiKq+2qz6GoDO25B7id9PjjjsmmEyHYSbtPK+tIkNEYzWeU6ezY6TI+8A2fAQjb tKuQ== X-Gm-Message-State: ALoCoQn+rgLyx8QCyDOVsa+FBYQkJG4sxLPDQDMq1z9UoFdza87KenLowTfpT5u0LHJQaDtN5yP4 X-Received: by 10.107.163.129 with SMTP id m123mr9051128ioe.85.1422643754292; Fri, 30 Jan 2015 10:49:14 -0800 (PST) Received: from localhost ([2620:0:1000:1600:4c85:5ef9:b599:2f24]) by mx.google.com with ESMTPSA id g20sm1607434igt.14.2015.01.30.10.49.12 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 30 Jan 2015 10:49:13 -0800 (PST) From: Haixia Shi To: dri-devel Subject: [PATCH 1/2] drm/udl: optimize udl_compress_hline16 Date: Fri, 30 Jan 2015 10:49:08 -0800 Message-Id: <1422643749-24402-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;