From nobody Wed Jul 5 15:38:50 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 4Qx3jQ5fW5z4lLgL; Wed, 5 Jul 2023 15:38:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Qx3jQ54lDz4B7f; Wed, 5 Jul 2023 15:38:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688571530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aOUUSPwvV2eT2GWR3QX6liUaKQH4WDANAQ1h5Zf/BF8=; b=hqRcORsWqw0CyQp9QZCF9QPjWwVFkJ8J6ANUWUPBFOyyPRDkLOJGaXILZJIRAQnOK9Jpw4 WCHjNClyhEzQhegsPNTPTF2Tt3yhGr/k8xWGnkQd1wK/gfzJrFYRqj5CQDXQ/ARh1BxWdT V2yG8lYUppsoQbg0bgrvMCCoMLX3qdWVuHbFNjhPQQDZRIkwGZiGIOyeSMdr2sdpw5Kwbu 5GmISQoUq6H0jng5w782OtJCdnBbbnL43T0TKx0Bm0Nq73ImzOEGD/c+TyB57l8JnW8MlX li+y5xG2v0IbPKwWualciOE1BtrbHOMzNAfG4cLho4S/aJ8EJSNxmdXgLDIkfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688571530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aOUUSPwvV2eT2GWR3QX6liUaKQH4WDANAQ1h5Zf/BF8=; b=kYdPcu3x5DiQfSxQMGD2hI03IicyzSBvBi0Q5CAAokG/qp3YuG3dk+EHdVaMrScQ4zRaIP G+5T+tF9/CvwP2WWtHQ1IdeYE+AMyScNnKSK1Ey/ZiziAMRNNoIM6PPJZNlKAMgWw8w45Z AnxAa6YZ7kNNoARZrG/5NbXq5mk5R7nLjzYAQzsppq3ujpWTpftqrZEX7Q+LzmCgtlQsma UTBXscBljT8YZXWI0MYIrPC9zWPjwLUZwbv+7eyF05ijzf5yOlwlH9lqgveO+7HJcyaTLQ DH2gQh/mYWKznYfpp1X7EC1aX+9n7CKCz/o4oUvzOOOEjzzPw2ADCzrXEcdKFQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688571530; a=rsa-sha256; cv=none; b=WeispA7S2lCLR37KBxklW9839Rglgth8Rr4ij+7xD5lRtLqvKVfUDKLje1ByAmuDgxozPe RRjkyJmoaTAa9Ghm/jslTjqdsxZkbhYCaJVlQqw+z61iHRVKyalJA5+YVbmNXjAj3zZliH dPdZusbcWRUUT9scTxS+dKG1OWtbP/4YxtmpzWqUXpYQpjwbFwGQY+lPDhK/JmrkUC2V0O PKURXYZRJ+o/FYBQ7oM9BhDXS7FUUPuCuG0ClITo4/o3neQtiV95GGChTrKh919+/6SYAv KrnYpyg1TAanbY7CuDybXBlFeFA32dVUBj1YYlXib739s+WCDO7eJPNyvUKJfg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Qx3jQ49PFzL6H; Wed, 5 Jul 2023 15:38:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 365FcoHP017984; Wed, 5 Jul 2023 15:38:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 365FcoZR017983; Wed, 5 Jul 2023 15:38:50 GMT (envelope-from git) Date: Wed, 5 Jul 2023 15:38:50 GMT Message-Id: <202307051538.365FcoZR017983@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: cebb8646c4ee - main - Support byte-sized enums 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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cebb8646c4ee559aedcbc1b27bf30faa70a1f716 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=cebb8646c4ee559aedcbc1b27bf30faa70a1f716 commit cebb8646c4ee559aedcbc1b27bf30faa70a1f716 Author: Mateusz Guzik AuthorDate: 2023-03-12 19:29:20 +0000 Commit: Mateusz Guzik CommitDate: 2023-07-05 14:46:30 +0000 Support byte-sized enums To that end add __enum_uint8_decl and __enum_uint8. By default enums take 4 bytes, but vast majority of them have values which would fit in a byte. One can try to workaround the problem by using bitfields, like so: enum some_small_enum foo:8; 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). Both gcc 13 and clang support specifying the size, and for older variants one can fallback to the "packed" attribute. Names are mangled in order to avoid mix use with plain enum. Reviewed by: Differential Revision: https://reviews.freebsd.org/D39031 --- sys/sys/types.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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)); } +#if (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 13)) +#define __enum_uint8_decl(name) enum enum_ ## name ## _uint8 : uint8_t +#define __enum_uint8(name) enum enum_ ## name ## _uint8 +#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