@@ -493,43 +493,119 @@ size_t compare_scanlines(const image_descriptor *imageInfo, const char *aPtr,
493493 // If the data type is 101010, then ignore bits 31 and 32 when
494494 // comparing the row
495495 case CL_UNORM_INT_101010: {
496- cl_uint aPixel = *(cl_uint *)aPtr;
497- cl_uint bPixel = *(cl_uint *)bPtr;
496+ cl_uint aPixel = 0 ;
497+ cl_uint bPixel = 0 ;
498+ memcpy (&aPixel, aPtr, sizeof (aPixel));
499+ memcpy (&bPixel, bPtr, sizeof (bPixel));
498500 if ((aPixel & 0x3fffffff ) != (bPixel & 0x3fffffff ))
499501 return column;
500502 }
501503 break ;
502504
503505 // If the data type is 555, ignore bit 15 when comparing the row
504506 case CL_UNORM_SHORT_555: {
505- cl_ushort aPixel = *(cl_ushort *)aPtr;
506- cl_ushort bPixel = *(cl_ushort *)bPtr;
507+ cl_ushort aPixel = 0 ;
508+ cl_ushort bPixel = 0 ;
509+ memcpy (&aPixel, aPtr, sizeof (aPixel));
510+ memcpy (&bPixel, bPtr, sizeof (bPixel));
507511 if ((aPixel & 0x7fff ) != (bPixel & 0x7fff )) return column;
508512 }
509513 break ;
510514
515+ // 16-bit per-channel formats with LSB padding (per spec); compare
516+ // defined bits only.
517+ case CL_UNSIGNED_INT10X6_EXT:
518+ case CL_UNORM_INT10X6_EXT: {
519+ const size_t channel_count =
520+ get_format_channel_count (imageInfo->format );
521+ for (size_t chan = 0 ; chan < channel_count; ++chan)
522+ {
523+ cl_ushort aChanVal = 0 ;
524+ cl_ushort bChanVal = 0 ;
525+ const char *aChan = aPtr + chan * sizeof (cl_ushort);
526+ const char *bChan = bPtr + chan * sizeof (cl_ushort);
527+ memcpy (&aChanVal, aChan, sizeof (aChanVal));
528+ memcpy (&bChanVal, bChan, sizeof (bChanVal));
529+ if ((aChanVal & 0xffc0 ) != (bChanVal & 0xffc0 ))
530+ return column;
531+ }
532+ }
533+ break ;
534+ case CL_UNSIGNED_INT12X4_EXT:
535+ case CL_UNORM_INT12X4_EXT: {
536+ const size_t channel_count =
537+ get_format_channel_count (imageInfo->format );
538+ for (size_t chan = 0 ; chan < channel_count; ++chan)
539+ {
540+ cl_ushort aChanVal = 0 ;
541+ cl_ushort bChanVal = 0 ;
542+ const char *aChan = aPtr + chan * sizeof (cl_ushort);
543+ const char *bChan = bPtr + chan * sizeof (cl_ushort);
544+ memcpy (&aChanVal, aChan, sizeof (aChanVal));
545+ memcpy (&bChanVal, bChan, sizeof (bChanVal));
546+ if ((aChanVal & 0xfff0 ) != (bChanVal & 0xfff0 ))
547+ return column;
548+ }
549+ }
550+ break ;
551+ case CL_UNSIGNED_INT14X2_EXT:
552+ case CL_UNORM_INT14X2_EXT: {
553+ const size_t channel_count =
554+ get_format_channel_count (imageInfo->format );
555+ for (size_t chan = 0 ; chan < channel_count; ++chan)
556+ {
557+ cl_ushort aChanVal = 0 ;
558+ cl_ushort bChanVal = 0 ;
559+ const char *aChan = aPtr + chan * sizeof (cl_ushort);
560+ const char *bChan = bPtr + chan * sizeof (cl_ushort);
561+ memcpy (&aChanVal, aChan, sizeof (aChanVal));
562+ memcpy (&bChanVal, bChan, sizeof (bChanVal));
563+ if ((aChanVal & 0xfffc ) != (bChanVal & 0xfffc ))
564+ return column;
565+ }
566+ }
567+ break ;
568+
511569 case CL_SNORM_INT8: {
512- cl_uchar aPixel = *(cl_uchar *)aPtr;
513- cl_uchar bPixel = *(cl_uchar *)bPtr;
514- // -1.0 is defined as 0x80 and 0x81
515- aPixel = (aPixel == 0x80 ) ? 0x81 : aPixel;
516- bPixel = (bPixel == 0x80 ) ? 0x81 : bPixel;
517- if (aPixel != bPixel)
570+ const size_t channel_count =
571+ get_format_channel_count (imageInfo->format );
572+ for (size_t chan = 0 ; chan < channel_count; ++chan)
518573 {
519- return column;
574+ cl_uchar aChanVal = 0 ;
575+ cl_uchar bChanVal = 0 ;
576+ const char *aChan = aPtr + chan * sizeof (cl_uchar);
577+ const char *bChan = bPtr + chan * sizeof (cl_uchar);
578+ memcpy (&aChanVal, aChan, sizeof (aChanVal));
579+ memcpy (&bChanVal, bChan, sizeof (bChanVal));
580+ // -1.0 is defined as 0x80 and 0x81
581+ aChanVal = (aChanVal == 0x80 ) ? 0x81 : aChanVal;
582+ bChanVal = (bChanVal == 0x80 ) ? 0x81 : bChanVal;
583+ if (aChanVal != bChanVal)
584+ {
585+ return column;
586+ }
520587 }
521588 }
522589 break ;
523590
524591 case CL_SNORM_INT16: {
525- cl_ushort aPixel = *(cl_ushort *)aPtr;
526- cl_ushort bPixel = *(cl_ushort *)bPtr;
527- // -1.0 is defined as 0x8000 and 0x8001
528- aPixel = (aPixel == 0x8000 ) ? 0x8001 : aPixel;
529- bPixel = (bPixel == 0x8000 ) ? 0x8001 : bPixel;
530- if (aPixel != bPixel)
592+ const size_t channel_count =
593+ get_format_channel_count (imageInfo->format );
594+ for (size_t chan = 0 ; chan < channel_count; ++chan)
531595 {
532- return column;
596+ cl_ushort aChanVal = 0 ;
597+ cl_ushort bChanVal = 0 ;
598+ const char *aChan = aPtr + chan * sizeof (cl_ushort);
599+ const char *bChan = bPtr + chan * sizeof (cl_ushort);
600+ memcpy (&aChanVal, aChan, sizeof (aChanVal));
601+ memcpy (&bChanVal, bChan, sizeof (bChanVal));
602+ // -1.0 is defined as 0x8000 and 0x8001
603+ aChanVal = (aChanVal == 0x8000 ) ? 0x8001 : aChanVal;
604+ bChanVal = (bChanVal == 0x8000 ) ? 0x8001 : bChanVal;
605+ if (aChanVal != bChanVal)
606+ {
607+ return column;
608+ }
533609 }
534610 }
535611 break ;
@@ -544,6 +620,7 @@ size_t compare_scanlines(const image_descriptor *imageInfo, const char *aPtr,
544620 }
545621
546622 // If we didn't find a difference, return the width of the image
623+ assert (column == imageInfo->width );
547624 return column;
548625}
549626
@@ -1208,19 +1285,21 @@ void escape_inf_nan_subnormal_values(char *data, size_t allocSize)
12081285{
12091286 // filter values with 8 not-quite-highest bits
12101287 unsigned int *intPtr = (unsigned int *)data;
1211- for (size_t i = 0 ; i< allocSize>> 2 ; i++)
1288+ for (size_t i = 0 ; i < ( allocSize >> 2 ) ; i++)
12121289 {
1213- if ((intPtr[i] & 0x7F800000 ) == 0x7F800000 ) intPtr[i] ^= 0x40000000 ;
1290+ if ((intPtr[i] & 0x7F800000 ) == 0x7F800000 )
1291+ intPtr[i] ^= 0x40000000 ;
12141292 else if ((intPtr[i] & 0x7F800000 ) == 0 )
12151293 intPtr[i] ^= 0x40000000 ;
12161294 }
12171295
12181296 // Ditto with half floats (16-bit numbers with the 5 not-quite-highest bits
12191297 // = 0x7C00 are special)
12201298 unsigned short *shortPtr = (unsigned short *)data;
1221- for (size_t i = 0 ; i< allocSize>> 1 ; i++)
1299+ for (size_t i = 0 ; i < ( allocSize >> 1 ) ; i++)
12221300 {
1223- if ((shortPtr[i] & 0x7C00 ) == 0x7C00 ) shortPtr[i] ^= 0x4000 ;
1301+ if ((shortPtr[i] & 0x7C00 ) == 0x7C00 )
1302+ shortPtr[i] ^= 0x4000 ;
12241303 else if ((shortPtr[i] & 0x7C00 ) == 0 )
12251304 shortPtr[i] ^= 0x4000 ;
12261305 }
@@ -3191,12 +3270,12 @@ void pack_image_pixel_error(const float *srcVector,
31913270 case CL_UNSIGNED_INT32: {
31923271 const cl_uint *ptr = (const cl_uint *)results;
31933272 for (unsigned int i = 0 ; i < channelCount; i++)
3194- errors[i] = (cl_float)(
3195- (cl_long)ptr[i]
3196- - (cl_long) CONVERT_UINT (
3197- srcVector[i] ,
3198- MAKE_HEX_FLOAT ( 0x1 . fffffep31f , 0x1fffffe , 31 - 23 ),
3199- CL_UINT_MAX));
3273+ errors[i] = (cl_float)((cl_long)ptr[i]
3274+ - (cl_long)CONVERT_UINT (
3275+ srcVector[i],
3276+ MAKE_HEX_FLOAT ( 0x1 . fffffep31f ,
3277+ 0x1fffffe , 31 - 23 ),
3278+ CL_UINT_MAX));
32003279 break ;
32013280 }
32023281 case CL_UNSIGNED_INT10X6_EXT: {
0 commit comments