resize 2.10 - fix gcc loop control and msvc arm32
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jeff Roberts (Bellevue) · committed by Jeff Roberts (Bellevue) · parent f7f20f3 · Browse files · 1 file·+48 added−37 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+48 added−37 removed
- other:+48 added−37 removed
Provenance
- Commit
64e783d- Tree
fb89172- Author
Jeff Roberts (Bellevue) <jeffr@radgametools.com>- Committer
Jeff Roberts (Bellevue) <jeffr@radgametools.com>- Parent
f7f20f3
1 file changed+48 added−37 removed
modified:stb_image_resize2.h+48 added-37 removed
1-/* stb_image_resize2 - v2.09 - public domain image resizing1+/* stb_image_resize2 - v2.10 - public domain image resizing2 3 by Jeff Roberts (v2) and Jorge L Rodriguez4 http://github.com/nothings/stb5 321 unmodified lines327 Aras Pranckevicius: bugfixes328 Nathan Reed: warning fixes for 1.0329 330 REVISIONS331+ 2.10 (2024-07-27) fix the defines GCC and mingw for loop unroll control,332+ fix MSVC 32-bit arm half float routines.333 2.09 (2024-06-19) fix the defines for 32-bit ARM GCC builds (was selecting334 hardware half floats).335 2.08 (2024-06-10) fix for RGB->BGR three channel flips and add SIMD (thanks336 to Ryan Salsbury), fix for sub-rect resizes, use the889 unmodified lines1226 #define STBIR_NO_UNROLL_LOOP_START _Pragma("GCC unroll 0") _Pragma("GCC novector")1227 #else1228 #define STBIR_NO_UNROLL_LOOP_START1229 #endif1230+ #define STBIR_NO_UNROLL_LOOP_START_INF_FOR1231 #else1232 #define STBIR_STREAMOUT_PTR( star ) star1233 #define STBIR_NO_UNROLL( ptr )1234 #define STBIR_NO_UNROLL_LOOP_START1235 #endif1236 1237+#ifndef STBIR_NO_UNROLL_LOOP_START_INF_FOR1238+#define STBIR_NO_UNROLL_LOOP_START_INF_FOR STBIR_NO_UNROLL_LOOP_START1239+#endif1240+1241 #ifdef STBIR_NO_SIMD // force simd off for whatever reason1242 1243 // force simd off overrides everything else, so clear it all1244 1181 unmodified lines2426 final = _mm_packs_epi32(final, final2);2427 stbir__simdi_store( output,final );2428 }2429 2423-#elif defined(STBIR_WASM) || (defined(STBIR_NEON) && (defined(_MSC_VER) || defined(_M_ARM) || defined(__arm__))) // WASM or 32-bit ARM on MSVC/clang2424-2425- static stbir__inline void stbir__half_to_float_SIMD(float * output, stbir__FP16 const * input)2426- {2427- for (int i=0; i<8; i++)2428- {2429- output[i] = stbir__half_to_float(input[i]);2430- }2431- }2432-2433- static stbir__inline void stbir__float_to_half_SIMD(stbir__FP16 * output, float const * input)2434- {2435- for (int i=0; i<8; i++)2436- {2437- output[i] = stbir__float_to_half(input[i]);2438- }2439- }2440-2430 #elif defined(STBIR_NEON) && defined(_MSC_VER) && defined(_M_ARM64) && !defined(__clang__) // 64-bit ARM on MSVC (not clang)2431 2432 static stbir__inline void stbir__half_to_float_SIMD(float * output, stbir__FP16 const * input)2433 {46 unmodified lines2480 {2481 return vget_lane_f16(vcvt_f16_f32(vdupq_n_f32(f)), 0);2482 }2483 2484+#elif defined(STBIR_WASM) || (defined(STBIR_NEON) && (defined(_MSC_VER) || defined(_M_ARM) || defined(__arm__))) // WASM or 32-bit ARM on MSVC/clang2485+2486+ static stbir__inline void stbir__half_to_float_SIMD(float * output, stbir__FP16 const * input)2487+ {2488+ for (int i=0; i<8; i++)2489+ {2490+ output[i] = stbir__half_to_float(input[i]);2491+ }2492+ }2493+ static stbir__inline void stbir__float_to_half_SIMD(stbir__FP16 * output, float const * input)2494+ {2495+ for (int i=0; i<8; i++)2496+ {2497+ output[i] = stbir__float_to_half(input[i]);2498+ }2499+ }2500+2501 #endif2502 2503 2504 #ifdef STBIR_SIMD45 unmodified lines2550 // Adding this switch saves about 5K on clang which is Captain Unroll the 3rd.2551 #define STBIR_SIMD_STREAMOUT_PTR( star ) STBIR_STREAMOUT_PTR( star )2552 #define STBIR_SIMD_NO_UNROLL(ptr) STBIR_NO_UNROLL(ptr)2553 #define STBIR_SIMD_NO_UNROLL_LOOP_START STBIR_NO_UNROLL_LOOP_START2554+#define STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR STBIR_NO_UNROLL_LOOP_START_INF_FOR2555 2556 #ifdef STBIR_MEMCPY2557 #undef STBIR_MEMCPY2558 #endif31 unmodified lines2590 stbir__simdf_load( x, ( d + ofs_to_src ) );2591 stbir__simdf_store( d, x );2592 d = (char*)( ( ( (size_t)d ) + 16 ) & ~15 );2593 2587- STBIR_SIMD_NO_UNROLL_LOOP_START2594+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR2595 for(;;)2596 {2597 STBIR_SIMD_NO_UNROLL(d);2598 24 unmodified lines2623 stbir__simdfX_store( d + 8*stbir__simdfX_float_count, x2 );2624 stbir__simdfX_store( d + 12*stbir__simdfX_float_count, x3 );2625 d = (char*)( ( ( (size_t)d ) + (16*stbir__simdfX_float_count) ) & ~((16*stbir__simdfX_float_count)-1) );2626 2620- STBIR_SIMD_NO_UNROLL_LOOP_START2627+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR2628 for(;;)2629 {2630 STBIR_SIMD_NO_UNROLL(d);2631 56 unmodified lines2688 // when in scalar mode, we let unrolling happen, so this macro just does the __restrict2689 #define STBIR_SIMD_STREAMOUT_PTR( star ) STBIR_STREAMOUT_PTR( star )2690 #define STBIR_SIMD_NO_UNROLL(ptr)2691 #define STBIR_SIMD_NO_UNROLL_LOOP_START2692+#define STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR2693 2694 #endif // SSE22695 2696 2697 #ifdef STBIR_PROFILE2698 2699+#ifndef STBIR_PROFILE_FUNC2700+2701 #if defined(_x86_64) || defined( __x86_64__ ) || defined( _M_X64 ) || defined(__x86_64) || defined(__SSE2__) || defined(STBIR_SSE) || defined( _M_IX86_FP ) || defined(__i386) || defined( __i386__ ) || defined( _M_IX86 ) || defined( _X86_ )2702 2703 #ifdef _MSC_VER2704 31 unmodified lines2736 #else // x64, arm2737 2738 #error Unknown platform for profiling.2739 2730-#endif //x64 and2740+#endif // x64, arm2741 2742+#endif // STBIR_PROFILE_FUNC2743 2744 #define STBIR_ONLY_PROFILE_GET_SPLIT_INFO ,stbir__per_split_info * split_info2745 #define STBIR_ONLY_PROFILE_SET_SPLIT_INFO ,split_info2746 5460 unmodified lines8207 unsigned char const * end_input_m16 = input + width_times_channels - 16;8208 if ( width_times_channels >= 16 )8209 {8210 decode_end -= 16;8200- STBIR_NO_UNROLL_LOOP_START8211+ STBIR_NO_UNROLL_LOOP_START_INF_FOR8212 for(;;)8213 {8214 #ifdef STBIR_SIMD88215 stbir__simdi i; stbir__simdi8 o0,o1;90 unmodified lines8306 if ( width_times_channels >= stbir__simdfX_float_count*2 )8307 {8308 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;8309 end_output -= stbir__simdfX_float_count*2;8299- STBIR_NO_UNROLL_LOOP_START8310+ STBIR_NO_UNROLL_LOOP_START_INF_FOR8311 for(;;)8312 {8313 stbir__simdfX e0, e1;8314 stbir__simdi i;109 unmodified lines8424 unsigned char const * end_input_m16 = input + width_times_channels - 16;8425 if ( width_times_channels >= 16 )8426 {8427 decode_end -= 16;8417- STBIR_NO_UNROLL_LOOP_START8428+ STBIR_NO_UNROLL_LOOP_START_INF_FOR8429 for(;;)8430 {8431 #ifdef STBIR_SIMD88432 stbir__simdi i; stbir__simdi8 o0,o1;84 unmodified lines8517 if ( width_times_channels >= stbir__simdfX_float_count*2 )8518 {8519 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;8520 end_output -= stbir__simdfX_float_count*2;8510- STBIR_SIMD_NO_UNROLL_LOOP_START8521+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR8522 for(;;)8523 {8524 stbir__simdfX e0, e1;8525 stbir__simdi i;194 unmodified lines8720 if ( width_times_channels >= 16 )8721 {8722 float const * end_encode_m16 = encode + width_times_channels - 16;8723 end_output -= 16;8713- STBIR_SIMD_NO_UNROLL_LOOP_START8724+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR8725 for(;;)8726 {8727 stbir__simdf f0, f1, f2, f3;8728 stbir__simdi i0, i1, i2, i3;94 unmodified lines8823 if ( width_times_channels >= 16 )8824 {8825 float const * end_encode_m16 = encode + width_times_channels - 16;8826 end_output -= 16;8816- STBIR_SIMD_NO_UNROLL_LOOP_START8827+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR8828 for(;;)8829 {8830 stbir__simdf f0, f1, f2, f3;8831 stbir__simdi i0, i1, i2, i3;83 unmodified lines8915 if ( width_times_channels >= 16 )8916 {8917 float const * end_encode_m16 = encode + width_times_channels - 16;8918 end_output -= 16;8908- STBIR_SIMD_NO_UNROLL_LOOP_START8919+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR8920 for(;;)8921 {8922 stbir__simdf f0, f1, f2, f3;8923 stbir__simdi i0, i1, i2, i3;54 unmodified lines8978 unsigned short const * end_input_m8 = input + width_times_channels - 8;8979 if ( width_times_channels >= 8 )8980 {8981 decode_end -= 8;8971- STBIR_NO_UNROLL_LOOP_START8982+ STBIR_NO_UNROLL_LOOP_START_INF_FOR8983 for(;;)8984 {8985 #ifdef STBIR_SIMD88986 stbir__simdi i; stbir__simdi8 o;80 unmodified lines9067 if ( width_times_channels >= stbir__simdfX_float_count*2 )9068 {9069 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;9070 end_output -= stbir__simdfX_float_count*2;9060- STBIR_SIMD_NO_UNROLL_LOOP_START9071+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR9072 for(;;)9073 {9074 stbir__simdfX e0, e1;9075 stbir__simdiX i;107 unmodified lines9183 unsigned short const * end_input_m8 = input + width_times_channels - 8;9184 if ( width_times_channels >= 8 )9185 {9186 decode_end -= 8;9176- STBIR_NO_UNROLL_LOOP_START9187+ STBIR_NO_UNROLL_LOOP_START_INF_FOR9188 for(;;)9189 {9190 #ifdef STBIR_SIMD89191 stbir__simdi i; stbir__simdi8 o;76 unmodified lines9268 if ( width_times_channels >= stbir__simdfX_float_count*2 )9269 {9270 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;9271 end_output -= stbir__simdfX_float_count*2;9261- STBIR_SIMD_NO_UNROLL_LOOP_START9272+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR9273 for(;;)9274 {9275 stbir__simdfX e0, e1;9276 stbir__simdiX i;89 unmodified lines9366 if ( width_times_channels >= 8 )9367 {9368 stbir__FP16 const * end_input_m8 = input + width_times_channels - 8;9369 decode_end -= 8;9359- STBIR_NO_UNROLL_LOOP_START9370+ STBIR_NO_UNROLL_LOOP_START_INF_FOR9371 for(;;)9372 {9373 STBIR_NO_UNROLL(decode);9374 76 unmodified lines9451 if ( width_times_channels >= 8 )9452 {9453 float const * end_encode_m8 = encode + width_times_channels - 8;9454 end_output -= 8;9444- STBIR_SIMD_NO_UNROLL_LOOP_START9455+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR9456 for(;;)9457 {9458 STBIR_SIMD_NO_UNROLL(encode);9459 #ifdef stbir__decode_swizzle77 unmodified lines9537 if ( width_times_channels >= 16 )9538 {9539 float const * end_input_m16 = input + width_times_channels - 16;9540 decode_end -= 16;9530- STBIR_NO_UNROLL_LOOP_START9541+ STBIR_NO_UNROLL_LOOP_START_INF_FOR9542 for(;;)9543 {9544 STBIR_NO_UNROLL(decode);9545 #ifdef stbir__decode_swizzle116 unmodified lines9662 if ( width_times_channels >= ( stbir__simdfX_float_count * 2 ) )9663 {9664 float const * end_encode_m8 = encode + width_times_channels - ( stbir__simdfX_float_count * 2 );9665 end_output -= ( stbir__simdfX_float_count * 2 );9655- STBIR_SIMD_NO_UNROLL_LOOP_START9666+ STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR9667 for(;;)9668 {9669 stbir__simdfX e0, e1;9670 STBIR_SIMD_NO_UNROLL(encode);902 unmodified lines