[{"id":38226,"web_url":"https://patchwork.libcamera.org/comment/38226/","msgid":"<177149121093.607498.3273126268880367668@neptunite.rasen.tech>","date":"2026-02-19T08:53:30","subject":"Re: [PATCH v7 03/15] ipa: libipa: fixedpoint: Fix unsigned usage","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Kieran Bingham (2026-02-14 01:57:42)\n> The fixedToFloatingPoint does not support unsigned Q types, and\n> incorrectly sign-extends all values which have the top most bit set in\n> the quantized values.\n> \n> Fix this by ensuring that only signed types perform sign extension, and\n> simplify the calculation for unsigned types.\n> \n> Convert the storage of the test cases to signed types to correctly\n> represent their intended purpose, to prevent test failures.\n> \n> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> \n> ---\n> \n> v6:\n>  - Use T{1} << F instead of 1 << F\n> \n> v7:\n>  - Fix checkstyle issues\n> ---\n>  src/ipa/libipa/fixedpoint.h    | 3 +++\n>  test/ipa/libipa/fixedpoint.cpp | 6 +++---\n>  2 files changed, 6 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\n> index 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>         static_assert(sizeof(int) >= sizeof(T));\n>         static_assert(I + F <= sizeof(T) * 8);\n>  \n> +       if constexpr (std::is_unsigned_v<T>)\n> +               return static_cast<R>(number) / static_cast<R>(T{ 1 } << F);\n> +\n>         /*\n>          * Recreate the upper bits in case of a negative number by shifting the sign\n>          * bit from the fixed point to the first bit of the unsigned and then right shifting\n> diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\n> index 99eb662ddf4e..4b017e86a74f 100644\n> --- a/test/ipa/libipa/fixedpoint.cpp\n> +++ b/test/ipa/libipa/fixedpoint.cpp\n> @@ -68,7 +68,7 @@ protected:\n>                  * The second 7.992 test is to test that unused bits don't\n>                  * affect the result.\n>                  */\n> -               std::map<double, uint16_t> testCases = {\n> +               std::map<double, int16_t> testCases = {\n>                         { 7.992, 0x3ff },\n>                         {   0.2, 0x01a },\n>                         {  -0.2, 0x7e6 },\n> @@ -81,14 +81,14 @@ protected:\n>  \n>                 int ret;\n>                 for (const auto &testCase : testCases) {\n> -                       ret = testSingleFixedPoint<4, 7, uint16_t>(testCase.first,\n> +                       ret = testSingleFixedPoint<4, 7, int16_t>(testCase.first,\n>                                                                    testCase.second);\n>                         if (ret != TestPass)\n>                                 return ret;\n>                 }\n>  \n>                 /* Special case with a superfluous one in the unused bits */\n> -               ret = testFixedToFloat<4, 7, uint16_t, double>(0xbff, 7.992);\n> +               ret = testFixedToFloat<4, 7, int16_t, double>(0xbff, 7.992);\n>                 if (ret != TestPass)\n>                         return ret;\n>  \n> \n> -- \n> 2.52.0\n>","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 C1287C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Feb 2026 08:53:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7611162230;\n\tThu, 19 Feb 2026 09:53:40 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 88F3862010\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Feb 2026 09:53:39 +0100 (CET)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:3150:3f17:6415:4c60])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 39B4B379;\n\tThu, 19 Feb 2026 09:52:45 +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=\"R1GgWvEB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1771491166;\n\tbh=zOvgtnBXQyUS/rPCySk3p5oDUAmWULQOklPgdGABvfQ=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=R1GgWvEBE/afG8epbAiwp0PQweMXtPNyRyW4txCjDqrBwLF/bg7826azEGafSpOOM\n\tZ11tKmyOJBDESFuLfGgY5zjHSqJMo45Fy2xvfPARXjHoK0VppyAnzq1LYAk2NCs88o\n\tlvjvoHOct0bObvfJqTxLfpXI53T//PUFMCB3oPmI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20260213-kbingham-quantizers-v7-3-1626b9aaabf1@ideasonboard.com>","References":"<20260213-kbingham-quantizers-v7-0-1626b9aaabf1@ideasonboard.com>\n\t<20260213-kbingham-quantizers-v7-3-1626b9aaabf1@ideasonboard.com>","Subject":"Re: [PATCH v7 03/15] ipa: libipa: fixedpoint: Fix unsigned usage","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tIsaac Scott <isaac.scott@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 19 Feb 2026 17:53:30 +0900","Message-ID":"<177149121093.607498.3273126268880367668@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}},{"id":38246,"web_url":"https://patchwork.libcamera.org/comment/38246/","msgid":"<20260219120842.GJ520738@killaraus.ideasonboard.com>","date":"2026-02-19T12:08:42","subject":"Re: [PATCH v7 03/15] ipa: libipa: fixedpoint: Fix unsigned usage","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, Feb 13, 2026 at 04:57:42PM +0000, Kieran Bingham wrote:\n> The fixedToFloatingPoint does not support unsigned Q types, and\n> incorrectly sign-extends all values which have the top most bit set in\n> the quantized values.\n> \n> Fix this by ensuring that only signed types perform sign extension, and\n> simplify the calculation for unsigned types.\n> \n> Convert the storage of the test cases to signed types to correctly\n> represent their intended purpose, to prevent test failures.\n> \n> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> \n> v6:\n>  - Use T{1} << F instead of 1 << F\n> \n> v7:\n>  - Fix checkstyle issues\n> ---\n>  src/ipa/libipa/fixedpoint.h    | 3 +++\n>  test/ipa/libipa/fixedpoint.cpp | 6 +++---\n>  2 files changed, 6 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\n> index 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\n> diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\n> index 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>","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 B266FC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Feb 2026 12:08:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7056D62245;\n\tThu, 19 Feb 2026 13:08:47 +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 D09236223F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Feb 2026 13:08:45 +0100 (CET)","from killaraus.ideasonboard.com (unknown [83.245.237.175])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 8514D4D3;\n\tThu, 19 Feb 2026 13:07:52 +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=\"GIhzERFh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1771502872;\n\tbh=f0SQpzv5icltO3J2P2AwEjcIs6gZg3j0NhN4TFGXVRQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=GIhzERFh/Rzt4JrFZWltD5/xh/VagDbSHTKz3z9WtQdebaC/KJKp5sJ9EQ2Py+muN\n\t2IiSt9t6bzxqIRDPLp89RPeiYSx8pxtFsQ3xzN4AmMVpD2hbAovH9+rRffsCxGA9Ae\n\tq1guI3Gy+2J6COoOF7D2vCFyyFwQ6W2p+J1kCpYA=","Date":"Thu, 19 Feb 2026 13:08:42 +0100","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tIsaac Scott <isaac.scott@ideasonboard.com>","Subject":"Re: [PATCH v7 03/15] ipa: libipa: fixedpoint: Fix unsigned usage","Message-ID":"<20260219120842.GJ520738@killaraus.ideasonboard.com>","References":"<20260213-kbingham-quantizers-v7-0-1626b9aaabf1@ideasonboard.com>\n\t<20260213-kbingham-quantizers-v7-3-1626b9aaabf1@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20260213-kbingham-quantizers-v7-3-1626b9aaabf1@ideasonboard.com>","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>"}}]