From patchwork Fri Sep 27 01:44:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 51896 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp862519vqb; Sat, 28 Sep 2024 01:11:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUwrsQTrep739ozkwjF3vcYuoJyoopteYs6RzGMTO3vD8Gpe6xJFTq0Inyj5pEKzyxCaUKW0LXFn/gc1jq7olpJ@gmail.com X-Google-Smtp-Source: AGHT+IH48o74ym1X+mRu+mA7OvvFetkk09dpStxltsIwsz7ft6FnvPVAcm9qrr9abtDD7k6Y0WDY X-Received: by 2002:a17:906:c10a:b0:a90:c411:24f8 with SMTP id a640c23a62f3a-a93c48e7ff6mr587560566b.2.1727511074680; Sat, 28 Sep 2024 01:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727511074; cv=none; d=google.com; s=arc-20240605; b=h5lAV2SmqsjbF6jchTAzhcUoQgY1FBk52wr6GsO8RfvmhV4X6FiQcRExeM+ygLGJw/ Bh317SvMddR7nR8a9kXe2HAd3kxcGani+dVGSn6jmEkT8vqc64O162xroAVHfND9PKoZ esvQa4D7geP0eCgWJ0xxWxyk8/rIWViLaRgImHpIjaDTUS7k2s5wYiCaPO7VilNRz5iU Z0jt8mwLfuX56R071j2HYXkEmAqju6I4U7dwNXYghas5m4QTNMoFKXQtht3bDmcH/A+O JE2rhwdxKIzfMf81NVGi6RKJzu4ptGm/CxzGGkn+nWWEL7HFl+oEw0NcM8cg/gf3BtoD JMDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=kHZQiYEL3B5FgaAmq8AQ7P8xKnTqoMEJz8aEMy2M/0s=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=dhUidpJdsI+q0xt9XMjg47NEpFP5Li91K0EJxPlAZqfG2RBZWo5PSN4g4C7TlOgDiJ 825ADjPxRpStJDjwvbU7Ch3VnXphEoUmakP813UqePFgg+jr+dayIDFMMrSyLf3Kil78 wFXYrfnGo+6CA8uyyWFA57ULkruKR6ghPakrDGr6uH0v/w8r07+ui14ZpX5Ydhe/MSdk VoxW8p1G+SGZu4KJ2osyx12ARLkL3Zsac4Cwg6HwWVxUVGIGqp41IHL6ZWD9SZO8GARg qtScId9mmH4O8SjyelV5gOeKmqn6G5qvCSqlQCHOKt9VznDWdcSUK3/bII5QwMhBLwvm 0FkQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="RpZz4/lC"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a93c2aa8d5dsi279000166b.1045.2024.09.28.01.11.14; Sat, 28 Sep 2024 01:11:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="RpZz4/lC"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C08368DA91; Fri, 27 Sep 2024 04:44:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AAD1568DA33 for ; Fri, 27 Sep 2024 04:44:18 +0300 (EEST) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-71b8d10e990so85543b3a.3 for ; Thu, 26 Sep 2024 18:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727401456; x=1728006256; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=2fUyhX54YWTs6o8pkrXKg9ZA4qdn9+h6S7NXbvkYs7k=; b=RpZz4/lCQyE/pPL3Tbr33zh3E6uX/9QODGNvNCP+twOMGRW81Qk6/OnpUcu8adgEYK oa7HWyian1dRtbrwzIGZgyXS10e2KI56nl1HpiSAf4oWEUg4k7Xw2pSFX716OhaPGiNo wacsYl+X0FjUSpznoGru73aZBY8S3Ag/UK+RScemoWu/dbm+sdzcUJscnrSAtL0wfsqT YO8PJkkWxBumPbWgPrhdZO9RAejBNsrFOgcwZ/ocQgw41+54YaJunxxEjCYB8kLJ+epQ cue0vVCglOBdcBa8Ce7ZTDGWCX7DGRt3nXPPMpHR70Q96844APopFmu9AZfsUOHM9HZD Ajog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727401456; x=1728006256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2fUyhX54YWTs6o8pkrXKg9ZA4qdn9+h6S7NXbvkYs7k=; b=VR6JeobJpxIEGpHEMIe4NdS2exX2N9PZgYJVor1djmzAYGQ2y87HTbFE3DtJEEjFIS sUnw5oNJsDDOZ0DA2EQvGmBpzL9bI1EvaSBFFNrhGWL1jnBWFNe6X5lYvZKle04MnVzd nTZ7K0iqwc6vCReniMcJJpkl1T7aGvIUHX/E+gEUyCk1XXVoDZwgVTp6CnnwN7CeuNF2 CaZ+kZ7vox5LP+H3aw3YHhoVawhlfOtp8GnbY5mRiuRkjlNedT1QRa+K3TNDRqpe7l8q /EPFqoSJVGQu0Mrnd7AD13Q3OcnBeApbMtpNnjGLyeyoPQ1YunT+Fij02P7vPo5P1KTI Q6yQ== X-Gm-Message-State: AOJu0YxVXqiBgbOisBIEMvI8IffRSGL5uZWSLP5HQkiV5qh/8p4ORnZo hVB+PHTrXk05BPHwbjlF988M7eViYk/fdI4PlOuJY3Twve3BHNjLFq4nFA== X-Received: by 2002:a05:6a00:b43:b0:70a:fb91:66d7 with SMTP id d2e1a72fcca58-71b2604609emr2276452b3a.20.1727401455755; Thu, 26 Sep 2024 18:44:15 -0700 (PDT) Received: from localhost.localdomain ([181.92.233.116]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b2649c6a1sm541928b3a.44.2024.09.26.18.44.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 18:44:14 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 26 Sep 2024 22:44:33 -0300 Message-ID: <20240927014436.15622-2-jamrial@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240927014436.15622-1-jamrial@gmail.com> References: <20240927014436.15622-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] compat/stdckdint: remove C++ version and the non checked generic fallback X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4cLXVSdJD4Ed We only want these to be available for C source files. additionally, the generic fallback exists for non-C11 compilers, which we no longer support. Signed-off-by: James Almer --- compat/stdckdint/stdckdint.h | 270 +---------------------------------- 1 file changed, 1 insertion(+), 269 deletions(-) diff --git a/compat/stdckdint/stdckdint.h b/compat/stdckdint/stdckdint.h index 2d36e8ad89..d5fda2fee6 100644 --- a/compat/stdckdint/stdckdint.h +++ b/compat/stdckdint/stdckdint.h @@ -99,270 +99,6 @@ typedef unsigned __ckd_intmax __ckd_uintmax_t; #define ckd_sub(res, x, y) __builtin_sub_overflow((x), (y), (res)) #define ckd_mul(res, x, y) __builtin_mul_overflow((x), (y), (res)) -#elif (defined(__cplusplus) && \ - (__cplusplus >= 201103L || \ - (defined(_MSC_VER) && __cplusplus >= 199711L && \ - __ckd_has_include() && \ - __ckd_has_include()))) -#include -#include - -template -inline bool ckd_add(__T *__res, __U __a, __V __b) { - static_assert(std::is_integral<__T>::value && - std::is_integral<__U>::value && - std::is_integral<__V>::value, - "non-integral types not allowed"); - static_assert(!std::is_same<__T, bool>::value && - !std::is_same<__U, bool>::value && - !std::is_same<__V, bool>::value, - "checked booleans not supported"); - static_assert(!std::is_same<__T, char>::value && - !std::is_same<__U, char>::value && - !std::is_same<__V, char>::value, - "unqualified char type is ambiguous"); - __ckd_uintmax_t __x = __a; - __ckd_uintmax_t __y = __b; - __ckd_uintmax_t __z = __x + __y; - *__res = __z; - if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) { - if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) { - return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z); - } else if (!std::is_same<__T, __ckd_uintmax_t>::value) { - return (__z != static_cast<__T>(__z) || - ((std::is_signed<__U>::value || - std::is_signed<__V>::value) && - static_cast<__ckd_intmax_t>(__z) < 0)); - } - } - bool __truncated = false; - if (sizeof(__T) < sizeof(__ckd_intmax_t)) { - __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z)); - } - switch (std::is_signed<__T>::value << 2 | // - std::is_signed<__U>::value << 1 | // - std::is_signed<__V>::value) { - case 0: // u = u + u - return __truncated | (__z < __x); - case 1: // u = u + s - __y ^= std::numeric_limits<__ckd_intmax_t>::min(); - return __truncated | - (static_cast<__ckd_intmax_t>((__z ^ __x) & - (__z ^ __y)) < 0); - case 2: // u = s + u - __x ^= std::numeric_limits<__ckd_intmax_t>::min(); - return __truncated | - (static_cast<__ckd_intmax_t>((__z ^ __x) & - (__z ^ __y)) < 0); - case 3: // u = s + s - return __truncated | - (static_cast<__ckd_intmax_t>(((__z | __x) & __y) | - ((__z & __x) & ~__y)) < 0); - case 4: // s = u + u - return __truncated | (__z < __x) | (static_cast<__ckd_intmax_t>(__z) < 0); - case 5: // s = u + s - __y ^= std::numeric_limits<__ckd_intmax_t>::min(); - return __truncated | (__x + __y < __y); - case 6: // s = s + u - __x ^= std::numeric_limits<__ckd_intmax_t>::min(); - return __truncated | (__x + __y < __x); - case 7: // s = s + s - return __truncated | - (static_cast<__ckd_intmax_t>((__z ^ __x) & - (__z ^ __y)) < 0); - default: - for (;;) (void)0; - } -} - -template -inline bool ckd_sub(__T *__res, __U __a, __V __b) { - static_assert(std::is_integral<__T>::value && - std::is_integral<__U>::value && - std::is_integral<__V>::value, - "non-integral types not allowed"); - static_assert(!std::is_same<__T, bool>::value && - !std::is_same<__U, bool>::value && - !std::is_same<__V, bool>::value, - "checked booleans not supported"); - static_assert(!std::is_same<__T, char>::value && - !std::is_same<__U, char>::value && - !std::is_same<__V, char>::value, - "unqualified char type is ambiguous"); - __ckd_uintmax_t __x = __a; - __ckd_uintmax_t __y = __b; - __ckd_uintmax_t __z = __x - __y; - *__res = __z; - if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) { - if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) { - return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z); - } else if (!std::is_same<__T, __ckd_uintmax_t>::value) { - return (__z != static_cast<__T>(__z) || - ((std::is_signed<__U>::value || - std::is_signed<__V>::value) && - static_cast<__ckd_intmax_t>(__z) < 0)); - } - } - bool __truncated = false; - if (sizeof(__T) < sizeof(__ckd_intmax_t)) { - __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z)); - } - switch (std::is_signed<__T>::value << 2 | // - std::is_signed<__U>::value << 1 | // - std::is_signed<__V>::value) { - case 0: // u = u - u - return __truncated | (__x < __y); - case 1: // u = u - s - __y ^= std::numeric_limits<__ckd_intmax_t>::min(); - return __truncated | - (static_cast<__ckd_intmax_t>((__x ^ __y) & - (__z ^ __x)) < 0); - case 2: // u = s - u - return __truncated | (__y > __x) | (static_cast<__ckd_intmax_t>(__x) < 0); - case 3: // u = s - s - return __truncated | - (static_cast<__ckd_intmax_t>(((__z & __x) & __y) | - ((__z | __x) & ~__y)) < 0); - case 4: // s = u - u - return __truncated | - ((__x < __y) ^ (static_cast<__ckd_intmax_t>(__z) < 0)); - case 5: // s = u - s - __y ^= std::numeric_limits<__ckd_intmax_t>::min(); - return __truncated | (__x >= __y); - case 6: // s = s - u - __x ^= std::numeric_limits<__ckd_intmax_t>::min(); - return __truncated | (__x < __y); - case 7: // s = s - s - return __truncated | - (static_cast<__ckd_intmax_t>((__x ^ __y) & - (__z ^ __x)) < 0); - default: - for (;;) (void)0; - } -} - -template -inline bool ckd_mul(__T *__res, __U __a, __V __b) { - static_assert(std::is_integral<__T>::value && - std::is_integral<__U>::value && - std::is_integral<__V>::value, - "non-integral types not allowed"); - static_assert(!std::is_same<__T, bool>::value && - !std::is_same<__U, bool>::value && - !std::is_same<__V, bool>::value, - "checked booleans not supported"); - static_assert(!std::is_same<__T, char>::value && - !std::is_same<__U, char>::value && - !std::is_same<__V, char>::value, - "unqualified char type is ambiguous"); - __ckd_uintmax_t __x = __a; - __ckd_uintmax_t __y = __b; - if ((sizeof(__U) * 8 - std::is_signed<__U>::value) + - (sizeof(__V) * 8 - std::is_signed<__V>::value) <= - (sizeof(__T) * 8 - std::is_signed<__T>::value)) { - if (sizeof(__ckd_uintmax_t) > sizeof(__T) || std::is_signed<__T>::value) { - __ckd_intmax_t __z = __x * __y; - return __z != (*__res = __z); - } else if (!std::is_same<__T, __ckd_uintmax_t>::value) { - __ckd_uintmax_t __z = __x * __y; - *__res = __z; - return (__z != static_cast<__T>(__z) || - ((std::is_signed<__U>::value || - std::is_signed<__V>::value) && - static_cast<__ckd_intmax_t>(__z) < 0)); - } - } - switch (std::is_signed<__T>::value << 2 | // - std::is_signed<__U>::value << 1 | // - std::is_signed<__V>::value) { - case 0: { // u = u * u - __ckd_uintmax_t __z = __x * __y; - int __o = __x && __z / __x != __y; - *__res = __z; - return __o | (sizeof(__T) < sizeof(__z) && - __z != static_cast<__ckd_uintmax_t>(*__res)); - } - case 1: { // u = u * s - __ckd_uintmax_t __z = __x * __y; - int __o = __x && __z / __x != __y; - *__res = __z; - return (__o | ((static_cast<__ckd_intmax_t>(__y) < 0) & !!__x) | - (sizeof(__T) < sizeof(__z) && - __z != static_cast<__ckd_uintmax_t>(*__res))); - } - case 2: { // u = s * u - __ckd_uintmax_t __z = __x * __y; - int __o = __x && __z / __x != __y; - *__res = __z; - return (__o | ((static_cast<__ckd_intmax_t>(__x) < 0) & !!__y) | - (sizeof(__T) < sizeof(__z) && - __z != static_cast<__ckd_uintmax_t>(*__res))); - } - case 3: { // u = s * s - int __o = false; - if (static_cast<__ckd_intmax_t>(__x & __y) < 0) { - __x = -__x; - __y = -__y; - } else if (static_cast<__ckd_intmax_t>(__x ^ __y) < 0) { - __o = __x && __y; - } - __ckd_uintmax_t __z = __x * __y; - __o |= __x && __z / __x != __y; - *__res = __z; - return __o | (sizeof(__T) < sizeof(__z) && - __z != static_cast<__ckd_uintmax_t>(*__res)); - } - case 4: { // s = u * u - __ckd_uintmax_t __z = __x * __y; - int __o = __x && __z / __x != __y; - *__res = __z; - return (__o | (static_cast<__ckd_intmax_t>(__z) < 0) | - (sizeof(__T) < sizeof(__z) && - __z != static_cast<__ckd_uintmax_t>(*__res))); - } - case 5: { // s = u * s - __ckd_uintmax_t __t = -__y; - __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __y : __t; - __ckd_uintmax_t __p = __t * __x; - int __o = __t && __p / __t != __x; - int __n = static_cast<__ckd_intmax_t>(__y) < 0; - __ckd_uintmax_t __z = __n ? -__p : __p; - *__res = __z; - __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max(); - return (__o | (__p > __m + __n) | - (sizeof(__T) < sizeof(__z) && - __z != static_cast<__ckd_uintmax_t>(*__res))); - } - case 6: { // s = s * u - __ckd_uintmax_t __t = -__x; - __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __x : __t; - __ckd_uintmax_t __p = __t * __y; - int __o = __t && __p / __t != __y; - int __n = static_cast<__ckd_intmax_t>(__x) < 0; - __ckd_uintmax_t __z = __n ? -__p : __p; - *__res = __z; - __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max(); - return (__o | (__p > __m + __n) | - (sizeof(__T) < sizeof(__z) && - __z != static_cast<__ckd_uintmax_t>(*__res))); - } - case 7: { // s = s * s - __ckd_uintmax_t __z = __x * __y; - *__res = __z; - return ((((static_cast<__ckd_intmax_t>(__y) < 0) && - (static_cast<__ckd_intmax_t>(__x) == - std::numeric_limits<__ckd_intmax_t>::min())) || - (__y && ((static_cast<__ckd_intmax_t>(__z) / - static_cast<__ckd_intmax_t>(__y)) != - static_cast<__ckd_intmax_t>(__x)))) | - (sizeof(__T) < sizeof(__z) && - __z != static_cast<__ckd_uintmax_t>(*__res))); - } - default: - for (;;) (void)0; - } -} - #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L #define ckd_add(res, a, b) __ckd_expr(add, (res), (a), (b)) @@ -652,11 +388,7 @@ __ckd_declare_mul(__ckd_mul_uint128, unsigned __int128) #endif #else -#pragma message "checked integer arithmetic unsupported in this environment" - -#define ckd_add(res, x, y) (*(res) = (x) + (y), 0) -#define ckd_sub(res, x, y) (*(res) = (x) - (y), 0) -#define ckd_mul(res, x, y) (*(res) = (x) * (y), 0) +# error Not implemented. #endif /* GNU */ #endif /* stdckdint.h */