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

Unsigned integers #120

Open
Razem opened this issue May 19, 2018 · 2 comments
Open

Unsigned integers #120

Razem opened this issue May 19, 2018 · 2 comments

Comments

@Razem
Copy link

Razem commented May 19, 2018

Feature Request

Overview

Walt currently supports only signed integers and signed operations. Since WebAssembly also supports unsigned operations, it would be really neat to also have unsigned types u32 and u64. These operations should be used:

  • i32.div_u and i64.div_u (x / y)
  • i32.rem_u and i64.rem_u (x % y)
  • i32.shr_u and i64.shr_u (x >> y)
  • i32.lt_u and i64.lt_u (x < y)
  • i32.le_u and i64.le_u (x <= y)
  • i32.gt_u and i64.gt_u (x > y)
  • i32.ge_u and i64.ge_u (x >= y)
  • i64.load32_u (const x: u32 = 10; const y: u64 = x;)
  • i32.trunc_u/f32 (const x: f32 = 10; const y: u32 = x;)
  • i32.trunc_u/f64 (const x: f64 = 10; const y: u32 = x;)
  • i64.extend_u/i32 (const x: u32 = 10; const y: u64 = x;)
  • i64.trunc_u/f32 (const x: f32 = 10; const y: u64 = x;)
  • i64.trunc_u/f64 (const x: f64 = 10; const y: u64 = x;)
  • f32.convert_u/i32 (const x: u32 = 10; const y: f32 = x;)
  • f32.convert_u/i64 (const x: u64 = 10; const y: f32 = x;)
  • f64.convert_u/i32 (const x: u32 = 10; const y: f64 = x;)
  • f64.convert_u/i64 (const x: u64 = 10; const y: f64 = x;)

Example

const x: u32 = 42;
const y: u32 = 0xffffffff;
const z: i32 = x < y; // should be 1
@ballercat
Copy link
Owner

Hey, thanks for the suggestion! I can see this being useful for sure. This will add an edge case of signed < unsigned comparisons but without the types, we would have to expose the opcodes above directly.

Will implement this, in some near future.

@Razem
Copy link
Author

Razem commented May 21, 2018

Well, I think in the case of signed < unsigned both operands should be treated as unsigned integers (with some additional option to manually cast an unsigned integer to a signed one). But it would be nice to also have all opcodes accessible in some form.

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

No branches or pull requests

2 participants