-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: simd/m128: single instruction multiple data API #60149
Comments
Some notes:
|
I'm not sure I understand this. You say that the total length of |
This is the imperfection of the proposal, and I have revised it to the following statement: The value of offset must be a multiple of unsafe.Sizeof(T) and less than unsafe.Sizeof(M128) |
func (mem *M128[T])Set(offect int8,value T) This is just changing one of these n T-type data 2.Regarding the API for loading and storing, taking storage as an example: Store(dst []T, offset int, vec M128[T]) Can be written as: for i:=int8(0);i<len(dst);i++{
vec.Set(int8(unsafe.Sizeof(T))*i+int8(offset),dst[i])
} It seems that this can be regarded as a syntactic sugar that calls the Set or Get method continuously. |
Rethinking @merykitty,I don't quite understand the semantics of Load (src [] T, offset int) M128[T] you wrote. If you use src data to generate M128[T], this is the function of Store. |
1, In vector world, to change an element, you take a vector, and return a new vector with one element changed. This is similar to how you flip a bit in an 2, How do you use |
It seems that I misunderstood your expression. I thought Load was reading [] T from M128, but what you wanted to express seems to be loading [] T into M128 |
M128 [T] is just a 128 bit continuous memory that can be used for SIMD operations, storing n data of type T. func (mem *M128[T])Set(offect int8,value T)Equivalent to the following code: if offset>unsafe.Sizeof(M128)||offset%unsafe.Sizeof(T)!=0{//Check if the offset is greater than unsafe. Sizeof (M128) or not a multiple of unsafe. Sizeof (T)
//panic or runtime.throw
}
ptr:=unsafe.Pointer(mem)
ptr=unsafe.Add(ptr,offset)
*(*T)(ptr)=value |
After consideration, the proposal proposes to add 2 APIs for loading or storing M128 [T] using [] T: // Store copies all data from src into the memory of unsafe.Add(unsafe.Pointer(mem),offset) // Load sets dst to the M128 data starting with offset |
Should this issue be added to the review minutes? |
Background
Discussed the issue #53171 of adding advanced APIs using SIMD instructions, which was closed due to lack of clear plans.
See also #53171 (comment)
Proposal
Inspired by C++' s intrinsics function using specific types (such as __m128) to represent data that can be used for single instruction multiple data operation), a simd/m128 package can be added to realize 128-bit single instruction multiple data operation API.
The proposed API is as follows:
according to
#53171 (comment) and #53171 (comment)
The above APIs are arranged by the compiler for appropriate implementation,
For the ease of use of the API, SIMD operations use functions instead of methods
The text was updated successfully, but these errors were encountered: