{"id":26706,"url":"https://patchwork.libcamera.org/api/patches/26706/?format=json","web_url":"https://patchwork.libcamera.org/patch/26706/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260508223733.DA0831EA006C@mailuser.phl.internal>","date":"2026-05-08T21:35:46","name":"[v2,1/2] libcamera: libipa: Add right-shift operators to Vector","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c2a6fbccd4988d9309e8a3e0e43e9aead4fb37ea","submitter":{"id":261,"url":"https://patchwork.libcamera.org/api/people/261/?format=json","name":"Javier Tia","email":"floss@jetm.me"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26706/mbox/","series":[{"id":5929,"url":"https://patchwork.libcamera.org/api/series/5929/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5929","date":"2026-05-08T21:35:24","name":"libcamera: Vector right-shift operators and SwStatsCpu use site","version":2,"mbox":"https://patchwork.libcamera.org/series/5929/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26706/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26706/checks/","tags":{},"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 E1C3ABE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  8 May 2026 22:37:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4697B63021;\n\tSat,  9 May 2026 00:37:37 +0200 (CEST)","from fhigh-a5-smtp.messagingengine.com\n\t(fhigh-a5-smtp.messagingengine.com [103.168.172.156])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AE18362010\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  9 May 2026 00:37:34 +0200 (CEST)","from phl-compute-02.internal (phl-compute-02.internal\n\t[10.202.2.42])\n\tby mailfhigh.phl.internal (Postfix) with ESMTP id 088481400105;\n\tFri,  8 May 2026 18:37:34 -0400 (EDT)","from phl-imap-07 ([10.202.2.97])\n\tby phl-compute-02.internal (MEProxy); Fri, 08 May 2026 18:37:34 -0400","by mailuser.phl.internal (Postfix, from userid 501)\n\tid DA0831EA006C; Fri,  8 May 2026 18:37:33 -0400 (EDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=jetm.me header.i=@jetm.me header.b=\"EJZo4LTP\";\n\tdkim=pass (2048-bit key;\n\tunprotected) header.d=messagingengine.com\n\theader.i=@messagingengine.com header.b=\"QxhAvqVF\"; \n\tdkim-atps=neutral","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=jetm.me; h=cc:cc\n\t:content-transfer-encoding:content-type:content-type:date:date\n\t:from:from:in-reply-to:in-reply-to:message-id:mime-version\n\t:references:reply-to:subject:subject:to:to; s=fm2; t=1778279854;\n\tx=1778366254; bh=LYgKNhBmw3BUeU2oSK8zFiAHchHx5V+6HJB/+afKJhM=; b=\n\tEJZo4LTP8VtGEBQKBVmoPXk8HJqCPrvuefXCuZsqpXlXqsrmheSX+5FXqff2Jsje\n\thUOUR9Mo6pMS8wv88O7D7yx+iiO/4KLLiqTfWvYtp6PBaUQ4j4al8e21o1aH+xW2\n\t/A2Hj2FCRdTpYBu18vv66+5zerb3xJIrFj0B281uasYr/UBKmg1Wm6sfzubhMxM1\n\t1JcIdVpb5lYpbpIHmwdRz8MPYLnu+FPcDmk7mkSeGPhmdFQBwTbvC58wigOWYxOs\n\tnnBlMi+BoiWy3mpOsfLxkh7XxHkDXX2umDorOPU9lpoUqbsGqZ/UVuvHgHvA4QW7\n\tXYTZFLtRh96i0NzDEcc/fA==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=\n\tmessagingengine.com; h=cc:cc:content-transfer-encoding\n\t:content-type:content-type:date:date:feedback-id:feedback-id\n\t:from:from:in-reply-to:in-reply-to:message-id:mime-version\n\t:references:reply-to:subject:subject:to:to:x-me-proxy\n\t:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1778279854; x=\n\t1778366254; bh=LYgKNhBmw3BUeU2oSK8zFiAHchHx5V+6HJB/+afKJhM=; b=Q\n\txhAvqVFeoWF0EhHMiUwTY1R9UDvd6ew++qXwmr5tOpOAyx3Wv+TL/hMFRRlRvIz3\n\tK0vMKBrWOLc9hIOOc1nMZGWWaKd7O8JC/I1oL3TrvxqPO8jerCqmpqAv1u0q+7rz\n\tBi/Li4+wn9zKsKK7VdJSSTEQbelQXYanbvqzJpdmjHO10vq9+tabqF1U1aSSyhCt\n\ty84pi/zJs7qR0rxOkuBnuv0mNsobwrxJ9aurkE0OS13GA0jBT7Qzca7SuW/Tu5IB\n\tC2UDj6D3Zo1InCNeJ04DCZ2WPDWcQYEh3QqFH3apCilsgz37k55U7xQqQ67LeP/R\n\tzQEC/hRF87ehXe7a6Wsag=="],"X-ME-Sender":"<xms:rWX-aUH5jWevVNDLteCuikVi5FnDwtbN7kh95NCwBF7h0YU7K6G-zg>\n\t<xme:rWX-aYJa3qZY4ZdoWOwoWp5FQ3fxxIRLJ0Qels5yBOhcoboKykH5UoqYfcxaxj80Y\n\tljYbyFQBO4oIxOb6WWhzhgvj2y_6b2ZYFLJf1hhZXB81HaPgUg9lzY>","X-ME-Proxy-Cause":"gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduudduheejucetufdoteggodetrf\n\tdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu\n\trghilhhouhhtmecufedttdenucgopfhokfffucdluddtmdenucfjughrpefotggggffhvf\n\tffufevjghfsehtkedttdertdejnecuhfhrohhmpeflrghvihgvrhcuvfhirgcuoehflhho\n\tshhssehjvghtmhdrmhgvqeenucggtffrrghtthgvrhhnpedtudejffejkeekteelueefvd\n\tejvdeuhfefteehkeevtddvleduteekleetvdelhfenucevlhhushhtvghrufhiiigvpedt\n\tnecurfgrrhgrmhepmhgrihhlfhhrohhmpehflhhoshhssehjvghtmhdrmhgvpdhnsggprh\n\tgtphhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehrohgsvghrthdr\n\tmhgruggvrhestgholhhlrggsohhrrgdrtghomhdprhgtphhtthhopegsrghrnhgrsggrsh\n\tdrphhotgiivgesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohepkhhivghr\n\trghnrdgsihhnghhhrghmsehiuggvrghsohhnsghorghrugdrtghomhdprhgtphhtthhope\n\thlrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgrrhgurdgtohhmpdhr\n\ttghpthhtohepfhhlohhsshesjhgvthhmrdhmvgdprhgtphhtthhopehlihgstggrmhgvrh\n\tgrqdguvghvvghlsehlihhsthhsrdhlihgstggrmhgvrhgrrdhorhhgpdhrtghpthhtohep\n\tmhiirghmrgiirghlsehrvgguhhgrthdrtghomh","X-ME-Proxy":"<xmx:rWX-aWeglUHf-5eH9e2YiBSQ6v73oI9kcqPJbZUhfEr8wlHon2xhNA>\n\t<xmx:rWX-aQ5EdRrTy2WUEnOcw1f4k7uUvDUDZW16pBMcXHlfpUm80n7wXQ>\n\t<xmx:rWX-aVtir8cQzSX8sbtvDBGx5LgfQCSb09ApJ_fdo-m1ew5SX0hFtQ>\n\t<xmx:rWX-aYgCPIC8-2LUszI_VOgSdMBCcQLEv89SOGN0-u_jtr16Qw-2xg>\n\t<xmx:rmX-aX_IwUlPLle5jPrrFBY0nHkTjCYJxez7-a2sppL_oodd36d1y_Qt>","Feedback-ID":"i9dde48b3:Fastmail","X-Mailer":"MessagingEngine.com Webmail Interface","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","From":"Javier Tia <floss@jetm.me>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 08 May 2026 15:35:46 -0600","Subject":"[PATCH v2 1/2] libcamera: libipa: Add right-shift operators to\n\tVector","Cc":"mzamazal@redhat.com, kieran.bingham@ideasonboard.com,\n\tlaurent.pinchart@ideasonboard.com, barnabas.pocze@ideasonboard.com,\n\trobert.mader@collabora.com","In-Reply-To":"<177827984964.786021.2242634090011461397@jetm.me>","References":"<177827984964.786021.2242634090011461397@jetm.me>","Message-Id":"<20260508223733.DA0831EA006C@mailuser.phl.internal>","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>"},"content":"Add operator>> and operator>>= for right-shifting all elements by a\nscalar shift amount. Both operate element-wise: operator>> returns a\nnew Vector with each element shifted, operator>>= shifts in place and\nreturns a reference to *this.\n\nThe motivating use case is SwStatsCpu::finishFrame(), which right-shifts\nthree individual components of the RGB sum by the same sumShift_ value.\nWith these operators that becomes a single sum_ >>= sumShift_ expression.\n\nThe private apply() helpers for non-mutating and mutating scalar\noperations are templated on the scalar type so the existing operators\nkeep working with T while shift can pass an unsigned int. A\nstatic_assert in each shift operator restricts them to integer element\ntypes since right-shift is undefined on floating-point Vectors.\n\nSuggested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nSuggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Javier Tia <floss@jetm.me>\n---\n include/libcamera/internal/vector.h | 22 ++++++++++++++++++----\n src/libcamera/vector.cpp            | 14 ++++++++++++++\n 2 files changed, 32 insertions(+), 4 deletions(-)","diff":"diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\nindex ed7490e1..e3ea723d 100644\n--- a/include/libcamera/internal/vector.h\n+++ b/include/libcamera/internal/vector.h\n@@ -111,6 +111,13 @@ public:\n \t\treturn apply(*this, scalar, std::divides<>{});\n \t}\n \n+\tconstexpr Vector operator>>(unsigned int shift) const\n+\t{\n+\t\tstatic_assert(std::is_integral_v<T>,\n+\t\t\t      \"Vector::operator>> requires an integer element type\");\n+\t\treturn apply(*this, shift, [](T a, unsigned int b) { return a >> b; });\n+\t}\n+\n \tVector &operator+=(const Vector &other)\n \t{\n \t\treturn apply(other, [](T a, T b) { return a + b; });\n@@ -151,6 +158,13 @@ public:\n \t\treturn apply(scalar, [](T a, T b) { return a / b; });\n \t}\n \n+\tVector &operator>>=(unsigned int shift)\n+\t{\n+\t\tstatic_assert(std::is_integral_v<T>,\n+\t\t\t      \"Vector::operator>>= requires an integer element type\");\n+\t\treturn apply(shift, [](T a, unsigned int b) { return a >> b; });\n+\t}\n+\n \tconstexpr Vector min(const Vector &other) const\n \t{\n \t\treturn apply(*this, other, [](T a, T b) { return std::min(a, b); });\n@@ -260,8 +274,8 @@ private:\n \t\treturn result;\n \t}\n \n-\ttemplate<class BinaryOp>\n-\tstatic constexpr Vector apply(const Vector &lhs, T rhs, BinaryOp op)\n+\ttemplate<class U, class BinaryOp>\n+\tstatic constexpr Vector apply(const Vector &lhs, U rhs, BinaryOp op)\n \t{\n \t\tVector result;\n \t\tstd::transform(lhs.data_.begin(), lhs.data_.end(),\n@@ -281,8 +295,8 @@ private:\n \t\treturn *this;\n \t}\n \n-\ttemplate<class BinaryOp>\n-\tVector &apply(T scalar, BinaryOp op)\n+\ttemplate<class U, class BinaryOp>\n+\tVector &apply(U scalar, BinaryOp op)\n \t{\n \t\tstd::for_each(data_.begin(), data_.end(),\n \t\t\t      [&op, scalar](T &v) { v = op(v, scalar); });\ndiff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\nindex 86b9f9bb..d3b7e4ab 100644\n--- a/src/libcamera/vector.cpp\n+++ b/src/libcamera/vector.cpp\n@@ -126,6 +126,20 @@ LOG_DEFINE_CATEGORY(Vector)\n  * \\return The element-wise division of this vector by \\a scalar\n  */\n \n+/**\n+ * \\fn Vector::operator>>(unsigned int shift) const\n+ * \\brief Right-shift each element of this vector by \\a shift bits\n+ * \\param[in] shift The shift amount\n+ * \\return A new vector with each element right-shifted by \\a shift\n+ */\n+\n+/**\n+ * \\fn Vector::operator>>=(unsigned int shift)\n+ * \\brief Right-shift each element of this vector by \\a shift bits in place\n+ * \\param[in] shift The shift amount\n+ * \\return This vector\n+ */\n+\n /**\n  * \\fn Vector::operator+=(Vector const &other)\n  * \\brief Add \\a other element-wise to this vector\n","prefixes":["v2","1/2"]}