math32 icon indicating copy to clipboard operation
math32 copied to clipboard

Broken assembly implementations

Open soypat opened this issue 4 years ago • 0 comments

Due to recent developments, some assembly implementations have been discovered to be broken.

  • arm64 https://github.com/chewxy/math32/blob/master/_exp_arm64.s
  • risc64 https://github.com/chewxy/math32/blob/master/_stubs_risc64.s

An idea for 64bit assembly implementations

Disclaimer: I'm unsure if casting float64s is desirable. This is just a shot-in-the-dark idea.

Instead of us hosting the assembly implementation for 64 bit architectures we could provide an additional boolean build flag similar to haveArchFunc, but indicating that the Go standard library has the 64 bit implementation, thus we can just use a wrapper func style implementation.

This may be clearer if I illustrate with an example Today The Sqrt implementation is as follows:

func Sqrt(x float32) float32 {
	if haveArchSqrt {
		return archSqrt(x)
	}
	return sqrt(x)
}

I propose adding a new constant haveStdlibSqrt and a new file sqrt_stdlib.go. The above code changes as follows

func Sqrt(x float32) float32 {
	if haveArchSqrt {
		return archSqrt(x)
	}
	if haveStdlibSqrt {
		return float32(math.Sqrt(float32(x)))
	}
	return sqrt(x)
}

The new file sqrt_stdlib.go has the following contents.

//go:build !noasm && (arm64 || risc64)
package math32

import "math"

const haveStdlibSqrt = true // set to false in _noasm and _asm files

soypat avatar May 06 '22 23:05 soypat