Skip to content
Prev 61393 / 63421 Next

Possible NA Propagation Failure in RISC-V64 CPU?

On 2/24/23 00:39, Jane He wrote:
Please see this bug report for a related discussion: 
https://bugs.r-project.org/show_bug.cgi?id=18416

This is a known problem and has been discussed a number of times before 
RISC-V. Still, RISC-V is a bit unique architecture in that it 
deliberately does not propagate NaN payloads at all and it cannot be 
enabled. R's distinction of NA vs NaN however depends on that propagation.

The propagation of NAs through computations in R is not reliable even on 
other current platforms (due to what the hardware does, but also what 
the compilers and libraries do, see e.g. ?NaN) and technically it is not 
guaranteed and R packages are advised not to depend on it, but various 
package checks and existing software adjusted to how the propagation 
happens to work on widely used platforms, now probably mostly x86_64. 
64-bit ARM is even a bit more friendly to R than that (when the CPU is 
switched to such mode, which R does). If RISC-V supported such mode, R 
would enable it as well, but it deliberately does not support it.

Good defensive portable code would not depend on the propagation to 
happen in hardware/compilers but add checks in software, if propagation 
was needed. I doubt that the performance overhead would be too high if 
done well, particularly for vectorized computations, but it will be 
noticeable and in some cases may be high. This would have to include 
special handling of data including NAs when they are passed to external 
numerical libraries, which would be a lot of work to implement and 
maintain, it seems unrealistic. At the same time there is no strong 
incentive to do so: people who want the propagation seem to be 
reasonably happy with how it happens to work on major platforms.

For the current R to work well on RISC-V, really, the platform would 
have to support the propagation, at least optionally, perhaps like 
64-bit ARM. Unless major platforms in the future stop supporting the 
propagation, I am skeptical anything major could change on the R side.

Best
Tomas