From patchwork Tue Feb 17 20:38:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Streetman X-Patchwork-Id: 440704 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E0242140213 for ; Wed, 18 Feb 2015 07:39:27 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id A28141A08CC for ; Wed, 18 Feb 2015 07:39:27 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-ie0-f171.google.com (mail-ie0-f171.google.com [209.85.223.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 86FD21A056E for ; Wed, 18 Feb 2015 07:39:23 +1100 (AEDT) Received: by iecrl12 with SMTP id rl12so41496610iec.2 for ; Tue, 17 Feb 2015 12:39:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6UnYcfBzFWi3T261jsdBY4M52m4Wo73yS9Ir/Cd71Bw=; b=jPJ6wk+47AthL4NXR/sQbylS7vWBxj3jcFe1F25DrpdwCgmUvYn96LFMjyUguC5A0w DsvAV+0n9Pe7XvGT+mcvI+ZOiXd6isGDUbpG+QlOSGH1T0lRn4TQZ3X7UHGmbQE/lB0x /WEulkllWsZPO2WBl+9+kNwFBYVq8TyVGnRxWTMkkz8k8DOYtmeXwEEVvdjMS72r5Tz2 Tl+hoR96IPR5tL6Z6O2ABV8hrGcnioalWL40kgkKxw0Q4cBEpCqskG2oxiDLMuWJyQx8 Uoqdu0sVLAZCN7SRdjJ6tXw1lhT0YCa1VLniESkf9CMD5a00kvw7qprGGDTLTx27nkXo RpXQ== X-Received: by 10.42.130.74 with SMTP id u10mr31547249ics.61.1424205561415; Tue, 17 Feb 2015 12:39:21 -0800 (PST) Received: from toughbook.com (user-0c8hjgg.cable.mindspring.com. [24.136.206.16]) by mx.google.com with ESMTPSA id s17sm10676817igr.2.2015.02.17.12.39.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Feb 2015 12:39:20 -0800 (PST) From: Dan Streetman To: skiboot@lists.ozlabs.org Date: Tue, 17 Feb 2015 15:38:50 -0500 Message-Id: <1424205534-25180-2-git-send-email-ddstreet@ieee.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1424205534-25180-1-git-send-email-ddstreet@ieee.org> References: <1424205534-25180-1-git-send-email-ddstreet@ieee.org> Subject: [Skiboot] [PATCH 1/5] simplify GET/SETFIELD() use, add MASK_TO_LSH() X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Currently, the GETFIELD() and SETFIELD() macros require the user to define both the _MASK and the _LSH of the field. However, the shift of the field is trivially determinable and there is no reason it needs to be specified by the user. Add MASK_TO_LSH() macro, which determines the shift of a given mask. Change GETFIELD() and SETFIELD() to use MASK_TO_LSH() to determine the shift of the specified mask, instead of requiring it to be specified by the user. Signed-off-by: Dan Streetman --- include/bitutils.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/bitutils.h b/include/bitutils.h index 7e5b6eb..baa752b 100644 --- a/include/bitutils.h +++ b/include/bitutils.h @@ -36,15 +36,16 @@ * PPC bitmask field manipulation */ +/* Find left shift from first set bit in mask */ +#define MASK_TO_LSH(m) (__builtin_ffsl(m) - 1) + /* Extract field fname from val */ -#define GETFIELD(fname, val) \ - (((val) & fname##_MASK) >> fname##_LSH) +#define GETFIELD(m, v) (((v) & (m)) >> MASK_TO_LSH(m)) /* Set field fname of oval to fval * NOTE: oval isn't modified, the combined result is returned */ -#define SETFIELD(fname, oval, fval) \ - (((oval) & ~fname##_MASK) | \ - ((((typeof(oval))(fval)) << fname##_LSH) & fname##_MASK)) +#define SETFIELD(m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) #endif /* __BITUTILS_H */