From: Tobias Burnus <tobias@codesourcery.com>
To: <newlib@sourceware.org>
Cc: Andrew Stubbs <ams@codesourcery.com>
Subject: [Patch] amdgcn: Replace asm("s8") by __builtin_gcn_kernarg_ptr if existing
Date: Fri, 18 Nov 2022 09:50:20 +0100 [thread overview]
Message-ID: <70c6dbbb-9087-856c-b99d-5968d4d85886@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 440 bytes --]
This avoids a hard-coded assembler value by replacing it by a call
to a builtin (if available). This builtin is provided by GCC mainline (GCC 13).
Thanks,
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: newlib-kernarg-ptr.diff --]
[-- Type: text/x-patch, Size: 2848 bytes --]
amdgcn: Replace asm("s8") by __builtin_gcn_kernarg_ptr if existing
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)
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"
+ : "=Sg"(return_value) : "r"(__builtin_gcn_kernarg_ptr()));
+#else
asm ("s_load_dwordx2 %0, s[8:9], 16 glc\n\t"
"s_waitcnt 0" : "=Sg"(return_value));
+#endif
*return_value = val;
/* Terminate the current kernel. */
diff --git a/newlib/libc/machine/amdgcn/mlock.c b/newlib/libc/machine/amdgcn/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 == (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 = __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]" : "=Sg"(kernargs));
+#endif
/* The heap data is at kernargs[3]. */
struct heap *heap = *(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)
}
/* The output data is at ((void*)kernargs)[2]. */
+#if defined(__has_builtin) && __has_builtin(__builtin_gcn_kernarg_ptr)
+ register void **kernargs = __builtin_gcn_kernarg_ptr ();
+#else
register void **kernargs asm("s8");
+#endif
struct output *data = (struct output *)kernargs[2];
/* Each output slot allows 256 bytes, so reserve as many as we need. */
next reply other threads:[~2022-11-18 8:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 8:50 Tobias Burnus [this message]
2022-11-21 12:13 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=70c6dbbb-9087-856c-b99d-5968d4d85886@codesourcery.com \
--to=tobias@codesourcery.com \
--cc=ams@codesourcery.com \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).