Add Level trait in codegen to consolidate the generation logic#177
Conversation
df3da05 to
6da4c80
Compare
6da4c80 to
3a77421
Compare
3a77421 to
2350250
Compare
LaurenzV
left a comment
There was a problem hiding this comment.
I haven't checked in detail that all previous comments/code parts were preserved correctly after being moved around, but I trust that you did your best in this regard! Other than that, since the generated code is pretty much the same, LGTM. 😄
| let simd_impl = mk_simd_impl(); | ||
| let ty_impl = mk_type_impl(); | ||
| fn max_block_size(&self) -> usize { | ||
| 128 |
There was a problem hiding this comment.
Don't we support 256 and 512 too? 🤔 But I probably just forgot what this is actually used for...
There was a problem hiding this comment.
I realize now that I hadn't actually added any documentation for what these functions represent.
I've added some documentation to all the Level functions that the various implementations are expected to implement or potentially override, and also replaced make_vectorize_body with a simpler function that only returns the target features that need to be enabled.
| f() | ||
| } | ||
| unsafe { vectorize_simd128(f) } | ||
| f() |
There was a problem hiding this comment.
This is possible because it's enabled statically, right?
There was a problem hiding this comment.
Yes; I left a comment on this in mk_wasm.
This PR is stacked on top of #177. After adding the `Level` trait as an abstraction, we can use it to merge the AVX2 and SSE4.2 implementations into a single module. Most of the logic is the same, except for a few functions which need to do something different if AVX2 is supported. This gets rid of a lot of duplicate code.
This PR is stacked on top of #176, and adds a
Leveltrait to fearless_simd_gen. The different code generation backends (Neon, AVX2, etc) all implement this trait.The various level-specific code generation functions are now mostly trait methods. The
Leveltrait implements some default trait methods, which call into the level-specific ones as necessary. Some of the code that was previously level-specific is actually identical between all implementations, and was moved onto theLeveltrait.