From patchwork Wed Jan 28 21:41:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haixia Shi X-Patchwork-Id: 5731361 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 B3E639F38B for ; Wed, 28 Jan 2015 21:41:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B146D201DD for ; Wed, 28 Jan 2015 21:41:20 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id A5C032018E for ; Wed, 28 Jan 2015 21:41:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2B3856E473; Wed, 28 Jan 2015 13:41:18 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ie0-f172.google.com (mail-ie0-f172.google.com [209.85.223.172]) by gabe.freedesktop.org (Postfix) with ESMTP id BEB456E473 for ; Wed, 28 Jan 2015 13:41:17 -0800 (PST) Received: by mail-ie0-f172.google.com with SMTP id rd18so25331150iec.3 for ; Wed, 28 Jan 2015 13:41:17 -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=gZv3NNI4HKqme7qeSKLcnWo8WChiyuvONcTWOnXBzGs=; b=TKE+Hces/Ql4cAASuLCZf2js9KOQPcRP11MzNJN7VbMxi9S9l7GIt1mRvmfHBE9HGe XAJyWzRbTDl8AMRIkseqOkl5q+rVtQU4vIQR3lA3K5D4Etwdt05mvsenphxLGdyfUw4v Rw989Ibn+pzerpDFJeQ0pIkXJGmo+CuBykROs= 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=gZv3NNI4HKqme7qeSKLcnWo8WChiyuvONcTWOnXBzGs=; b=gOqumFMd9J/ne/cfo+kQv0ejKko0digIcSxIuKhvLBTiV1CimDNd7oygMavALRPcQj AWYY7WF7jMZbg5195nenSgiifc2Or2BTQlxvmruX7kxVSb5PDlbqaS60e43FCMIdPkzN /292uw28utnQhFpXvnrNy5ZKU0BvH+H4V+yVGrKBzc60+phggmaPk17Jj2H/jjvsENN+ dkrYOdlO2lrf9rN5UAMdQhGyFyBVoqOmNPIt83CvdHMWEqVpQeNROedhdLKFHcoyrip3 PYvmSn8q9TphHQg2spm8VGI0LOqfDDQ4yEASM7IpZU1NMHlm8kLgxSFUHUOAApaODClX EbZg== X-Gm-Message-State: ALoCoQm+QPIgjYo/Q8oFavzUTXgRqQbNTg9/QSXiLY6vY+1ljLcYYmsDHaUw6y9tDRuo2k8pTMeN X-Received: by 10.42.121.84 with SMTP id i20mr5653595icr.20.1422481277508; Wed, 28 Jan 2015 13:41:17 -0800 (PST) Received: from localhost ([2620:0:1000:1600:603d:d2f3:f7e8:f7e1]) by mx.google.com with ESMTPSA id n4sm3393986igr.3.2015.01.28.13.41.16 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 28 Jan 2015 13:41:16 -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 13:41:12 -0800 Message-Id: <1422481273-14970-1-git-send-email-hshi@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <20150128211232.GJ25850@nuc-i3427.alporthouse.com> References: <20150128211232.GJ25850@nuc-i3427.alporthouse.com> 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;