mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
39 lines
735 B
Plaintext
39 lines
735 B
Plaintext
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
typedef metal::uint type1[1];
|
|
struct PrimeIndices {
|
|
type1 data;
|
|
};
|
|
|
|
metal::uint collatz_iterations(
|
|
metal::uint n_base
|
|
) {
|
|
metal::uint n;
|
|
metal::uint i = 0u;
|
|
n = n_base;
|
|
while(true) {
|
|
if (n <= 1u) {
|
|
break;
|
|
}
|
|
if ((n % 2u) == 0u) {
|
|
n = n / 2u;
|
|
} else {
|
|
n = (3u * n) + 1u;
|
|
}
|
|
i = i + 1u;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
struct main1Input {
|
|
};
|
|
kernel void main1(
|
|
metal::uint3 global_id [[thread_position_in_grid]]
|
|
, device PrimeIndices& v_indices [[user(fake0)]]
|
|
) {
|
|
metal::uint _e9 = collatz_iterations(v_indices.data[global_id.x]);
|
|
v_indices.data[global_id.x] = _e9;
|
|
return;
|
|
}
|