[v3,07/14] ipa: libipa: Provide Q5.4 FixedPoint support
diff mbox series

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

Commit Message

Kieran Bingham Nov. 13, 2025, 12:24 p.m. UTC
Provide a FixedPoint Quantized type to support the Q5.4 format
representing values in the range [-16.0, 15.9375] with a resolution of
1/16.

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

---

This format is used by the RKISP1/i.MX8MP for Chromatic Abberation
Correction handling

 src/ipa/libipa/fixedpoint.cpp  | 9 +++++++++
 src/ipa/libipa/fixedpoint.h    | 2 ++
 test/ipa/libipa/fixedpoint.cpp | 5 +++++
 3 files changed, 16 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp
index 5b5d3721bf85..5c7e05f99076 100644
--- a/src/ipa/libipa/fixedpoint.cpp
+++ b/src/ipa/libipa/fixedpoint.cpp
@@ -132,6 +132,15 @@  namespace ipa {
  * values in the range [0.0, 1.992] with a resolution of 1/128.
  */
 
+/**
+ * \typedef Q5_4
+ * \brief 5.4 signed fixed-point quantizer
+ *
+ * A Quantized type using 5 bit for the integer part and 4 bits for the
+ * fractional part, stored in an signed 16-bit integer (\c int16_t). Represents
+ * values in the range [-16.0, 15.9375] with a resolution of 1/16.
+ */
+
 /**
  * \typedef Q12_4
  * \brief 12.4 signed fixed-point quantizer
diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h
index c3ee6b2ed69f..39d03632cb24 100644
--- a/src/ipa/libipa/fixedpoint.h
+++ b/src/ipa/libipa/fixedpoint.h
@@ -103,6 +103,8 @@  struct FixedPointQTraits {
 using Q1_7 = Quantized<FixedPointQTraits<1, 7, int8_t>>;
 using UQ1_7 = Quantized<FixedPointQTraits<1, 7, uint8_t>>;
 
+using Q5_4 = Quantized<FixedPointQTraits<5, 4, int16_t>>;
+
 using Q12_4 = Quantized<FixedPointQTraits<12, 4, int16_t>>;
 using UQ12_4 = Quantized<FixedPointQTraits<12, 4, uint16_t>>;
 
diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp
index a806aa1e0ef6..61ad487fd950 100644
--- a/test/ipa/libipa/fixedpoint.cpp
+++ b/test/ipa/libipa/fixedpoint.cpp
@@ -190,6 +190,11 @@  protected:
 		fails += quantizedCheck<Q4_7>(-0.4f, 0b1111'1001101, -0.398438f);	/* 0x7cd */
 		fails += quantizedCheck<Q4_7>(-1.4f, 0b1110'1001101, -1.39844f);	/* 0x74d */
 
+		/* Q5_4(-16 .. 15.9375)  Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625 */
+		introduce<Q5_4>("Q5_4");
+		fails += quantizedCheck<Q5_4>(-16.00f, 0b10000'0000, -16.00f);
+		fails += quantizedCheck<Q5_4>( 15.94f, 0b01111'1111,  15.9375f);
+
 		/* 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);