Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp919148rdg; Fri, 13 Oct 2023 05:22:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBD+YwsglQaCoN4SgjfAhNOxUjGhjEJfdfHSEKIN4Lu2p/lhSBy8SmnMILmsCEsABd0ChH X-Received: by 2002:a05:6870:ea95:b0:1dd:58a1:2879 with SMTP id s21-20020a056870ea9500b001dd58a12879mr30631644oap.35.1697199776986; Fri, 13 Oct 2023 05:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697199776; cv=none; d=google.com; s=arc-20160816; b=NYAE5L+orAuyinwwTqxNdbTByi3D11vl78V8a7hMS2YAgkKTS7Gn/VoiWJMygrj7Sj Gqw1dwXeJKkvc/XJodPHoPxU5u9EwGNaWuDbevgGyoX7sw+uu0fn1hRBPk8ltDTzwSEB EVHIFoUwXC3Ru24Qj3q4AjkOODSzHqcOMIeNpSDnT5PC+II79NNC5+TuWcuUyG7IK2Y7 7A6JVEXwwiJNUGryeDKnrpri24a4M6Ex21fOJXnSZE+MW8DVW/o9FoaPdM6eowdRDpC+ UBOO73kndQeWgB+VdMe9+qONtXQvvi+bVvKQGOMgb336qkzi0g1u8QYpoYI+LTRyaxLM a83g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2zx15p0SmnRH09BE0u4PUAnqk7+Zw8rJ36gokTY/TP8=; fh=49yGyKQ7swI3VvkPnIWqRIRtkNmXqk/M8wtKRZ1KL/o=; b=CkYv/bnc7W1HiuWAwx+AHUGNP8iadxHwP9ZMa0Y0mTQsm7L/p78+hirjlrbPPlwGXi 4v/I1AYxypSXfd9+5vA8UhWkX+MDr5ESB+qBN96UvkaL2ykuTCU2fYTQ0nBAFxIfSak0 XNqnS8y16UfZKKNyFZf4/UWYnKJeQqL3QyWE57XyB9EixwDaE+J9yD6YeDLI6ofpwPZh AaXQb0AAzj/9p0VBAgi2g5nw8TbI0wP7mut/jHoP5a8wp5dRclhiGUmcKG0HaL3+Hr8g DqFhNEego22LDe10ktSpyDCsjxxggKHSilRFinoRFzbYHsp7rKXiatmCA79OLOhomxlp f3eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aMPVCWPL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b4-20020a656684000000b00578d71884b4si4332211pgw.194.2023.10.13.05.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:22:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aMPVCWPL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id A0DAA81DD257; Fri, 13 Oct 2023 05:22:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231556AbjJMMWr (ORCPT + 99 others); Fri, 13 Oct 2023 08:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbjJMMWq (ORCPT ); Fri, 13 Oct 2023 08:22:46 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5124BF; Fri, 13 Oct 2023 05:22:44 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c746bc3bceso5602485ad.1; Fri, 13 Oct 2023 05:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697199764; x=1697804564; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2zx15p0SmnRH09BE0u4PUAnqk7+Zw8rJ36gokTY/TP8=; b=aMPVCWPLUm/yNcUul5Bcwo/D6XX9JAaqJKITX2A6quJxheuplRVWCdHO6GwLzoj4Xr 5pC1OM5VTzufH80nfta7x7nbuXJpY95i+huY6UeFDFLk+tpLlyjleOfFQ3/8jjSeYixu hKGjdA3GRLNYNQ/ya3hfxCJ9z3lOHORW/GMNVjX3JuVw07EC3fBlr0k5aV0YpyJuYaZj oU8mu2yrgJwqD7mNyDoD29hTV2OALYYGRa/aq+yjW0nwOvqQ9TdbbpMYrSpjbX4uFg4h BWwLYT6+oEIjYM7Prsd2I1xptclx/1SoI0lnrg1B3ANAWFPCEsiKC12Rg3UMRTm7whz1 /1eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199764; x=1697804564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2zx15p0SmnRH09BE0u4PUAnqk7+Zw8rJ36gokTY/TP8=; b=eh7et56HpvsJKViGmKR+QCVm6aC9tKGovQV2QZQnDIfj2OZW6NxZ/W+MpuqW28grhK b/gq7cvHSYyn4WiBmpxiyYyy40IaPTRTwh+PCHG6K6hSHBg0+U+hOt6b+LAq0d31xTyz kqBkKt3xAyk5acs6WJX8KmA5aarkNZ6hsGzVIpx3NyQQBSxNLoqJaBJplXrUiUd9qvmk H1hAsNM9vOdMzfXiB1XkQwPbpJr+pFRwnhMo7c8roaTt7Azqt09HNxlFfmkGsgeRuRwK fDqnB9wO1zVYAJAel5Ct+eaqbgOinwDU9M7Jz0AGPpym3K1VMABDo0l1PNIL1vIItRin 1Mrw== X-Gm-Message-State: AOJu0Yyy4IQR16RhsA8WR+BRxz7MzYGzyRjtOzn2eVVHP+2TekyN1p2y 3B1Ie9/7KVsDRtKRf4/3NhM= X-Received: by 2002:a05:6a20:4407:b0:133:6e3d:68cd with SMTP id ce7-20020a056a20440700b001336e3d68cdmr36263214pzb.3.1697199764020; Fri, 13 Oct 2023 05:22:44 -0700 (PDT) Received: from localhost.localdomain ([140.116.154.65]) by smtp.gmail.com with ESMTPSA id jd22-20020a170903261600b001bc930d4517sm3781802plb.42.2023.10.13.05.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:22:43 -0700 (PDT) From: Kuan-Wei Chiu To: dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, ira.weiny@intel.com Cc: rafael@kernel.org, lenb@kernel.org, nvdimm@lists.linux.dev, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH v2] ACPI: NFIT: Optimize nfit_mem_cmp() for efficiency Date: Fri, 13 Oct 2023 20:22:36 +0800 Message-Id: <20231013122236.2127269-1-visitorckw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231012215903.2104652-1-visitorckw@gmail.com> References: <20231012215903.2104652-1-visitorckw@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 13 Oct 2023 05:22:53 -0700 (PDT) The original code used conditional branching in the nfit_mem_cmp function to compare two values and return -1, 1, or 0 based on the result. However, the list_sort comparison function only needs results <0, >0, or =0. This patch optimizes the code to make the comparison branchless, improving efficiency and reducing code size. This change reduces the number of comparison operations from 1-2 to a single subtraction operation, thereby saving the number of instructions. Signed-off-by: Kuan-Wei Chiu --- v1 -> v2: - Add explicit type cast in case the sizes of u32 and int differ. drivers/acpi/nfit/core.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index f96bf32cd368..563a32eba888 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -1138,11 +1138,7 @@ static int nfit_mem_cmp(void *priv, const struct list_head *_a, handleA = __to_nfit_memdev(a)->device_handle; handleB = __to_nfit_memdev(b)->device_handle; - if (handleA < handleB) - return -1; - else if (handleA > handleB) - return 1; - return 0; + return (int)handleA - (int)handleB; } static int nfit_mem_init(struct acpi_nfit_desc *acpi_desc) -- 2.25.1