Lines Matching full:cdf

55 // decreasing as the values of index increases (note that the |cdf| array is
57 uint32_t ScaleCdf(uint32_t values_in_range_shifted, const uint16_t* const cdf, in ScaleCdf() argument
59 return ((values_in_range_shifted * (cdf[index] >> kCdfPrecision)) >> 1) + in ScaleCdf()
63 void UpdateCdf(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol_count, in UpdateCdf() argument
65 const uint16_t count = cdf[symbol_count]; in UpdateCdf()
67 // 3 + ( cdf[N] > 15 ) + ( cdf[N] > 31 ) + Min(FloorLog2(N), 2) in UpdateCdf()
68 // In this case cdf[N] is |count|. in UpdateCdf()
98 // cdf[i] += static_cast<int16_t>(a - cdf[i]) >> rate; in UpdateCdf()
101 // The subtraction (a - cdf[i]) relies on the overflow semantics of unsigned in UpdateCdf()
110 cdf[i] += (kCdfMaxProbability - cdf[i]) >> rate; in UpdateCdf()
112 cdf[i] -= cdf[i] >> rate; in UpdateCdf()
115 cdf[symbol_count] += static_cast<uint16_t>(count < 32); in UpdateCdf()
128 // cdf[i] += (kCdfMaxProbability - cdf[i]) >> rate;
130 // cdf[i] -= cdf[i] >> rate;
140 // cdf[i] += static_cast<int16_t>(a - cdf[i]) >> rate;
148 // cdf[i] -= static_cast<int16_t>(cdf[i] - a) >> rate;
155 // The cdf array has symbol_count + 1 elements. The first symbol_count elements
156 // are the CDF. The last element is a count that is initialized to 0 and may
157 // grow up to 32. The for loop in UpdateCdf updates the CDF in the array. Since
158 // cdf[symbol_count - 1] is always 0, the for loop does not update
159 // cdf[symbol_count - 1]. However, it would be correct to have the for loop
160 // update cdf[symbol_count - 1] anyway: since symbol_count - 1 >= symbol, the
162 // cdf[i] -= cdf[i] >> rate;
163 // Since cdf[symbol_count - 1] is 0, cdf[symbol_count - 1] would still be 0
169 // the cdf array. Since an invalid CDF value is written into cdf[7], the
170 // count in cdf[7] needs to be fixed up after the vectorized code.
172 void UpdateCdf5(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf5() argument
173 uint16x4_t cdf_vec = vld1_u16(cdf); in UpdateCdf5()
174 const uint16_t count = cdf[5]; in UpdateCdf5()
182 // i < symbol: 32768 - cdf, i >= symbol: 65535 - cdf. in UpdateCdf5()
184 // i < symbol: cdf - 0, i >= symbol: cdf - 65535. in UpdateCdf5()
187 // i < symbol: (32768 - cdf) >> rate, i >= symbol: (65535 (-1) - cdf) >> rate. in UpdateCdf5()
189 // i < symbol: (cdf - 0) + ((32768 - cdf) >> rate). in UpdateCdf5()
190 // i >= symbol: (cdf - 65535) + ((65535 - cdf) >> rate). in UpdateCdf5()
192 vst1_u16(cdf, cdf_vec); in UpdateCdf5()
193 cdf[5] = count + static_cast<uint16_t>(count < 32); in UpdateCdf5()
199 void UpdateCdf7To9(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf7To9() argument
201 uint16x8_t cdf_vec = vld1q_u16(cdf); in UpdateCdf7To9()
202 const uint16_t count = cdf[symbol_count]; in UpdateCdf7To9()
216 vst1q_u16(cdf, cdf_vec); in UpdateCdf7To9()
217 cdf[symbol_count] = count + static_cast<uint16_t>(count < 32); in UpdateCdf7To9()
220 void UpdateCdf7(uint16_t* const cdf, const int symbol) { in UpdateCdf7() argument
221 UpdateCdf7To9<7>(cdf, symbol); in UpdateCdf7()
224 void UpdateCdf8(uint16_t* const cdf, const int symbol) { in UpdateCdf8() argument
225 UpdateCdf7To9<8>(cdf, symbol); in UpdateCdf8()
228 void UpdateCdf9(uint16_t* const cdf, const int symbol) { in UpdateCdf9() argument
229 UpdateCdf7To9<9>(cdf, symbol); in UpdateCdf9()
233 void UpdateCdf11(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf11() argument
234 uint16x8_t cdf_vec = vld1q_u16(cdf + 2); in UpdateCdf11()
235 const uint16_t count = cdf[11]; in UpdateCdf11()
236 cdf[11] = count + static_cast<uint16_t>(count < 32); in UpdateCdf11()
239 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in UpdateCdf11()
240 cdf[1] += (kCdfMaxProbability - cdf[1]) >> rate; in UpdateCdf11()
253 vst1q_u16(cdf + 2, cdf_vec); in UpdateCdf11()
256 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in UpdateCdf11()
257 cdf[1] -= cdf[1] >> rate; in UpdateCdf11()
259 cdf[0] -= cdf[0] >> rate; in UpdateCdf11()
260 cdf[1] -= cdf[1] >> rate; in UpdateCdf11()
265 vst1q_u16(cdf + 2, cdf_vec); in UpdateCdf11()
270 void UpdateCdf13(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf13() argument
271 uint16x8_t cdf_vec0 = vld1q_u16(cdf); in UpdateCdf13()
272 uint16x8_t cdf_vec1 = vld1q_u16(cdf + 4); in UpdateCdf13()
273 const uint16_t count = cdf[13]; in UpdateCdf13()
287 vst1q_u16(cdf, cdf_vec0); in UpdateCdf13()
297 vst1q_u16(cdf + 4, cdf_vec1); in UpdateCdf13()
299 cdf[13] = count + static_cast<uint16_t>(count < 32); in UpdateCdf13()
303 void UpdateCdf16(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf16() argument
304 uint16x8_t cdf_vec = vld1q_u16(cdf); in UpdateCdf16()
305 const uint16_t count = cdf[16]; in UpdateCdf16()
319 vst1q_u16(cdf, cdf_vec); in UpdateCdf16()
321 cdf_vec = vld1q_u16(cdf + 8); in UpdateCdf16()
330 vst1q_u16(cdf + 8, cdf_vec); in UpdateCdf16()
332 cdf[16] = count + static_cast<uint16_t>(count < 32); in UpdateCdf16()
355 void UpdateCdf5(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf5() argument
356 __m128i cdf_vec = LoadLo8(cdf); in UpdateCdf5()
357 const uint16_t count = cdf[5]; in UpdateCdf5()
367 // i < symbol: 32768 - cdf, i >= symbol: 65535 - cdf. in UpdateCdf5()
369 // i < symbol: cdf - 0, i >= symbol: cdf - 65535. in UpdateCdf5()
371 // i < symbol: (32768 - cdf) >> rate, i >= symbol: (65535 (-1) - cdf) >> rate. in UpdateCdf5()
373 // i < symbol: (cdf - 0) + ((32768 - cdf) >> rate). in UpdateCdf5()
374 // i >= symbol: (cdf - 65535) + ((65535 - cdf) >> rate). in UpdateCdf5()
376 StoreLo8(cdf, cdf_vec); in UpdateCdf5()
377 cdf[5] = count + static_cast<uint16_t>(count < 32); in UpdateCdf5()
383 void UpdateCdf7To9(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf7To9() argument
385 __m128i cdf_vec = LoadUnaligned16(cdf); in UpdateCdf7To9()
386 const uint16_t count = cdf[symbol_count]; in UpdateCdf7To9()
399 StoreUnaligned16(cdf, cdf_vec); in UpdateCdf7To9()
400 cdf[symbol_count] = count + static_cast<uint16_t>(count < 32); in UpdateCdf7To9()
403 void UpdateCdf7(uint16_t* const cdf, const int symbol) { in UpdateCdf7() argument
404 UpdateCdf7To9<7>(cdf, symbol); in UpdateCdf7()
407 void UpdateCdf8(uint16_t* const cdf, const int symbol) { in UpdateCdf8() argument
408 UpdateCdf7To9<8>(cdf, symbol); in UpdateCdf8()
411 void UpdateCdf9(uint16_t* const cdf, const int symbol) { in UpdateCdf9() argument
412 UpdateCdf7To9<9>(cdf, symbol); in UpdateCdf9()
416 void UpdateCdf11(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf11() argument
417 __m128i cdf_vec = LoadUnaligned16(cdf + 2); in UpdateCdf11()
418 const uint16_t count = cdf[11]; in UpdateCdf11()
419 cdf[11] = count + static_cast<uint16_t>(count < 32); in UpdateCdf11()
422 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in UpdateCdf11()
423 cdf[1] += (kCdfMaxProbability - cdf[1]) >> rate; in UpdateCdf11()
435 StoreUnaligned16(cdf + 2, cdf_vec); in UpdateCdf11()
438 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in UpdateCdf11()
439 cdf[1] -= cdf[1] >> rate; in UpdateCdf11()
441 cdf[0] -= cdf[0] >> rate; in UpdateCdf11()
442 cdf[1] -= cdf[1] >> rate; in UpdateCdf11()
446 StoreUnaligned16(cdf + 2, cdf_vec); in UpdateCdf11()
451 void UpdateCdf13(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf13() argument
452 __m128i cdf_vec0 = LoadLo8(cdf); in UpdateCdf13()
453 __m128i cdf_vec1 = LoadUnaligned16(cdf + 4); in UpdateCdf13()
454 const uint16_t count = cdf[13]; in UpdateCdf13()
467 StoreLo8(cdf, cdf_vec0); in UpdateCdf13()
477 StoreUnaligned16(cdf + 4, cdf_vec1); in UpdateCdf13()
479 cdf[13] = count + static_cast<uint16_t>(count < 32); in UpdateCdf13()
482 void UpdateCdf16(uint16_t* LIBGAV1_RESTRICT const cdf, const int symbol) { in UpdateCdf16() argument
483 __m128i cdf_vec0 = LoadUnaligned16(cdf); in UpdateCdf16()
484 const uint16_t count = cdf[16]; in UpdateCdf16()
498 StoreUnaligned16(cdf, cdf_vec0); in UpdateCdf16()
500 __m128i cdf_vec1 = LoadUnaligned16(cdf + 8); in UpdateCdf16()
509 StoreUnaligned16(cdf + 8, cdf_vec1); in UpdateCdf16()
511 cdf[16] = count + static_cast<uint16_t>(count < 32); in UpdateCdf16()
516 void UpdateCdf5(uint16_t* const cdf, const int symbol) { in UpdateCdf5() argument
517 UpdateCdf(cdf, 5, symbol); in UpdateCdf5()
520 void UpdateCdf7(uint16_t* const cdf, const int symbol) { in UpdateCdf7() argument
521 UpdateCdf(cdf, 7, symbol); in UpdateCdf7()
524 void UpdateCdf8(uint16_t* const cdf, const int symbol) { in UpdateCdf8() argument
525 UpdateCdf(cdf, 8, symbol); in UpdateCdf8()
528 void UpdateCdf9(uint16_t* const cdf, const int symbol) { in UpdateCdf9() argument
529 UpdateCdf(cdf, 9, symbol); in UpdateCdf9()
532 void UpdateCdf11(uint16_t* const cdf, const int symbol) { in UpdateCdf11() argument
533 UpdateCdf(cdf, 11, symbol); in UpdateCdf11()
536 void UpdateCdf13(uint16_t* const cdf, const int symbol) { in UpdateCdf13() argument
537 UpdateCdf(cdf, 13, symbol); in UpdateCdf13()
540 void UpdateCdf16(uint16_t* const cdf, const int symbol) { in UpdateCdf16() argument
541 UpdateCdf(cdf, 16, symbol); in UpdateCdf16()
647 int EntropyDecoder::ReadSymbol(uint16_t* LIBGAV1_RESTRICT const cdf, in ReadSymbol() argument
649 const int symbol = ReadSymbolImpl(cdf, symbol_count); in ReadSymbol()
651 UpdateCdf(cdf, symbol_count, symbol); in ReadSymbol()
656 bool EntropyDecoder::ReadSymbol(uint16_t* LIBGAV1_RESTRICT cdf) { in ReadSymbol() argument
657 assert(cdf[1] == 0); in ReadSymbol()
658 const bool symbol = ReadSymbolImpl(cdf[0]) != 0; in ReadSymbol()
660 const uint16_t count = cdf[2]; in ReadSymbol()
662 // 3 + ( cdf[N] > 15 ) + ( cdf[N] > 31 ) + Min(FloorLog2(N), 2) in ReadSymbol()
663 // In this case N is 2 and cdf[N] is |count|. So the equation becomes: in ReadSymbol()
677 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in ReadSymbol()
679 cdf[0] -= cdf[0] >> rate; in ReadSymbol()
681 cdf[2] += static_cast<uint16_t>(count < 32); in ReadSymbol()
686 bool EntropyDecoder::ReadSymbolWithoutCdfUpdate(uint16_t cdf) { in ReadSymbolWithoutCdfUpdate() argument
687 return ReadSymbolImpl(cdf) != 0; in ReadSymbolWithoutCdfUpdate()
691 int EntropyDecoder::ReadSymbol(uint16_t* LIBGAV1_RESTRICT const cdf) { in ReadSymbol() argument
694 return ReadSymbol3Or4(cdf, symbol_count); in ReadSymbol()
698 symbol = ReadSymbolImpl8(cdf); in ReadSymbol()
700 symbol = ReadSymbolImpl(cdf, symbol_count); in ReadSymbol()
702 symbol = ReadSymbolImplBinarySearch(cdf, symbol_count); in ReadSymbol()
706 UpdateCdf5(cdf, symbol); in ReadSymbol()
708 UpdateCdf7(cdf, symbol); in ReadSymbol()
710 UpdateCdf8(cdf, symbol); in ReadSymbol()
712 UpdateCdf9(cdf, symbol); in ReadSymbol()
714 UpdateCdf11(cdf, symbol); in ReadSymbol()
716 UpdateCdf13(cdf, symbol); in ReadSymbol()
718 UpdateCdf16(cdf, symbol); in ReadSymbol()
720 UpdateCdf(cdf, symbol_count, symbol); in ReadSymbol()
726 int EntropyDecoder::ReadSymbolImpl(const uint16_t* LIBGAV1_RESTRICT const cdf, in ReadSymbolImpl() argument
728 assert(cdf[symbol_count - 1] == 0); in ReadSymbolImpl()
735 // Search through the |cdf| array to determine where the scaled cdf value and in ReadSymbolImpl()
739 curr = (((values_in_range_ >> 8) * (cdf[++symbol] >> kCdfPrecision)) >> 1) + in ReadSymbolImpl()
750 const uint16_t* LIBGAV1_RESTRICT const cdf, int symbol_count) { in ReadSymbolImplBinarySearch() argument
751 assert(cdf[symbol_count - 1] == 0); in ReadSymbolImplBinarySearch()
755 // Search through the |cdf| array to determine where the scaled cdf value and in ReadSymbolImplBinarySearch()
757 // search to do this. Let |symbol| be the index of the first |cdf| array in ReadSymbolImplBinarySearch()
758 // entry whose scaled cdf value is less than or equal to |symbol_value|. The in ReadSymbolImplBinarySearch()
764 // The binary search maintains the invariants that |prev| is the scaled cdf in ReadSymbolImplBinarySearch()
765 // value for low - 1 and |curr| is the scaled cdf value for high + 1. (By in ReadSymbolImplBinarySearch()
766 // convention, the scaled cdf value for -1 is values_in_range_.) When the in ReadSymbolImplBinarySearch()
767 // binary search terminates, |prev| is the scaled cdf value for symbol - 1 in ReadSymbolImplBinarySearch()
768 // and |curr| is the scaled cdf value for |symbol|. in ReadSymbolImplBinarySearch()
775 ScaleCdf(values_in_range_shifted, cdf, mid, symbol_count); in ReadSymbolImplBinarySearch()
792 int EntropyDecoder::ReadSymbolImpl(uint16_t cdf) { in ReadSymbolImpl() argument
795 (((values_in_range_ >> 8) * (cdf >> kCdfPrecision)) >> 1) + in ReadSymbolImpl()
808 // Equivalent to ReadSymbol(cdf, [3,4]), with the ReadSymbolImpl and UpdateCdf
810 int EntropyDecoder::ReadSymbol3Or4(uint16_t* LIBGAV1_RESTRICT const cdf, in ReadSymbol3Or4() argument
812 assert(cdf[symbol_count - 1] == 0); in ReadSymbol3Or4()
819 // Search through the |cdf| array to determine where the scaled cdf value and in ReadSymbol3Or4()
820 // |symbol_value| cross over. If allow_update_cdf_ is true, update the |cdf| in ReadSymbol3Or4()
829 // ((values_in_range_shifted * (cdf[++symbol] >> kCdfPrecision)) >> 1) in ReadSymbol3Or4()
834 // UpdateCdf(cdf, [3,4], symbol); in ReadSymbol3Or4()
843 ((values_in_range_shifted * (cdf[symbol] >> kCdfPrecision)) >> 1) + delta; in ReadSymbol3Or4()
847 // Inlined version of UpdateCdf(cdf, [3,4], /*symbol=*/0). in ReadSymbol3Or4()
848 const uint16_t count = cdf[symbol_count]; in ReadSymbol3Or4()
849 cdf[symbol_count] += static_cast<uint16_t>(count < 32); in ReadSymbol3Or4()
858 uint16x4_t cdf_vec = vld1_u16(cdf); in ReadSymbol3Or4()
862 vst1_u16(cdf, cdf_vec); in ReadSymbol3Or4()
864 __m128i cdf_vec = LoadLo8(cdf); in ReadSymbol3Or4()
867 StoreLo8(cdf, cdf_vec); in ReadSymbol3Or4()
869 cdf[0] -= cdf[0] >> rate; in ReadSymbol3Or4()
870 cdf[1] -= cdf[1] >> rate; in ReadSymbol3Or4()
871 cdf[2] -= cdf[2] >> rate; in ReadSymbol3Or4()
874 cdf[0] -= cdf[0] >> rate; in ReadSymbol3Or4()
875 cdf[1] -= cdf[1] >> rate; in ReadSymbol3Or4()
885 ((values_in_range_shifted * (cdf[symbol] >> kCdfPrecision)) >> 1) + delta; in ReadSymbol3Or4()
889 // Inlined version of UpdateCdf(cdf, [3,4], /*symbol=*/1). in ReadSymbol3Or4()
890 const uint16_t count = cdf[symbol_count]; in ReadSymbol3Or4()
891 cdf[symbol_count] += static_cast<uint16_t>(count < 32); in ReadSymbol3Or4()
893 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in ReadSymbol3Or4()
894 cdf[1] -= cdf[1] >> rate; in ReadSymbol3Or4()
895 if (symbol_count == 4) cdf[2] -= cdf[2] >> rate; in ReadSymbol3Or4()
904 curr = ((values_in_range_shifted * (cdf[symbol] >> kCdfPrecision)) >> 1) + in ReadSymbol3Or4()
909 // Inlined version of UpdateCdf(cdf, 4, /*symbol=*/2). in ReadSymbol3Or4()
910 const uint16_t count = cdf[4]; in ReadSymbol3Or4()
911 cdf[4] += static_cast<uint16_t>(count < 32); in ReadSymbol3Or4()
913 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in ReadSymbol3Or4()
914 cdf[1] += (kCdfMaxProbability - cdf[1]) >> rate; in ReadSymbol3Or4()
915 cdf[2] -= cdf[2] >> rate; in ReadSymbol3Or4()
924 // Since cdf[symbol_count - 1] is 0 and |delta| is 0, |curr| is also 0. in ReadSymbol3Or4()
928 // Inlined version of UpdateCdf(cdf, [3,4], /*symbol=*/[2,3]). in ReadSymbol3Or4()
929 const uint16_t count = cdf[symbol_count]; in ReadSymbol3Or4()
930 cdf[symbol_count] += static_cast<uint16_t>(count < 32); in ReadSymbol3Or4()
937 uint16x4_t cdf_vec = vld1_u16(cdf); in ReadSymbol3Or4()
945 vst1_u16(cdf, cdf_vec); in ReadSymbol3Or4()
946 cdf[3] = 0; in ReadSymbol3Or4()
948 __m128i cdf_vec = LoadLo8(cdf); in ReadSymbol3Or4()
954 StoreLo8(cdf, cdf_vec); in ReadSymbol3Or4()
955 cdf[3] = 0; in ReadSymbol3Or4()
957 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in ReadSymbol3Or4()
958 cdf[1] += (kCdfMaxProbability - cdf[1]) >> rate; in ReadSymbol3Or4()
959 cdf[2] += (kCdfMaxProbability - cdf[2]) >> rate; in ReadSymbol3Or4()
962 cdf[0] += (kCdfMaxProbability - cdf[0]) >> rate; in ReadSymbol3Or4()
963 cdf[1] += (kCdfMaxProbability - cdf[1]) >> rate; in ReadSymbol3Or4()
976 const uint16_t* LIBGAV1_RESTRICT const cdf) { in ReadSymbolImpl8() argument
977 assert(cdf[7] == 0); in ReadSymbolImpl8()
982 // Search through the |cdf| array to determine where the scaled cdf value and in ReadSymbolImpl8()
991 // (((values_in_range_ >> 8) * (cdf[++symbol] >> kCdfPrecision)) >> 1) in ReadSymbolImpl8()
1001 curr = (((values_in_range_ >> 8) * (cdf[symbol] >> kCdfPrecision)) >> 1) + \ in ReadSymbolImpl8()
1021 (((values_in_range_ >> 8) * (cdf[symbol] >> kCdfPrecision)) >> 1) + delta; in ReadSymbolImpl8()
1027 // Since cdf[7] is 0 and |delta| is 0, |curr| is also 0. in ReadSymbolImpl8()
1106 template int EntropyDecoder::ReadSymbol<3>(uint16_t* cdf);
1107 template int EntropyDecoder::ReadSymbol<4>(uint16_t* cdf);
1108 template int EntropyDecoder::ReadSymbol<5>(uint16_t* cdf);
1109 template int EntropyDecoder::ReadSymbol<6>(uint16_t* cdf);
1110 template int EntropyDecoder::ReadSymbol<7>(uint16_t* cdf);
1111 template int EntropyDecoder::ReadSymbol<8>(uint16_t* cdf);
1112 template int EntropyDecoder::ReadSymbol<9>(uint16_t* cdf);
1113 template int EntropyDecoder::ReadSymbol<10>(uint16_t* cdf);
1114 template int EntropyDecoder::ReadSymbol<11>(uint16_t* cdf);
1115 template int EntropyDecoder::ReadSymbol<12>(uint16_t* cdf);
1116 template int EntropyDecoder::ReadSymbol<13>(uint16_t* cdf);
1117 template int EntropyDecoder::ReadSymbol<14>(uint16_t* cdf);
1118 template int EntropyDecoder::ReadSymbol<16>(uint16_t* cdf);