C++ Logo

std-proposals

Advanced search

Re: [std-proposals] TBAA and extended floating-point types

From: Paul Caprioli <paul_at_[hidden]>
Date: Tue, 26 Aug 2025 04:19:46 +0000
Given std::vector<double> x(40); suppose we allowed: std::span<std::float64_t, 40>(x); Philosophically, I want a non-owning view of the data, so maybe std::span is a good choice? I don't want actual conversion; I think I'd prefer compilation to fail. The compiler would have to understand that these two particular objects alias even though the elements have different types. But that's nicer than prohibiting TBAA of all doubles and std::float64_ts. -----Original message----- From: Sebastian Wittmeier <wittmeier_at_[hidden]> Sent: Monday, August 25 2025, 2:05 pm To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>; Paul Caprioli <paul_at_[hidden]> Subject: AW: [std-proposals] TBAA and extended floating-point types Perhaps we need bit_cast or other conversions for arrays and templated containers. Either as noop or as actual conversion. ranges? adapter classes? Do we have enough facilities? -----Ursprüngliche Nachricht----- Von: Paul Caprioli <paul_at_[hidden]> Gesendet: Mo 25.08.2025 22:03 Betreff: RE: [std-proposals] TBAA and extended floating-point types An: std-proposals_at_[hidden]; CC: Sebastian Wittmeier <wittmeier_at_[hidden]>; > What about bitcast instead? I'm thinking about the following, and don't see how bitcast is useful:  void daxpy(std::size_t n, const std::float64_t alpha, const std::float64_t* x,             std::float64_t* y) {      for (std::size_t i = 0; i < n; ++i) y[i] += alpha * x[i];  }  int main() {      std::size_t n = 40;      double alpha = 2.0;      std::vector<double> x(n, 1.0);      std::vector<double> y(n, 3.0);      daxpy(n, alpha, x.data(), y.data());      std::cout << y[17] << '\n';  // UB  }

Received on 2025-08-26 04:19:50