From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 0F479384F4A3; Mon, 21 Nov 2022 12:12:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F479384F4A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669032746; bh=r3MxkyFd6C470iyDYKA/lxWzyYtCyqL6MQE3y45nIdI=; h=From:To:Subject:Date:From; b=TP3YeoLHApM86bX79q2sn4ziQg2wHkfj1TpJUMDsNn0H/F1rq96vpmK5s55q1Mvfp LOMuEf8aq7dwZMrHHCRU74nrb+Q319JlJ1ovHef3US1dibTfnR0opHqt8+s0xjjAWS rbh/FeuHM8toF70+VewtHuibe8RDfxI9/mopAfW8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] amdgcn: Replace asm("s8") by __builtin_gcn_kernarg_ptr if existing X-Act-Checkin: newlib-cygwin X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/master X-Git-Oldrev: 32d6a6cb5f1e5a136ae86247e124edd68dc1800e X-Git-Newrev: b9898fc99379b35e41311012c4a3fe5b60305a3d Message-Id: <20221121121226.0F479384F4A3@sourceware.org> Date: Mon, 21 Nov 2022 12:12:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Db9898fc9937= 9b35e41311012c4a3fe5b60305a3d commit b9898fc99379b35e41311012c4a3fe5b60305a3d Author: Tobias Burnus Date: Fri Nov 18 09:50:20 2022 +0100 amdgcn: Replace asm("s8") by __builtin_gcn_kernarg_ptr if existing =20 Check whether __builtin_gcn_kernarg_ptr is available and, if it is, call it instead using the hard-coded 'asm("s8")' in: * newlib/libc/machine/amdgcn/exit-value.h (exit_with_int) * newlib/libc/machine/amdgcn/mlock.c (sbrk) * newlib/libc/sys/amdgcn/write.c (write) =20 newlib/libc/machine/amdgcn/exit-value.h | 6 ++++++ newlib/libc/machine/amdgcn/mlock.c | 10 +++++++--- newlib/libc/sys/amdgcn/write.c | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) Diff: --- newlib/libc/machine/amdgcn/exit-value.h | 6 ++++++ newlib/libc/machine/amdgcn/mlock.c | 10 +++++++--- newlib/libc/sys/amdgcn/write.c | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/newlib/libc/machine/amdgcn/exit-value.h b/newlib/libc/machine/= amdgcn/exit-value.h index 6e88625b7..7aa2508bb 100644 --- a/newlib/libc/machine/amdgcn/exit-value.h +++ b/newlib/libc/machine/amdgcn/exit-value.h @@ -21,8 +21,14 @@ exit_with_int (int val) { /* Write the exit value to the conventional place. */ int *return_value; +#if defined(__has_builtin) && __has_builtin(__builtin_gcn_kernarg_ptr) + asm ("s_load_dwordx2 %0, %1, 16 glc\n\t" + "s_waitcnt 0" + : "=3DSg"(return_value) : "r"(__builtin_gcn_kernarg_ptr())); +#else asm ("s_load_dwordx2 %0, s[8:9], 16 glc\n\t" "s_waitcnt 0" : "=3DSg"(return_value)); +#endif *return_value =3D val; =20 /* Terminate the current kernel. */ diff --git a/newlib/libc/machine/amdgcn/mlock.c b/newlib/libc/machine/amdgc= n/mlock.c index 4848c978c..fbc4944e6 100644 --- a/newlib/libc/machine/amdgcn/mlock.c +++ b/newlib/libc/machine/amdgcn/mlock.c @@ -39,11 +39,15 @@ sbrk (ptrdiff_t nbytes) { if (__heap_ptr =3D=3D (char *)-1) { - /* Find the heap from kernargs. - The kernargs pointer is in s[8:9]. - This will break if the enable_sgpr_* flags are ever changed. */ + /* Find the heap from kernargs. */ char *kernargs; +#if defined(__has_builtin) && __has_builtin(__builtin_gcn_kernarg_ptr) + kernargs =3D __builtin_gcn_kernarg_ptr (); +#else + /* The kernargs pointer is in s[8:9]. + This will break if the enable_sgpr_* flags are ever changed. */ asm ("s_mov_b64 %0, s[8:9]" : "=3DSg"(kernargs)); +#endif =20 /* The heap data is at kernargs[3]. */ struct heap *heap =3D *(struct heap **)(kernargs + 24); diff --git a/newlib/libc/sys/amdgcn/write.c b/newlib/libc/sys/amdgcn/write.c index 9c0d2a968..39e28c1e6 100644 --- a/newlib/libc/sys/amdgcn/write.c +++ b/newlib/libc/sys/amdgcn/write.c @@ -56,7 +56,11 @@ _READ_WRITE_RETURN_TYPE write (int fd, const void *buf, = size_t count) } =20 /* The output data is at ((void*)kernargs)[2]. */ +#if defined(__has_builtin) && __has_builtin(__builtin_gcn_kernarg_ptr) + register void **kernargs =3D __builtin_gcn_kernarg_ptr (); +#else register void **kernargs asm("s8"); +#endif struct output *data =3D (struct output *)kernargs[2]; =20 /* Each output slot allows 256 bytes, so reserve as many as we need. */