Optimized implementations for specific architectures

suggest change

Another 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.

xor_generic.go

//go:build !amd64 && !ppc64 && !ppc64le

package cipher

func xorBytes(dst, a, b []byte) int { 
	// generic implementation if more specific is not available
}

xor_ppc64x.go

//go:build ppc64 || ppc64le

package cipher

func xorBytes(dst, a, b []byte) int {
	// implementation specific to ppc64 processor
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents