From patchwork Mon Mar 7 20:53:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 12772372 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB9ECC4332F for ; Mon, 7 Mar 2022 20:53:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 858D210E282; Mon, 7 Mar 2022 20:53:52 +0000 (UTC) Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by gabe.freedesktop.org (Postfix) with ESMTPS id C104410E284 for ; Mon, 7 Mar 2022 20:53:46 +0000 (UTC) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by albert.telenet-ops.be with bizsmtp id 3Ytm2700A1Yj8bA06Ytmfi; Mon, 07 Mar 2022 21:53:46 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nRKMU-0036UX-1G; Mon, 07 Mar 2022 21:53:46 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKMT-0034o1-GF; Mon, 07 Mar 2022 21:53:45 +0100 From: Geert Uytterhoeven To: dri-devel@lists.freedesktop.org Subject: [PATCH RFC libdrm 1/2] intel: Improve checks for big-endian Date: Mon, 7 Mar 2022 21:53:41 +0100 Message-Id: <9a2d5522f15688981783c5f113563c2bb562568d.1646684158.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - sparc64-linux-gnu-gcc does not define __BIG_ENDIAN__ or SPARC, but does define __sparc__, hence replace the check for SPARC by a check for __sparc__, - powerpc{,64,64}-linux-gnu-gcc does not define __ppc__ or __ppc64__, but does define __BIG_ENDIAN__. powerpc64le-linux-gnu-gcc does not define __ppc__ or __ppc64__, but does define __LITTLE_ENDIAN__. Hence remove the checks for __ppc__ and __ppc64__. - mips{,64}-linux-gnu{,abi64}-gcc does not define __BIG_ENDIAN__, but does define __MIPSEB__, so add a check for the latter, - m68k-linux-gnu-gcc does not define __BIG_ENDIAN__, but does define __mc68000__, so add a check for the latter, - hppa{,64}-linux-gnu-gcc defines __BIG_ENDIAN__, and thus should work out-of-the-box. Signed-off-by: Geert Uytterhoeven --- Untested due to lack of hardware. --- intel/uthash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intel/uthash.h b/intel/uthash.h index 45d1f9fc12a1d6f9..0f5480be6e8ca033 100644 --- a/intel/uthash.h +++ b/intel/uthash.h @@ -648,7 +648,7 @@ do { #define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 3UL) == 2UL) #define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 3UL) == 3UL) #define WP(p) ((uint32_t*)((unsigned long)(p) & ~3UL)) -#if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) || defined(__ppc64__)) +#if (defined(__BIG_ENDIAN__) || defined(__sparc__) || defined(__mc68000__) || defined(__MIPSEB__)) #define MUR_THREE_ONE(p) ((((*WP(p))&0x00ffffff) << 8) | (((*(WP(p)+1))&0xff000000) >> 24)) #define MUR_TWO_TWO(p) ((((*WP(p))&0x0000ffff) <<16) | (((*(WP(p)+1))&0xffff0000) >> 16)) #define MUR_ONE_THREE(p) ((((*WP(p))&0x000000ff) <<24) | (((*(WP(p)+1))&0xffffff00) >> 8)) From patchwork Mon Mar 7 20:53:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 12772371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53606C433F5 for ; Mon, 7 Mar 2022 20:53:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A58BC10E284; Mon, 7 Mar 2022 20:53:52 +0000 (UTC) Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by gabe.freedesktop.org (Postfix) with ESMTPS id C16D310E287 for ; Mon, 7 Mar 2022 20:53:46 +0000 (UTC) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by laurent.telenet-ops.be with bizsmtp id 3Ytm270041Yj8bA01Ytm36; Mon, 07 Mar 2022 21:53:46 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nRKMU-0036UY-1h; Mon, 07 Mar 2022 21:53:46 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKMT-0034o8-Gx; Mon, 07 Mar 2022 21:53:45 +0100 From: Geert Uytterhoeven To: dri-devel@lists.freedesktop.org Subject: [PATCH RFC libdrm 2/2] util: Fix 32 bpp patterns on big-endian Date: Mon, 7 Mar 2022 21:53:42 +0100 Message-Id: <1be5820fe86d6940aab8acd52a522d39a35995c3.1646684158.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" DRM formats are defined to be little-endian, unless the DRM_FORMAT_BIG_ENDIAN flag is set. Hence writes of multi-byte pixel values need to take endianness into account. Introduce a cpu_to_le32() helper to convert 32-bit values from CPU-endian to little-endian, and use them in the various pattern fill functions for 32-bit formats. Signed-off-by: Geert Uytterhoeven Acked-by: Pekka Paalanen --- Works now with Linux' drm_fb_xrgb8888_to_rgb332_line(), which uses le32_to_cpu() to read pixel values from memory. --- tests/util/pattern.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/util/pattern.c b/tests/util/pattern.c index 42d75d700700dc3d..48677ea6d25b2676 100644 --- a/tests/util/pattern.c +++ b/tests/util/pattern.c @@ -61,6 +61,18 @@ struct color_yuv { .u = MAKE_YUV_601_U(r, g, b), \ .v = MAKE_YUV_601_V(r, g, b) } +#if defined(__BIG_ENDIAN__) || defined(__sparc__) || defined(__mc68000__) || defined(__MIPSEB__) +static inline uint32_t cpu_to_le32(uint32_t x) +{ + return ((x & 0x000000ffU) << 24) | + ((x & 0x0000ff00U) << 8) | + ((x & 0x00ff0000U) >> 8) | + ((x & 0xff000000U) >> 24); +} +#else +#define cpu_to_le32(x) (x) +#endif + /* This function takes 8-bit color values */ static inline uint32_t shiftcolor8(const struct util_color_component *comp, uint32_t value) @@ -520,26 +532,26 @@ static void fill_smpte_rgb32(const struct util_rgb_info *rgb, void *mem, for (y = 0; y < height * 6 / 9; ++y) { for (x = 0; x < width; ++x) - ((uint32_t *)mem)[x] = colors_top[x * 7 / width]; + ((uint32_t *)mem)[x] = cpu_to_le32(colors_top[x * 7 / width]); mem += stride; } for (; y < height * 7 / 9; ++y) { for (x = 0; x < width; ++x) - ((uint32_t *)mem)[x] = colors_middle[x * 7 / width]; + ((uint32_t *)mem)[x] = cpu_to_le32(colors_middle[x * 7 / width]); mem += stride; } for (; y < height; ++y) { for (x = 0; x < width * 5 / 7; ++x) ((uint32_t *)mem)[x] = - colors_bottom[x * 4 / (width * 5 / 7)]; + cpu_to_le32(colors_bottom[x * 4 / (width * 5 / 7)]); for (; x < width * 6 / 7; ++x) ((uint32_t *)mem)[x] = - colors_bottom[(x - width * 5 / 7) * 3 - / (width / 7) + 4]; + cpu_to_le32(colors_bottom[(x - width * 5 / 7) * 3 + / (width / 7) + 4]); for (; x < width; ++x) - ((uint32_t *)mem)[x] = colors_bottom[7]; + ((uint32_t *)mem)[x] = cpu_to_le32(colors_bottom[7]); mem += stride; } } @@ -1017,7 +1029,7 @@ static void fill_tiles_rgb32(const struct util_format_info *info, void *mem, (rgb32 >> 8) & 0xff, rgb32 & 0xff, alpha); - ((uint32_t *)mem)[x] = color; + ((uint32_t *)mem)[x] = cpu_to_le32(color); } mem += stride; } @@ -1164,7 +1176,7 @@ static void fill_gradient_rgb32(const struct util_rgb_info *rgb, for (j = 0; j < width / 2; j++) { uint32_t value = MAKE_RGBA10(rgb, j & 0x3ff, j & 0x3ff, j & 0x3ff, 0); - row[2*j] = row[2*j+1] = value; + row[2*j] = row[2*j+1] = cpu_to_le32(value); } mem += stride; } @@ -1174,7 +1186,7 @@ static void fill_gradient_rgb32(const struct util_rgb_info *rgb, for (j = 0; j < width / 2; j++) { uint32_t value = MAKE_RGBA10(rgb, j & 0x3fc, j & 0x3fc, j & 0x3fc, 0); - row[2*j] = row[2*j+1] = value; + row[2*j] = row[2*j+1] = cpu_to_le32(value); } mem += stride; }