Michael McLoughlin
Michael McLoughlin

Reputation: 1112

Documentation for architecture-specific Golang function

I have a function that I would like to provide an assembly implementation for on amd64 architecture. For the sake of discussion let's just suppose it's an Add function, but it's actually more complicated than this. I have the assembly version working but my question concerns getting the godoc to display correctly. I have a feeling this is currenty impossible, but I wanted to seek advice.

Some more details:

The implementation is structured like this gist. At a high level:

This approach works. However the godoc output is crappy because in the amd64 case the function is actually a variable. Note godoc appears to be picking up the same build tags as the machine it's running on. I'm not sure what godoc.org would do.

Alternatives considered:

So I guess the questions are:

  1. Is there a better way to structure the code to achieve the performance I want, and have it appear properly in documentation.
  2. If there is no alternative, is there some other way to "trick" godoc?

Upvotes: 3

Views: 326

Answers (1)

Thundercat
Thundercat

Reputation: 121049

See math.Sqrt for an example of how to do this.

To handle the cpuid check, set a package variable in init() and conditionally jump based on that variable in the assembly implementation.

Upvotes: 1

Related Questions