Skip to content

Commit

Permalink
Micro optimization of ArithmeticDecoder_readBit
Browse files Browse the repository at this point in the history
  • Loading branch information
p01 committed Mar 13, 2014
1 parent 2b6cb31 commit bd9419f
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/core/arithmetic_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,41 +128,39 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
var qeTableIcx = QeTable[cx_index];
var qeIcx = qeTableIcx.qe;
var nmpsIcx = qeTableIcx.nmps;
var nlpsIcx = qeTableIcx.nlps;
var switchIcx = qeTableIcx.switchFlag;
var d;
this.a -= qeIcx;
var a = this.a - qeIcx;

if (this.chigh < qeIcx) {
// exchangeLps
if (this.a < qeIcx) {
this.a = qeIcx;
if (a < qeIcx) {
a = qeIcx;
d = cx_mps;
cx_index = nmpsIcx;
cx_index = qeTableIcx.nmps;
} else {
this.a = qeIcx;
d = 1 - cx_mps;
if (switchIcx) {
a = qeIcx;
d = 1 ^ cx_mps;
if (qeTableIcx.switchFlag === 1) {
cx_mps = d;
}
cx_index = nlpsIcx;
cx_index = qeTableIcx.nlps;
}
} else {
this.chigh -= qeIcx;
if ((this.a & 0x8000) !== 0) {
if ((a & 0x8000) !== 0) {
this.a = a;
return cx_mps;
}
// exchangeMps
if (this.a < qeIcx) {
d = 1 - cx_mps;
if (switchIcx) {
if (a < qeIcx) {
d = 1 ^ cx_mps;
if (qeTableIcx.switchFlag === 1) {
cx_mps = d;
}
cx_index = nlpsIcx;
cx_index = qeTableIcx.nlps;
} else {
d = cx_mps;
cx_index = nmpsIcx;
cx_index = qeTableIcx.nmps;
}
}
// C.3.3 renormD;
Expand All @@ -171,11 +169,12 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
this.byteIn();
}

this.a <<= 1;
a <<= 1;
this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
this.clow = (this.clow << 1) & 0xFFFF;
this.ct--;
} while ((this.a & 0x8000) === 0);
} while ((a & 0x8000) === 0);
this.a = a;

contexts[pos] = cx_index << 1 | cx_mps;
return d;
Expand Down

0 comments on commit bd9419f

Please sign in to comment.