NEON: 5% faster conversion to RGB565 and RGBA4444

We use the magic 'shift and insert' instruction instead of
the multiple shifts and or's.

Change-Id: I48df0320668b502a91792defc0423a9441669d19
This commit is contained in:
Pascal Massimino 2016-12-20 17:01:48 +01:00
parent 58fc507842
commit 341d711c43

View File

@ -93,7 +93,6 @@ static void Upsample16Pixels(const uint8_t *r1, const uint8_t *r2,
static const int16_t kCoeffs1[4] = { 19077, 26149, 6419, 13320 }; static const int16_t kCoeffs1[4] = { 19077, 26149, 6419, 13320 };
#define v255 vdup_n_u8(255) #define v255 vdup_n_u8(255)
#define v_0x0f vdup_n_u8(15)
#define STORE_Rgb(out, r, g, b) do { \ #define STORE_Rgb(out, r, g, b) do { \
uint8x8x3_t r_g_b; \ uint8x8x3_t r_g_b; \
@ -132,21 +131,16 @@ static const int16_t kCoeffs1[4] = { 19077, 26149, 6419, 13320 };
#endif #endif
#define STORE_Rgba4444(out, r, g, b) do { \ #define STORE_Rgba4444(out, r, g, b) do { \
const uint8x8_t r1 = vshl_n_u8(vshr_n_u8(r, 4), 4); /* 4bits */ \ const uint8x8_t rg = vsri_n_u8(r, g, 4); /* shift g, insert r */ \
const uint8x8_t g1 = vshr_n_u8(g, 4); \ const uint8x8_t ba = vsri_n_u8(b, v255, 4); /* shift a, insert b */ \
const uint8x8_t ba = vorr_u8(b, v_0x0f); \
const uint8x8_t rg = vorr_u8(r1, g1); \
const uint8x8x2_t rgba4444 = ZIP_U8(rg, ba); \ const uint8x8x2_t rgba4444 = ZIP_U8(rg, ba); \
vst1q_u8(out, vcombine_u8(rgba4444.val[0], rgba4444.val[1])); \ vst1q_u8(out, vcombine_u8(rgba4444.val[0], rgba4444.val[1])); \
} while (0) } while (0)
#define STORE_Rgb565(out, r, g, b) do { \ #define STORE_Rgb565(out, r, g, b) do { \
const uint8x8_t r1 = vshl_n_u8(vshr_n_u8(r, 3), 3); /* 5bits */ \ const uint8x8_t rg = vsri_n_u8(r, g, 5); /* shift g and insert r */ \
const uint8x8_t g1 = vshr_n_u8(g, 5); /* upper 3bits */\ const uint8x8_t g1 = vshl_n_u8(g, 3); /* pre-shift g: 3bits */ \
const uint8x8_t g2 = vshl_n_u8(vshr_n_u8(g, 2), 5); /* lower 3bits */\ const uint8x8_t gb = vsri_n_u8(g1, b, 3); /* shift b and insert g */ \
const uint8x8_t b1 = vshr_n_u8(b, 3); /* 5bits */ \
const uint8x8_t rg = vorr_u8(r1, g1); \
const uint8x8_t gb = vorr_u8(g2, b1); \
const uint8x8x2_t rgb565 = ZIP_U8(rg, gb); \ const uint8x8x2_t rgb565 = ZIP_U8(rg, gb); \
vst1q_u8(out, vcombine_u8(rgb565.val[0], rgb565.val[1])); \ vst1q_u8(out, vcombine_u8(rgb565.val[0], rgb565.val[1])); \
} while (0) } while (0)