Skip to content

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

@grondilu

Description

@grondilu

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?

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