From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by sourceware.org (Postfix) with ESMTPS id D569F3858CDB for ; Mon, 6 Nov 2023 11:28:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D569F3858CDB 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 D569F3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699270136; cv=none; b=RGcS3S+EuUN2G6r14zEpI0zd7TSPRAuXw4J7HnzO4Y+1PUXntXT9AOm5ILtOa07nYehUBmTvIUKW6Z4n+WFsl4JQ04HrsxIwpWRd7e2toNH6Eo70xcanlOQ64//p0Bn8px7lQeMgPjBrmfda/yqV+9CMqNXqGS5uVDUeojqruas= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699270136; c=relaxed/simple; bh=0+XuyZ22fQ/F9UeamvV6qzWSsgSFN2SITN2EG1Tty3s=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=adKn2uU5itzJZc+Cpach+PuM3+m162/VD2FUZJrL1hVAM0foNvNVH7iZaGLXbT56Jj9qYN2ub/FpXHBdwF7imce3xflvcere/67DSCCnSjVEnZiC2ozQZP69zVu29nILwEv3MqEZhiJYJR2TQYtfNS5REKjErq6QbDmQvFWbGyM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-d9ac3b4f42cso4625193276.0 for ; Mon, 06 Nov 2023 03:28:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270134; x=1699874934; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=glw8PPvSBJsF9nWpVwAzT/yddSCFSVx4e03zsLr6OK4=; b=E8uvwxeY2FndkDUwzEg7WW/oL5lDBUpbUiLP1DwvxOG4/X55sHX47a2rgbZ/Ec19j2 TsRe5kG/mxp9MO+wNIZyDNXm6smOw7rnvSX20Zu7Rjck6ql9BsJ6AiQDMsl9ycNulGLN Rw1zpeZg27koltR/WkvSbBzPVFcjOwU4nk9VbNiblL40uK+fMH4tuzqlnmKkKCIiYVGT olKVHGQkcd5HnRRNQnrbbt9+n9Q1IJNMcbyvbwCFGlon3QXftYUA4piQ8WupjNzg0rOP 1/BZI4I4BuL3+uu41XP4fzsKAzudYycPUDamb+aOX/Y/YpLJtkimm0SlObuZk24nCQZp vpRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270134; x=1699874934; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=glw8PPvSBJsF9nWpVwAzT/yddSCFSVx4e03zsLr6OK4=; b=pdbTmiXZyPOBlaUwjmjHEKLCEYYdLGUbJymVEm/8I3HnBPRPSpAm8zSNDwoKZzHBk0 Mc3aGeAibyXgwz1bdT3/ZXFLCcnzrW+UamwyvU/IN4fEnPnuOsYBSeH0SB0zasXjtZTk 4HhnxFcO8MyEZYezm2krID32W3qvXNjYKZOWTxyaWNHRq2KUqSY3Y2AuaSkOc1yrmv0x OoBDtxTxzVrfanXLxsrvLvzI7FbP3ZnGgFQAZL7PDRuLitioFBRp1vQjm4KE35CkP4u7 9fEwZ/8h+YWqQpv6XyvslahU8bKJ9vOa66VJzzcNT08ArFhljChfqFpEVqc7abPTrCf6 TNFw== X-Gm-Message-State: AOJu0YyFdT40Wy6Gq0dXortlGco8GjtOONOS5QUSpIlJAwpcxYAjlQrS /SMEAPhJ7SEm6KWHxAYxQoAizvclGAzQH2L/cH8JtQ== X-Google-Smtp-Source: AGHT+IHTskBHYh9J2PFZwrp9xvsk6v0tJC1vlt17H778mWOoWIcY5zZbYnMW6IwoRmVk67/93mPxKQ== X-Received: by 2002:a25:c088:0:b0:d85:e0d4:1c31 with SMTP id c130-20020a25c088000000b00d85e0d41c31mr6097355ybf.7.1699270134176; Mon, 06 Nov 2023 03:28:54 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c0:a715:e513:925e:1fa6:9bda? ([2804:1b3:a7c0:a715:e513:925e:1fa6:9bda]) by smtp.gmail.com with ESMTPSA id 4-20020a251104000000b00d9cb47932a0sm3821175ybr.25.2023.11.06.03.28.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Nov 2023 03:28:53 -0800 (PST) Message-ID: Date: Mon, 6 Nov 2023 08:28:51 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 5/7] riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022) Content-Language: en-US To: Bruno Haible , libc-alpha@sourceware.org References: <20231103122416.2724355-1-adhemerval.zanella@linaro.org> <20231103122416.2724355-6-adhemerval.zanella@linaro.org> <87031122.BzKH3j3Lxt@nimes> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <87031122.BzKH3j3Lxt@nimes> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 05/11/23 21:21, Bruno Haible wrote: > This code gave me puzzles: > > long int env = (long int) envp - (long int) FE_DFL_ENV; > if (env != 0) > env = *envp; > > * What is the intent of the code? > * Can signed integer overflow happen in the first line? (It cannot, due to > the value of FE_DFL_ENV being -1 and envp being otherwise aligned mod 4. > But one should not have to think that far.) > * It assumes that intptr_t is the same as 'long int'. Which is not > universally true. > > I would suggest to replace the function with this code: > > libc_feupdateenv_riscv (const fenv_t *envp) > { > long int env = (envp != FE_DFL_ENV ? *envp : 0); > > _FPU_SETCW (env | riscv_getflags ()); > } > > * It is clearer. > * It does not make assumptions regarding FE_DFL_ENV or alignment. > * It produces the exact same code; see attached foo.c and foo.s, > generated by "riscv64-linux-gnu-gcc -O2 -S foo.c". Indeed I was not sure why libc_fesetenv_riscv used this specific idiom to check whether the input is FE_DFL_ENV. I will change to this, it is clear. > > Probably the idiom that you copied was meant to allow the use of a > conditional load instruction. But I would avoid such micro-optimizations > and instead rely on the compiler to choose the best instructions for a > task. > > Bruno