Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: clarify addVW and subVW preconditions #10525

Closed
josharian opened this issue Apr 21, 2015 · 1 comment
Closed

math/big: clarify addVW and subVW preconditions #10525

josharian opened this issue Apr 21, 2015 · 1 comment

Comments

@josharian
Copy link
Contributor

I'm working on an arm64 math/big implementation.

The docs for addVW (arith.go) say:

// Argument y must be either 0 or 1.
func addVW_g(z, x []Word, y Word) (c Word)

But e.g. running TestFloatSetPrec sends in many values for y. The existing implementations handle them correctly. I care because my initial arm64 implementation transfers y directly to the carry flag at the start, which only works if y is 0 or 1.

subVW does not say that y must be either 0 or 1, but in practice it appears to be, and the semantics are less clear if it is not. However, TestFunVW appears to intentionally send in y=2 to confirm that there's no bad behavior when z and x are nil.

What preconditions do addVW and subVW actually have?

@griesemer feel free to clarify here or just send a CL.

(Additional docs in general in arith.go would be awesome. Right now I'm inferring shlVU and friends from the existing code.)

@griesemer
Copy link
Contributor

addVW originally was expected to only consume 0 and 1, but it's used at least in one place for other values (float.go:496).

subVW may only receive 0 and 1 but for the tests, but I believe the Go and assembly code (x86) can handle arbitrary words. It's not hard.

Suggested course of action:

  • Adjust doc strings; perhaps add extra tests.
  • If it's hugely faster to just have to deal with 0 and 1, perhaps special case in the assembly routine with a test. This is not where the time goes.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants