Optimized implementations for specific architectures
suggest changeAnother use case for build tags is writing an optimized implementation of a function that takes advantage of a specific architecture.
For example, the Go standard library uses this technique for an optimized xor implementation.
//go:build !amd64 && !ppc64 && !ppc64le
package cipher
func xorBytes(dst, a, b []byte) int {
// generic implementation if more specific is not available
}
//go:build ppc64 || ppc64le
package cipher
func xorBytes(dst, a, b []byte) int {
// implementation specific to ppc64 processor
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents