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

Suggestion : writing 'sign' and 'grade' in WebAssembly #12

Open
grondilu opened this issue Aug 26, 2017 · 0 comments
Open

Suggestion : writing 'sign' and 'grade' in WebAssembly #12

grondilu opened this issue Aug 26, 2017 · 0 comments

Comments

@grondilu
Copy link

grondilu commented Aug 26, 2017

Hello,

for better performance, it may be desirable to port this library to WebAssembly.

It is a bit early to try to port the whole thing, but two crucial functions can already be ported easily : 'sign' and 'grade'. It is my understanding that those two functions are a performance bottleneck, so they may be worth implementing right now.

The following C code can be compiled for instance with the WASM explorer:

typedef unsigned long int integer;
int grade(integer b);

int sign(integer a, integer b) {
  integer n = a >> 1;
  int sum = 0;
  while (n != 0) {
    sum += grade(n & b);
    n >>= 1;
  }
  return sum&1 ? -1 : 1;
}

int grade(integer b) {
  unsigned int n = 0;
  while (b != 0) {
    if (b&1) { n++; }
    b >>= 1;
  }
  return n;
}

That would limit the number of vector dimensions to 32 (or 64 if we really want that), but who needs more than 32 vector dimensions anyway?

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