From owner-svn-src-head@freebsd.org Mon Jun 29 20:26:59 2020 Return-Path: Delivered-To: svn-src-head@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 93CFB354823 for ; Mon, 29 Jun 2020 20:26:59 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49wfD21pT3z4M1K for ; Mon, 29 Jun 2020 20:26:58 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qt1-x836.google.com with SMTP id z2so13931217qts.5 for ; Mon, 29 Jun 2020 13:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Rmy7dZwkTK1bYLQg/Pld80RFXvuLEQQ2YYkZrrodFn8=; b=ZHIL2eONoPmq4TfX5Vaa7hJrPvBe6+yWIPV4XEtrttGaMl+iell1kCI3ZBX8un2zlw fic3sLYOK87PbbAB9ak3G/WP0C0w/LyVhzgp5zLNNAgrbAyL8gBWjLvMrh7uG0JxW0e9 Y7EqBv2NywddRN9+WBJckFql7im/HfRwRO5ADr8OagMRTIuHHfn89e3TYizjA1WUmhlO U+uYogIDoUbH4OF4rNz/BRWywfn19L9zhgWRM7SHqiLNihhkOSLlcZckOb/GBPv2+JRx p42yj4jS0my1Q2PfaKJ1i7wEchHSk34UoOm8uX+P+vgxBtsoSC/aMHSXwVaCvP9KXWtm 70jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Rmy7dZwkTK1bYLQg/Pld80RFXvuLEQQ2YYkZrrodFn8=; b=U2WUsXul/pXoF9aOKmkV8TSKPUPVYjSdAd0rlzXvSwCoawql+jzJEerVs3K89QHSHI dIOvIH8/ociEmP15rLq9iEpfnCqWu3AIuTbsXxUTwPuMLvm0tFih82BACFJuwotcfQ87 fXASPqQGAZCGHa8+TSrtHwIrmVpA+oKeU0AvoljH63IpDDZQ7jWni20hYwPNgBxMlwGV w275EUMOcBA1IIEEph4WcMW6sLO0aNh1osnm11ioNH+gJTq3Ft9C2hI0TultNbaEnlSL h0bbDlo+Ia9A+54zg1niKhk9qiX1hw59cscHNOIDieLxn6jH1clbpUOSlDqLOvqyeGLO 044w== X-Gm-Message-State: AOAM530YQTcOC/lXVoLbN7avPHHWBhGCmwnqBrT7i0NwH0KABUH6xuse VMdkaWJX+eHe9IAdZkk0QIMwwuO8RmzaGwiVxUWwUGDC998= X-Google-Smtp-Source: ABdhPJzlKKyNgHS/3h3L04hLNrqYilp5a1tRIdf0toT+hWVGxP9sqLOVxAugC6llE5QNDrsfKu0QNc5gKK8r5yiuL50= X-Received: by 2002:ac8:34e8:: with SMTP id x37mr18184850qtb.291.1593462417047; Mon, 29 Jun 2020 13:26:57 -0700 (PDT) MIME-Version: 1.0 References: <202006291308.05TD8eTP014019@repo.freebsd.org> In-Reply-To: From: Warner Losh Date: Mon, 29 Jun 2020 14:26:45 -0600 Message-ID: Subject: Re: svn commit: r362781 - head/sys/compat/linuxkpi/common/include/linux To: Ravi Pokala Cc: Hans Petter Selasky , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org X-Rspamd-Queue-Id: 49wfD21pT3z4M1K X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=bsdimp-com.20150623.gappssmtp.com header.s=20150623 header.b=ZHIL2eON; dmarc=none; spf=none (mx1.freebsd.org: domain of wlosh@bsdimp.com has no SPF policy when checking 2607:f8b0:4864:20::836) smtp.mailfrom=wlosh@bsdimp.com X-Spamd-Result: default: False [-2.64 / 15.00]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20150623.gappssmtp.com:s=20150623]; NEURAL_HAM_MEDIUM(-0.97)[-0.970]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-0.99)[-0.995]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[svn-src-head@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; RCPT_COUNT_FIVE(0.00)[5]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[bsdimp-com.20150623.gappssmtp.com:+]; NEURAL_HAM_SHORT(-0.67)[-0.671]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::836:from]; R_SPF_NA(0.00)[no SPF record]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[imp@bsdimp.com,wlosh@bsdimp.com] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.33 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2020 20:26:59 -0000 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? 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_ */ > > >