From patchwork Mon Apr 28 17:03:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 885481 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp5289543wrs; Mon, 28 Apr 2025 10:05:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUajryZe0YL/eWs6NYeQVh26iTDGB42ne4LqK1pnrPksbkEpN6el/KLnpWm6JWiZtMqY+m2WQ==@linaro.org X-Google-Smtp-Source: AGHT+IHHXE0QXbWDe2Qk1OI+ndeIjh5A0BaY4CK23ruh/Fr6jISDRv3x6J94sKfIeuhV9W9pi24z X-Received: by 2002:a05:600c:1c05:b0:43d:1b95:6d0e with SMTP id 5b1f17b1804b1-441ac88c26amr675095e9.23.1745859927944; Mon, 28 Apr 2025 10:05:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1745859927; cv=pass; d=google.com; s=arc-20240605; b=S8JWKXahF6oV+TNX54Z/2PwbTvZlJS48g9rUM0Zgm6MVECSRd2NOHJ7IUafc8cJGdb fvqAvftVVb7qwN1r4TS10Sb0UEdrM5wlVUDDg8NG9z0yE6ogGMNMXa9vW6GNNBvdb/fr KToLlyybeLdYK9bjKMC/0ZiNxxXZas8E/KKCX0Dtyrdiq9vFKjhHDEPyipj4nXiv4cvg y0oeO9Eb/9p0ZeGy5VAVwC7iCObx/4Vxlw7/kHgD/F4Uib1se31FsiWzRaRJTBtPtHAg UCksV1e7yiOIdZ7gn17YSA3aL2FFdl5RML+pgM4vkfcKNZtPUU/23l8ite6DtGsjbtCU H4Jg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=b103fI+4oeML+jOWazzvzpVVrPdBgnlmA3O+U9yIhAA=; fh=GVJhlWdd4NNaBhOZ/uQFycFAyzDMQer7CEL5IpLL3Iw=; b=GbIWOnwVUKFibLel3i6pigEp6W2+N2vdprqThc3GKUKDMJhMTsD0YqtmvXPjS0jvH0 4PBow7Lrd6TMciXMDL4qUHSjKJEOqgnqfB918vyka0wD4hdURIBaXEyqUy9qQVA0nFua gfZ/80r7R/2TPWJZdB26anuFm2xXRPDe1GuNKFl3wDwarVLMPqK85ewbK3OenZ9Bpj1T QVl8ytXuF68jP2WAzIPPbVEWpk/4Kl848ddyRWis+cUHdUubXxUruyPw6wDO6KXxbyc6 LxA/EFx4zsPS08mHeWhWbQaS1aWLlFyq+/n0IRYju9SWUveo+Mg0aN1z6IJh5HM4/sVf kK7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iobtjTGL; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 5b1f17b1804b1-440a53f0bd9si59873295e9.184.2025.04.28.10.05.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 10:05:27 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iobtjTGL; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9513B3858408 for ; Mon, 28 Apr 2025 17:05:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9513B3858408 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=iobtjTGL X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id E1EDD3858406 for ; Mon, 28 Apr 2025 17:04:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1EDD3858406 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E1EDD3858406 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1035 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745859879; cv=none; b=XO43Sv0zhtx1rCFDlYTk/AmVk03Mg/XgQXXKjYXP32PtWK2v5KgLb+gXOhiIcO+6K7dA+cfbKJSU0TPsycGwn1Q7kmlYN4OxEHokqN2MbSw12Ug07ZGuE22ttF98sfBkv3KFOkMumWUWApnEZDoNhkKQJzp8ZbGETDIzxVRV1d0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745859879; c=relaxed/simple; bh=HMxy3Sy6LxvWijtmq1AIVnlP1cY+BNP2kpMxSCv8fiU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ibnBZzsuA5CXizmEuk1jcsWsjQYdTst9diLA6B4yXGWsYNooeYKmRZUZ8WnGO8N7Optwsikhbnz/shZxM3M1eVPF9v/uJcFCG64KXZsN9E/YnKRcPp+AGB+ePDfzd/8lELVk2msaX2TyXu/62PgQ/xWV94bo8RLxhMmaI3xIJAw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1EDD3858406 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-309d2e8c20cso6181401a91.0 for ; Mon, 28 Apr 2025 10:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745859878; x=1746464678; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b103fI+4oeML+jOWazzvzpVVrPdBgnlmA3O+U9yIhAA=; b=iobtjTGLk+Nsekq4+d+Otml0Xym6IrqiqQpR0e7/d+oWRkSxbFB5crNJEtLqx3SbiK 6sA/PNoahPp0LGhLy3WrPgcKe3tdWli8LEqhrVCHkT2axNYEElxL3Mx8MMaKlhG+6Pnw 7qh5tDXcfZHWodLhC48sOwvAr5bIqskF2CcB316//9DXl8/6PLHuaSrBDahbT7RqURSP 3P6Kn0rVv/ldKjkogHh8D3+9/oPBa5lBBCz3HFiqebSe9MAPtpVBluQjjob3oY+H/DRa HwmEs0weANX2ZUTgrCtFxEq6MhSg9YYTuBFdt5rIbHs7Mgd+++EcqKc9pYy2vflpeaqp VAgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745859878; x=1746464678; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b103fI+4oeML+jOWazzvzpVVrPdBgnlmA3O+U9yIhAA=; b=Q6e/MKPgnLfmt+vahabmAciNVBWaqGADI0vkcZeN555pkFssiBbhl0+3Fy0ai6rY8v gdWX4MrqjHgfC6xmZSqiOu9e+yFer2CNe4QIUcrjF5RzwWw6vF8ZXZcbrJDyr/Bx7f8/ 8knA3Zse/vK+5ONVKIil+K1Aasz55xBxvHu3ZcF08ozL/VA+hhi3/eVqT9ha2XGZeAGr KuGTWD7ibbSBZep2l94YQ+TXA+Ti14WwovG8EjF7irVgmYNykekzrPsVJNyBJFLZYTHv OXtcYvQYYPoxlGFe95Nje+8UTaApNCnceWj+E1bwdvUxO+BoSPx3yRexdNIoCV7U0CHV RVjQ== X-Gm-Message-State: AOJu0YyE253RuRuDCy7cdh2VMPKP+/c8Z0wMpJ8WRdK0MGuXUwoLfgln U1WAuRJS4xlj3j5G5sef8akg4alAZ7B4g4An7BVd8+TjoiRj0aSBsSeFoSfNbcnc2GHXUmdAbQk n X-Gm-Gg: ASbGncvXaXGnPGyof2L/Pws2zNVKTKK6OB9sU4FdVVek5CklJUWVzqaPve7Pakr0QQa Jw0Ndy5JOV2qGM14GtrhD8MyNjLjltjZPPN+iHJqIk4vBfQwZf7x+CoecJs37KxwZ/BPp3nLEqB kcRld1VhH4O5jtktJPeioHzOpDCsMO9u3ZXuO6PyksJu7RDSN61Hiu14An+jrw5nCkISnrtons1 O54ht4sKXp8K+wgJIfOqWEM+0tNllGyINmZUWCh0vQxm4w/GsBaPqnONqsoi4JGz9SUJSjQi3C9 xRbJLu5F9fTxeRrVqr3k0f6JqDQIjLL3L0U64Y6BY4/n9o+jeasz7A== X-Received: by 2002:a17:90b:4e90:b0:309:e351:2e3d with SMTP id 98e67ed59e1d1-309f7ddfe75mr23184203a91.12.1745859877683; Mon, 28 Apr 2025 10:04:37 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:9bf1:ce18:36e8:dea9:8b39]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-309f773725csm8322332a91.3.2025.04.28.10.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 10:04:37 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Wilco Dijkstra Subject: [PATCH v2 0/4] Remove UB and optimize ilogbf/ilogb Date: Mon, 28 Apr 2025 14:03:40 -0300 Message-ID: <20250428170430.2030400-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org >From a recent experiment to build glibc with -fsanitize=undefined [1], I found that both the float and double ilogb triggered UB due to the use of shift with a signed integer. This patchset fixes the UB issues on both implementations by reimplementing with a slightly better code. [1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/ubsan-undef Adhemerval Zanella (4): math: Remove UB and optimize double ilogb math: Optimize double ilogb/llogb math: Remove UB and optimize double ilogbf math: Optimize float ilogb/llogb sysdeps/i386/fpu/math_err.c | 1 - sysdeps/ieee754/dbl-64/e_ilogb.c | 64 +-------------------------- sysdeps/ieee754/dbl-64/math_config.h | 2 + sysdeps/ieee754/dbl-64/math_err.c | 32 ++++++++++++++ sysdeps/ieee754/dbl-64/w_ilogb.c | 63 ++++++++++++++++++++++++++ sysdeps/ieee754/dbl-64/w_llogb.c | 2 + sysdeps/ieee754/flt-32/e_ilogbf.c | 44 +------------------ sysdeps/ieee754/flt-32/math_config.h | 2 + sysdeps/ieee754/flt-32/math_errf.c | 33 ++++++++++++++ sysdeps/ieee754/flt-32/w_ilogbf.c | 66 ++++++++++++++++++++++++++++ sysdeps/ieee754/flt-32/w_llogbf.c | 2 + 11 files changed, 204 insertions(+), 107 deletions(-) delete mode 100644 sysdeps/i386/fpu/math_err.c create mode 100644 sysdeps/ieee754/dbl-64/w_ilogb.c create mode 100644 sysdeps/ieee754/dbl-64/w_llogb.c create mode 100644 sysdeps/ieee754/flt-32/w_ilogbf.c create mode 100644 sysdeps/ieee754/flt-32/w_llogbf.c