Description
When writing generic types, using a pattern as seen in Vector<T> (if (typeof(T) == typeof(int)) ... if (typeof(T) == typeof(float)) ...) once this construct grows to 9 blocks JIT will end up not correctly eliding some casts:
See sharplab
Removing any two blocks from As2<T> will improve code gen significantly (matching a non-generic version & the other version)
splitting up the function will also resolve the issue.
Description
When writing generic types, using a pattern as seen in
Vector<T>(if (typeof(T) == typeof(int)) ... if (typeof(T) == typeof(float)) ...) once this construct grows to 9 blocks JIT will end up not correctly eliding some casts:See sharplab
Removing any two blocks from
As2<T>will improve code gen significantly (matching a non-generic version & the other version)splitting up the function will also resolve the issue.