From patchwork Wed Jan 28 18:15:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haixia Shi X-Patchwork-Id: 5728891 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 006FE9F1AF for ; Wed, 28 Jan 2015 18:15:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F8E0202FE for ; Wed, 28 Jan 2015 18:15:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5D175202D1 for ; Wed, 28 Jan 2015 18:15:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 21D9F6E43F; Wed, 28 Jan 2015 10:15:35 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by gabe.freedesktop.org (Postfix) with ESMTP id C3A206E43F for ; Wed, 28 Jan 2015 10:15:33 -0800 (PST) Received: by mail-ie0-f180.google.com with SMTP id rl12so23481827iec.11 for ; Wed, 28 Jan 2015 10:15:33 -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; bh=gZv3NNI4HKqme7qeSKLcnWo8WChiyuvONcTWOnXBzGs=; b=lb2Eq0e/FLtJ2LeCMpBXeqB7T79jDqc0Pu8AREEzziTm6a+7Gfb8yJXb8iz4dP3mR7 n8T058HwHOy1DMJNtZWK8IgUkEbXb1kij81uG4QNAbiNOKPhwZE4TQOw5G9NaIGKNr+v 88o8fp4dYd355Mi6ANVtvAKZahuFvKIhVaojE= 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; bh=gZv3NNI4HKqme7qeSKLcnWo8WChiyuvONcTWOnXBzGs=; b=iP9E+d1oMUXIi88C0MRQLhvMgSBHvGgpU8Zi6Pv23RBql+wp1JNr9y5d+SK8nR6vOy 39Hc0Ncd+mvgEPJ9/4aYI9/cGA8Hbn4SrMpF5n4xE7t7TrycIPxv4CRWoLFVHKUc0FYY COR9xA4fy/xgrw/D0ahtJIVRCw+Wz8G67TERQF4dlEv895XC3XoQ+fTebdf5R4I5UAfG 0V68YiRm5zBbQMTMtbc1ylj/ErXn+sn2Sa8knnl5l4vFjG9bpZBc1pvnekXKMmFVPPO9 R4cWxv7VuDzhF55iktX6jCgAOmO/w8PowXY4isH1MXJW/35Ev2SlYnKq02OCFvhlTM4P uncg== X-Gm-Message-State: ALoCoQn0MWzE2HJj565rccwdQ9NbEQhInCC17TebE0axquRsxTl6yYVetbTSyVFoJapUfY7oI5s1 X-Received: by 10.50.67.100 with SMTP id m4mr5309913igt.22.1422468933416; Wed, 28 Jan 2015 10:15:33 -0800 (PST) Received: from localhost ([2620:0:1000:1600:fc0d:8d23:d42f:ba6f]) by mx.google.com with ESMTPSA id cj7sm9809786igb.10.2015.01.28.10.15.31 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 28 Jan 2015 10:15:32 -0800 (PST) From: Haixia Shi To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm/udl: optimize udl_compress_hline16 Date: Wed, 28 Jan 2015 10:15:29 -0800 Message-Id: <1422468930-20592-1-git-send-email-hshi@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c 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 | 41 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/udl/udl_transfer.c b/drivers/gpu/drm/udl/udl_transfer.c index f343db7..eadddf9 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 = *(uint16_t *)pixel; + else if (bpp == 4) + pixel_val16 = pixel32_to_be16p(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 u8 * const repeating_pixel = 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 > repeating_pixel + 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;