Skip to content

Alternative way for "decode bit" #7

@42Bastian

Description

@42Bastian

Hi
there is already one "alternative", but w.r.t. 8bit CPUs it can be changed like this:

 unsigned char prob  = upkr_probs[context_index];
 int bit = (upkr_state & 255) < prob ? 1 : 0;
 if ( bit ) prob = -prob;
 upkr_state -= ((upkr_state >> 8)+(bit ^ 1))*prob;
 prob -= (prob + 8)>>4;
 if ( bit ) prob = -prob;

The difference is the use of char which removes the need for 256-prob.

Another alternative:

  int prob  = upkr_probs[context_index];
  int bit = (upkr_state & 255) < prob ? 1 : 0;
  if ( bit ) {
    upkr_state = (upkr_state >> 8)*prob+(upkr_state & 0xff);
    prob += (256 + 8 - prob) >> 4;
  } else {
    upkr_state -= ((upkr_state >> 8) + 1)*prob;
    prob -= (prob+8)>>4;
  }

Maybe add this also to c_unpacker folder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions