diff options
author | Roger Sayle <roger@nextmovesoftware.com> | 2021-08-24 17:24:19 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2021-08-25 10:20:27 +0200 |
commit | 6bb96d13a2d7f652b614850eb341905031101d32 (patch) | |
tree | c0619f4dbf59c8796a7d20b7992c4f2b1f2064c0 /newlib/libc | |
parent | 1a821390d11d3bc66e6858f27dceeef67e14078d (diff) | |
download | newlib-6bb96d13a2d7f652b614850eb341905031101d32.zip newlib-6bb96d13a2d7f652b614850eb341905031101d32.tar.gz newlib-6bb96d13a2d7f652b614850eb341905031101d32.tar.bz2 |
nvptx: Emulate clock and other machine stubs.
This patch to the libc/machine/nvptx port of newlib implements an
approximation of "clock" and provides some additional stub routines.
These changes not only reduce the number of (link) failures in the GCC
testsuite when targeting nvptx-none, but also allow the NIST scimark4
benchmark to compile and run without modification.
newlib already contains support for backends to provide their own
clock implementations via -DCLOCK_PROVIDED. That functionality is
used here to return an approximate elapsed time based on the NVidia
GPU's clock64 cycle counter. Although not great, this is better than
the current behaviour of link error from the unresolved symbol
_times_r.
The other part of the patch is to add a small number of stub functions
to nvptx's misc.c. Adding isatty, for example, resolves linking
problems in libc from the dependency in __smakebuf_r, and the sync
stub, for example, fixes the failure with GCC's
testsuite/gfortran.dg/ISO_Fortran_binding_14.f90 [which simply tests
that gfortran can call a/any C function].
newlib/
configure.host: Add -DCLOCK_PROVIDED to newlib_cflags on nvptx*.
newlib/libc/machine/nvptx
Makefile.am: Add clock.c to lib_a_SOURCES.
clock.c: New source file to implement/approximate clock().
misc.c: Add stubs for fstat, isatty, open, sync and unlink.
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/machine/nvptx/Makefile.am | 2 | ||||
-rw-r--r-- | newlib/libc/machine/nvptx/Makefile.in | 11 | ||||
-rw-r--r-- | newlib/libc/machine/nvptx/clock.c | 18 | ||||
-rw-r--r-- | newlib/libc/machine/nvptx/configure | 2 | ||||
-rw-r--r-- | newlib/libc/machine/nvptx/misc.c | 25 |
5 files changed, 55 insertions, 3 deletions
diff --git a/newlib/libc/machine/nvptx/Makefile.am b/newlib/libc/machine/nvptx/Makefile.am index 66664d3..b0d4c78 100644 --- a/newlib/libc/machine/nvptx/Makefile.am +++ b/newlib/libc/machine/nvptx/Makefile.am @@ -10,7 +10,7 @@ noinst_LIBRARIES = lib.a lib_a_SOURCES = calloc.c callocr.c malloc.c mallocr.c realloc.c reallocr.c \ free.c write.c assert.c puts.c putchar.c printf.c abort.c \ - exit.c misc.c + exit.c misc.c clock.c lib_a_CFLAGS = $(AM_CFLAGS) ACLOCAL_AMFLAGS = -I ../../.. -I ../../../.. diff --git a/newlib/libc/machine/nvptx/Makefile.in b/newlib/libc/machine/nvptx/Makefile.in index 75256b3..a01e097 100644 --- a/newlib/libc/machine/nvptx/Makefile.in +++ b/newlib/libc/machine/nvptx/Makefile.in @@ -76,7 +76,7 @@ am_lib_a_OBJECTS = lib_a-calloc.$(OBJEXT) lib_a-callocr.$(OBJEXT) \ lib_a-assert.$(OBJEXT) lib_a-puts.$(OBJEXT) \ lib_a-putchar.$(OBJEXT) lib_a-printf.$(OBJEXT) \ lib_a-abort.$(OBJEXT) lib_a-exit.$(OBJEXT) \ - lib_a-misc.$(OBJEXT) + lib_a-misc.$(OBJEXT) lib_a-clock.$(OBJEXT) lib_a_OBJECTS = $(am_lib_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = @@ -188,6 +188,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ +shared_machine_dir = @shared_machine_dir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sys_dir = @sys_dir@ @@ -202,7 +203,7 @@ AM_CCASFLAGS = $(INCLUDES) noinst_LIBRARIES = lib.a lib_a_SOURCES = calloc.c callocr.c malloc.c mallocr.c realloc.c reallocr.c \ free.c write.c assert.c puts.c putchar.c printf.c abort.c \ - exit.c misc.c + exit.c misc.c clock.c lib_a_CFLAGS = $(AM_CFLAGS) ACLOCAL_AMFLAGS = -I ../../.. -I ../../../.. @@ -355,6 +356,12 @@ lib_a-misc.o: misc.c lib_a-misc.obj: misc.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-misc.obj `if test -f 'misc.c'; then $(CYGPATH_W) 'misc.c'; else $(CYGPATH_W) '$(srcdir)/misc.c'; fi` +lib_a-clock.o: clock.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-clock.o `test -f 'clock.c' || echo '$(srcdir)/'`clock.c + +lib_a-clock.obj: clock.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-clock.obj `if test -f 'clock.c'; then $(CYGPATH_W) 'clock.c'; else $(CYGPATH_W) '$(srcdir)/clock.c'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ diff --git a/newlib/libc/machine/nvptx/clock.c b/newlib/libc/machine/nvptx/clock.c new file mode 100644 index 0000000..1ad69f1 --- /dev/null +++ b/newlib/libc/machine/nvptx/clock.c @@ -0,0 +1,18 @@ +/* clock.c + * Support file for nvptx in newlib. + */ +#include <time.h> + +clock_t +clock () +{ + unsigned long long now; +#if __PTX_SM__ >= 310 + asm volatile("mov.u64 %0, %%globaltimer;" : "=r"(now)); + return now/((1000000000ull)/CLOCKS_PER_SEC); +#else + asm volatile("mov.u64 %0, %%clock64;" : "=r"(now)); + // Assume a GPU base clock frequency of 1250MHz. + return now/((1250000000ull)/CLOCKS_PER_SEC); +#endif +} diff --git a/newlib/libc/machine/nvptx/configure b/newlib/libc/machine/nvptx/configure index 282728e..29d16d9 100644 --- a/newlib/libc/machine/nvptx/configure +++ b/newlib/libc/machine/nvptx/configure @@ -565,6 +565,7 @@ ac_unique_file="Makefile.am" ac_subst_vars='LTLIBOBJS LIBOBJS sys_dir +shared_machine_dir machine_dir libm_machine_dir lpfx @@ -3428,6 +3429,7 @@ OBJEXT=${oext} + ac_config_files="$ac_config_files Makefile" cat >confcache <<\_ACEOF diff --git a/newlib/libc/machine/nvptx/misc.c b/newlib/libc/machine/nvptx/misc.c index ed1bc34..ef76eaa 100644 --- a/newlib/libc/machine/nvptx/misc.c +++ b/newlib/libc/machine/nvptx/misc.c @@ -15,6 +15,7 @@ #include <errno.h> #include <sys/types.h> +#include <sys/stat.h> #undef errno extern int errno; @@ -23,12 +24,36 @@ close(int fd) { return -1; } +int +fstat (int fd, struct stat *buf) { + return -1; +} + +int +isatty (int fd) { + return fd == 1; +} + off_t lseek(int fd, off_t offset, int whence) { return 0; } int +open (const char *pathname, int flags, ...) { + return -1; +} + +int read(int fd, void *buf, size_t count) { return 0; } + +void +sync (void) { +} + +int +unlink (const char *pathname) { + return -1; +} |