[PATCH] Emulate clock and other stubs on nvptx

Roger Sayle roger@nextmovesoftware.com
Thu Aug 19 13:57:09 GMT 2021


Hi Joel,


The nvptx-none target doesn’t have an OS, a run-time nor a BIOS.

The only reason that clock may be emulated, is that the hardware has

a register containing the cycle count.  Pretty much the only function

provided is _vprintf, and the entire newlib-cygwin port builds off

of that.  Hence, newlib + the libc/machine/nvptx directory is the

entire operating system.


See https://sourceware.org/legacy-ml/newlib/2018/msg00299.html






From: Joel Sherrill <joel@rtems.org> 
Sent: 19 August 2021 13:59
To: Roger Sayle <roger@nextmovesoftware.com>
Cc: Newlib <newlib@sourceware.org>
Subject: Re: [PATCH] Emulate clock and other stubs on nvptx


Should these be in a machine directory or a libgloss directory? If you ran a different run-time/OS on the CPU, at least some of these wouldn't make sense to be there. 




On Wed, Aug 18, 2021, 11:43 AM Roger Sayle <roger@nextmovesoftware.com <mailto:roger@nextmovesoftware.com> > wrote:

Please be gentle, this is my first patch to newlib.

This patch to the libc/machine/nvptx port of newlib implements an
of "clock" and provides some additional stub routines.  These changes not
reduce the number of (link) failures in the GCC testsuite when targeting
but also allow the NIST scimark4 benchmark to compile and run without

newlib already contains support for backends to provide their own clock
via -DCLOCK_PROVIDED.  That functionality is used here to return an
elapsed time based on the NVidia GPU's clock64 cycle counter.  Although not
this is better than the current behaviour of link error from the unresolved

The other part of the patch is to add a small number of stub functions to
misc.c.  Adding isatty, for example, resolves linking problems in libc from
dependency in __smakebuf_r, and the sync stub, for example, fixes the
with GCC's testsuite/gfortran.dg/ISO_Fortran_binding_14.f90 [which simply
tests that gfortran can call a/any C function].

Hopefully, these changes are acceptable.  If so, if someone could please
them for me that would be much appreciated (as I don't have repository
Likewise, these changes should be obvious enough to not require a copyright
assignment, but to avoid any objections, I'm happy to put them in the public

2021-08-18  Roger Sayle  <roger@nextmovesoftware.com>

        configure.host: Add -DCLOCK_PROVIDED to newlib_cflags on 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.
        Makefile.in: Regenerate.

Many thanks in advance,
Roger Sayle
NextMove Software Limited
Cambridge, UK

More information about the Newlib mailing list