[{"id":36855,"web_url":"https://patchwork.libcamera.org/comment/36855/","msgid":"<d9df8321-e32c-4dac-9142-146f393e33b0@ideasonboard.com>","date":"2025-11-17T11:56:52","subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 11. 14. 1:54 keltezéssel, Kieran Bingham írta:\n> Provide a FixedPoint Quantized type to support the Q4.8 format\n> representing values in the range [0 .. 15.9961] with a resolution of\n> 1/256.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> This type is used by the Mali-C55 AWB Gains\n> \n>   src/ipa/libipa/fixedpoint.cpp  | 9 +++++++++\n>   src/ipa/libipa/fixedpoint.h    | 2 ++\n>   test/ipa/libipa/fixedpoint.cpp | 5 +++++\n>   3 files changed, 16 insertions(+)\n> \n> diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\n> index a6f8ef351c32..03053668ed79 100644\n> --- a/src/ipa/libipa/fixedpoint.cpp\n> +++ b/src/ipa/libipa/fixedpoint.cpp\n> @@ -139,6 +139,15 @@ namespace ipa {\n>    * values in the range [0.0, 1.992] with a resolution of 1/128.\n>    */\n>   \n> +/**\n> + * \\typedef UQ4_8\n> + * \\brief 4.8 unsigned fixed-point quantizer\n> + *\n> + * A Quantized type using 4 bits for the integer part and 8 bits for the\n> + * fractional part, stored in an unsigned 16-bit integer (\\c uint16_t). Represents\n> + * values in the range [0.0, 15.9961] with a resolution of 1/256.\n> + */\n> +\n>   /**\n>    * \\typedef Q5_4\n>    * \\brief 5.4 signed fixed-point quantizer\n> diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\n> index 8f095210a918..05dd97e64f40 100644\n> --- a/src/ipa/libipa/fixedpoint.h\n> +++ b/src/ipa/libipa/fixedpoint.h\n> @@ -105,6 +105,8 @@ struct FixedPointQTraits {\n>   using Q1_7 = Quantized<FixedPointQTraits<1, 7, int8_t>>;\n>   using UQ1_7 = Quantized<FixedPointQTraits<1, 7, uint8_t>>;\n>   \n> +using UQ4_8 = Quantized<FixedPointQTraits<4, 8, uint16_t>>;\n> +\n>   using Q5_4 = Quantized<FixedPointQTraits<5, 4, int16_t>>;\n>   using UQ5_8 = Quantized<FixedPointQTraits<5, 8, uint16_t>>;\n\nI'm wondering if we might want to add a type alias template instead of adding\neach manually. E.g. something along these lines:\n\nnamespace fixp {\n\nnamespace details {\n\ntemplate<unsigned int Bits>\nconstexpr auto qtype()\n{\n     static_assert(Bits <= 64);\n\n     if constexpr (Bits <= 8) return int8_t();\n     else if constexpr (Bits <= 16) return int16_t();\n     else if constexpr (Bits <= 32) return int32_t();\n     else if constexpr (Bits <= 64) return int64_t();\n}\n\n}\n\ntemplate<unsigned int I, unsigned int F>\nusing Q = Quantized<FixedPointQTraits<I, F, decltype(details::qtype<I + F>())>>;\n\ntemplate<unsigned int I, unsigned int F>\nusing UQ = Quantized<FixedPointQTraits<I, F, std::make_unsigned_t<decltype(details::qtype<I + F>())>>>;\n\n}\n\n\nRegards,\nBarnabás Pőcze\n\n\n>   \n> diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\n> index c830b5f05a19..f3773dfe6ad4 100644\n> --- a/test/ipa/libipa/fixedpoint.cpp\n> +++ b/test/ipa/libipa/fixedpoint.cpp\n> @@ -190,6 +190,11 @@ protected:\n>   \t\tfails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);\t/* 0x7cd */\n>   \t\tfails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);\t/* 0x74d */\n>   \n> +\t\t/* UQ4_8(0 .. 15.9961)  Min: [0x0000:0] -- Max: [0x0fff:15.9961] Step:0.00390625 */\n> +\t\tintroduce<UQ4_8>(\"UQ4_8\");\n> +\t\tfails += quantizedCheck<UQ4_8>( 0.0f, 0b0000'00000000,  0.00f);\n> +\t\tfails += quantizedCheck<UQ4_8>(16.0f, 0b1111'11111111, 15.9961f);\n> +\n>   \t\t/* Q5_4(-16 .. 15.9375)  Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625 */\n>   \t\tintroduce<Q5_4>(\"Q5_4\");\n>   \t\tfails += quantizedCheck<Q5_4>(-16.00f, 0b10000'0000, -16.00f);","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 5118EC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 17 Nov 2025 11:57:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8E2FC60A80;\n\tMon, 17 Nov 2025 12:56:59 +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 02D9A60856\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 17 Nov 2025 12:56:57 +0100 (CET)","from [192.168.33.31] (185.221.143.100.nat.pool.zt.hu\n\t[185.221.143.100])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A983FB5;\n\tMon, 17 Nov 2025 12:54: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=\"ZMbZ5QhD\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763380494;\n\tbh=dzPEcasw6l0LNpTA74EbRkIdjf4WZrGi2qKjGWuTmnM=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=ZMbZ5QhDEnJHkt+Foggon26RjZ64LXIxHwKlPUILaoQmHfMcZHy49CA62WG3CT3cQ\n\tDwb0e1J7KRnEdnAMsSTLEh3+cAaCmhGQ2YZibuh43o1jaBSg3qudpOM0Ur5vnx5EpI\n\tDyDe4/cOIeE00T1QUXDACeTtu313hvBi9p/P+p5E=","Message-ID":"<d9df8321-e32c-4dac-9142-146f393e33b0@ideasonboard.com>","Date":"Mon, 17 Nov 2025 12:56:52 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","References":"<20251114005428.90024-1-kieran.bingham@ideasonboard.com>\n\t<20251114005428.90024-10-kieran.bingham@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20251114005428.90024-10-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","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>"}},{"id":36857,"web_url":"https://patchwork.libcamera.org/comment/36857/","msgid":"<176338149169.1979555.10986925501180588171@ping.linuxembedded.co.uk>","date":"2025-11-17T12:11:31","subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2025-11-17 11:56:52)\n> Hi\n> \n> 2025. 11. 14. 1:54 keltezéssel, Kieran Bingham írta:\n> > Provide a FixedPoint Quantized type to support the Q4.8 format\n> > representing values in the range [0 .. 15.9961] with a resolution of\n> > 1/256.\n> > \n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > \n> > ---\n> > This type is used by the Mali-C55 AWB Gains\n> > \n> >   src/ipa/libipa/fixedpoint.cpp  | 9 +++++++++\n> >   src/ipa/libipa/fixedpoint.h    | 2 ++\n> >   test/ipa/libipa/fixedpoint.cpp | 5 +++++\n> >   3 files changed, 16 insertions(+)\n> > \n> > diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\n> > index a6f8ef351c32..03053668ed79 100644\n> > --- a/src/ipa/libipa/fixedpoint.cpp\n> > +++ b/src/ipa/libipa/fixedpoint.cpp\n> > @@ -139,6 +139,15 @@ namespace ipa {\n> >    * values in the range [0.0, 1.992] with a resolution of 1/128.\n> >    */\n> >   \n> > +/**\n> > + * \\typedef UQ4_8\n> > + * \\brief 4.8 unsigned fixed-point quantizer\n> > + *\n> > + * A Quantized type using 4 bits for the integer part and 8 bits for the\n> > + * fractional part, stored in an unsigned 16-bit integer (\\c uint16_t). Represents\n> > + * values in the range [0.0, 15.9961] with a resolution of 1/256.\n> > + */\n> > +\n> >   /**\n> >    * \\typedef Q5_4\n> >    * \\brief 5.4 signed fixed-point quantizer\n> > diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\n> > index 8f095210a918..05dd97e64f40 100644\n> > --- a/src/ipa/libipa/fixedpoint.h\n> > +++ b/src/ipa/libipa/fixedpoint.h\n> > @@ -105,6 +105,8 @@ struct FixedPointQTraits {\n> >   using Q1_7 = Quantized<FixedPointQTraits<1, 7, int8_t>>;\n> >   using UQ1_7 = Quantized<FixedPointQTraits<1, 7, uint8_t>>;\n> >   \n> > +using UQ4_8 = Quantized<FixedPointQTraits<4, 8, uint16_t>>;\n> > +\n> >   using Q5_4 = Quantized<FixedPointQTraits<5, 4, int16_t>>;\n> >   using UQ5_8 = Quantized<FixedPointQTraits<5, 8, uint16_t>>;\n> \n> I'm wondering if we might want to add a type alias template instead of adding\n> each manually. E.g. something along these lines:\n> \n> namespace fixp {\n> \n> namespace details {\n> \n> template<unsigned int Bits>\n> constexpr auto qtype()\n> {\n>      static_assert(Bits <= 64);\n> \n>      if constexpr (Bits <= 8) return int8_t();\n>      else if constexpr (Bits <= 16) return int16_t();\n>      else if constexpr (Bits <= 32) return int32_t();\n>      else if constexpr (Bits <= 64) return int64_t();\n> }\n> \n> }\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> }\n> \n\nThis looks like magic, but I like it ;-)\n\nI guess that means we then do:\n\nusing Q5_8 = Q<5, 8>;\nusing UQ5_8 = UQ<5, 8>;\n\nWhich gets the down to being really elegant, and we can even use that\ninline in code as just Q<4,4>(2.25f); if we wish.\n\nVery cool addition.\n\n> \n> Regards,\n> Barnabás Pőcze\n> \n> \n> >   \n> > diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\n> > index c830b5f05a19..f3773dfe6ad4 100644\n> > --- a/test/ipa/libipa/fixedpoint.cpp\n> > +++ b/test/ipa/libipa/fixedpoint.cpp\n> > @@ -190,6 +190,11 @@ protected:\n> >               fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);       /* 0x7cd */\n> >               fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);        /* 0x74d */\n> >   \n> > +             /* UQ4_8(0 .. 15.9961)  Min: [0x0000:0] -- Max: [0x0fff:15.9961] Step:0.00390625 */\n> > +             introduce<UQ4_8>(\"UQ4_8\");\n> > +             fails += quantizedCheck<UQ4_8>( 0.0f, 0b0000'00000000,  0.00f);\n> > +             fails += quantizedCheck<UQ4_8>(16.0f, 0b1111'11111111, 15.9961f);\n> > +\n> >               /* Q5_4(-16 .. 15.9375)  Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625 */\n> >               introduce<Q5_4>(\"Q5_4\");\n> >               fails += quantizedCheck<Q5_4>(-16.00f, 0b10000'0000, -16.00f);\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 A1710C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 17 Nov 2025 12:11:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C79FE60A81;\n\tMon, 17 Nov 2025 13:11:35 +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 A872A60856\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 17 Nov 2025 13:11:34 +0100 (CET)","from pendragon.ideasonboard.com\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 96CF442B;\n\tMon, 17 Nov 2025 13:09:31 +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=\"jdnXwLx8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763381371;\n\tbh=SVtxIB8ctPSIT6WuLXFiybnIzgWE0Yrf5f84/PPMExQ=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=jdnXwLx83c/aMuidJWvo9/nDb6BU9qTABk/dc5N283oKshBKke2CuzKjZV4mLNUGi\n\tlirI0RK0kqAIWHFKMGI/hxtP/AywlG+tE04bSFc1p3Y9+aCB9s6ZjAA0XiWvDCLD9q\n\tVyBG0oi98tX3eDhCfVeUZm2x/YaCl7DC09ZukYGs=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<d9df8321-e32c-4dac-9142-146f393e33b0@ideasonboard.com>","References":"<20251114005428.90024-1-kieran.bingham@ideasonboard.com>\n\t<20251114005428.90024-10-kieran.bingham@ideasonboard.com>\n\t<d9df8321-e32c-4dac-9142-146f393e33b0@ideasonboard.com>","Subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Mon, 17 Nov 2025 12:11:31 +0000","Message-ID":"<176338149169.1979555.10986925501180588171@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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":36875,"web_url":"https://patchwork.libcamera.org/comment/36875/","msgid":"<176346957075.880260.3241882339025380663@isaac-ThinkPad-T16-Gen-2>","date":"2025-11-18T12:39:30","subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","submitter":{"id":215,"url":"https://patchwork.libcamera.org/api/people/215/","name":"Isaac Scott","email":"isaac.scott@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch!\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n\nQuoting Kieran Bingham (2025-11-14 00:54:13)\n> Provide a FixedPoint Quantized type to support the Q4.8 format\n> representing values in the range [0 .. 15.9961] with a resolution of\n> 1/256.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> This type is used by the Mali-C55 AWB Gains\n> \n>  src/ipa/libipa/fixedpoint.cpp  | 9 +++++++++\n>  src/ipa/libipa/fixedpoint.h    | 2 ++\n>  test/ipa/libipa/fixedpoint.cpp | 5 +++++\n>  3 files changed, 16 insertions(+)\n> \n> diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\n> index a6f8ef351c32..03053668ed79 100644\n> --- a/src/ipa/libipa/fixedpoint.cpp\n> +++ b/src/ipa/libipa/fixedpoint.cpp\n> @@ -139,6 +139,15 @@ namespace ipa {\n>   * values in the range [0.0, 1.992] with a resolution of 1/128.\n>   */\n>  \n> +/**\n> + * \\typedef UQ4_8\n> + * \\brief 4.8 unsigned fixed-point quantizer\n> + *\n> + * A Quantized type using 4 bits for the integer part and 8 bits for the\n> + * fractional part, stored in an unsigned 16-bit integer (\\c uint16_t). Represents\n> + * values in the range [0.0, 15.9961] with a resolution of 1/256.\n> + */\n> +\n>  /**\n>   * \\typedef Q5_4\n>   * \\brief 5.4 signed fixed-point quantizer\n> diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\n> index 8f095210a918..05dd97e64f40 100644\n> --- a/src/ipa/libipa/fixedpoint.h\n> +++ b/src/ipa/libipa/fixedpoint.h\n> @@ -105,6 +105,8 @@ struct FixedPointQTraits {\n>  using Q1_7 = Quantized<FixedPointQTraits<1, 7, int8_t>>;\n>  using UQ1_7 = Quantized<FixedPointQTraits<1, 7, uint8_t>>;\n>  \n> +using UQ4_8 = Quantized<FixedPointQTraits<4, 8, uint16_t>>;\n> +\n>  using Q5_4 = Quantized<FixedPointQTraits<5, 4, int16_t>>;\n>  using UQ5_8 = Quantized<FixedPointQTraits<5, 8, uint16_t>>;\n>  \n> diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\n> index c830b5f05a19..f3773dfe6ad4 100644\n> --- a/test/ipa/libipa/fixedpoint.cpp\n> +++ b/test/ipa/libipa/fixedpoint.cpp\n> @@ -190,6 +190,11 @@ protected:\n>                 fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);       /* 0x7cd */\n>                 fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);        /* 0x74d */\n>  \n> +               /* UQ4_8(0 .. 15.9961)  Min: [0x0000:0] -- Max: [0x0fff:15.9961] Step:0.00390625 */\n> +               introduce<UQ4_8>(\"UQ4_8\");\n> +               fails += quantizedCheck<UQ4_8>( 0.0f, 0b0000'00000000,  0.00f);\n> +               fails += quantizedCheck<UQ4_8>(16.0f, 0b1111'11111111, 15.9961f);\n> +\n>                 /* Q5_4(-16 .. 15.9375)  Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625 */\n>                 introduce<Q5_4>(\"Q5_4\");\n>                 fails += quantizedCheck<Q5_4>(-16.00f, 0b10000'0000, -16.00f);\n> -- \n> 2.51.1\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 52CE0BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 18 Nov 2025 12:39:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0145360A8B;\n\tTue, 18 Nov 2025 13:39:35 +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 6214060A85\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 18 Nov 2025 13:39:33 +0100 (CET)","from thinkpad.ideasonboard.com\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 A2FA0D52;\n\tTue, 18 Nov 2025 13:37:29 +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=\"swabg2kq\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763469449;\n\tbh=O6ABXjzu/hJDvQkDmvmj3dyUl5W7NKBSGsaGBcXN9w0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=swabg2kq4bdHQiih1P6LskRIDeHDy3HZQCRvoauGc0si3Sgo6eiMfiuvll07jHZeV\n\tp2lO/vkUbSrpBZ7IRIcema4yr7WNmDvldvxNfipIdyge4ynWXhWgh5ZL6/BzHAP882\n\tKWFa9o9kKeN5blEFI0P68Xd73bsS6wi8ikOZs1/A=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251114005428.90024-10-kieran.bingham@ideasonboard.com>","References":"<20251114005428.90024-1-kieran.bingham@ideasonboard.com>\n\t<20251114005428.90024-10-kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","From":"Isaac Scott <isaac.scott@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Tue, 18 Nov 2025 12:39:30 +0000","Message-ID":"<176346957075.880260.3241882339025380663@isaac-ThinkPad-T16-Gen-2>","User-Agent":"alot/0.10","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":36905,"web_url":"https://patchwork.libcamera.org/comment/36905/","msgid":"<20251119043115.GV10711@pendragon.ideasonboard.com>","date":"2025-11-19T04:31:15","subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Mon, Nov 17, 2025 at 12:11:31PM +0000, Kieran Bingham wrote:\n> Quoting Barnabás Pőcze (2025-11-17 11:56:52)\n> > 2025. 11. 14. 1:54 keltezéssel, Kieran Bingham írta:\n> > > Provide a FixedPoint Quantized type to support the Q4.8 format\n> > > representing values in the range [0 .. 15.9961] with a resolution of\n> > > 1/256.\n> > > \n> > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > > \n> > > ---\n> > > This type is used by the Mali-C55 AWB Gains\n> > > \n> > >   src/ipa/libipa/fixedpoint.cpp  | 9 +++++++++\n> > >   src/ipa/libipa/fixedpoint.h    | 2 ++\n> > >   test/ipa/libipa/fixedpoint.cpp | 5 +++++\n> > >   3 files changed, 16 insertions(+)\n> > > \n> > > diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\n> > > index a6f8ef351c32..03053668ed79 100644\n> > > --- a/src/ipa/libipa/fixedpoint.cpp\n> > > +++ b/src/ipa/libipa/fixedpoint.cpp\n> > > @@ -139,6 +139,15 @@ namespace ipa {\n> > >    * values in the range [0.0, 1.992] with a resolution of 1/128.\n> > >    */\n> > >   \n> > > +/**\n> > > + * \\typedef UQ4_8\n> > > + * \\brief 4.8 unsigned fixed-point quantizer\n> > > + *\n> > > + * A Quantized type using 4 bits for the integer part and 8 bits for the\n> > > + * fractional part, stored in an unsigned 16-bit integer (\\c uint16_t). Represents\n> > > + * values in the range [0.0, 15.9961] with a resolution of 1/256.\n> > > + */\n> > > +\n> > >   /**\n> > >    * \\typedef Q5_4\n> > >    * \\brief 5.4 signed fixed-point quantizer\n> > > diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\n> > > index 8f095210a918..05dd97e64f40 100644\n> > > --- a/src/ipa/libipa/fixedpoint.h\n> > > +++ b/src/ipa/libipa/fixedpoint.h\n> > > @@ -105,6 +105,8 @@ struct FixedPointQTraits {\n> > >   using Q1_7 = Quantized<FixedPointQTraits<1, 7, int8_t>>;\n> > >   using UQ1_7 = Quantized<FixedPointQTraits<1, 7, uint8_t>>;\n> > >   \n> > > +using UQ4_8 = Quantized<FixedPointQTraits<4, 8, uint16_t>>;\n> > > +\n> > >   using Q5_4 = Quantized<FixedPointQTraits<5, 4, int16_t>>;\n> > >   using UQ5_8 = Quantized<FixedPointQTraits<5, 8, uint16_t>>;\n> > \n> > I'm wondering if we might want to add a type alias template instead of adding\n> > each manually. E.g. something along these lines:\n> > \n> > namespace fixp {\n> > \n> > namespace details {\n> > \n> > template<unsigned int Bits>\n> > constexpr auto qtype()\n> > {\n> >      static_assert(Bits <= 64);\n> > \n> >      if constexpr (Bits <= 8) return int8_t();\n> >      else if constexpr (Bits <= 16) return int16_t();\n> >      else if constexpr (Bits <= 32) return int32_t();\n> >      else if constexpr (Bits <= 64) return int64_t();\n> > }\n> > \n> > }\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> > }\n\nI was going to propose something similar as I went through the patches\nand got increasingly bothered by the proliferation of types :-)\n\n> > \n> \n> This looks like magic, but I like it ;-)\n> \n> I guess that means we then do:\n> \n> using Q5_8 = Q<5, 8>;\n> using UQ5_8 = UQ<5, 8>;\n> \n> Which gets the down to being really elegant, and we can even use that\n> inline in code as just Q<4,4>(2.25f); if we wish.\n\nI'd use Q<4, 4> only, without a Q4_4 type alias. Or if you want to save\nthree characters, I'd add the type aliases where used, not in\nfixedpoint.h.\n\n> Very cool addition.\n> \n> > > diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\n> > > index c830b5f05a19..f3773dfe6ad4 100644\n> > > --- a/test/ipa/libipa/fixedpoint.cpp\n> > > +++ b/test/ipa/libipa/fixedpoint.cpp\n> > > @@ -190,6 +190,11 @@ protected:\n> > >               fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);       /* 0x7cd */\n> > >               fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);        /* 0x74d */\n> > >   \n> > > +             /* UQ4_8(0 .. 15.9961)  Min: [0x0000:0] -- Max: [0x0fff:15.9961] Step:0.00390625 */\n> > > +             introduce<UQ4_8>(\"UQ4_8\");\n> > > +             fails += quantizedCheck<UQ4_8>( 0.0f, 0b0000'00000000,  0.00f);\n> > > +             fails += quantizedCheck<UQ4_8>(16.0f, 0b1111'11111111, 15.9961f);\n\nIs there a way we could also generalize the tests instead of open-coding\nthem ? That could be done later too if it's too complicated.\n\n> > > +\n> > >               /* Q5_4(-16 .. 15.9375)  Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625 */\n> > >               introduce<Q5_4>(\"Q5_4\");\n> > >               fails += quantizedCheck<Q5_4>(-16.00f, 0b10000'0000, -16.00f);\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 5C9B0C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 19 Nov 2025 04:31:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0E29E60A8B;\n\tWed, 19 Nov 2025 05:31:49 +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 6917360A7B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 Nov 2025 05:31:47 +0100 (CET)","from pendragon.ideasonboard.com (unknown [205.220.129.225])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 5CD0EDD9;\n\tWed, 19 Nov 2025 05:29:40 +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=\"Rs6/VeIw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763526583;\n\tbh=/Ebo1zOF6mr71wiPAXvpYFglu5CcnzWxpf/dj3nr4v4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Rs6/VeIwkYFr/Ce8LGXSz0AvrJ/vrR7f7pYoyrNoH2MWcbUoU6rc0q5MWs1s+MXDA\n\tz9y3fwm+KXMcTyCilJ8xl5N8lbRmpafZJ7hn7d4COFNLM2Zky5sSwOcQT/6g0zvKbu\n\tQoaH1VsV+Lm4Zr7MjQobHUMM011/FKmo1LiPIPqU=","Date":"Wed, 19 Nov 2025 13:31:15 +0900","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","Message-ID":"<20251119043115.GV10711@pendragon.ideasonboard.com>","References":"<20251114005428.90024-1-kieran.bingham@ideasonboard.com>\n\t<20251114005428.90024-10-kieran.bingham@ideasonboard.com>\n\t<d9df8321-e32c-4dac-9142-146f393e33b0@ideasonboard.com>\n\t<176338149169.1979555.10986925501180588171@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<176338149169.1979555.10986925501180588171@ping.linuxembedded.co.uk>","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":36912,"web_url":"https://patchwork.libcamera.org/comment/36912/","msgid":"<176354454617.442425.4613443361500902381@ping.linuxembedded.co.uk>","date":"2025-11-19T09:29:06","subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2025-11-19 04:31:15)\n> On Mon, Nov 17, 2025 at 12:11:31PM +0000, Kieran Bingham wrote:\n> > Quoting Barnabás Pőcze (2025-11-17 11:56:52)\n> > > 2025. 11. 14. 1:54 keltezéssel, Kieran Bingham írta:\n> > > > Provide a FixedPoint Quantized type to support the Q4.8 format\n> > > > representing values in the range [0 .. 15.9961] with a resolution of\n> > > > 1/256.\n> > > > \n> > > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > > > \n> > > > ---\n> > > > This type is used by the Mali-C55 AWB Gains\n> > > > \n> > > >   src/ipa/libipa/fixedpoint.cpp  | 9 +++++++++\n> > > >   src/ipa/libipa/fixedpoint.h    | 2 ++\n> > > >   test/ipa/libipa/fixedpoint.cpp | 5 +++++\n> > > >   3 files changed, 16 insertions(+)\n> > > > \n> > > > diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\n> > > > index a6f8ef351c32..03053668ed79 100644\n> > > > --- a/src/ipa/libipa/fixedpoint.cpp\n> > > > +++ b/src/ipa/libipa/fixedpoint.cpp\n> > > > @@ -139,6 +139,15 @@ namespace ipa {\n> > > >    * values in the range [0.0, 1.992] with a resolution of 1/128.\n> > > >    */\n> > > >   \n> > > > +/**\n> > > > + * \\typedef UQ4_8\n> > > > + * \\brief 4.8 unsigned fixed-point quantizer\n> > > > + *\n> > > > + * A Quantized type using 4 bits for the integer part and 8 bits for the\n> > > > + * fractional part, stored in an unsigned 16-bit integer (\\c uint16_t). Represents\n> > > > + * values in the range [0.0, 15.9961] with a resolution of 1/256.\n> > > > + */\n> > > > +\n> > > >   /**\n> > > >    * \\typedef Q5_4\n> > > >    * \\brief 5.4 signed fixed-point quantizer\n> > > > diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\n> > > > index 8f095210a918..05dd97e64f40 100644\n> > > > --- a/src/ipa/libipa/fixedpoint.h\n> > > > +++ b/src/ipa/libipa/fixedpoint.h\n> > > > @@ -105,6 +105,8 @@ struct FixedPointQTraits {\n> > > >   using Q1_7 = Quantized<FixedPointQTraits<1, 7, int8_t>>;\n> > > >   using UQ1_7 = Quantized<FixedPointQTraits<1, 7, uint8_t>>;\n> > > >   \n> > > > +using UQ4_8 = Quantized<FixedPointQTraits<4, 8, uint16_t>>;\n> > > > +\n> > > >   using Q5_4 = Quantized<FixedPointQTraits<5, 4, int16_t>>;\n> > > >   using UQ5_8 = Quantized<FixedPointQTraits<5, 8, uint16_t>>;\n> > > \n> > > I'm wondering if we might want to add a type alias template instead of adding\n> > > each manually. E.g. something along these lines:\n> > > \n> > > namespace fixp {\n> > > \n> > > namespace details {\n> > > \n> > > template<unsigned int Bits>\n> > > constexpr auto qtype()\n> > > {\n> > >      static_assert(Bits <= 64);\n> > > \n> > >      if constexpr (Bits <= 8) return int8_t();\n> > >      else if constexpr (Bits <= 16) return int16_t();\n> > >      else if constexpr (Bits <= 32) return int32_t();\n> > >      else if constexpr (Bits <= 64) return int64_t();\n> > > }\n> > > \n> > > }\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> > > }\n> \n> I was going to propose something similar as I went through the patches\n> and got increasingly bothered by the proliferation of types :-)\n\nSo - I actaully /really/ like the addition of types. As a developer -\nespecially when we come to adding / referencing a new fixed point type\nused by hardware - I would be really happy to be able to reference the\ndocumentation which states the full range of the type, and the step size\n... which is why I've added all of that explicitly!\n\nI don't think it's a /requirement/ to add a type - but anywhere it's\nused in more places or is a common fixed point type I think it could be\nuseful. But as you see later (ipa: rkisp1: ccm: Use Q4_7 format\ndirectly), when there is only a single line usage of the type I kept the\nQ local.\n\nTo me, This:\n\n \\typedef UQ4_8\n \\brief 4.8 unsigned fixed-point quantizer\n\n A Quantized type using 4 bits for the integer part and 8 bits for the\n fractional part, stored in an unsigned 16-bit integer (\\c uint16_t). Represents\n values in the range [0.0, 15.9961] with a resolution of 1/256.\n\nis part of the value add for our documentation!\n\n\n\n> > This looks like magic, but I like it ;-)\n> > \n> > I guess that means we then do:\n> > \n> > using Q5_8 = Q<5, 8>;\n> > using UQ5_8 = UQ<5, 8>;\n> > \n> > Which gets the down to being really elegant, and we can even use that\n> > inline in code as just Q<4,4>(2.25f); if we wish.\n> \n> I'd use Q<4, 4> only, without a Q4_4 type alias. Or if you want to save\n> three characters, I'd add the type aliases where used, not in\n> fixedpoint.h.\n> \n> > Very cool addition.\n> > \n> > > > diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\n> > > > index c830b5f05a19..f3773dfe6ad4 100644\n> > > > --- a/test/ipa/libipa/fixedpoint.cpp\n> > > > +++ b/test/ipa/libipa/fixedpoint.cpp\n> > > > @@ -190,6 +190,11 @@ protected:\n> > > >               fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);       /* 0x7cd */\n> > > >               fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);        /* 0x74d */\n> > > >   \n> > > > +             /* UQ4_8(0 .. 15.9961)  Min: [0x0000:0] -- Max: [0x0fff:15.9961] Step:0.00390625 */\n> > > > +             introduce<UQ4_8>(\"UQ4_8\");\n> > > > +             fails += quantizedCheck<UQ4_8>( 0.0f, 0b0000'00000000,  0.00f);\n> > > > +             fails += quantizedCheck<UQ4_8>(16.0f, 0b1111'11111111, 15.9961f);\n> \n> Is there a way we could also generalize the tests instead of open-coding\n> them ? That could be done later too if it's too complicated.\n\nMaybe - but these tests have been vital *for me* to make sure this was\nall correct. They pop up as soon as I break anything when I make a typo\nin all of the refactoring here.\n\nThis process has really been test-driven-development based around\nguarnateeing that these checks return exactly as they are expected ;-)\n\nIn other words - I have found having these open coded to be far more\nvaluable than any generic. If it was generic I'd then want extra tests\nto make sure the generic was doing what I expected :D - these are really\nclear to me.\n\n\n> > > > +\n> > > >               /* Q5_4(-16 .. 15.9375)  Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625 */\n> > > >               introduce<Q5_4>(\"Q5_4\");\n> > > >               fails += quantizedCheck<Q5_4>(-16.00f, 0b10000'0000, -16.00f);\n> > >\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","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 57ECCBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 19 Nov 2025 09:29:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3ADF960A8B;\n\tWed, 19 Nov 2025 10:29:11 +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 5195760805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 Nov 2025 10:29:09 +0100 (CET)","from pendragon.ideasonboard.com\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 91101EB7;\n\tWed, 19 Nov 2025 10:27:04 +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=\"ZqFUhWNE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763544424;\n\tbh=P1dcYZfVClCgGguLkZwpeAelTUTuFQXJNgbH4RacfuI=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=ZqFUhWNEm1P8H5QEB5UaTQq3dy+mN8htvcK0YvHg58Jp7utYAQTU/pQ0pm05oSIpt\n\t4EuvHcW1WTU9jggcO0w4KJ+Xnf+/yMAv0w31Y2WSNhQ2sXwaTvGTkLzK8U+TzfigFu\n\tOMywt8Zs5RRdnqRMFD6D4w1hSfgPqb8e65oKp7KM=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251119043115.GV10711@pendragon.ideasonboard.com>","References":"<20251114005428.90024-1-kieran.bingham@ideasonboard.com>\n\t<20251114005428.90024-10-kieran.bingham@ideasonboard.com>\n\t<d9df8321-e32c-4dac-9142-146f393e33b0@ideasonboard.com>\n\t<176338149169.1979555.10986925501180588171@ping.linuxembedded.co.uk>\n\t<20251119043115.GV10711@pendragon.ideasonboard.com>","Subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Date":"Wed, 19 Nov 2025 09:29:06 +0000","Message-ID":"<176354454617.442425.4613443361500902381@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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":36928,"web_url":"https://patchwork.libcamera.org/comment/36928/","msgid":"<20251120015937.GG10711@pendragon.ideasonboard.com>","date":"2025-11-20T01:59:37","subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Nov 19, 2025 at 09:29:06AM +0000, Kieran Bingham wrote:\n> Quoting Laurent Pinchart (2025-11-19 04:31:15)\n> > On Mon, Nov 17, 2025 at 12:11:31PM +0000, Kieran Bingham wrote:\n> > > Quoting Barnabás Pőcze (2025-11-17 11:56:52)\n> > > > 2025. 11. 14. 1:54 keltezéssel, Kieran Bingham írta:\n> > > > > Provide a FixedPoint Quantized type to support the Q4.8 format\n> > > > > representing values in the range [0 .. 15.9961] with a resolution of\n> > > > > 1/256.\n> > > > > \n> > > > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > > > > \n> > > > > ---\n> > > > > This type is used by the Mali-C55 AWB Gains\n> > > > > \n> > > > >   src/ipa/libipa/fixedpoint.cpp  | 9 +++++++++\n> > > > >   src/ipa/libipa/fixedpoint.h    | 2 ++\n> > > > >   test/ipa/libipa/fixedpoint.cpp | 5 +++++\n> > > > >   3 files changed, 16 insertions(+)\n> > > > > \n> > > > > diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\n> > > > > index a6f8ef351c32..03053668ed79 100644\n> > > > > --- a/src/ipa/libipa/fixedpoint.cpp\n> > > > > +++ b/src/ipa/libipa/fixedpoint.cpp\n> > > > > @@ -139,6 +139,15 @@ namespace ipa {\n> > > > >    * values in the range [0.0, 1.992] with a resolution of 1/128.\n> > > > >    */\n> > > > >   \n> > > > > +/**\n> > > > > + * \\typedef UQ4_8\n> > > > > + * \\brief 4.8 unsigned fixed-point quantizer\n> > > > > + *\n> > > > > + * A Quantized type using 4 bits for the integer part and 8 bits for the\n> > > > > + * fractional part, stored in an unsigned 16-bit integer (\\c uint16_t). Represents\n> > > > > + * values in the range [0.0, 15.9961] with a resolution of 1/256.\n> > > > > + */\n> > > > > +\n> > > > >   /**\n> > > > >    * \\typedef Q5_4\n> > > > >    * \\brief 5.4 signed fixed-point quantizer\n> > > > > diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\n> > > > > index 8f095210a918..05dd97e64f40 100644\n> > > > > --- a/src/ipa/libipa/fixedpoint.h\n> > > > > +++ b/src/ipa/libipa/fixedpoint.h\n> > > > > @@ -105,6 +105,8 @@ struct FixedPointQTraits {\n> > > > >   using Q1_7 = Quantized<FixedPointQTraits<1, 7, int8_t>>;\n> > > > >   using UQ1_7 = Quantized<FixedPointQTraits<1, 7, uint8_t>>;\n> > > > >   \n> > > > > +using UQ4_8 = Quantized<FixedPointQTraits<4, 8, uint16_t>>;\n> > > > > +\n> > > > >   using Q5_4 = Quantized<FixedPointQTraits<5, 4, int16_t>>;\n> > > > >   using UQ5_8 = Quantized<FixedPointQTraits<5, 8, uint16_t>>;\n> > > > \n> > > > I'm wondering if we might want to add a type alias template instead of adding\n> > > > each manually. E.g. something along these lines:\n> > > > \n> > > > namespace fixp {\n> > > > \n> > > > namespace details {\n> > > > \n> > > > template<unsigned int Bits>\n> > > > constexpr auto qtype()\n> > > > {\n> > > >      static_assert(Bits <= 64);\n> > > > \n> > > >      if constexpr (Bits <= 8) return int8_t();\n> > > >      else if constexpr (Bits <= 16) return int16_t();\n> > > >      else if constexpr (Bits <= 32) return int32_t();\n> > > >      else if constexpr (Bits <= 64) return int64_t();\n> > > > }\n> > > > \n> > > > }\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> > > > }\n> > \n> > I was going to propose something similar as I went through the patches\n> > and got increasingly bothered by the proliferation of types :-)\n> \n> So - I actaully /really/ like the addition of types. As a developer -\n> especially when we come to adding / referencing a new fixed point type\n> used by hardware - I would be really happy to be able to reference the\n> documentation which states the full range of the type, and the step size\n> ... which is why I've added all of that explicitly!\n> \n> I don't think it's a /requirement/ to add a type - but anywhere it's\n> used in more places or is a common fixed point type I think it could be\n> useful. But as you see later (ipa: rkisp1: ccm: Use Q4_7 format\n> directly), when there is only a single line usage of the type I kept the\n> Q local.\n> \n> To me, This:\n> \n>  \\typedef UQ4_8\n>  \\brief 4.8 unsigned fixed-point quantizer\n> \n>  A Quantized type using 4 bits for the integer part and 8 bits for the\n>  fractional part, stored in an unsigned 16-bit integer (\\c uint16_t). Represents\n>  values in the range [0.0, 15.9961] with a resolution of 1/256.\n> \n> is part of the value add for our documentation!\n\nThe range and resolution are trivially derived from the fixed-point\nrepresentation. I don't see much value in documenting dozens of\nfixed-point types with what will be copy & paste of the same text with\nsmall changes.\n\n> > > This looks like magic, but I like it ;-)\n> > > \n> > > I guess that means we then do:\n> > > \n> > > using Q5_8 = Q<5, 8>;\n> > > using UQ5_8 = UQ<5, 8>;\n> > > \n> > > Which gets the down to being really elegant, and we can even use that\n> > > inline in code as just Q<4,4>(2.25f); if we wish.\n> > \n> > I'd use Q<4, 4> only, without a Q4_4 type alias. Or if you want to save\n> > three characters, I'd add the type aliases where used, not in\n> > fixedpoint.h.\n> > \n> > > Very cool addition.\n> > > \n> > > > > diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp\n> > > > > index c830b5f05a19..f3773dfe6ad4 100644\n> > > > > --- a/test/ipa/libipa/fixedpoint.cpp\n> > > > > +++ b/test/ipa/libipa/fixedpoint.cpp\n> > > > > @@ -190,6 +190,11 @@ protected:\n> > > > >               fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);       /* 0x7cd */\n> > > > >               fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);        /* 0x74d */\n> > > > >   \n> > > > > +             /* UQ4_8(0 .. 15.9961)  Min: [0x0000:0] -- Max: [0x0fff:15.9961] Step:0.00390625 */\n> > > > > +             introduce<UQ4_8>(\"UQ4_8\");\n> > > > > +             fails += quantizedCheck<UQ4_8>( 0.0f, 0b0000'00000000,  0.00f);\n> > > > > +             fails += quantizedCheck<UQ4_8>(16.0f, 0b1111'11111111, 15.9961f);\n> > \n> > Is there a way we could also generalize the tests instead of open-coding\n> > them ? That could be done later too if it's too complicated.\n> \n> Maybe - but these tests have been vital *for me* to make sure this was\n> all correct. They pop up as soon as I break anything when I make a typo\n> in all of the refactoring here.\n> \n> This process has really been test-driven-development based around\n> guarnateeing that these checks return exactly as they are expected ;-)\n> \n> In other words - I have found having these open coded to be far more\n> valuable than any generic. If it was generic I'd then want extra tests\n> to make sure the generic was doing what I expected :D - these are really\n> clear to me.\n\nIf the test simply copies the implementation of the fixed point\nconversion, then it will indeed not be very useful.\n\n> > > > > +\n> > > > >               /* Q5_4(-16 .. 15.9375)  Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625 */\n> > > > >               introduce<Q5_4>(\"Q5_4\");\n> > > > >               fails += quantizedCheck<Q5_4>(-16.00f, 0b10000'0000, -16.00f);","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 AA36DBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 20 Nov 2025 02:00:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EF97560A8B;\n\tThu, 20 Nov 2025 03:00:01 +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 3CDB5606D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 20 Nov 2025 03:00:00 +0100 (CET)","from pendragon.ideasonboard.com (fs276ed015.tkyc509.ap.nuro.jp\n\t[39.110.208.21])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 4E502C77;\n\tThu, 20 Nov 2025 02:57: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=\"weaVtKqQ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763603875;\n\tbh=JmmaxWpk9F+7ZaxzTS7Sr3Rdo4tkdrojb+fR7pYCBsI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=weaVtKqQVV5ML/LrBJO1vV6jfl8qu/NbeTeRH6E2AHk6uoaVU+WWmdmIOcT5BFPwQ\n\trg0Lb3KAE7lWzfwxkh6Wl6FdBdPMHd1wCcrSeBcNISyjTKaYockDcXOHpPSvPDph4U\n\tVe67f4RubstblAGHbgkF3BvjryCzt+jHQigkEGmI=","Date":"Thu, 20 Nov 2025 10:59:37 +0900","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH v4 09/21] ipa: libipa: Provide Q4.8 FixedPoint support","Message-ID":"<20251120015937.GG10711@pendragon.ideasonboard.com>","References":"<20251114005428.90024-1-kieran.bingham@ideasonboard.com>\n\t<20251114005428.90024-10-kieran.bingham@ideasonboard.com>\n\t<d9df8321-e32c-4dac-9142-146f393e33b0@ideasonboard.com>\n\t<176338149169.1979555.10986925501180588171@ping.linuxembedded.co.uk>\n\t<20251119043115.GV10711@pendragon.ideasonboard.com>\n\t<176354454617.442425.4613443361500902381@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<176354454617.442425.4613443361500902381@ping.linuxembedded.co.uk>","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>"}}]