Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp142964pxb; Thu, 30 Sep 2021 03:01:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKRj/YuS7oY62vKKy3Rqo2atvOocKvMW4q0rL5jk84jhESXwjeW77e7iltdybvUi+prRsE X-Received: by 2002:a63:4003:: with SMTP id n3mr4076365pga.413.1632996109193; Thu, 30 Sep 2021 03:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632996109; cv=none; d=google.com; s=arc-20160816; b=cvmpGZyYl18AQv9JgzVQv4D8qnJrj8X0za4JXqRosa4R8Xip+YKeyjp56YN6deN04g ECi60LaeLuIvjdmKPe6pCW59YXs9LYJ0LDT5o2Jh4yooDkvSLGvz5nUsYZyLwZ6hf1j1 Yi+0OZ6VJCvaZ+G9KVsTB7WohWoSyyvMVqeDvrEmGmHareg333Yb9AXcZ/nqgQy3CZxs EiMTzAf+1XHsup+e7flmuCxxdh5uAowjypXTCzB2NgQvkWbuP9Qnfp1p6yny3S+rvfeR m70Q5vwhMHipYRWIe7O7HReSDC8yaneEckC+8y7BvAH1B/+3RY/u+FgZJXOpRN2oYcZT H8sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=3mBFN8y8jlN8AKDp4dPucX255oXviKTmCFTgoY6tBFE=; b=sU+vEmKUiSsxkE6Xlf9QGjD7OCABLAwm2vqMUNg/7meP4c4QsvN0S2yvpUSBrJjXHF sce7+W0qhbzm7dSXvGIYzQdmC+G8iczLLAxrGT48GS0L/+/b9rEbPxq/tBMmkXz+P3I3 j7QDY5/Wd+vYGA/ozIeZVLZ/hAHp4hssE+UNqfYQ9g0S1XOK3FO0vCguPDdVwctfrOSb KN73Jht3Ewwwvc7QhQZ7LqOP7mkmZA3AuNxegtMsz0ySY4dAkxHOu5+E5FcURQjKpZox dG2nVpvJ8xFODVV6fyRPk1wLcr6JyKKpjdG0xKc/Kb4ajF2kbZJbd12fsIQmJL/yrYS7 FQpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 5si3111448pga.607.2021.09.30.03.01.18; Thu, 30 Sep 2021 03:01:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349629AbhI3KBx (ORCPT + 99 others); Thu, 30 Sep 2021 06:01:53 -0400 Received: from foss.arm.com ([217.140.110.172]:51548 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238316AbhI3KBw (ORCPT ); Thu, 30 Sep 2021 06:01:52 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 03E24106F; Thu, 30 Sep 2021 03:00:10 -0700 (PDT) Received: from [10.1.36.24] (e122027.cambridge.arm.com [10.1.36.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A57EE3F793; Thu, 30 Sep 2021 03:00:08 -0700 (PDT) Subject: Re: [PATCH v2 2/3] drm/i915/utils: do not depend on config being defined To: Lucas De Marchi , intel-gfx@lists.freedesktop.org Cc: Daniel Vetter , dri-devel@lists.freedesktop.org, Masahiro Yamada , linux-kernel@vger.kernel.org References: <20210929183357.1490204-1-lucas.demarchi@intel.com> <20210929183357.1490204-3-lucas.demarchi@intel.com> From: Steven Price Message-ID: <2dd723c8-6aed-857c-23f3-d0381fcb52c2@arm.com> Date: Thu, 30 Sep 2021 11:00:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210929183357.1490204-3-lucas.demarchi@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/09/2021 19:33, Lucas De Marchi wrote: > Like the IS_ENABLED() counterpart, we can make IS_CONFIG_NONZERO() to > return the right thing when the config is not defined rather than a > build error, with the limitation that it can't be used on preprocessor > context. > > The trick here is that macro names can't start with a number or dash, so > we stringify the argument and check that the first char is a number != 0 > (or starting with a dash to cover negative numbers). Except for -O0 > builds the strings are all eliminated. > > Taking CONFIG_DRM_I915_REQUEST_TIMEOUT in > drivers/gpu/drm/i915/gem/i915_gem_context.c as example, we have the > following output of the preprocessor: > > old: > if (((20000) != 0) && > new: > if (( ("20000"[0] > '0' && "20000"[0] < '9') || "20000"[0] == '-' ) && > > New one looks worse, but is also eliminated from the object: > > $ size drivers/gpu/drm/i915/gem/i915_gem_context.o.* > text data bss dec hex filename > 52021 1070 232 53323 d04b drivers/gpu/drm/i915/gem/i915_gem_context.o.new > 52021 1070 232 53323 d04b drivers/gpu/drm/i915/gem/i915_gem_context.o.old > > Signed-off-by: Lucas De Marchi > --- > drivers/gpu/drm/i915/i915_utils.h | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h > index 02bbfa4d68d3..436ce612c46a 100644 > --- a/drivers/gpu/drm/i915/i915_utils.h > +++ b/drivers/gpu/drm/i915/i915_utils.h > @@ -28,6 +28,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -469,6 +470,9 @@ static inline bool timer_expired(const struct timer_list *t) > * > * Returns 0 if @config is 0, 1 if set to any value. > */ > -#define IS_CONFIG_NONZERO(config) ((config) != 0) > +#define IS_CONFIG_NONZERO(config) ( \ > + (__stringify_1(config)[0] > '0' && __stringify_1(config)[0] < '9') || \ Shouldn't this be "<= '9'". Otherwise numbers starting with a 9 are not "non zero". Steve > + __stringify_1(config)[0] == '-' \ > +) > > #endif /* !__I915_UTILS_H */ >