Skip to content

Commit

Permalink
Fix stackleft on nvc.
Browse files Browse the repository at this point in the history
  • Loading branch information
insertinterestingnamehere committed Oct 7, 2024
1 parent e49b933 commit f6379ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/qthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,11 +1291,17 @@ API_FUNC void *qthread_bos(void) {
}

size_t API_FUNC qthread_stackleft(void) { /*{{{ */
#if defined(__NVCOMPILER)
qthread_t const volatile *f = qthread_internal_self();
#else
qthread_t const *f = qthread_internal_self();
#endif

if ((f != NULL) && (f->rdata->stack != NULL)) {
#ifdef __INTEL_COMPILER
#if defined(__INTEL_COMPILER)
size_t current = (size_t)&f;
#elif defined(__NVCOMPILER)
volatile size_t current = (size_t)&f;
#else
size_t current = (size_t)__builtin_frame_address(0);
#endif
Expand Down
13 changes: 12 additions & 1 deletion test/basics/qthread_stackleft.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ static aligned_t alldone;

#ifdef __clang__
#define STACKLEFT_NOINLINE __attribute__((optnone))
#elif __GNUC__
#elif defined(__NVCOMPILER)
#define STACKLEFT_NOINLINE __attribute__((noinline))
#elif defined(__GNUC__)
#define STACKLEFT_NOINLINE __attribute__((optimize(0)))
#else
#define STACKLEFT_NOINLINE
Expand All @@ -35,6 +37,11 @@ static aligned_t alldone;
#define QT_SKIP_THREAD_SANITIZER
#endif

#ifdef __NVCOMPILER
#pragma GCC push_options
#pragma GCC optimize("O0")
#endif

static STACKLEFT_NOINLINE size_t thread2(size_t left, size_t depth) {
size_t foo = qthread_stackleft();
iprintf("leveli%i: %zu bytes left\n", (int)depth, foo);
Expand All @@ -43,6 +50,10 @@ static STACKLEFT_NOINLINE size_t thread2(size_t left, size_t depth) {
return 1;
}

#ifdef __NVCOMPILER
#pragma GCC pop_options
#endif

static QT_SKIP_THREAD_SANITIZER aligned_t thread(void *arg) {
int me = qthread_id();
size_t foo = qthread_stackleft();
Expand Down

0 comments on commit f6379ac

Please sign in to comment.