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

[shader-ast] Bitwise shift operation #434

Open
sylee957 opened this issue Dec 28, 2023 · 3 comments
Open

[shader-ast] Bitwise shift operation #434

sylee957 opened this issue Dec 28, 2023 · 3 comments

Comments

@sylee957
Copy link

I can't find bitwise shift operators >>, << in shader-ast.
Is it not implemented yet?
I'm trying the workaround

export const lshift = <T extends "int" | "uint" | IVec | UVec>(
  a: Term<T>,
  b: IntTerm | UintTerm
) => op2("<<", a, b) as Op2<T>;
export const rshift = <T extends "int" | "uint" | IVec | UVec>(
  a: Term<T>,
  b: IntTerm | UintTerm
) => op2(">>", a, b) as Op2<T>;
@postspectacular
Copy link
Member

I'm really surprised these weren't included yet, I will have to add a few more variations (function overrides) for these, but in general, yes, the above is the correct approach...

@postspectacular
Copy link
Member

The 2 relevant commits, just for reference:

a986766

a78d313

@sylee957
Copy link
Author

sylee957 commented Dec 31, 2023

Unfortunately, I still see some problems for types if one operand is signed and the other operand is unsigned

I found this from specification:

One operand can be signed while the other is unsigned.

const a = sym("int");
const b = sym("uint");
lshift(a, b);
const a = sym("uint");
const b = sym("int");
lshift(a, b);

And I think that same applies for vectors, such as

const a = sym("uvec2");
const b = sym("int");
lshift(a, b);
const a = sym("uvec2");
const b = sym("ivec2");
lshift(a, b);

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

2 participants