jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Cast of prim to small types gives no feedback

Open eponier opened this issue 4 years ago • 2 comments

Consider this example

export fn f (reg u128 x y) -> reg u128 {
   reg u128 z;
   z = (32u)#VPAND(x, y);
   return z;
}

This example compiles fine. The cast (32u) is silently ignored. I think this is done on purpose, but really confusing for the user that has no feedback on what happens. An error would be more user-friendly. Or a warning explaining that this is ignored.

eponier avatar Oct 28 '21 16:10 eponier

The cast is "ignored" since VPAND is by default VPAND_128 and 32 < 128. Actually, the cast is there, but not taken into account for typing.

eponier avatar Oct 28 '21 16:10 eponier

Actually after discussing a bit with @bgregoir, these are not really casts but instead instruction modifiers. Maybe we should think of another syntax then?

Here is another counter-intuitive example. The first one compiles fine, since (32u) is ignored like in the first example above. And the second fails with the message: "typing error: can not implicitly cast u32 into u64". While without (32u) they are both compiled to the same assembly.

export fn f (reg u64 x y) -> reg u64 {
   reg u64 z;
   reg u64 x1 y1;
   x1 = x;
   y1 = y;
   z = (32u)#AND(x1, y1);
   return z;
}
export fn f (reg u64 x y) -> reg u64 {
   reg u64 z;
   reg u64 x1 y1;
   x1 = x;
   y1 = y;
   z = (32u)x1 & y1;
   return z;
}

eponier avatar Oct 29 '21 10:10 eponier