[v4,06/21] test: libipa: Add Q4.7 type and tests to match existing use case tests
diff mbox series

Message ID 20251114005428.90024-7-kieran.bingham@ideasonboard.com
State New
Headers show
Series
  • libipa: Introduce a Quantized type
Related show

Commit Message

Kieran Bingham Nov. 14, 2025, 12:54 a.m. UTC
The existing fixed point test cases utilise a signed Q4.7 format. Add
matching tests covering the same values and extend to validate the full
type.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

---
v4:
- Remove redundant "No Sign Extension" comment

 test/ipa/libipa/fixedpoint.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Barnabás Pőcze Nov. 14, 2025, 6:08 p.m. UTC | #1
2025. 11. 14. 1:54 keltezéssel, Kieran Bingham írta:
> The existing fixed point test cases utilise a signed Q4.7 format. Add
> matching tests covering the same values and extend to validate the full
> type.

I must be missing something, but why are these not added in the first round?


> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> ---
> v4:
> - Remove redundant "No Sign Extension" comment
> 
>   test/ipa/libipa/fixedpoint.cpp | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
> 
> diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp
> index 3f2d9ac97fe5..338571e38f68 100644
> --- a/test/ipa/libipa/fixedpoint.cpp
> +++ b/test/ipa/libipa/fixedpoint.cpp
> @@ -20,6 +20,9 @@ using namespace std;
>   using namespace libcamera;
>   using namespace ipa;
>   
> +/* Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125 */
> +using Q4_7 = Quantized<FixedPointQTraits<4, 7, int16_t>>;
> +
>   class FixedPointUtilsTest : public Test
>   {
>   protected:
> @@ -172,6 +175,21 @@ protected:
>   		fails += quantizedCheck<UQ1_7>(1.0f,   0b1'0000000, 1.0f);		/* Mid */
>   		fails += quantizedCheck<UQ1_7>(1.992f, 0b1'1111111, 1.99219f);		/* Max */
>   
> +		/* Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125 */
> +		introduce<Q4_7>("Q4_7");
> +		fails += quantizedCheck<Q4_7>(-8.0f,   0b1000'0000000, -8.0f);		/* Min */
> +		fails += quantizedCheck<Q4_7>(-0.008f, 0b1111'1111111, -0.0078125);	/* -1 step */
> +		fails += quantizedCheck<Q4_7>( 0.0f,   0b0000'0000000,  0.0f);		/* Zero */
> +		fails += quantizedCheck<Q4_7>( 0.008f, 0b0000'0000001,  0.0078125f);	/* +1 step */
> +		fails += quantizedCheck<Q4_7>( 7.992f, 0b0111'1111111,  7.99219f);	/* Max */
> +
> +		/* Retain additional tests from original testFixedPoint() */
> +		fails += quantizedCheck<Q4_7>( 0.2f, 0b0000'0011010,  0.203125f);	/* 0x01a */
> +		fails += quantizedCheck<Q4_7>(-0.2f, 0b1111'1100110, -0.203125f);	/* 0x7e6 */
> +		fails += quantizedCheck<Q4_7>(-0.8f, 0b1111'0011010, -0.796875f);	/* 0x79a */
> +		fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);	/* 0x7cd */
> +		fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);	/* 0x74d */
> +
>   		/* Q12.4(-2048 .. 2047.94)  Min: [0x8000:-2048] -- Max: [0x7fff:2047.94] Step:0.0625 */
>   		introduce<Q12_4>("Q12_4");
>   		fails += quantizedCheck<Q12_4>(0.0f, 0b000000000000'0000, 0.0f);
Kieran Bingham Nov. 14, 2025, 6:51 p.m. UTC | #2
Quoting Barnabás Pőcze (2025-11-14 18:08:28)
> 2025. 11. 14. 1:54 keltezéssel, Kieran Bingham írta:
> > The existing fixed point test cases utilise a signed Q4.7 format. Add
> > matching tests covering the same values and extend to validate the full
> > type.
> 
> I must be missing something, but why are these not added in the first round?
> 

These are the replication of the existing fixed point test cases. So
they are here separated to make it clear that these *duplicate* the
tests higher in the file which use the old helpers directly.

--
Kieran

> 
> > 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > 
> > ---
> > v4:
> > - Remove redundant "No Sign Extension" comment
> > 
> >   test/ipa/libipa/fixedpoint.cpp | 18 ++++++++++++++++++
> >   1 file changed, 18 insertions(+)
> > 
> > diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp
> > index 3f2d9ac97fe5..338571e38f68 100644
> > --- a/test/ipa/libipa/fixedpoint.cpp
> > +++ b/test/ipa/libipa/fixedpoint.cpp
> > @@ -20,6 +20,9 @@ using namespace std;
> >   using namespace libcamera;
> >   using namespace ipa;
> >   
> > +/* Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125 */
> > +using Q4_7 = Quantized<FixedPointQTraits<4, 7, int16_t>>;
> > +
> >   class FixedPointUtilsTest : public Test
> >   {
> >   protected:
> > @@ -172,6 +175,21 @@ protected:
> >               fails += quantizedCheck<UQ1_7>(1.0f,   0b1'0000000, 1.0f);              /* Mid */
> >               fails += quantizedCheck<UQ1_7>(1.992f, 0b1'1111111, 1.99219f);          /* Max */
> >   
> > +             /* Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125 */
> > +             introduce<Q4_7>("Q4_7");
> > +             fails += quantizedCheck<Q4_7>(-8.0f,   0b1000'0000000, -8.0f);          /* Min */
> > +             fails += quantizedCheck<Q4_7>(-0.008f, 0b1111'1111111, -0.0078125);     /* -1 step */
> > +             fails += quantizedCheck<Q4_7>( 0.0f,   0b0000'0000000,  0.0f);          /* Zero */
> > +             fails += quantizedCheck<Q4_7>( 0.008f, 0b0000'0000001,  0.0078125f);    /* +1 step */
> > +             fails += quantizedCheck<Q4_7>( 7.992f, 0b0111'1111111,  7.99219f);      /* Max */
> > +
> > +             /* Retain additional tests from original testFixedPoint() */
> > +             fails += quantizedCheck<Q4_7>( 0.2f, 0b0000'0011010,  0.203125f);       /* 0x01a */
> > +             fails += quantizedCheck<Q4_7>(-0.2f, 0b1111'1100110, -0.203125f);       /* 0x7e6 */
> > +             fails += quantizedCheck<Q4_7>(-0.8f, 0b1111'0011010, -0.796875f);       /* 0x79a */
> > +             fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);       /* 0x7cd */
> > +             fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);        /* 0x74d */
> > +
> >               /* Q12.4(-2048 .. 2047.94)  Min: [0x8000:-2048] -- Max: [0x7fff:2047.94] Step:0.0625 */
> >               introduce<Q12_4>("Q12_4");
> >               fails += quantizedCheck<Q12_4>(0.0f, 0b000000000000'0000, 0.0f);
>
Isaac Scott Nov. 18, 2025, 12:38 p.m. UTC | #3
Hi Kieran,

Thank you for the patch!

Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>

Quoting Kieran Bingham (2025-11-14 00:54:10)
> The existing fixed point test cases utilise a signed Q4.7 format. Add
> matching tests covering the same values and extend to validate the full
> type.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> ---
> v4:
> - Remove redundant "No Sign Extension" comment
> 
>  test/ipa/libipa/fixedpoint.cpp | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp
> index 3f2d9ac97fe5..338571e38f68 100644
> --- a/test/ipa/libipa/fixedpoint.cpp
> +++ b/test/ipa/libipa/fixedpoint.cpp
> @@ -20,6 +20,9 @@ using namespace std;
>  using namespace libcamera;
>  using namespace ipa;
>  
> +/* Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125 */
> +using Q4_7 = Quantized<FixedPointQTraits<4, 7, int16_t>>;
> +
>  class FixedPointUtilsTest : public Test
>  {
>  protected:
> @@ -172,6 +175,21 @@ protected:
>                 fails += quantizedCheck<UQ1_7>(1.0f,   0b1'0000000, 1.0f);              /* Mid */
>                 fails += quantizedCheck<UQ1_7>(1.992f, 0b1'1111111, 1.99219f);          /* Max */
>  
> +               /* Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125 */
> +               introduce<Q4_7>("Q4_7");
> +               fails += quantizedCheck<Q4_7>(-8.0f,   0b1000'0000000, -8.0f);          /* Min */
> +               fails += quantizedCheck<Q4_7>(-0.008f, 0b1111'1111111, -0.0078125);     /* -1 step */
> +               fails += quantizedCheck<Q4_7>( 0.0f,   0b0000'0000000,  0.0f);          /* Zero */
> +               fails += quantizedCheck<Q4_7>( 0.008f, 0b0000'0000001,  0.0078125f);    /* +1 step */
> +               fails += quantizedCheck<Q4_7>( 7.992f, 0b0111'1111111,  7.99219f);      /* Max */
> +
> +               /* Retain additional tests from original testFixedPoint() */
> +               fails += quantizedCheck<Q4_7>( 0.2f, 0b0000'0011010,  0.203125f);       /* 0x01a */
> +               fails += quantizedCheck<Q4_7>(-0.2f, 0b1111'1100110, -0.203125f);       /* 0x7e6 */
> +               fails += quantizedCheck<Q4_7>(-0.8f, 0b1111'0011010, -0.796875f);       /* 0x79a */
> +               fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);       /* 0x7cd */
> +               fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);        /* 0x74d */
> +
>                 /* Q12.4(-2048 .. 2047.94)  Min: [0x8000:-2048] -- Max: [0x7fff:2047.94] Step:0.0625 */
>                 introduce<Q12_4>("Q12_4");
>                 fails += quantizedCheck<Q12_4>(0.0f, 0b000000000000'0000, 0.0f);
> -- 
> 2.51.1
>

Patch
diff mbox series

diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp
index 3f2d9ac97fe5..338571e38f68 100644
--- a/test/ipa/libipa/fixedpoint.cpp
+++ b/test/ipa/libipa/fixedpoint.cpp
@@ -20,6 +20,9 @@  using namespace std;
 using namespace libcamera;
 using namespace ipa;
 
+/* Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125 */
+using Q4_7 = Quantized<FixedPointQTraits<4, 7, int16_t>>;
+
 class FixedPointUtilsTest : public Test
 {
 protected:
@@ -172,6 +175,21 @@  protected:
 		fails += quantizedCheck<UQ1_7>(1.0f,   0b1'0000000, 1.0f);		/* Mid */
 		fails += quantizedCheck<UQ1_7>(1.992f, 0b1'1111111, 1.99219f);		/* Max */
 
+		/* Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125 */
+		introduce<Q4_7>("Q4_7");
+		fails += quantizedCheck<Q4_7>(-8.0f,   0b1000'0000000, -8.0f);		/* Min */
+		fails += quantizedCheck<Q4_7>(-0.008f, 0b1111'1111111, -0.0078125);	/* -1 step */
+		fails += quantizedCheck<Q4_7>( 0.0f,   0b0000'0000000,  0.0f);		/* Zero */
+		fails += quantizedCheck<Q4_7>( 0.008f, 0b0000'0000001,  0.0078125f);	/* +1 step */
+		fails += quantizedCheck<Q4_7>( 7.992f, 0b0111'1111111,  7.99219f);	/* Max */
+
+		/* Retain additional tests from original testFixedPoint() */
+		fails += quantizedCheck<Q4_7>( 0.2f, 0b0000'0011010,  0.203125f);	/* 0x01a */
+		fails += quantizedCheck<Q4_7>(-0.2f, 0b1111'1100110, -0.203125f);	/* 0x7e6 */
+		fails += quantizedCheck<Q4_7>(-0.8f, 0b1111'0011010, -0.796875f);	/* 0x79a */
+		fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);	/* 0x7cd */
+		fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);	/* 0x74d */
+
 		/* Q12.4(-2048 .. 2047.94)  Min: [0x8000:-2048] -- Max: [0x7fff:2047.94] Step:0.0625 */
 		introduce<Q12_4>("Q12_4");
 		fails += quantizedCheck<Q12_4>(0.0f, 0b000000000000'0000, 0.0f);