Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative way for "decode bit" #7

Open
42Bastian opened this issue Nov 7, 2022 · 0 comments
Open

Alternative way for "decode bit" #7

42Bastian opened this issue Nov 7, 2022 · 0 comments

Comments

@42Bastian
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant