{"id":25811,"url":"https://patchwork.libcamera.org/api/patches/25811/?format=json","web_url":"https://patchwork.libcamera.org/patch/25811/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260114173918.1744023-16-kieran.bingham@ideasonboard.com>","date":"2026-01-14T17:39:15","name":"[v5,15/16] ipa: libipa: fixedpoint: Move float conversion inline","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"93fc888d9002112f000d4d0c34d85d3518ec7ae0","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25811/mbox/","series":[{"id":5708,"url":"https://patchwork.libcamera.org/api/series/5708/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5708","date":"2026-01-14T17:39:00","name":"libipa: Introduce a Quantized type","version":5,"mbox":"https://patchwork.libcamera.org/series/5708/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25811/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25811/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 76B83C32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Jan 2026 17:39:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 18B5A61FD7;\n\tWed, 14 Jan 2026 18:39:42 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EFDD461FD9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Jan 2026 18:39:26 +0100 (CET)","from Monstersaurus.infra.iob\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 104C82835;\n\tWed, 14 Jan 2026 18:39:00 +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=\"CiwYs72H\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768412340;\n\tbh=p59VEdYtGBIOVU/88itgeMbzeNFIHgsYdld9mxiccq4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=CiwYs72HJN3GEj0dtukideL2hykVVTUUH6mtTomyR6mvaQW68RLi11c+N3K3ysSWb\n\ttRz84sDgJlS7dVSLlEcbdc+8vpWFfgxEQuA0c4TCkQ16mxkX/3X5sHJIS59XHS4rdQ\n\tX0r0IIZDXrX//11T1VF0MUj5yG76cTqtdZ3DQbFU=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tIsaac Scott <isaac.scott@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"[PATCH v5 15/16] ipa: libipa: fixedpoint: Move float conversion\n\tinline","Date":"Wed, 14 Jan 2026 17:39:15 +0000","Message-ID":"<20260114173918.1744023-16-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20260114173918.1744023-1-kieran.bingham@ideasonboard.com>","References":"<20260114173918.1744023-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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":"With all users of the floatingToFixedPoint and fixedToFloatingPoint\ncalls converted to use the FixedPoint Quantized types, remove the calls\nand documentation and move the implementation inline in the\nFixedPointTraits implementation.\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv5:\n - Reflow text when moved\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/libipa/fixedpoint.cpp | 22 ----------\n src/ipa/libipa/fixedpoint.h   | 77 +++++++++++------------------------\n 2 files changed, 24 insertions(+), 75 deletions(-)","diff":"diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\nindex 43d76f745d8a..6a15f9b068c7 100644\n--- a/src/ipa/libipa/fixedpoint.cpp\n+++ b/src/ipa/libipa/fixedpoint.cpp\n@@ -15,28 +15,6 @@ namespace libcamera {\n \n namespace ipa {\n \n-/**\n- * \\fn R floatingToFixedPoint(T number)\n- * \\brief Convert a floating point number to a fixed-point representation\n- * \\tparam I Bit width of the integer part of the fixed-point\n- * \\tparam F Bit width of the fractional part of the fixed-point\n- * \\tparam R Return type of the fixed-point representation\n- * \\tparam T Input type of the floating point representation\n- * \\param number The floating point number to convert to fixed point\n- * \\return The converted value\n- */\n-\n-/**\n- * \\fn R fixedToFloatingPoint(T number)\n- * \\brief Convert a fixed-point number to a floating point representation\n- * \\tparam I Bit width of the integer part of the fixed-point\n- * \\tparam F Bit width of the fractional part of the fixed-point\n- * \\tparam R Return type of the floating point representation\n- * \\tparam T Input type of the fixed-point representation\n- * \\param number The fixed point number to convert to floating point\n- * \\return The converted value\n- */\n-\n /**\n  * \\struct libcamera::ipa::FixedPointQTraits\n  * \\brief Traits type implementing fixed-point quantisation conversions\ndiff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\nindex 4f6ee081604b..1d53b0b9fdde 100644\n--- a/src/ipa/libipa/fixedpoint.h\n+++ b/src/ipa/libipa/fixedpoint.h\n@@ -16,55 +16,6 @@ namespace libcamera {\n \n namespace ipa {\n \n-#ifndef __DOXYGEN__\n-template<unsigned int I, unsigned int F, typename R, typename T,\n-\t std::enable_if_t<std::is_integral_v<R> &&\n-\t\t\t  std::is_floating_point_v<T>> * = nullptr>\n-#else\n-template<unsigned int I, unsigned int F, typename R, typename T>\n-#endif\n-constexpr R floatingToFixedPoint(T number)\n-{\n-\tstatic_assert(sizeof(int) >= sizeof(R));\n-\tstatic_assert(I + F <= sizeof(R) * 8);\n-\n-\t/*\n-\t * The intermediate cast to int is needed on arm platforms to properly\n-\t * cast negative values. See\n-\t * https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/\n-\t */\n-\tR mask = (1 << (F + I)) - 1;\n-\tR frac = static_cast<R>(static_cast<int>(std::round(number * (1 << F)))) & mask;\n-\n-\treturn frac;\n-}\n-\n-#ifndef __DOXYGEN__\n-template<unsigned int I, unsigned int F, typename R, typename T,\n-\t std::enable_if_t<std::is_floating_point_v<R> &&\n-\t\t\t  std::is_integral_v<T>> * = nullptr>\n-#else\n-template<unsigned int I, unsigned int F, typename R, typename T>\n-#endif\n-constexpr R fixedToFloatingPoint(T number)\n-{\n-\tstatic_assert(sizeof(int) >= sizeof(T));\n-\tstatic_assert(I + F <= sizeof(T) * 8);\n-\n-\tif constexpr (std::is_unsigned_v<T>)\n-\t\treturn static_cast<R>(number) / static_cast<R>(1 << F);\n-\n-\t/*\n-\t * Recreate the upper bits in case of a negative number by shifting the sign\n-\t * bit from the fixed point to the first bit of the unsigned and then right shifting\n-\t * by the same amount which keeps the sign bit in place.\n-\t * This can be optimized by the compiler quite well.\n-\t */\n-\tint remaining_bits = sizeof(int) * 8 - (I + F);\n-\tint t = static_cast<int>(static_cast<unsigned>(number) << remaining_bits) >> remaining_bits;\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@@ -91,11 +42,25 @@ public:\n \n \tstatic constexpr float toFloat(QuantizedType q)\n \t{\n-\t\treturn fixedToFloatingPoint<I, F, float, QuantizedType>(q);\n+\t\tif constexpr (std::is_unsigned_v<T>)\n+\t\t\treturn static_cast<float>(q) / static_cast<float>(1 << F);\n+\n+\t\t/*\n+\t\t * Recreate the upper bits in case of a negative number by\n+\t\t * shifting the sign bit from the fixed point to the first bit\n+\t\t * of the unsigned and then right shifting by the same amount\n+\t\t * which keeps the sign bit in place. This can be optimized by\n+\t\t * the compiler quite well.\n+\t\t */\n+\t\tstatic_assert(sizeof(int) >= sizeof(T));\n+\n+\t\tint remaining_bits = sizeof(int) * 8 - (I + F);\n+\t\tint t = static_cast<int>(static_cast<unsigned>(q) << remaining_bits) >> remaining_bits;\n+\t\treturn static_cast<float>(t) / static_cast<float>(1 << F);\n \t}\n \n-\tstatic constexpr float min = fixedToFloatingPoint<I, F, float>(qMin);\n-\tstatic constexpr float max = fixedToFloatingPoint<I, F, float>(qMax);\n+\tstatic constexpr float min = toFloat(qMin);\n+\tstatic constexpr float max = toFloat(qMax);\n \n \tstatic_assert(min < max, \"FixedPointQTraits: Minimum must be less than maximum\");\n \n@@ -103,7 +68,13 @@ public:\n \tstatic QuantizedType fromFloat(float v)\n \t{\n \t\tv = std::clamp(v, min, max);\n-\t\treturn floatingToFixedPoint<I, F, QuantizedType, float>(v);\n+\n+\t\t/*\n+\t\t * The intermediate cast to int is needed on arm platforms to\n+\t\t * properly cast negative values. See\n+\t\t * https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/\n+\t\t */\n+\t\treturn static_cast<T>(static_cast<int>(std::round(v * (1 << F)))) & bitMask;\n \t}\n };\n \n","prefixes":["v5","15/16"]}