| OLD | NEW |
| 1 // qcms | 1 // qcms |
| 2 // Copyright (C) 2009 Mozilla Foundation | 2 // Copyright (C) 2009 Mozilla Foundation |
| 3 // | 3 // |
| 4 // Permission is hereby granted, free of charge, to any person obtaining | 4 // Permission is hereby granted, free of charge, to any person obtaining |
| 5 // a copy of this software and associated documentation files (the "Software"), | 5 // a copy of this software and associated documentation files (the "Software"), |
| 6 // to deal in the Software without restriction, including without limitation | 6 // to deal in the Software without restriction, including without limitation |
| 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, | 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 // and/or sell copies of the Software, and to permit persons to whom the Softwar
e | 8 // and/or sell copies of the Software, and to permit persons to whom the Softwar
e |
| 9 // is furnished to do so, subject to the following conditions: | 9 // is furnished to do so, subject to the following conditions: |
| 10 // | 10 // |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #define FLOATSCALE (float)(PRECACHE_OUTPUT_SIZE) | 27 #define FLOATSCALE (float)(PRECACHE_OUTPUT_SIZE) |
| 28 #define CLAMPMAXVAL ( ((float) (PRECACHE_OUTPUT_SIZE - 1)) / PRECACHE_OUTPUT_SIZ
E ) | 28 #define CLAMPMAXVAL ( ((float) (PRECACHE_OUTPUT_SIZE - 1)) / PRECACHE_OUTPUT_SIZ
E ) |
| 29 static const ALIGN float floatScaleX4[4] = | 29 static const ALIGN float floatScaleX4[4] = |
| 30 { FLOATSCALE, FLOATSCALE, FLOATSCALE, FLOATSCALE}; | 30 { FLOATSCALE, FLOATSCALE, FLOATSCALE, FLOATSCALE}; |
| 31 static const ALIGN float clampMaxValueX4[4] = | 31 static const ALIGN float clampMaxValueX4[4] = |
| 32 { CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL}; | 32 { CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL}; |
| 33 | 33 |
| 34 void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform, | 34 void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform, |
| 35 unsigned char *src, | 35 unsigned char *src, |
| 36 unsigned char *dest, | 36 unsigned char *dest, |
| 37 size_t length) | 37 size_t length, |
| 38 qcms_format_type output_format) |
| 38 { | 39 { |
| 39 unsigned int i; | 40 unsigned int i; |
| 40 float (*mat)[4] = transform->matrix; | 41 float (*mat)[4] = transform->matrix; |
| 41 char input_back[32]; | 42 char input_back[32]; |
| 42 /* Ensure we have a buffer that's 16 byte aligned regardless of the original | 43 /* Ensure we have a buffer that's 16 byte aligned regardless of the original |
| 43 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(
align(32)) | 44 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(
align(32)) |
| 44 * because they don't work on stack variables. gcc 4.4 does do the right thi
ng | 45 * because they don't work on stack variables. gcc 4.4 does do the right thi
ng |
| 45 * on x86 but that's too new for us right now. For more info: gcc bug #16660
*/ | 46 * on x86 but that's too new for us right now. For more info: gcc bug #16660
*/ |
| 46 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); | 47 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); |
| 47 /* share input and output locations to save having to keep the | 48 /* share input and output locations to save having to keep the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 63 const __m128 mat1 = _mm_load_ps(mat[1]); | 64 const __m128 mat1 = _mm_load_ps(mat[1]); |
| 64 const __m128 mat2 = _mm_load_ps(mat[2]); | 65 const __m128 mat2 = _mm_load_ps(mat[2]); |
| 65 | 66 |
| 66 /* these values don't change, either */ | 67 /* these values don't change, either */ |
| 67 const __m128 max = _mm_load_ps(clampMaxValueX4); | 68 const __m128 max = _mm_load_ps(clampMaxValueX4); |
| 68 const __m128 min = _mm_setzero_ps(); | 69 const __m128 min = _mm_setzero_ps(); |
| 69 const __m128 scale = _mm_load_ps(floatScaleX4); | 70 const __m128 scale = _mm_load_ps(floatScaleX4); |
| 70 | 71 |
| 71 /* working variables */ | 72 /* working variables */ |
| 72 __m128 vec_r, vec_g, vec_b, result; | 73 __m128 vec_r, vec_g, vec_b, result; |
| 74 const int r_out = output_format.r; |
| 75 const int b_out = output_format.b; |
| 73 | 76 |
| 74 /* CYA */ | 77 /* CYA */ |
| 75 if (!length) | 78 if (!length) |
| 76 return; | 79 return; |
| 77 | 80 |
| 78 /* one pixel is handled outside of the loop */ | 81 /* one pixel is handled outside of the loop */ |
| 79 length--; | 82 length--; |
| 80 | 83 |
| 81 /* setup for transforming 1st pixel */ | 84 /* setup for transforming 1st pixel */ |
| 82 vec_r = _mm_load_ss(&igtbl_r[src[0]]); | 85 vec_r = _mm_load_ss(&igtbl_r[src[0]]); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 109 result = _mm_movehl_ps(result, result); | 112 result = _mm_movehl_ps(result, result); |
| 110 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result) ; | 113 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result) ; |
| 111 | 114 |
| 112 /* load for next loop while store completes */ | 115 /* load for next loop while store completes */ |
| 113 vec_r = _mm_load_ss(&igtbl_r[src[0]]); | 116 vec_r = _mm_load_ss(&igtbl_r[src[0]]); |
| 114 vec_g = _mm_load_ss(&igtbl_g[src[1]]); | 117 vec_g = _mm_load_ss(&igtbl_g[src[1]]); |
| 115 vec_b = _mm_load_ss(&igtbl_b[src[2]]); | 118 vec_b = _mm_load_ss(&igtbl_b[src[2]]); |
| 116 src += 3; | 119 src += 3; |
| 117 | 120 |
| 118 /* use calc'd indices to output RGB values */ | 121 /* use calc'd indices to output RGB values */ |
| 119 dest[0] = otdata_r[output[0]]; | 122 dest[r_out] = otdata_r[output[0]]; |
| 120 dest[1] = otdata_g[output[1]]; | 123 dest[1] = otdata_g[output[1]]; |
| 121 dest[2] = otdata_b[output[2]]; | 124 dest[b_out] = otdata_b[output[2]]; |
| 122 dest += 3; | 125 dest += 3; |
| 123 } | 126 } |
| 124 | 127 |
| 125 /* handle final (maybe only) pixel */ | 128 /* handle final (maybe only) pixel */ |
| 126 | 129 |
| 127 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0); | 130 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0); |
| 128 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0); | 131 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0); |
| 129 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0); | 132 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0); |
| 130 | 133 |
| 131 vec_r = _mm_mul_ps(vec_r, mat0); | 134 vec_r = _mm_mul_ps(vec_r, mat0); |
| 132 vec_g = _mm_mul_ps(vec_g, mat1); | 135 vec_g = _mm_mul_ps(vec_g, mat1); |
| 133 vec_b = _mm_mul_ps(vec_b, mat2); | 136 vec_b = _mm_mul_ps(vec_b, mat2); |
| 134 | 137 |
| 135 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b)); | 138 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b)); |
| 136 vec_r = _mm_max_ps(min, vec_r); | 139 vec_r = _mm_max_ps(min, vec_r); |
| 137 vec_r = _mm_min_ps(max, vec_r); | 140 vec_r = _mm_min_ps(max, vec_r); |
| 138 result = _mm_mul_ps(vec_r, scale); | 141 result = _mm_mul_ps(vec_r, scale); |
| 139 | 142 |
| 140 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result); | 143 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result); |
| 141 result = _mm_movehl_ps(result, result); | 144 result = _mm_movehl_ps(result, result); |
| 142 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result); | 145 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result); |
| 143 | 146 |
| 144 dest[0] = otdata_r[output[0]]; | 147 dest[r_out] = otdata_r[output[0]]; |
| 145 dest[1] = otdata_g[output[1]]; | 148 dest[1] = otdata_g[output[1]]; |
| 146 dest[2] = otdata_b[output[2]]; | 149 dest[b_out] = otdata_b[output[2]]; |
| 147 | 150 |
| 148 _mm_empty(); | 151 _mm_empty(); |
| 149 } | 152 } |
| 150 | 153 |
| 151 void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform, | 154 void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform, |
| 152 unsigned char *src, | 155 unsigned char *src, |
| 153 unsigned char *dest, | 156 unsigned char *dest, |
| 154 size_t length) | 157 size_t length, |
| 158 qcms_format_type output_format) |
| 155 { | 159 { |
| 156 unsigned int i; | 160 unsigned int i; |
| 157 float (*mat)[4] = transform->matrix; | 161 float (*mat)[4] = transform->matrix; |
| 158 char input_back[32]; | 162 char input_back[32]; |
| 159 /* Ensure we have a buffer that's 16 byte aligned regardless of the original | 163 /* Ensure we have a buffer that's 16 byte aligned regardless of the original |
| 160 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(
align(32)) | 164 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(
align(32)) |
| 161 * because they don't work on stack variables. gcc 4.4 does do the right thi
ng | 165 * because they don't work on stack variables. gcc 4.4 does do the right thi
ng |
| 162 * on x86 but that's too new for us right now. For more info: gcc bug #16660
*/ | 166 * on x86 but that's too new for us right now. For more info: gcc bug #16660
*/ |
| 163 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); | 167 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); |
| 164 /* share input and output locations to save having to keep the | 168 /* share input and output locations to save having to keep the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 180 const __m128 mat1 = _mm_load_ps(mat[1]); | 184 const __m128 mat1 = _mm_load_ps(mat[1]); |
| 181 const __m128 mat2 = _mm_load_ps(mat[2]); | 185 const __m128 mat2 = _mm_load_ps(mat[2]); |
| 182 | 186 |
| 183 /* these values don't change, either */ | 187 /* these values don't change, either */ |
| 184 const __m128 max = _mm_load_ps(clampMaxValueX4); | 188 const __m128 max = _mm_load_ps(clampMaxValueX4); |
| 185 const __m128 min = _mm_setzero_ps(); | 189 const __m128 min = _mm_setzero_ps(); |
| 186 const __m128 scale = _mm_load_ps(floatScaleX4); | 190 const __m128 scale = _mm_load_ps(floatScaleX4); |
| 187 | 191 |
| 188 /* working variables */ | 192 /* working variables */ |
| 189 __m128 vec_r, vec_g, vec_b, result; | 193 __m128 vec_r, vec_g, vec_b, result; |
| 194 const int r_out = output_format.r; |
| 195 const int b_out = output_format.b; |
| 190 unsigned char alpha; | 196 unsigned char alpha; |
| 191 | 197 |
| 192 /* CYA */ | 198 /* CYA */ |
| 193 if (!length) | 199 if (!length) |
| 194 return; | 200 return; |
| 195 | 201 |
| 196 /* one pixel is handled outside of the loop */ | 202 /* one pixel is handled outside of the loop */ |
| 197 length--; | 203 length--; |
| 198 | 204 |
| 199 /* setup for transforming 1st pixel */ | 205 /* setup for transforming 1st pixel */ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 result = _mm_movehl_ps(result, result); | 238 result = _mm_movehl_ps(result, result); |
| 233 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result); | 239 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result); |
| 234 | 240 |
| 235 /* load gamma values for next loop while store completes */ | 241 /* load gamma values for next loop while store completes */ |
| 236 vec_r = _mm_load_ss(&igtbl_r[src[0]]); | 242 vec_r = _mm_load_ss(&igtbl_r[src[0]]); |
| 237 vec_g = _mm_load_ss(&igtbl_g[src[1]]); | 243 vec_g = _mm_load_ss(&igtbl_g[src[1]]); |
| 238 vec_b = _mm_load_ss(&igtbl_b[src[2]]); | 244 vec_b = _mm_load_ss(&igtbl_b[src[2]]); |
| 239 src += 4; | 245 src += 4; |
| 240 | 246 |
| 241 /* use calc'd indices to output RGB values */ | 247 /* use calc'd indices to output RGB values */ |
| 242 dest[0] = otdata_r[output[0]]; | 248 dest[r_out] = otdata_r[output[0]]; |
| 243 dest[1] = otdata_g[output[1]]; | 249 dest[1] = otdata_g[output[1]]; |
| 244 dest[2] = otdata_b[output[2]]; | 250 dest[b_out] = otdata_b[output[2]]; |
| 245 dest += 4; | 251 dest += 4; |
| 246 } | 252 } |
| 247 | 253 |
| 248 /* handle final (maybe only) pixel */ | 254 /* handle final (maybe only) pixel */ |
| 249 | 255 |
| 250 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0); | 256 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0); |
| 251 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0); | 257 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0); |
| 252 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0); | 258 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0); |
| 253 | 259 |
| 254 vec_r = _mm_mul_ps(vec_r, mat0); | 260 vec_r = _mm_mul_ps(vec_r, mat0); |
| 255 vec_g = _mm_mul_ps(vec_g, mat1); | 261 vec_g = _mm_mul_ps(vec_g, mat1); |
| 256 vec_b = _mm_mul_ps(vec_b, mat2); | 262 vec_b = _mm_mul_ps(vec_b, mat2); |
| 257 | 263 |
| 258 dest[3] = alpha; | 264 dest[3] = alpha; |
| 259 | 265 |
| 260 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b)); | 266 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b)); |
| 261 vec_r = _mm_max_ps(min, vec_r); | 267 vec_r = _mm_max_ps(min, vec_r); |
| 262 vec_r = _mm_min_ps(max, vec_r); | 268 vec_r = _mm_min_ps(max, vec_r); |
| 263 result = _mm_mul_ps(vec_r, scale); | 269 result = _mm_mul_ps(vec_r, scale); |
| 264 | 270 |
| 265 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result); | 271 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result); |
| 266 result = _mm_movehl_ps(result, result); | 272 result = _mm_movehl_ps(result, result); |
| 267 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result); | 273 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result); |
| 268 | 274 |
| 269 dest[0] = otdata_r[output[0]]; | 275 dest[r_out] = otdata_r[output[0]]; |
| 270 dest[1] = otdata_g[output[1]]; | 276 dest[1] = otdata_g[output[1]]; |
| 271 dest[2] = otdata_b[output[2]]; | 277 dest[b_out] = otdata_b[output[2]]; |
| 272 | 278 |
| 273 _mm_empty(); | 279 _mm_empty(); |
| 274 } | 280 } |
| OLD | NEW |