Received: by 10.213.65.68 with SMTP id h4csp1741190imn; Sun, 1 Apr 2018 13:42:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx48e92l5Qgb3lprsCQv1omopPrlP51Oz2rjhP/Th/EkCd5YEsDM/el7wcDeiYfw4t+fHm2yv X-Received: by 10.101.97.1 with SMTP id z1mr2133223pgu.134.1522615375568; Sun, 01 Apr 2018 13:42:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522615375; cv=none; d=google.com; s=arc-20160816; b=Lmhsf7+Y7JpBraL0hysQzv50sht+Rc+mNR8VMY458QqrzpbUAEPPe9je9BXNNIS4xA G7j2rkO193E5Ssg1Sm0h8H4WKNkO1ciI/Lz+WLojysXzTRayHqdlblNyUKCeqDkkyh3E S107K4hdNPoWSJauah7Pa+gWv6jfUkXLst8GnFRfDDhk5nIHRvbV1eCG0XV90BEim7MJ BkM9zLaKIlR0I4s8zEi5kPJ8LubpMXyNfoMgH6tcseV8O9QCU2zQZdeDCEh2AEDauC69 JMmOCeciWCkxPJn8NJZ9n5ZtUU1A9WrIOouYjuR+ocWJM2ox4D0bQqHzSjdt8ObdoYj4 0xUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject :organization:arc-authentication-results; bh=GsVt9s6PwDAT9dgRPUl0w+qlxzFdZumnhUFAph3+l5w=; b=M8u7seb6Xq/NWr1Yf1/04z9/7Sq3YAO+jP9UrapWrFf/K0SeeLFgTfcvJ3AdnlyyTB OABmpTVb0tHhxzA9zXdqxdwkTCgbBRi3VGWyLUea0N+bebw5w1OvAlxGVnc1uPGeHAKB RquLTvcWRqv6IZ35qQ0untXUM7dU59XlJXZauEXobcF6F3MfIuXOpzkyrfiWkyYZY8UI VQtAu3Z9FD65u8y8JQHbXF7rMIpWYueGsgP1Ib7iB27hNPIla/tfAW+JQ5tHXlA8entw HOSz+Juy8IH1ofsCjt48trNfOL6tpocaBy2mXSbuHTiKgr+8LQW6TzHz+ywPe7WcH2Wr t18g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t190si8743014pgt.745.2018.04.01.13.42.41; Sun, 01 Apr 2018 13:42:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754130AbeDAUlG (ORCPT + 99 others); Sun, 1 Apr 2018 16:41:06 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42124 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753951AbeDAUlE (ORCPT ); Sun, 1 Apr 2018 16:41:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42AB04023141 for ; Sun, 1 Apr 2018 20:41:04 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-59.rdu2.redhat.com [10.10.120.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7B06111CB9C; Sun, 1 Apr 2018 20:41:03 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 08/45] C++: Implement abs() as an inline template function From: David Howells To: linux-kernel@vger.kernel.org Date: Sun, 01 Apr 2018 21:41:03 +0100 Message-ID: <152261526342.30503.10484708592420310318.stgit@warthog.procyon.org.uk> In-Reply-To: <152261521484.30503.16131389653845029164.stgit@warthog.procyon.org.uk> References: <152261521484.30503.16131389653845029164.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 01 Apr 2018 20:41:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 01 Apr 2018 20:41:04 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement abs() as an C++ inline template function as that greatly simplifies the source. Signed-off-by: David Howells --- include/linux/kernel.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index e779a7487c34..59089f76c7d8 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -246,20 +246,11 @@ extern int _cond_resched(void); * * Return: an absolute value of x. */ -#define abs(x) __abs_choose_expr(x, long long, \ - __abs_choose_expr(x, long, \ - __abs_choose_expr(x, int, \ - __abs_choose_expr(x, short, \ - __abs_choose_expr(x, char, \ - __builtin_choose_expr( \ - __builtin_types_compatible_p(typeof(x), char), \ - (char)({ signed char __x = (x); __x<0?-__x:__x; }), \ - ((void)0))))))) - -#define __abs_choose_expr(x, type, other) __builtin_choose_expr( \ - __builtin_types_compatible_p(typeof(x), signed type) || \ - __builtin_types_compatible_p(typeof(x), unsigned type), \ - ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other) +template +static inline T abs(T v) +{ + return v < 0 ? -v : v; +} /** * reciprocal_scale - "scale" a value into range [0, ep_ro)