From patchwork Thu Jul 4 10:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20575 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 05A99BD87C for ; Thu, 4 Jul 2024 10:07:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BC75463331; Thu, 4 Jul 2024 12:07:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VT0HL3m5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E456062C99 for ; Thu, 4 Jul 2024 12:07:49 +0200 (CEST) Received: from pendragon.ideasonboard.com (117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 32326502 for ; Thu, 4 Jul 2024 12:07:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720087641; bh=8LebbM0aCqbkp6m+2kw82pa2NKtp9xCiQnVo7asxN4g=; h=From:To:Subject:Date:From; b=VT0HL3m5C236cbedouB+e1/Mrp89gijO5tFyhhqR03XdOe8LoxeIByAmjkIwEQVer gJSFGTZeYM+oExi3bXBgpRLfDPIoZ9YA/sDVT0gInSX6PXIz7CwuebFNv1cR6/vrbI hk5uHBQj7q9zDO8ezUSRBRC0ir0EpMK4XNKrd1dc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 1/2] libcamera: base: utils: Implement hex() for 8-bit and 16-bit values Date: Thu, 4 Jul 2024 13:07:27 +0300 Message-ID: <20240704100728.7003-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The utils::hex() function is implemented for 32-bit and 64-bit integers, but not for 8-bit and 16-bit. This causes a link error (possibly at runtime for IPA modules due to lazy linking) when trying to print 8-bit or 16-bit integers. Implement additional specializations to fix it. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Stefan Klug --- include/libcamera/base/utils.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index 4ae02dc97478..734ff81e2860 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -90,6 +90,30 @@ template +inline _hex hex(int8_t value, unsigned int width) +{ + return { static_cast(value), width ? width : 2 }; +} + +template<> +inline _hex hex(uint8_t value, unsigned int width) +{ + return { static_cast(value), width ? width : 2 }; +} + +template<> +inline _hex hex(int16_t value, unsigned int width) +{ + return { static_cast(value), width ? width : 4 }; +} + +template<> +inline _hex hex(uint16_t value, unsigned int width) +{ + return { static_cast(value), width ? width : 4 }; +} + template<> inline _hex hex(int32_t value, unsigned int width) { From patchwork Thu Jul 4 10:07:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20576 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8FAC6BD87C for ; Thu, 4 Jul 2024 10:07:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 50F0162E23; Thu, 4 Jul 2024 12:07:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Jq3m31L8"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B2F1962C99 for ; Thu, 4 Jul 2024 12:07:50 +0200 (CEST) Received: from pendragon.ideasonboard.com (117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 00EEC502 for ; Thu, 4 Jul 2024 12:07:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720087642; bh=Vm9wRSTV0IeMd0LOvRW/+SEM/plQTMEztMPGz278Z0E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Jq3m31L8qqlZRDCQZ8z8DpP0Xd49exOWGBsBaLtuAc/DIMfDrtMhHSnJJPEEIpKou U220Hhnz+/L28YGpZ7kGEreoTXK+3FMP2XtMi6AI0RKX/sCUR9RFRYvtf8wEGMdQfi xvKNVlD248Qllqx8yVGCJVFiCJcfgnJG2see9i5g= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 2/2] test: utils: Extend utils::hex() test to 8-bit and 16-bit values Date: Thu, 4 Jul 2024 13:07:28 +0300 Message-ID: <20240704100728.7003-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240704100728.7003-1-laurent.pinchart@ideasonboard.com> References: <20240704100728.7003-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that the utils::hex() function supports 8-bit and 16-bit integers, extend the unit test to cover them. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Stefan Klug --- test/utils.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/utils.cpp b/test/utils.cpp index 41af954b326f..d25475cb93b9 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -176,6 +176,14 @@ protected: std::ostringstream os; std::string ref; + os << utils::hex(static_cast(0x42)) << " "; + ref += "0x42 "; + os << utils::hex(static_cast(0x42)) << " "; + ref += "0x42 "; + os << utils::hex(static_cast(0x42)) << " "; + ref += "0x0042 "; + os << utils::hex(static_cast(0x42)) << " "; + ref += "0x0042 "; os << utils::hex(static_cast(0x42)) << " "; ref += "0x00000042 "; os << utils::hex(static_cast(0x42)) << " "; @@ -184,6 +192,15 @@ protected: ref += "0x0000000000000042 "; os << utils::hex(static_cast(0x42)) << " "; ref += "0x0000000000000042 "; + + os << utils::hex(static_cast(0x42), 6) << " "; + ref += "0x000042 "; + os << utils::hex(static_cast(0x42), 1) << " "; + ref += "0x42 "; + os << utils::hex(static_cast(0x42), 6) << " "; + ref += "0x000042 "; + os << utils::hex(static_cast(0x42), 1) << " "; + ref += "0x42 "; os << utils::hex(static_cast(0x42), 4) << " "; ref += "0x0042 "; os << utils::hex(static_cast(0x42), 1) << " ";