OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 } | 2074 } |
2075 | 2075 |
2076 for (int i = 0; i < 1280; ++i) { | 2076 for (int i = 0; i < 1280; ++i) { |
2077 EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); | 2077 EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); |
2078 EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); | 2078 EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); |
2079 EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); | 2079 EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); |
2080 EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); | 2080 EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); |
2081 } | 2081 } |
2082 } | 2082 } |
2083 | 2083 |
2084 TEST_F(LibYUVPlanarTest, TestHalfFloatPlane) { | 2084 int TestHalfFloatPlane(int benchmark_width, int benchmark_height, |
| 2085 int benchmark_iterations, |
| 2086 int disable_cpu_flags, int benchmark_cpu_info, |
| 2087 float scale) { |
2085 int i, j; | 2088 int i, j; |
2086 const int y_plane_size = benchmark_width_ * benchmark_height_ * 2; | 2089 const int y_plane_size = benchmark_width * benchmark_height * 2; |
2087 | 2090 |
2088 align_buffer_page_end(orig_y, y_plane_size); | 2091 align_buffer_page_end(orig_y, y_plane_size); |
2089 align_buffer_page_end(dst_c, y_plane_size); | 2092 align_buffer_page_end(dst_c, y_plane_size); |
2090 align_buffer_page_end(dst_opt, y_plane_size); | 2093 align_buffer_page_end(dst_opt, y_plane_size); |
2091 MemRandomize(orig_y, y_plane_size); | 2094 MemRandomize(orig_y, y_plane_size); |
2092 memset(dst_c, 0, y_plane_size); | 2095 memset(dst_c, 0, y_plane_size); |
2093 memset(dst_opt, 1, y_plane_size); | 2096 memset(dst_opt, 1, y_plane_size); |
2094 | 2097 |
2095 // Disable all optimizations. | 2098 // Disable all optimizations. |
2096 MaskCpuFlags(disable_cpu_flags_); | 2099 MaskCpuFlags(disable_cpu_flags); |
2097 double c_time = get_time(); | 2100 double c_time = get_time(); |
2098 for (j = 0; j < benchmark_iterations_; j++) { | 2101 for (j = 0; j < benchmark_iterations; j++) { |
2099 HalfFloatPlane((uint16*)orig_y, benchmark_width_ * 2, | 2102 HalfFloatPlane((uint16*)orig_y, benchmark_width * 2, |
2100 (uint16*)dst_c, benchmark_width_ * 2, | 2103 (uint16*)dst_c, benchmark_width * 2, |
2101 1.0f / 4096.0f, benchmark_width_, benchmark_height_); | 2104 scale, benchmark_width, benchmark_height); |
2102 } | 2105 } |
2103 c_time = (get_time() - c_time) / benchmark_iterations_; | 2106 c_time = (get_time() - c_time) / benchmark_iterations; |
2104 | 2107 |
2105 // Enable optimizations. | 2108 // Enable optimizations. |
2106 MaskCpuFlags(benchmark_cpu_info_); | 2109 MaskCpuFlags(benchmark_cpu_info); |
2107 double opt_time = get_time(); | 2110 double opt_time = get_time(); |
2108 for (j = 0; j < benchmark_iterations_; j++) { | 2111 for (j = 0; j < benchmark_iterations; j++) { |
2109 HalfFloatPlane((uint16*)orig_y, benchmark_width_ * 2, | 2112 HalfFloatPlane((uint16*)orig_y, benchmark_width * 2, |
2110 (uint16*)dst_opt, benchmark_width_ * 2, | 2113 (uint16*)dst_opt, benchmark_width * 2, |
2111 1.0f / 4096.0f, benchmark_width_, benchmark_height_); | 2114 scale, benchmark_width, benchmark_height); |
2112 } | 2115 } |
2113 opt_time = (get_time() - opt_time) / benchmark_iterations_; | 2116 opt_time = (get_time() - opt_time) / benchmark_iterations; |
2114 | 2117 |
| 2118 int diff = 0; |
2115 for (i = 0; i < y_plane_size; ++i) { | 2119 for (i = 0; i < y_plane_size; ++i) { |
2116 EXPECT_EQ(dst_c[i], dst_opt[i]); | 2120 diff = dst_c[i] - dst_opt[i]; |
| 2121 if (diff) break; |
2117 } | 2122 } |
2118 | 2123 |
2119 free_aligned_buffer_page_end(orig_y); | 2124 free_aligned_buffer_page_end(orig_y); |
2120 free_aligned_buffer_page_end(dst_c); | 2125 free_aligned_buffer_page_end(dst_c); |
2121 free_aligned_buffer_page_end(dst_opt); | 2126 free_aligned_buffer_page_end(dst_opt); |
| 2127 return diff; |
| 2128 } |
| 2129 |
| 2130 // 5 bit exponent with bias of 15 will underflow to a denormal if scale causes |
| 2131 // exponent to be less than 0. 15 - log2(65536) = -1/ This shouldnt normally |
| 2132 // happen since scale is 1/(1<<bits) where bits is 9, 10 or 12. |
| 2133 TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_denormal) { |
| 2134 int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_, |
| 2135 benchmark_iterations_, |
| 2136 disable_cpu_flags_, benchmark_cpu_info_, |
| 2137 1.0f / 65536.0f); |
| 2138 EXPECT_EQ(diff, 0); |
| 2139 } |
| 2140 |
| 2141 TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_Opt) { |
| 2142 int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_, |
| 2143 benchmark_iterations_, |
| 2144 disable_cpu_flags_, benchmark_cpu_info_, |
| 2145 1.0f / 4096.0f); |
| 2146 EXPECT_EQ(diff, 0); |
| 2147 } |
| 2148 |
| 2149 TEST_F(LibYUVPlanarTest, TestHalfFloatPlane_Offby1) { |
| 2150 int diff = TestHalfFloatPlane(benchmark_width_, benchmark_height_, |
| 2151 benchmark_iterations_, |
| 2152 disable_cpu_flags_, benchmark_cpu_info_, |
| 2153 1.0f / 1023.0f); |
| 2154 EXPECT_EQ(diff, 0); |
2122 } | 2155 } |
2123 | 2156 |
2124 TEST_F(LibYUVPlanarTest, TestARGBLumaColorTable) { | 2157 TEST_F(LibYUVPlanarTest, TestARGBLumaColorTable) { |
2125 SIMD_ALIGNED(uint8 orig_pixels[1280][4]); | 2158 SIMD_ALIGNED(uint8 orig_pixels[1280][4]); |
2126 SIMD_ALIGNED(uint8 dst_pixels_opt[1280][4]); | 2159 SIMD_ALIGNED(uint8 dst_pixels_opt[1280][4]); |
2127 SIMD_ALIGNED(uint8 dst_pixels_c[1280][4]); | 2160 SIMD_ALIGNED(uint8 dst_pixels_c[1280][4]); |
2128 memset(orig_pixels, 0, sizeof(orig_pixels)); | 2161 memset(orig_pixels, 0, sizeof(orig_pixels)); |
2129 | 2162 |
2130 align_buffer_page_end(lumacolortable, 32768); | 2163 align_buffer_page_end(lumacolortable, 32768); |
2131 int v = 0; | 2164 int v = 0; |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2487 } | 2520 } |
2488 | 2521 |
2489 free_aligned_buffer_page_end(src_pixels); | 2522 free_aligned_buffer_page_end(src_pixels); |
2490 free_aligned_buffer_page_end(tmp_pixels_u); | 2523 free_aligned_buffer_page_end(tmp_pixels_u); |
2491 free_aligned_buffer_page_end(tmp_pixels_v); | 2524 free_aligned_buffer_page_end(tmp_pixels_v); |
2492 free_aligned_buffer_page_end(dst_pixels_opt); | 2525 free_aligned_buffer_page_end(dst_pixels_opt); |
2493 free_aligned_buffer_page_end(dst_pixels_c); | 2526 free_aligned_buffer_page_end(dst_pixels_c); |
2494 } | 2527 } |
2495 | 2528 |
2496 } // namespace libyuv | 2529 } // namespace libyuv |
OLD | NEW |