mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 14:31:08 +01:00
Signed integer overflow is undefined behaviour in MSL. However, signed integers are defined to be two's complement. This allows us to cast signed values to their corresponding unsigned type, perform the arithmetic on these unsigned values (which has defined overflow behaviour) then cast the result back to signed. Care must be taken when emitting the isign polyfill, which uses metal::select(). We must ensure the -1, 0, and 1 literals used as inputs to select() have the correct width, else bitcasting the output of select() will fail due to mismatched widths.
24 lines
380 B
Plaintext
24 lines
380 B
Plaintext
// language: metal1.0
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
using metal::uint;
|
|
|
|
struct type_1 {
|
|
int member;
|
|
};
|
|
|
|
void function(
|
|
device type_1& unnamed
|
|
) {
|
|
int _e3 = unnamed.member;
|
|
unnamed.member = as_type<int>(as_type<uint>(_e3) + as_type<uint>(1));
|
|
return;
|
|
}
|
|
|
|
kernel void main_(
|
|
device type_1& unnamed [[user(fake0)]]
|
|
) {
|
|
function(unnamed);
|
|
}
|