From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751787AbcGROQW (ORCPT ); Mon, 18 Jul 2016 10:16:22 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:33538 "EHLO metis.ext.4.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751423AbcGROQT (ORCPT ); Mon, 18 Jul 2016 10:16:19 -0400 Message-ID: <1468851368.2994.54.camel@pengutronix.de> Subject: Re: [PATCH v4 09/12] [media] vivid: Local optimization From: Philipp Zabel To: Ricardo Ribalda Delgado Cc: Jonathan Corbet , Mauro Carvalho Chehab , Hans Verkuil , Markus Heiser , Laurent Pinchart , Helen Mae Koike Fornazier , Antti Palosaari , Shuah Khan , linux-doc@vger.kernel.org, LKML , linux-media Date: Mon, 18 Jul 2016 16:16:08 +0200 In-Reply-To: References: <1468845736-19651-1-git-send-email-ricardo.ribalda@gmail.com> <1468845736-19651-10-git-send-email-ricardo.ribalda@gmail.com> <1468847611.2994.22.camel@pengutronix.de> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.9-1+b1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:100:96de:80ff:fec2:9969 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ricardo, Am Montag, den 18.07.2016, 15:21 +0200 schrieb Ricardo Ribalda Delgado: > Hi Philipp > > On Mon, Jul 18, 2016 at 3:13 PM, Philipp Zabel wrote: > > Since the constant expressions are evaluated at compile time, you are > > not actually removing shifts. The code generated for precalculate_color > > by gcc 5.4 even grows by one asr instruction with this patch. > > > > I dont think that I follow you completely here. The original code was Sorry, I forgot to mention I compiled both versions for ARMv7-A, saw that object size increased, had a look the diff between objdump -d outputs and noticed an additional shift instruction. I have not checked this for x86_64. > if (a) > y= clamp(y, 16<<4, 235<<4) > > y = clamp(y>>4, 1, 254) > > And now is > > if (a) > y= clamp(y >>4, 16, 235) > else > y = clamp(y, 1, 254) y = clamp(y >>4, 1, 254) > On the previous case, when a was true there was 2 clamp operations. > Now it is only one. Yes. And now there's two shift operations (overall, still just one in each conditional path). It seems in my case the compiler was not clever enough to move all the right shifts out of the conditional paths, so I ended up with one more than before. You are right that in the limited range path the second clamps are now avoided though. Basically, feel free to disregard my comment. I had the best looking result with this variant, btw: y >>= 4; cb >>= 4; cr >>= 4; if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) { y = clamp(y, 16, 235); cb = clamp(cb, 16, 240); cr = clamp(cr, 16, 240); } else { y = clamp(y, 1, 254); cb = clamp(cb, 1, 254); cr = clamp(cr, 1, 254); } regards Philipp