1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
12 namespace cloudViewer {
15 // defines to simplify the SASS assembly structure file/line in the profiler
16 #define GET_BITFIELD_U32(OUT, VAL, POS, LEN) \
17 asm("bfe.u32 %0, %1, %2, %3;" : "=r"(OUT) : "r"(VAL), "r"(POS), "r"(LEN));
19 #define GET_BITFIELD_U64(OUT, VAL, POS, LEN) \
20 asm("bfe.u64 %0, %1, %2, %3;" : "=l"(OUT) : "l"(VAL), "r"(POS), "r"(LEN));
22 __device__ __forceinline__ unsigned int getBitfield(unsigned int val,
26 asm("bfe.u32 %0, %1, %2, %3;" : "=r"(ret) : "r"(val), "r"(pos), "r"(len));
30 __device__ __forceinline__ uint64_t getBitfield(uint64_t val,
34 asm("bfe.u64 %0, %1, %2, %3;" : "=l"(ret) : "l"(val), "r"(pos), "r"(len));
38 __device__ __forceinline__ unsigned int setBitfield(unsigned int val,
39 unsigned int toInsert,
43 asm("bfi.b32 %0, %1, %2, %3, %4;"
45 : "r"(toInsert), "r"(val), "r"(pos), "r"(len));
49 __device__ __forceinline__ int getLaneId() {
51 asm("mov.u32 %0, %%laneid;" : "=r"(laneId));
55 __device__ __forceinline__ unsigned getLaneMaskLt() {
57 asm("mov.u32 %0, %%lanemask_lt;" : "=r"(mask));
61 __device__ __forceinline__ unsigned getLaneMaskLe() {
63 asm("mov.u32 %0, %%lanemask_le;" : "=r"(mask));
67 __device__ __forceinline__ unsigned getLaneMaskGt() {
69 asm("mov.u32 %0, %%lanemask_gt;" : "=r"(mask));
73 __device__ __forceinline__ unsigned getLaneMaskGe() {
75 asm("mov.u32 %0, %%lanemask_ge;" : "=r"(mask));
79 __device__ __forceinline__ void namedBarrierWait(int name, int numThreads) {
80 asm volatile("bar.sync %0, %1;" : : "r"(name), "r"(numThreads) : "memory");
83 __device__ __forceinline__ void namedBarrierArrived(int name, int numThreads) {
84 asm volatile("bar.arrive %0, %1;"
86 : "r"(name), "r"(numThreads)
91 } // namespace cloudViewer