@@ -174,17 +174,24 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
174174 }
175175 }
176176
177- if (typeHnd == nullptr )
177+ if (sizeBytes != nullptr )
178+ {
179+ *sizeBytes = 0 ;
180+ }
181+
182+ if ((typeHnd == nullptr ) || !isIntrinsicType (typeHnd))
178183 {
179184 return CORINFO_TYPE_UNDEF;
180185 }
181186
187+ const char * namespaceName;
188+ const char * className = getClassNameFromMetadata (typeHnd, &namespaceName);
189+
182190 // fast path search using cached type handles of important types
183191 CorInfoType simdBaseJitType = CORINFO_TYPE_UNDEF;
184192 unsigned size = 0 ;
185193
186- // TODO - Optimize SIMD type recognition by IntrinsicAttribute
187- if (isSIMDClass (typeHnd))
194+ if (isNumericsNamespace (namespaceName))
188195 {
189196 // The most likely to be used type handles are looked up first followed by
190197 // less likely to be used type handles
@@ -290,143 +297,104 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
290297 // slow path search
291298 if (simdBaseJitType == CORINFO_TYPE_UNDEF)
292299 {
293- // Doesn't match with any of the cached type handles.
294- // Obtain base type by parsing fully qualified class name.
295- //
296- // TODO-Throughput: implement product shipping solution to query base type.
297- WCHAR className[256 ] = {0 };
298- WCHAR* pbuf = &className[0 ];
299- int len = ArrLen (className);
300- int outlen = info.compCompHnd ->appendClassName ((char16_t **)&pbuf, &len, typeHnd, true , false , false );
301- noway_assert (outlen >= 0 );
302- noway_assert ((size_t )(outlen + 1 ) <= ArrLen (className));
303- JITDUMP (" SIMD Candidate Type %S\n " , className);
304-
305- if (wcsncmp (className, W (" System.Numerics." ), 16 ) == 0 )
300+ JITDUMP (" SIMD Candidate Type %s\n " , className);
301+
302+ if (strcmp (className, " Vector`1" ) == 0 )
306303 {
307- if (wcsncmp (&(className[16 ]), W (" Vector`1[" ), 9 ) == 0 )
308- {
309- size = getSIMDVectorRegisterByteLength ();
304+ size = getSIMDVectorRegisterByteLength ();
310305
311- if (wcsncmp (&(className[25 ]), W (" System.Single" ), 13 ) == 0 )
312- {
306+ CORINFO_CLASS_HANDLE typeArgHnd = info.compCompHnd ->getTypeInstantiationArgument (typeHnd, 0 );
307+ simdBaseJitType = info.compCompHnd ->getTypeForPrimitiveNumericClass (typeArgHnd);
308+
309+ switch (simdBaseJitType)
310+ {
311+ case CORINFO_TYPE_FLOAT:
313312 m_simdHandleCache->SIMDFloatHandle = typeHnd;
314- simdBaseJitType = CORINFO_TYPE_FLOAT;
315- JITDUMP (" Found type SIMD Vector<Float>\n " );
316- }
317- else if (wcsncmp (&(className[25 ]), W (" System.Int32" ), 12 ) == 0 )
318- {
313+ break ;
314+ case CORINFO_TYPE_INT:
319315 m_simdHandleCache->SIMDIntHandle = typeHnd;
320- simdBaseJitType = CORINFO_TYPE_INT;
321- JITDUMP (" Found type SIMD Vector<Int>\n " );
322- }
323- else if (wcsncmp (&(className[25 ]), W (" System.UInt16" ), 13 ) == 0 )
324- {
316+ break ;
317+ case CORINFO_TYPE_USHORT:
325318 m_simdHandleCache->SIMDUShortHandle = typeHnd;
326- simdBaseJitType = CORINFO_TYPE_USHORT;
327- JITDUMP (" Found type SIMD Vector<ushort>\n " );
328- }
329- else if (wcsncmp (&(className[25 ]), W (" System.Byte" ), 11 ) == 0 )
330- {
319+ break ;
320+ case CORINFO_TYPE_UBYTE:
331321 m_simdHandleCache->SIMDUByteHandle = typeHnd;
332- simdBaseJitType = CORINFO_TYPE_UBYTE;
333- JITDUMP (" Found type SIMD Vector<ubyte>\n " );
334- }
335- else if (wcsncmp (&(className[25 ]), W (" System.Double" ), 13 ) == 0 )
336- {
322+ break ;
323+ case CORINFO_TYPE_DOUBLE:
337324 m_simdHandleCache->SIMDDoubleHandle = typeHnd;
338- simdBaseJitType = CORINFO_TYPE_DOUBLE;
339- JITDUMP (" Found type SIMD Vector<Double>\n " );
340- }
341- else if (wcsncmp (&(className[25 ]), W (" System.Int64" ), 12 ) == 0 )
342- {
325+ break ;
326+ case CORINFO_TYPE_LONG:
343327 m_simdHandleCache->SIMDLongHandle = typeHnd;
344- simdBaseJitType = CORINFO_TYPE_LONG;
345- JITDUMP (" Found type SIMD Vector<Long>\n " );
346- }
347- else if (wcsncmp (&(className[25 ]), W (" System.Int16" ), 12 ) == 0 )
348- {
328+ break ;
329+ case CORINFO_TYPE_SHORT:
349330 m_simdHandleCache->SIMDShortHandle = typeHnd;
350- simdBaseJitType = CORINFO_TYPE_SHORT;
351- JITDUMP (" Found type SIMD Vector<short>\n " );
352- }
353- else if (wcsncmp (&(className[25 ]), W (" System.SByte" ), 12 ) == 0 )
354- {
331+ break ;
332+ case CORINFO_TYPE_BYTE:
355333 m_simdHandleCache->SIMDByteHandle = typeHnd;
356- simdBaseJitType = CORINFO_TYPE_BYTE;
357- JITDUMP (" Found type SIMD Vector<byte>\n " );
358- }
359- else if (wcsncmp (&(className[25 ]), W (" System.UInt32" ), 13 ) == 0 )
360- {
334+ break ;
335+ case CORINFO_TYPE_UINT:
361336 m_simdHandleCache->SIMDUIntHandle = typeHnd;
362- simdBaseJitType = CORINFO_TYPE_UINT;
363- JITDUMP (" Found type SIMD Vector<uint>\n " );
364- }
365- else if (wcsncmp (&(className[25 ]), W (" System.UInt64" ), 13 ) == 0 )
366- {
337+ break ;
338+ case CORINFO_TYPE_ULONG:
367339 m_simdHandleCache->SIMDULongHandle = typeHnd;
368- simdBaseJitType = CORINFO_TYPE_ULONG;
369- JITDUMP (" Found type SIMD Vector<ulong>\n " );
370- }
371- else if (wcsncmp (&(className[25 ]), W (" System.IntPtr" ), 13 ) == 0 )
372- {
340+ break ;
341+ case CORINFO_TYPE_NATIVEINT:
373342 m_simdHandleCache->SIMDNIntHandle = typeHnd;
374- simdBaseJitType = CORINFO_TYPE_NATIVEINT;
375- JITDUMP (" Found type SIMD Vector<nint>\n " );
376- }
377- else if (wcsncmp (&(className[25 ]), W (" System.UIntPtr" ), 14 ) == 0 )
378- {
343+ break ;
344+ case CORINFO_TYPE_NATIVEUINT:
379345 m_simdHandleCache->SIMDNUIntHandle = typeHnd;
380- simdBaseJitType = CORINFO_TYPE_NATIVEUINT;
381- JITDUMP (" Found type SIMD Vector<nuint>\n " );
382- }
383- else
384- {
385- JITDUMP (" Unknown SIMD Vector<T>\n " );
386- }
346+ break ;
347+ default :
348+ simdBaseJitType = CORINFO_TYPE_UNDEF;
349+ break ;
387350 }
388- else if (wcsncmp (&(className[16 ]), W (" Vector2" ), 8 ) == 0 )
389- {
390- m_simdHandleCache->SIMDVector2Handle = typeHnd;
391351
392- simdBaseJitType = CORINFO_TYPE_FLOAT;
393- size = 2 * genTypeSize (TYP_FLOAT);
394- assert (size == roundUp (info.compCompHnd ->getClassSize (typeHnd), TARGET_POINTER_SIZE));
395- JITDUMP (" Found Vector2\n " );
396- }
397- else if (wcsncmp (&(className[16 ]), W (" Vector3" ), 8 ) == 0 )
352+ if (simdBaseJitType != CORINFO_TYPE_UNDEF)
398353 {
399- m_simdHandleCache->SIMDVector3Handle = typeHnd;
400-
401- simdBaseJitType = CORINFO_TYPE_FLOAT;
402- size = 3 * genTypeSize (TYP_FLOAT);
403- assert (size == info.compCompHnd ->getClassSize (typeHnd));
404- JITDUMP (" Found Vector3\n " );
405- }
406- else if (wcsncmp (&(className[16 ]), W (" Vector4" ), 8 ) == 0 )
407- {
408- m_simdHandleCache->SIMDVector4Handle = typeHnd;
409-
410- simdBaseJitType = CORINFO_TYPE_FLOAT;
411- size = 4 * genTypeSize (TYP_FLOAT);
412- assert (size == roundUp (info.compCompHnd ->getClassSize (typeHnd), TARGET_POINTER_SIZE));
413- JITDUMP (" Found Vector4\n " );
414- }
415- else if (wcsncmp (&(className[16 ]), W (" Vector" ), 6 ) == 0 )
416- {
417- m_simdHandleCache->SIMDVectorHandle = typeHnd;
418- size = getSIMDVectorRegisterByteLength ();
419- JITDUMP (" Found type Vector\n " );
354+ JITDUMP (" Found type SIMD Vector<%s>\n " , varTypeName (JitType2PreciseVarType (simdBaseJitType)));
420355 }
421356 else
422357 {
423- JITDUMP (" Unknown SIMD Type \n " );
358+ JITDUMP (" Unknown SIMD Vector<T> \n " );
424359 }
425360 }
361+ else if (strcmp (className, " Vector2" ) == 0 )
362+ {
363+ m_simdHandleCache->SIMDVector2Handle = typeHnd;
364+
365+ simdBaseJitType = CORINFO_TYPE_FLOAT;
366+ size = 2 * genTypeSize (TYP_FLOAT);
367+ assert (size == roundUp (info.compCompHnd ->getClassSize (typeHnd), TARGET_POINTER_SIZE));
368+ JITDUMP (" Found Vector2\n " );
369+ }
370+ else if (strcmp (className, " Vector3" ) == 0 )
371+ {
372+ m_simdHandleCache->SIMDVector3Handle = typeHnd;
373+
374+ simdBaseJitType = CORINFO_TYPE_FLOAT;
375+ size = 3 * genTypeSize (TYP_FLOAT);
376+ assert (size == info.compCompHnd ->getClassSize (typeHnd));
377+ JITDUMP (" Found Vector3\n " );
378+ }
379+ else if (strcmp (className, " Vector4" ) == 0 )
380+ {
381+ m_simdHandleCache->SIMDVector4Handle = typeHnd;
382+
383+ simdBaseJitType = CORINFO_TYPE_FLOAT;
384+ size = 4 * genTypeSize (TYP_FLOAT);
385+ assert (size == roundUp (info.compCompHnd ->getClassSize (typeHnd), TARGET_POINTER_SIZE));
386+ JITDUMP (" Found Vector4\n " );
387+ }
388+ else if (strcmp (className, " Vector" ) == 0 )
389+ {
390+ m_simdHandleCache->SIMDVectorHandle = typeHnd;
391+ size = getSIMDVectorRegisterByteLength ();
392+ JITDUMP (" Found type Vector\n " );
393+ }
426394 }
427395 }
428396#ifdef FEATURE_HW_INTRINSICS
429- else if ( isIntrinsicType (typeHnd))
397+ else
430398 {
431399 const size_t Vector64SizeBytes = 64 / 8 ;
432400 const size_t Vector128SizeBytes = 128 / 8 ;
@@ -662,7 +630,6 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
662630 if (simdBaseJitType == CORINFO_TYPE_UNDEF)
663631 {
664632 // Doesn't match with any of the cached type handles.
665- const char * className = getClassNameFromMetadata (typeHnd, nullptr );
666633 CORINFO_CLASS_HANDLE baseTypeHnd = getTypeInstantiationArgument (typeHnd, 0 );
667634
668635 if (baseTypeHnd != nullptr )
0 commit comments