summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/types/intptr.slang
blob: 491fc6c38dcc489f4d7cf04b19b8257f85ce1cb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// intptr.slang

// Test pointer-sized integer types.

//TEST(compute):COMPARE_COMPUTE_EX:-slang -cpu -compute

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

__target_intrinsic(cpp, "sizeof(intptr_t)")
__target_intrinsic(cuda, "sizeof(size_t)")
intptr_t getNativeIntPtrSize();

__generic<T>
__target_intrinsic(cpp, "sizeof($0)")
__target_intrinsic(cuda, "sizeof($0)")
intptr_t getSizeOf(T val);

intptr_t getIntPtrVal() { return 0z; }

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
    let expectedSize = getNativeIntPtrSize();
    intptr_t a = 0z;
    var actualSize = getSizeOf(getIntPtrVal());
    int testResult = 1;
    if (expectedSize != actualSize)
    {
        testResult = 0;
    }
    uintptr_t b = 50uz;
    actualSize = getSizeOf(b);
    if (expectedSize != actualSize)
    {
        testResult = 0;
    }
    outputBuffer[dispatchThreadID.x] = testResult;
    outputBuffer[dispatchThreadID.x+1] = int(b >> 1);

    vector<uintptr_t, 2> c = vector<uintptr_t, 2>(2uz);
    vector<uintptr_t, 2> d = vector<uintptr_t, 2>(3uz);
    outputBuffer[dispatchThreadID.x+2] = int((c+d).y);
}