How to define struct field type in Metal Shading Language?
You need to specify an address space for the function itself. Otherwise, you can't use address-space specific stuff.
Here's the right definition:
struct uint128_t {
uint64_t lo;
uint64_t hi;
device uint64_t& operator[](int i) device {
return (i == 0) ? lo : hi;
}
};