SPIRV-Cross/reference/shaders-msl-no-opt/comp/bitfield.comp
2019-09-24 14:35:25 -04:00

48 lines
1.2 KiB
Plaintext

#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
// Implementation of the GLSL findLSB() function
template<typename T>
inline T spvFindLSB(T x)
{
return select(ctz(x), T(-1), x == T(0));
}
// Implementation of the signed GLSL findMSB() function
template<typename T>
inline T spvFindSMSB(T x)
{
T v = select(x, T(-1) - x, x < T(0));
return select(clz(T(0)) - (clz(v) + T(1)), T(-1), v == T(0));
}
// Implementation of the unsigned GLSL findMSB() function
template<typename T>
inline T spvFindUMSB(T x)
{
return select(clz(T(0)) - (clz(x) + T(1)), T(-1), x == T(0));
}
kernel void main0()
{
int signed_value = 0;
uint unsigned_value = 0u;
int s = extract_bits(signed_value, uint(5), uint(20));
uint u = extract_bits(unsigned_value, uint(6), uint(21));
s = insert_bits(s, 40, uint(5), uint(4));
u = insert_bits(u, 60u, uint(5), uint(4));
u = reverse_bits(u);
s = reverse_bits(s);
int v0 = int(popcount(u));
int v1 = popcount(s);
int v2 = int(spvFindUMSB(u));
int v3 = spvFindSMSB(s);
int v4 = int(spvFindLSB(u));
int v5 = spvFindLSB(s);
}