michael@0: #include michael@0: michael@0: #include "qcmsint.h" michael@0: michael@0: /* pre-shuffled: just load these into XMM reg instead of load-scalar/shufps sequence */ michael@0: #define FLOATSCALE (float)(PRECACHE_OUTPUT_SIZE) michael@0: #define CLAMPMAXVAL ( ((float) (PRECACHE_OUTPUT_SIZE - 1)) / PRECACHE_OUTPUT_SIZE ) michael@0: static const ALIGN float floatScaleX4[4] = michael@0: { FLOATSCALE, FLOATSCALE, FLOATSCALE, FLOATSCALE}; michael@0: static const ALIGN float clampMaxValueX4[4] = michael@0: { CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL}; michael@0: michael@0: void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform, michael@0: unsigned char *src, michael@0: unsigned char *dest, michael@0: size_t length) michael@0: { michael@0: unsigned int i; michael@0: float (*mat)[4] = transform->matrix; michael@0: char input_back[32]; michael@0: /* Ensure we have a buffer that's 16 byte aligned regardless of the original michael@0: * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(align(32)) michael@0: * because they don't work on stack variables. gcc 4.4 does do the right thing michael@0: * on x86 but that's too new for us right now. For more info: gcc bug #16660 */ michael@0: float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); michael@0: /* share input and output locations to save having to keep the michael@0: * locations in separate registers */ michael@0: uint32_t const * output = (uint32_t*)input; michael@0: michael@0: /* deref *transform now to avoid it in loop */ michael@0: const float *igtbl_r = transform->input_gamma_table_r; michael@0: const float *igtbl_g = transform->input_gamma_table_g; michael@0: const float *igtbl_b = transform->input_gamma_table_b; michael@0: michael@0: /* deref *transform now to avoid it in loop */ michael@0: const uint8_t *otdata_r = &transform->output_table_r->data[0]; michael@0: const uint8_t *otdata_g = &transform->output_table_g->data[0]; michael@0: const uint8_t *otdata_b = &transform->output_table_b->data[0]; michael@0: michael@0: /* input matrix values never change */ michael@0: const __m128 mat0 = _mm_load_ps(mat[0]); michael@0: const __m128 mat1 = _mm_load_ps(mat[1]); michael@0: const __m128 mat2 = _mm_load_ps(mat[2]); michael@0: michael@0: /* these values don't change, either */ michael@0: const __m128 max = _mm_load_ps(clampMaxValueX4); michael@0: const __m128 min = _mm_setzero_ps(); michael@0: const __m128 scale = _mm_load_ps(floatScaleX4); michael@0: michael@0: /* working variables */ michael@0: __m128 vec_r, vec_g, vec_b, result; michael@0: michael@0: /* CYA */ michael@0: if (!length) michael@0: return; michael@0: michael@0: /* one pixel is handled outside of the loop */ michael@0: length--; michael@0: michael@0: /* setup for transforming 1st pixel */ michael@0: vec_r = _mm_load_ss(&igtbl_r[src[0]]); michael@0: vec_g = _mm_load_ss(&igtbl_g[src[1]]); michael@0: vec_b = _mm_load_ss(&igtbl_b[src[2]]); michael@0: src += 3; michael@0: michael@0: /* transform all but final pixel */ michael@0: michael@0: for (i=0; imatrix; michael@0: char input_back[32]; michael@0: /* Ensure we have a buffer that's 16 byte aligned regardless of the original michael@0: * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(align(32)) michael@0: * because they don't work on stack variables. gcc 4.4 does do the right thing michael@0: * on x86 but that's too new for us right now. For more info: gcc bug #16660 */ michael@0: float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); michael@0: /* share input and output locations to save having to keep the michael@0: * locations in separate registers */ michael@0: uint32_t const * output = (uint32_t*)input; michael@0: michael@0: /* deref *transform now to avoid it in loop */ michael@0: const float *igtbl_r = transform->input_gamma_table_r; michael@0: const float *igtbl_g = transform->input_gamma_table_g; michael@0: const float *igtbl_b = transform->input_gamma_table_b; michael@0: michael@0: /* deref *transform now to avoid it in loop */ michael@0: const uint8_t *otdata_r = &transform->output_table_r->data[0]; michael@0: const uint8_t *otdata_g = &transform->output_table_g->data[0]; michael@0: const uint8_t *otdata_b = &transform->output_table_b->data[0]; michael@0: michael@0: /* input matrix values never change */ michael@0: const __m128 mat0 = _mm_load_ps(mat[0]); michael@0: const __m128 mat1 = _mm_load_ps(mat[1]); michael@0: const __m128 mat2 = _mm_load_ps(mat[2]); michael@0: michael@0: /* these values don't change, either */ michael@0: const __m128 max = _mm_load_ps(clampMaxValueX4); michael@0: const __m128 min = _mm_setzero_ps(); michael@0: const __m128 scale = _mm_load_ps(floatScaleX4); michael@0: michael@0: /* working variables */ michael@0: __m128 vec_r, vec_g, vec_b, result; michael@0: unsigned char alpha; michael@0: michael@0: /* CYA */ michael@0: if (!length) michael@0: return; michael@0: michael@0: /* one pixel is handled outside of the loop */ michael@0: length--; michael@0: michael@0: /* setup for transforming 1st pixel */ michael@0: vec_r = _mm_load_ss(&igtbl_r[src[0]]); michael@0: vec_g = _mm_load_ss(&igtbl_g[src[1]]); michael@0: vec_b = _mm_load_ss(&igtbl_b[src[2]]); michael@0: alpha = src[3]; michael@0: src += 4; michael@0: michael@0: /* transform all but final pixel */ michael@0: michael@0: for (i=0; i