Patch Detail
Show a patch.
GET /api/patches/26146/?format=api
{ "id": 26146, "url": "https://patchwork.libcamera.org/api/patches/26146/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26146/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260213-kbingham-quantizers-v7-4-1626b9aaabf1@ideasonboard.com>", "date": "2026-02-13T16:57:43", "name": "[v7,04/15] ipa: libipa: Provide fixed point quantized traits", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "6f521a04fbe9869489436b51580cc787c425a82d", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26146/mbox/", "series": [ { "id": 5789, "url": "https://patchwork.libcamera.org/api/series/5789/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5789", "date": "2026-02-13T16:57:39", "name": "libipa: Introduce a Quantized type", "version": 7, "mbox": "https://patchwork.libcamera.org/series/5789/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26146/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26146/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B6878C32EF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 13 Feb 2026 16:58:17 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6B57B621D2;\n\tFri, 13 Feb 2026 17:58:12 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F1D84621D6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 13 Feb 2026 17:58:04 +0100 (CET)", "from ping.linuxembedded.co.uk\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F2FED268F;\n\tFri, 13 Feb 2026 17:57:15 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"orxB926E\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1771001836;\n\tbh=vXXLB7BliFyMfYE8yWizHfV2Yfiqc5LLVMaB56iK8kk=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=orxB926EzhhqWkEV+ocqS9rrK2ZiOSWq15mSXWT5FEf8vBqLBdhKJPeIfXIc6Wlr4\n\tZWornAjnIZRFIrIuzYMwv9Mo1L13zVKGYroe+Ho6i5XH7Wl38jxqaRdO3OuFd09/ks\n\tGxF+StIVvLf1NlwwSVVNxI1AqZtcOCVor4Ck5OPo=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "Date": "Fri, 13 Feb 2026 16:57:43 +0000", "Subject": "[PATCH v7 04/15] ipa: libipa: Provide fixed point quantized traits", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "8bit", "Message-Id": "<20260213-kbingham-quantizers-v7-4-1626b9aaabf1@ideasonboard.com>", "References": "<20260213-kbingham-quantizers-v7-0-1626b9aaabf1@ideasonboard.com>", "In-Reply-To": "<20260213-kbingham-quantizers-v7-0-1626b9aaabf1@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Kieran Bingham <kieran.bingham@ideasonboard.com>, \n\tIsaac Scott <isaac.scott@ideasonboard.com>", "X-Mailer": "b4 0.14.3", "X-Developer-Signature": "v=1; a=ed25519-sha256; t=1771001883; l=8494;\n\ti=kieran.bingham@ideasonboard.com; s=20260207;\n\th=from:subject:message-id; \n\tbh=vXXLB7BliFyMfYE8yWizHfV2Yfiqc5LLVMaB56iK8kk=;\n\tb=ekygsDu1LJYQ7bMSj8HvM2YYSC7VzcSCv3U108StoviAQWRoymqp7FvGH1LUe1nd5GZzDCZtb\n\twhVf0YwaEdbAi8xjHca4N7Wb1OMrscSfGJsSoMYX+yYsB+mJxFW5KUc", "X-Developer-Key": "i=kieran.bingham@ideasonboard.com; a=ed25519;\n\tpk=FVXKN7YuwHc6UtbRUeTMAmranfsQomA+vnilfglWdaY=", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Extend the new Quantized type infrastructure by providing a\nFixedPointQTraits template.\n\nThis allows construction of fixed point types with a Quantized storage\nthat allows easy reading of both the underlying quantized type value and\na floating point representation of that same value.\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv4:\n- Assert that the given type has enough bits for the usage\n- Use unsigned types for calculating qmin/qmax\n- Reorder toFloat/fromFloat and min/max for future inlining\n- Make toFloat and fromFloat constexpr\n\nv5:\n- Make UT, Bits and Bitmask private (and remove doxygen)\n- Remove constexpr from fromFloat which uses std::round (only constexpr\n in C++23)\n- static_assert that min<max when converted\n- Provide new Q and UQ automatic width types (Thanks Barnabás)\n- Convert types to shortened Q/UQ automatic widths\n- Use automatic width Q/UQ for 12,4\n- change qmin->qMin qmax->qMax Bits->bits BitMask->bitMask\n- Remove typedefs for Q1_7 etc\n\nv6:\n- Use 'quantized' over 'quantised'\n- Document sign is based on T and number of bits includes sign bit\n\n- Document that fromFloat also clamps between [min, max]\n\n- Remove 64 bit support. We have 32 bit assumptions on fromFloat\n\n- Restrict to 24 bits, to stay compatible with float types\n\nv7:\n- Use unsigned storage and ensure we don't have sign extension issues.\n---\n src/ipa/libipa/fixedpoint.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/fixedpoint.h | 74 ++++++++++++++++++++++++++++++++\n 2 files changed, 172 insertions(+)", "diff": "diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\nindex 6b698fc5d680..caa9ce0fc1ec 100644\n--- a/src/ipa/libipa/fixedpoint.cpp\n+++ b/src/ipa/libipa/fixedpoint.cpp\n@@ -37,6 +37,104 @@ namespace ipa {\n * \\return The converted value\n */\n \n+/**\n+ * \\struct libcamera::ipa::FixedPointQTraits\n+ * \\brief Traits type implementing fixed-point quantisation conversions\n+ *\n+ * The FixedPointQTraits structure defines a policy for mapping floating-point\n+ * values to and from fixed-point integer representations. It is parameterised\n+ * by the number of integer bits \\a I, fractional bits \\a F, and the integral\n+ * storage type \\a T. The traits are used with Quantized<Traits> to create a\n+ * quantized type that stores both the fixed-point representation and the\n+ * corresponding floating-point value.\n+ *\n+ * The signedness of the type is determined by the signedness of \\a T. For\n+ * signed types, the number of integer bits in \\a I includes the sign bit.\n+ *\n+ * Storage is determined by the total number of bits \\a (I + F) and is\n+ * automatically selected, but the internal storage type is always an unsigned\n+ * integer to guarantee against sign extension when storing quantized values\n+ * in registers.\n+ *\n+ * The trait exposes compile-time constants describing the bit layout, limits,\n+ * and scaling factors used in the fixed-point representation.\n+ *\n+ * \\tparam I Number of integer bits\n+ * \\tparam F Number of fractional bits\n+ * \\tparam T Integral type used to store the quantized value\n+ */\n+\n+/**\n+ * \\typedef FixedPointQTraits::QuantizedType\n+ * \\brief The integral storage type used for the fixed-point representation\n+ */\n+\n+/**\n+ * \\var FixedPointQTraits::qMin\n+ * \\brief Minimum representable quantized integer value\n+ *\n+ * This corresponds to the most negative value for signed formats or zero for\n+ * unsigned formats.\n+ */\n+\n+/**\n+ * \\var FixedPointQTraits::qMax\n+ * \\brief Maximum representable quantized integer value\n+ */\n+\n+/**\n+ * \\var FixedPointQTraits::min\n+ * \\brief Minimum representable floating-point value corresponding to qMin\n+ */\n+\n+/**\n+ * \\var FixedPointQTraits::max\n+ * \\brief Maximum representable floating-point value corresponding to qMax\n+ */\n+\n+/**\n+ * \\fn FixedPointQTraits::fromFloat(float v)\n+ * \\brief Convert a floating-point value to a fixed-point integer\n+ * \\param[in] v The floating-point value to be converted\n+ * \\return The quantized fixed-point integer representation\n+ *\n+ * The conversion first clamps the floating-point input \\a v to the range [min,\n+ * max] and then rounds it to the nearest integer according to the scaling\n+ * factor defined by the number of fractional bits F.\n+ */\n+\n+/**\n+ * \\fn FixedPointQTraits::toFloat(QuantizedType q)\n+ * \\brief Convert a fixed-point integer to a floating-point value\n+ * \\param[in] q The fixed-point integer value to be converted\n+ * \\return The corresponding floating-point value\n+ *\n+ * The conversion sign-extends the integer value if required and divides by the\n+ * scaling factor defined by the number of fractional bits F.\n+ */\n+\n+/**\n+ * \\typedef Q\n+ * \\brief Define a signed fixed-point quantized type with automatic storage width\n+ * \\tparam I The number of integer bits\n+ * \\tparam F The number of fractional bits\n+ *\n+ * This alias defines a signed fixed-point quantized type using the\n+ * \\ref FixedPointQTraits trait and a suitable signed integer storage type\n+ * automatically selected based on the total number of bits \\a (I + F).\n+ */\n+\n+/**\n+ * \\typedef UQ\n+ * \\brief Define an unsigned fixed-point quantized type with automatic storage width\n+ * \\tparam I The number of integer bits\n+ * \\tparam F The number of fractional bits\n+ *\n+ * This alias defines an unsigned fixed-point quantized type using the\n+ * \\ref FixedPointQTraits trait and a suitable unsigned integer storage type\n+ * automatically selected based on the total number of bits \\a (I + F).\n+ */\n+\n } /* namespace ipa */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\nindex aeb9bce3269b..b6b611df7fc3 100644\n--- a/src/ipa/libipa/fixedpoint.h\n+++ b/src/ipa/libipa/fixedpoint.h\n@@ -10,6 +10,8 @@\n #include <cmath>\n #include <type_traits>\n \n+#include \"quantized.h\"\n+\n namespace libcamera {\n \n namespace ipa {\n@@ -63,6 +65,78 @@ constexpr R fixedToFloatingPoint(T number)\n \treturn static_cast<R>(t) / static_cast<R>(1 << F);\n }\n \n+template<unsigned int I, unsigned int F, typename T>\n+struct FixedPointQTraits {\n+private:\n+\tstatic_assert(std::is_integral_v<T>, \"FixedPointQTraits: T must be integral\");\n+\tusing UT = std::make_unsigned_t<T>;\n+\n+\tstatic constexpr unsigned int bits = I + F;\n+\tstatic_assert(bits <= sizeof(UT) * 8, \"FixedPointQTraits: too many bits for type UT\");\n+\n+\t/*\n+\t * If fixed point storage is required with more than 24 bits, consider\n+\t * updating this implementation to use double-precision floating point.\n+\t */\n+\tstatic_assert(bits <= 24, \"Floating point precision may be insufficient for more than 24 bits\");\n+\n+\tstatic constexpr UT bitMask = bits < sizeof(UT) * 8\n+\t\t\t\t\t ? (UT{ 1 } << bits) - 1\n+\t\t\t\t\t : ~UT{ 0 };\n+\n+public:\n+\tusing QuantizedType = UT;\n+\n+\tstatic constexpr UT qMin = std::is_signed_v<T>\n+\t\t\t\t\t ? -(UT{ 1 } << (bits - 1))\n+\t\t\t\t\t : 0;\n+\n+\tstatic constexpr UT qMax = std::is_signed_v<T>\n+\t\t\t\t\t ? (UT{ 1 } << (bits - 1)) - 1\n+\t\t\t\t\t : bitMask;\n+\n+\tstatic constexpr float toFloat(QuantizedType q)\n+\t{\n+\t\treturn fixedToFloatingPoint<I, F, float, T>(q);\n+\t}\n+\n+\tstatic constexpr float min = fixedToFloatingPoint<I, F, float>(static_cast<T>(qMin));\n+\tstatic constexpr float max = fixedToFloatingPoint<I, F, float>(static_cast<T>(qMax));\n+\n+\tstatic_assert(min < max, \"FixedPointQTraits: Minimum must be less than maximum\");\n+\n+\t/* Conversion functions required by Quantized<Traits> */\n+\tstatic QuantizedType fromFloat(float v)\n+\t{\n+\t\tv = std::clamp(v, min, max);\n+\t\treturn floatingToFixedPoint<I, F, T, float>(v);\n+\t}\n+};\n+\n+namespace details {\n+\n+template<unsigned int Bits>\n+constexpr auto qtype()\n+{\n+\tstatic_assert(Bits <= 32,\n+\t\t \"Unsupported number of bits for quantized type\");\n+\n+\tif constexpr (Bits <= 8)\n+\t\treturn int8_t();\n+\telse if constexpr (Bits <= 16)\n+\t\treturn int16_t();\n+\telse if constexpr (Bits <= 32)\n+\t\treturn int32_t();\n+}\n+\n+} /* namespace details */\n+\n+template<unsigned int I, unsigned int F>\n+using Q = Quantized<FixedPointQTraits<I, F, decltype(details::qtype<I + F>())>>;\n+\n+template<unsigned int I, unsigned int F>\n+using UQ = Quantized<FixedPointQTraits<I, F, std::make_unsigned_t<decltype(details::qtype<I + F>())>>>;\n+\n } /* namespace ipa */\n \n } /* namespace libcamera */\n", "prefixes": [ "v7", "04/15" ] }