sw_engine common: Added neon version of rasterRGBA32 API.
authorMichal Szczecinski <mihashco89@gmail.com>
Tue, 27 Jul 2021 11:46:57 +0000 (13:46 +0200)
committerJunsuChoi <jsuya.choi@samsung.com>
Thu, 29 Jul 2021 01:14:54 +0000 (10:14 +0900)
Changes:
- Added 'neon' vector option in build system
- Introduced neon version of rasterRGBA32 API, which improves
speed of the funciton on ARM cpu's around ~35%

meson.build
meson_options.txt
src/lib/sw_engine/tvgSwCommon.h
src/meson.build

index 5563fbc..239ce51 100644 (file)
@@ -42,6 +42,10 @@ if get_option('vectors').contains('avx') == true
     config_h.set10('THORVG_AVX_VECTOR_SUPPORT', true)
 endif
 
+if get_option('vectors').contains('neon') == true
+    config_h.set10('THORVG_NEON_VECTOR_SUPPORT', true)
+endif
+
 if get_option('bindings').contains('capi') == true
     config_h.set10('THORVG_CAPI_BINDING_SUPPORT', true)
 endif
index 104f06c..2e3cee7 100644 (file)
@@ -17,9 +17,9 @@ option('savers',
    description: 'Enable File Savers in thorvg')
 
 option('vectors',
-   type: 'array',
-   choices: ['', 'avx'],
-   value: [''],
+   type: 'combo',
+   choices: ['', 'avx', 'neon'],
+   value: '',
    description: 'Enable CPU Vectorization(SIMD) in thorvg')
 
 option('bindings',
index 4349884..61cffcc 100644 (file)
     #include <immintrin.h>
 #endif
 
+#ifdef THORVG_NEON_VECTOR_SUPPORT
+    #include <arm_neon.h>
+#endif
+
 #if 0
 #include <sys/time.h>
 static double timeStamp()
@@ -362,7 +366,7 @@ bool rasterClear(SwSurface* surface);
 
 static inline void rasterRGBA32(uint32_t *dst, uint32_t val, uint32_t offset, int32_t len)
 {
-#ifdef THORVG_AVX_VECTOR_SUPPORT
+#if defined(THORVG_AVX_VECTOR_SUPPORT)
     //1. calculate how many iterations we need to cover length
     uint32_t iterations = len / 8;
     uint32_t avxFilled = iterations * 8;
@@ -383,6 +387,21 @@ static inline void rasterRGBA32(uint32_t *dst, uint32_t val, uint32_t offset, in
     dst+= avxFilled;
 
     while (leftovers--) *dst++ = val;
+#elif defined(THORVG_NEON_VECTOR_SUPPORT)
+    uint32_t iterations = len / 4;
+    uint32_t neonFilled = iterations * 4;
+    int32_t leftovers = 0;
+
+    dst+=offset;
+    uint32x4_t vectorVal = { val, val, val, val };
+
+    for (uint32_t i = 0; i < iterations; ++i) {
+        vst1q_u32(dst, vectorVal);
+        dst += 4;
+    }
+
+    leftovers = len - neonFilled;
+    while (leftovers--) *dst++ = val;
 #else
     dst += offset;
     while (len--) *dst++ = val;
index 4e2f4dc..fc4c352 100644 (file)
@@ -5,6 +5,9 @@ if (cc.get_id() != 'msvc')
     if get_option('vectors').contains('avx')
         compiler_flags += ['-mavx']
     endif
+    if get_option('vectors').contains('neon')
+        compiler_flags += ['-mfpu=neon-vfpv4']
+    endif
     if get_option('b_sanitize') == 'none'
         compiler_flags += ['-fno-exceptions', '-fno-rtti',
                            '-fno-unwind-tables' , '-fno-asynchronous-unwind-tables',