From nobody Wed Jul 5 15:42:14 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Qx3nc1hWyz4lMdy for ; Wed, 5 Jul 2023 15:42:28 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Qx3nb3x1Qz4DXM for ; Wed, 5 Jul 2023 15:42:27 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-313e742a787so828210f8f.1 for ; Wed, 05 Jul 2023 08:42:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688571745; x=1691163745; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4YXqLWdK9bTo/MafNo+Az/k/SN1YFvgrZuAd9Rhc4kw=; b=kP51NBNaPEfew8GuMpc6N8sL2Cv4LdaQJgf4YtbjIaEm7iftMQ2ySKMUZKPvHeZ2Db Q4KhzPbwwUSGIjx3z8Xgza58i0h3Iql4kpgPTt92UTAw8ksyym6e9erdM0IxchPU4Yt+ FIPbNxXOpVdUKCcx/P71yIg/DbjjLkSH0nDaDsEW2k0ic5YSvDf2FT1oT/AsyHO1U/EK pYftGNgV3IBpQMSZ9GhTZVfIBrb97RHf7SEB0yLiQ27go8JYPjVDHEskWQvY1y7ZZ53M er42tPWVJxxKntlQFExy7yD+dvbbfE1WYPWy1H6+9RTk/FRfrispuobmoeDrEdYbh3ur jqfQ== X-Gm-Message-State: ABy/qLYI+O8cTH7ah0OFMjtuoYh05yCGNykJ4rypIFxJGirSjnqidXKE 9oqlUR4z3KjeJJjt06yLNqF60GmITUvw8zEgUMRMLw== X-Google-Smtp-Source: APBJJlG+wP8QnVZ0h0QpUHPh1Yvxb0Q99XD9vA73LtSVJ6wzcteBWSi4R7VBS9VBkGVsga9ZbneNAQ== X-Received: by 2002:adf:ed02:0:b0:306:3352:5b8c with SMTP id a2-20020adfed02000000b0030633525b8cmr2793889wro.7.1688571745325; Wed, 05 Jul 2023 08:42:25 -0700 (PDT) Received: from smtpclient.apple ([131.111.5.246]) by smtp.gmail.com with ESMTPSA id m6-20020adffa06000000b00314417f5272sm4326669wrr.64.2023.07.05.08.42.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jul 2023 08:42:24 -0700 (PDT) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: Re: git: cebb8646c4ee - main - Support byte-sized enums From: Jessica Clarke In-Reply-To: <202307051538.365FcoZR017983@gitrepo.freebsd.org> Date: Wed, 5 Jul 2023 16:42:14 +0100 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <0AD6BA4D-E6B1-4C56-B7B7-A85D57188A34@freebsd.org> References: <202307051538.365FcoZR017983@gitrepo.freebsd.org> To: Mateusz Guzik X-Mailer: Apple Mail (2.3731.600.7) X-Rspamd-Queue-Id: 4Qx3nb3x1Qz4DXM X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 5 Jul 2023, at 16:38, Mateusz Guzik wrote: >=20 > The branch main has been updated by mjg: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3Dcebb8646c4ee559aedcbc1b27bf30faa= 70a1f716 >=20 > commit cebb8646c4ee559aedcbc1b27bf30faa70a1f716 > Author: Mateusz Guzik > AuthorDate: 2023-03-12 19:29:20 +0000 > Commit: Mateusz Guzik > CommitDate: 2023-07-05 14:46:30 +0000 >=20 > Support byte-sized enums >=20 > To that end add __enum_uint8_decl and __enum_uint8. >=20 > By default enums take 4 bytes, but vast majority of them have = values > which would fit in a byte. >=20 > One can try to workaround the problem by using bitfields, like so: > enum some_small_enum foo:8; >=20 > but that's ugly and runs into trouble when using atomic_load (you = can't > take an address of a bitfield, even if it is sized to a multiply of = a > byte). >=20 > Both gcc 13 and clang support specifying the size, and for older > variants one can fallback to the "packed" attribute. >=20 > Names are mangled in order to avoid mix use with plain enum. >=20 > Reviewed by: > Differential Revision: https://reviews.freebsd.org/D39031 > --- > sys/sys/types.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) >=20 > diff --git a/sys/sys/types.h b/sys/sys/types.h > index 0846f2a57670..c6f7abe1f524 100644 > --- a/sys/sys/types.h > +++ b/sys/sys/types.h > @@ -347,6 +347,18 @@ __makedev(int _Major, int _Minor) > ((dev_t)(_Minor & 0xff00) << 24) | (_Minor & 0xffff00ff)); > } >=20 > +#if (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >=3D 13)) > +#define __enum_uint8_decl(name) enum enum_ ## name ## _uint8 : = uint8_t > +#define __enum_uint8(name) enum enum_ ## name ## _uint8 What happened to zlei@=E2=80=99s feedback about making it so = __enum_uint8 isn=E2=80=99t needed everywhere? Jess > +#else > +/* > + * Note: there is no real size checking here, but the code below can = be > + * removed once we require GCC 13. > + */ > +#define __enum_uint8_decl(name) enum __attribute__((packed)) enum_ ## = name ## _uint8 > +#define __enum_uint8(name) enum __attribute__((packed)) enum_ ## name = ## _uint8 > +#endif > + > /* > * These declarations belong elsewhere, but are repeated here and in > * to give broken programs a better chance of working with