From patchwork Wed Oct 29 17:24:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 24893 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E36C2C3259 for ; Wed, 29 Oct 2025 17:25:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 90ACD6086F; Wed, 29 Oct 2025 18:25:02 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hNT3VDpg"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 377436085D for ; Wed, 29 Oct 2025 18:24:47 +0100 (CET) Received: from Monstersaurus.hippo-penny.ts.net (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D648C4E52; Wed, 29 Oct 2025 18:22:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761758578; bh=bFvf0xeM/xbCVogeYdUdPgQhaaUfcDmQSrgvHnM3eEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hNT3VDpgt2Kr0nH9Jzk/S0MhWH0nW4KRynWFGXBAQnWz5elXb7POppkze4UAlBp8C xpK6dGWMpW49thtQBBulXpAC5o4z4J7y1HnBXyl3RVt63gVbp78JETMsVQUAh5h47a Y6YNnunspWR+HVg7ANKlhTmrbK0y/bKiTgAZxpsY= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham Subject: [PATCH v2 04/13] test: libipa: Provide FixedPoint Quantized tests Date: Wed, 29 Oct 2025 17:24:29 +0000 Message-ID: <20251029172439.1513907-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251029172439.1513907-1-kieran.bingham@ideasonboard.com> References: <20251029172439.1513907-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Validate the new fixed-point Quantized types with tests covering Q1.7, UQ1.7, Q12.4 and UQ12.4 types. Signed-off-by: Kieran Bingham --- test/ipa/libipa/fixedpoint.cpp | 121 +++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 4 deletions(-) diff --git a/test/ipa/libipa/fixedpoint.cpp b/test/ipa/libipa/fixedpoint.cpp index 99eb662ddf4e..c88b53a31f28 100644 --- a/test/ipa/libipa/fixedpoint.cpp +++ b/test/ipa/libipa/fixedpoint.cpp @@ -5,12 +5,14 @@ * Fixed / Floating point utility tests */ +#include "../src/ipa/libipa/fixedpoint.h" + #include #include #include #include -#include "../src/ipa/libipa/fixedpoint.h" +#include #include "test.h" @@ -95,14 +97,125 @@ protected: return TestPass; } - int run() + template + int quantizedCheck(float input, typename Q::quantized_type expected, float value) { - /* fixed point conversion test */ - if (testFixedPoint() != TestPass) + Q q(input); + using T = typename Q::quantized_type; + + cerr << " Checking " << input << " == " << q.toString() << std::endl; + + T quantized = q.quantized(); + if (quantized != expected) { + cerr << " ** Q Expected " << input + << " to quantize to " << utils::hex(expected) + << ", got " << utils::hex(quantized) + << " - (" << q.toString() << ")" + << std::endl; + return 1; + } + + if ((std::abs(q.value() - value)) > 0.0001f) { + cerr << " ** V Expected " << input + << " to quantize to " << value + << ", got " << q.value() + << " - (" << q.toString() << ")" + << std::endl; + return 1; + } + + return 0; + } + + template + int introduce(std::string type) + { + using T = typename Q::quantized_type; + + std::cerr << std::endl; + + cerr << type << "(" << Q::TraitsType::min << " .. " << Q::TraitsType::max << ") " + << " Min: " << Q(Q::TraitsType::min).toString() + << " -- Max: " << Q(Q::TraitsType::max).toString() + << " Step:" << Q(T(1)).value() + << std::endl; + + if (Q::TraitsType::min > Q::TraitsType::max) { + cerr << " *** " << type + << " Min (" << Q::TraitsType::min + << ") must be less than max (" + << Q::TraitsType::max << ")" << std::endl; + return 1; + } + + return 0; + } + + int testFixedPointQuantizers() + { + unsigned int fails = 0; + + /* clang-format off */ + + /* Q1_7( -1 .. 0.992188) Min: Q:0x80 F:-1 -- Max: Q:0x7F V:0.992188 Step:0.0078125 */ + fails += introduce("Q1_7"); + fails += quantizedCheck(-1.000f, 0b1'0000000, -1.0f); /* Min */ + fails += quantizedCheck(-0.992f, 0b1'0000001, -0.992188f); /* Min + 1 step */ + fails += quantizedCheck(-0.006f, 0b1'1111111, -0.0078125f); /* -1 step */ + fails += quantizedCheck( 0.000f, 0b0'0000000, 0.0f); /* Zero */ + fails += quantizedCheck( 0.008f, 0b0'0000001, 0.0078125f); /* +1 step */ + fails += quantizedCheck( 0.992f, 0b0'1111111, 0.992188f); /* Max */ + + fails += introduce("UQ1_7"); + fails += quantizedCheck(0.0f, 0b0'0000000, 0.0f); /* Min / Zero */ + fails += quantizedCheck(1.0f, 0b1'0000000, 1.0f); /* Mid */ + fails += quantizedCheck(1.992f, 0b1'1111111, 1.99219f); /* Max */ + + /* Test Q12.4 */ + introduce("Q12.4"); + + /* Q12_4(-2048 .. 2047.94) Min: Q:0x8000 F:-2048 -- Max: Q:0x7FFF V:2047.94 Step:0.0625 */ + introduce("Q12_4"); + fails += quantizedCheck(0.0f, 0b000000000000'0000, 0.0f); + fails += quantizedCheck(7.5f, 0b000000000111'1000, 7.5f); + + introduce("UQ12_4"); + fails += quantizedCheck(0.0f, 0b000000000000'0000, 0.0f); + fails += quantizedCheck(7.5f, 0b000000000111'1000, 7.5f); + + /* Validate that exceeding limits clamps to type range */ + cerr << std::endl << "Range validation:" << std::endl; + fails += quantizedCheck(-100.0f, 0b1'0000000, -1.0f); + fails += quantizedCheck(+100.0f, 0b0'1111111, 0.992188f); + fails += quantizedCheck(-100.0f, 0b0'0000000, 0.0f); + fails += quantizedCheck(+100.0f, 0b1'1111111, 1.99219f); + + /* clang-format on */ + + std::cerr << std::endl; + + if (fails > 0) { + cerr << "Fixed point quantizer tests failed: " + << std::dec << fails << " failures." << std::endl; return TestFail; + } return TestPass; } + + int run() + { + unsigned int fails = 0; + + /* fixed point conversion test */ + if (testFixedPoint() != TestPass) + fails++; + + if (testFixedPointQuantizers() != TestPass) + fails++; + + return fails ? TestFail : TestPass; + } }; TEST_REGISTER(FixedPointUtilsTest)