{"id":26199,"url":"https://patchwork.libcamera.org/api/patches/26199/?format=json","web_url":"https://patchwork.libcamera.org/patch/26199/","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":"<20260219-kbingham-quantizers-v8-3-2b6ff68ead26@ideasonboard.com>","date":"2026-02-19T15:05:04","name":"[v8,03/15] ipa: libipa: fixedpoint: Fix unsigned usage","commit_ref":"cd3149a7fa84ae237f0bfbe71e8a68794e7fce06","pull_url":null,"state":"accepted","archived":false,"hash":"84fcb3cb9d048a0a6131ff64df919fc471d29964","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/26199/mbox/","series":[{"id":5802,"url":"https://patchwork.libcamera.org/api/series/5802/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5802","date":"2026-02-19T15:05:01","name":"libipa: Introduce a Quantized type","version":8,"mbox":"https://patchwork.libcamera.org/series/5802/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26199/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26199/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 D62FAC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Feb 2026 15:05:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0E1FD62277;\n\tThu, 19 Feb 2026 16:05:14 +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 5359C62253\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Feb 2026 16:05:09 +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 0A55DFCC;\n\tThu, 19 Feb 2026 16:04:16 +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=\"XlIzQ0zs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1771513456;\n\tbh=0w7k+nsaptyC4B22GJj31eSBRHS0E9X8RAxn0D4HPjg=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=XlIzQ0zsILsdyVrlY1Tpz+L4Ul3e2TMChCs+mcjmyMCtEpkFCokUeeBg2gd4xVoeg\n\tMKNHjdPvBueSJg7qNnfEwsrhTd42SM8PHayPaflzNiIGuAt8/Dq7Pm9oRGCYHM6PGE\n\t6HVldg0a+lppjktBNTgH8OIEKi9zfn5lsdflxonw=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Date":"Thu, 19 Feb 2026 15:05:04 +0000","Subject":"[PATCH v8 03/15] ipa: libipa: fixedpoint: Fix unsigned usage","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260219-kbingham-quantizers-v8-3-2b6ff68ead26@ideasonboard.com>","References":"<20260219-kbingham-quantizers-v8-0-2b6ff68ead26@ideasonboard.com>","In-Reply-To":"<20260219-kbingham-quantizers-v8-0-2b6ff68ead26@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>, \n\tIsaac Scott <isaac.scott@ideasonboard.com>, \n\tPaul Elder <paul.elder@ideasonboard.com>, \n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","X-Mailer":"b4 0.14.3","X-Developer-Signature":"v=1; a=ed25519-sha256; t=1771513507; l=2457;\n\ti=kieran.bingham@ideasonboard.com; s=20260207;\n\th=from:subject:message-id; \n\tbh=0w7k+nsaptyC4B22GJj31eSBRHS0E9X8RAxn0D4HPjg=;\n\tb=vfIN6Mwmybo7FoTLJ6FwlWO40OhB/O6U4EiPFYj9tpAcjc4U2hwZ++SMh9yr4qIg6/Q4YeW3m\n\tnnxxHqQVblqDf+xPNZ94vaAUYB1x4KR0fVeE/UBDh/kP5t4fBTaa+Gp","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":"The fixedToFloatingPoint does not support unsigned Q types, and\nincorrectly sign-extends all values which have the top most bit set in\nthe quantized values.\n\nFix this by ensuring that only signed types perform sign extension, and\nsimplify the calculation for unsigned types.\n\nConvert the storage of the test cases to signed types to correctly\nrepresent their intended purpose, to prevent test failures.\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/libipa/fixedpoint.h    | 3 +++\n test/ipa/libipa/fixedpoint.cpp | 6 +++---\n 2 files changed, 6 insertions(+), 3 deletions(-)","diff":"diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\nindex 709cf50f0fcd..aeb9bce3269b 100644\n--- a/src/ipa/libipa/fixedpoint.h\n+++ b/src/ipa/libipa/fixedpoint.h\n@@ -49,6 +49,9 @@ constexpr R fixedToFloatingPoint(T number)\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>(T{ 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\ndiff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\nindex 99eb662ddf4e..4b017e86a74f 100644\n--- a/test/ipa/libipa/fixedpoint.cpp\n+++ b/test/ipa/libipa/fixedpoint.cpp\n@@ -68,7 +68,7 @@ protected:\n \t\t * The second 7.992 test is to test that unused bits don't\n \t\t * affect the result.\n \t\t */\n-\t\tstd::map<double, uint16_t> testCases = {\n+\t\tstd::map<double, int16_t> testCases = {\n \t\t\t{ 7.992, 0x3ff },\n \t\t\t{   0.2, 0x01a },\n \t\t\t{  -0.2, 0x7e6 },\n@@ -81,14 +81,14 @@ protected:\n \n \t\tint ret;\n \t\tfor (const auto &testCase : testCases) {\n-\t\t\tret = testSingleFixedPoint<4, 7, uint16_t>(testCase.first,\n+\t\t\tret = testSingleFixedPoint<4, 7, int16_t>(testCase.first,\n \t\t\t\t\t\t\t\t   testCase.second);\n \t\t\tif (ret != TestPass)\n \t\t\t\treturn ret;\n \t\t}\n \n \t\t/* Special case with a superfluous one in the unused bits */\n-\t\tret = testFixedToFloat<4, 7, uint16_t, double>(0xbff, 7.992);\n+\t\tret = testFixedToFloat<4, 7, int16_t, double>(0xbff, 7.992);\n \t\tif (ret != TestPass)\n \t\t\treturn ret;\n \n","prefixes":["v8","03/15"]}