From owner-svn-src-all@freebsd.org Mon Jun 29 20:32:31 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6F081354E0C for ; Mon, 29 Jun 2020 20:32:31 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound2k.ore.mailhop.org (outbound2k.ore.mailhop.org [54.148.219.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 49wfLR15q2z4Mpm for ; Mon, 29 Jun 2020 20:32:30 +0000 (UTC) (envelope-from ian@freebsd.org) ARC-Seal: i=1; a=rsa-sha256; t=1593462749; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=kQGK021NYgzVKtbDaycNEgCT7+YWzHQjc+mGzJo7L2mLR4f8qqQbfOMOmCEI1/BKaxeQ6GlHsNFYW QAogdY6vrNeCu7uiBkuZJFRnDCaQMWUxO8Hv91nZdNxaVk7Ghp50PQZggTucy6iH6zoZZGyAobwJhK rOi/V7nMAbMuHUsJ3JRH16fPJSLe5Pdxc+GLRaYWu+ulG9hiyNVWRWBSkYp5QX+kqUycKgJ1im8kNy y66DJHVdl70b+OYnisul0Y8ee4rwOBClc0mMDAvJ5+UMtU4gavDl5ibIXew0JbPwiwX8aK2JrGeX+Y rr+LaXSntW+p1kUDGzFpkCiTcJng6BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:cc:to:from:subject:message-id:dkim-signature:from; bh=edzlQBa0SjdUnmITYOE26dMd8XfwDac11RHPxZ1jW/Q=; b=r4o9ykDWlnqld1vIBkchcK4vQkiveFRCKAsHE+2xNXx9XOtroh0gO7NNNC+qqgJHYowg75ijpACUO ysFCqz8XTgET8PnxF0iZPMGLlwlY7eWd8Os0c6KIO4ky22EZLSMooNs7O8v5r5Fg96XIDYx8/pXFO9 iep89xrcvNwZvIOUbi7A/AADWRGXy7Q06XBb4GVp9Pw3+s1KmABEtbKPNCzeUX+jXJ5clGjAuVbrN0 KIFeJ2qb0FV2J7zYUubs/fh+whAquOVrHXwCzW4/Ce2+ZqBq3JPRswgC6z91JwcM5ogFOcF0v9Hkxr x3WG3jINAJudwDCZDu5MBwR9Zi5GaTA== ARC-Authentication-Results: i=1; outbound4.ore.mailhop.org; spf=softfail smtp.mailfrom=freebsd.org smtp.remote-ip=67.177.211.60; dmarc=none header.from=freebsd.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:cc:to:from:subject:message-id:from; bh=edzlQBa0SjdUnmITYOE26dMd8XfwDac11RHPxZ1jW/Q=; b=hv9mh6sQF8LIkhIhVJp/hDuR+b63G0HJIf4vDmOtJiifv1JMDZpRnIWRIayIZOYJRtlFGsIbXzBvW 65Uxomud4BpELP08GjQQcCfEA6bdxC4Z4HSoe64wMNSYfZJnFuqjgUeBBKR2gFAr+MUhQeNx3bf8or hH0I/v7umPNqkqLLFK3Yj/hreJbSmVBzaEEqOsfJukxdlZHQghtkH6Gn64V5P9eJhh1VwHfp1vKS13 LgQJWFLLwk87AnilbiBDrfAVk87PiEGsIvdjyQAhkczxQ5h0RFXTdN/A+/0jfTdXqlazGcKiVJU+j8 JAvHWsw5tpyUnmkn3ja0Pq595gkqidw== X-MHO-RoutePath: aGlwcGll X-MHO-User: a5703780-ba47-11ea-b630-6b8aa7872eb8 X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 67.177.211.60 X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (c-67-177-211-60.hsd1.co.comcast.net [67.177.211.60]) by outbound4.ore.mailhop.org (Halon) with ESMTPSA id a5703780-ba47-11ea-b630-6b8aa7872eb8; Mon, 29 Jun 2020 20:32:28 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id 05TKWQb1085970; Mon, 29 Jun 2020 14:32:26 -0600 (MDT) (envelope-from ian@freebsd.org) Message-ID: <24a300c54e94be8e6915c588a25a641ca0620200.camel@freebsd.org> Subject: Re: svn commit: r362781 - head/sys/compat/linuxkpi/common/include/linux From: Ian Lepore To: Warner Losh , Ravi Pokala Cc: Hans Petter Selasky , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Date: Mon, 29 Jun 2020 14:32:26 -0600 In-Reply-To: References: <202006291308.05TD8eTP014019@repo.freebsd.org> Content-Type: text/plain; charset="ASCII" X-Mailer: Evolution 3.28.5 FreeBSD GNOME Team Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 49wfLR15q2z4Mpm X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [0.00 / 15.00]; local_wl_from(0.00)[freebsd.org]; ASN(0.00)[asn:16509, ipnet:54.148.0.0/15, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2020 20:32:31 -0000 On Mon, 2020-06-29 at 14:26 -0600, Warner Losh wrote: > On Mon, Jun 29, 2020, 2:15 PM Ravi Pokala > wrote: > > > -----Original Message----- > > From: on behalf of Hans Petter > > Selasky > > > > Date: 2020-06-29, Monday at 06:08 > > To: , , < > > svn-src-head@freebsd.org> > > Subject: svn commit: r362781 - > > head/sys/compat/linuxkpi/common/include/linux > > > > Author: hselasky > > Date: Mon Jun 29 13:08:40 2020 > > New Revision: 362781 > > URL: https://svnweb.freebsd.org/changeset/base/362781 > > > > Log: > > Implement is_signed(), type_max() and type_min() function > > macros in > > the > > LinuxKPI. > > > > MFC after: 1 week > > Sponsored by: Mellanox Technologies > > > > Modified: > > head/sys/compat/linuxkpi/common/include/linux/kernel.h > > > > Modified: > > head/sys/compat/linuxkpi/common/include/linux/kernel.h > > > > =================================================================== > > =========== > > --- head/sys/compat/linuxkpi/common/include/linux/kernel.h Mon > > Jun 29 > > 12:59:09 2020 (r362780) > > +++ head/sys/compat/linuxkpi/common/include/linux/kernel.h Mon > > Jun 29 > > 13:08:40 2020 (r362781) > > @@ -564,4 +564,20 @@ linux_ratelimited(linux_ratelimit_t *rl) > > #define __is_constexpr(x) \ > > __builtin_constant_p(x) > > > > Hi Hans, > > > > +#define is_signed(x) (((x)-1 / (x)2) == (x)0) > > > > It took me several reads to understand this, until I figured out > > that 'x' > > is not a variable, it's the name of a *type*. > > > > If 'x' is a variable, then '(x)-1' is subtraction, but '(x)2' and > > '(x)0' > > are nonsensical. > > > > If 'x' is a *type*, then '(x)-1' is typecasting '-1', and similarly > > for > > '(x)2' and '(x)0'. > > > > So, perhaps a comment, or a better name for 'x'? > > > > I had similar thoughts. Maybe 't' instead? > Or maybe since there's no one-character restriction on macro variable names, something actually descriptive like 'datatype'. -- Ian > Warner > > Thanks, > > > > Ravi (rpokala@) > > > > +#define type_max(x) ( > > \ > > + (sizeof(x) >= 8) ? (is_signed(x) ? INT64_MAX : UINT64_MAX) > > : \ > > + (sizeof(x) >= 4) ? (is_signed(x) ? INT32_MAX : UINT32_MAX) > > : \ > > + (sizeof(x) >= 2) ? (is_signed(x) ? INT16_MAX : UINT16_MAX) > > : \ > > + (is_signed(x) ? INT8_MAX : UINT8_MAX) \ > > +) > > + > > +#define type_min(x) > > ( \ > > + (sizeof(x) >= 8) ? (is_signed(x) ? INT64_MIN : 0) : \ > > + (sizeof(x) >= 4) ? (is_signed(x) ? INT32_MIN : 0) : \ > > + (sizeof(x) >= 2) ? (is_signed(x) ? INT16_MIN : 0) : \ > > + (is_signed(x) ? INT8_MIN : 0) \ > > +) > > + > > #endif /* _LINUX_KERNEL_H_ */ > > > > > >