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

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

Commit Message

Kieran Bingham Oct. 29, 2025, 5:24 p.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>
---
 test/ipa/libipa/fixedpoint.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Kieran Bingham Oct. 29, 2025, 9:09 p.m. UTC | #1
Quoting Kieran Bingham (2025-10-29 17:24:31)
> 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>
> ---
>  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 6f6ef4ce258e..4bffd40f5a63 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: Q:0x0400 V:-8 -- Max: Q:0x03ff V:7.99219 Step:0.0078125 */
> +using Q4_7 = Quantized<FixedPointQTraits<4, 7, int16_t>>;
> +
>  class FixedPointUtilsTest : public Test
>  {
>  protected:
> @@ -171,6 +174,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: Q:0x0400 F:-8 -- Max: Q:0x03FF V:7.99219 Step:0.0078125 */
> +               introduce<Q4_7>("Q4_7"); /* No Sign Extension */

This comment is outdated now - it's from when I was trying to make a
variation of types for 'no sign extension' because I thought I needed
them explicitly - but now I fixed the helpers this is wrong/redundant.

> +               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 */
> +
>                 /* Test Q12.4 */
>                 introduce<Q12_4>("Q12.4");
>  
> -- 
> 2.50.1
>

Patch
diff mbox series

diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp
index 6f6ef4ce258e..4bffd40f5a63 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: Q:0x0400 V:-8 -- Max: Q:0x03ff V:7.99219 Step:0.0078125 */
+using Q4_7 = Quantized<FixedPointQTraits<4, 7, int16_t>>;
+
 class FixedPointUtilsTest : public Test
 {
 protected:
@@ -171,6 +174,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: Q:0x0400 F:-8 -- Max: Q:0x03FF V:7.99219 Step:0.0078125 */
+		introduce<Q4_7>("Q4_7"); /* No Sign Extension */
+		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 */
+
 		/* Test Q12.4 */
 		introduce<Q12_4>("Q12.4");