type Vec64 [4]float64
The following minimal alignment properties are guaranteed:
- For a variable
xof any type:unsafe.Alignof(x)is at least 1.- For a variable
xof struct type:unsafe.Alignof(x)is the largest of all the valuesunsafe.Alignof(x.f)for each fieldfofx, but at least 1.- For a variable
xof array type:unsafe.Alignof(x)is the same asunsafe.Alignof(x[0]), but at least 1.
type A struct {
A float32
B complex128
}
unsafe.Alignof(x.A) == 4
unsafe.Alignof(x.B) == 8
Thus: unsafe.Alignof(x) == 8
Alignof returns the alignment of the value v. It is the maximum value m such that the address of a variable with the type of v will always be zero mod m. If v is of the form structValue.field, it returns the alignment of field f within struct object obj.
type A struct {
_ byte // Padding?
A float32
B float64
}
unsafe.Alignof(v): 8
unsafe.Alignof(v.A): 4
unsafe.Alignof(v.B): 8
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/IfKlAkvvSds/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
For an array type, unsafe.Alignof is the same as the array's first element type, so no explicit alignment of an array is allowed (so I should be using a struct).
The last part here structValue.field returning the alignment of field f within the struct object makes me think that I can add some padding or something manually to a struct to change it's alignment?type A struct {
_ byte // Padding?
A float32
B float64
}
Afaik 32byte aligned array's elements are 32byte-aligned, so a []struct{IntVal int64, pad [24]byte} will be ok.
everything in Go is implicitly aligned to whatever is needed for aligned assembly instructions to "just work" (unless the assembly instructions require 8-byte or larger alignment on a 32-bit system, or 16-byte or larger alignment on a 64-bit system)
you might have to do some special handling (which consists of using unaligned instructions for the smallest unaligned leading/trailing portion [which is usually 1-7 elements at most], and then aligned instructions for the rest). There are examples of this in the stdlib (look at the "bytes" package's assembly files).
type Vec64 struct{
X, Y, Z, W float64
}
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/IfKlAkvvSds/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Or I still don't understand.