Show a patch.

GET /api/patches/25050/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 25050,
    "url": "https://patchwork.libcamera.org/api/patches/25050/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/25050/",
    "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": "<20251114005428.90024-21-kieran.bingham@ideasonboard.com>",
    "date": "2025-11-14T00:54:24",
    "name": "[v4,20/21] ipa: libipa: fixedpoint: Move float conversion inline",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "e49b6c9c36630a4f47574e20124847140bd571f1",
    "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/25050/mbox/",
    "series": [
        {
            "id": 5589,
            "url": "https://patchwork.libcamera.org/api/series/5589/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5589",
            "date": "2025-11-14T00:54:04",
            "name": "libipa: Introduce a Quantized type",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/5589/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/25050/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/25050/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 D60C6C3336\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 14 Nov 2025 00:55:12 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7F63860AD0;\n\tFri, 14 Nov 2025 01:55:12 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E139560AB4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Nov 2025 01:54:54 +0100 (CET)",
            "from charm.hippo-penny.ts.net\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 65A8021B1;\n\tFri, 14 Nov 2025 01:52:54 +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=\"PvcP5dsJ\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763081574;\n\tbh=r+jmSGgwKOxgTlQD1/jrIVqqf02bCo3w3gFv/O7Otl4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=PvcP5dsJOXYDQWj1LgqGcFM0DMf1lj9Dnk3xFtuxyLZke+coBSyTG/HPdtZ6vOM1O\n\tyy9XO7wO9J98ZHsBJEKwD7EsTrxkjI2xWWPrVC+hH30UPfm65VDnn4wEdFcYrDiXLU\n\t82cF2wKrZUzhUdVLXkoLHS/BHN3fugjO2VEkhYmQ=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Cc": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "Subject": "[PATCH v4 20/21] ipa: libipa: fixedpoint: Move float conversion\n\tinline",
        "Date": "Fri, 14 Nov 2025 00:54:24 +0000",
        "Message-ID": "<20251114005428.90024-21-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.51.1",
        "In-Reply-To": "<20251114005428.90024-1-kieran.bingham@ideasonboard.com>",
        "References": "<20251114005428.90024-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\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/libipa/fixedpoint.cpp | 22 ----------\n src/ipa/libipa/fixedpoint.h   | 76 +++++++++++------------------------\n 2 files changed, 23 insertions(+), 75 deletions(-)",
    "diff": "diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\nindex 97cdd9b3f7aa..f2c93b1cf706 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 1e984350111c..fe75af16bb54 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 \tstatic_assert(std::is_integral_v<T>, \"FixedPointQTraits: T must be integral\");\n@@ -88,17 +39,36 @@ struct FixedPointQTraits {\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 shifting the sign\n+\t\t * bit from the fixed point to the first bit of the unsigned and then right shifting\n+\t\t * by the same amount which keeps the sign bit in place.\n+\t\t * This can be optimized by 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 \t/* Conversion functions required by Quantized<Traits> */\n \tstatic constexpr 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 properly\n+\t\t * 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": [
        "v4",
        "20/21"
    ]
}