llvm-capstone/libc
Joseph Huber 30307a7bb7 [libc] Implement the 'clock()' function on the GPU
This patch implements the `clock()` function on the GPU. This function
is supposed to return a timestamp that can be converted into seconds
using the `CLOCKS_PER_SEC` macro. The GPU has a fixed frequency timer
that can be used for this purpose. However, there are some
considerations.

First is that AMDGPU does not have a statically known fixed frequency. I
know internally that the gfx10xx and gfx11xx series use a 100 MHz clock
which will probably remain for the future. Gfx9xx typically uses a 25
MHz clock except for the Vega 10 GPU. The only way to know for sure is
to look it up from the runtime. For this purpose, I elected to default
it to some known values and assign these to an exteranlly visible symbol
that can be initialized if needed. If we do not have a good guess we
just return zero.

Second is that the `CLOCKS_PER_SEC` macro only gives about a microsecond
of resolution. POSIX demands that it's 1,000,000 so it's best that we
keep with this tradition as almost all targets seem to respect this. The
reason this is important is because on the GPU we will almost assuredly
be copying the host's macro value (see the wrapper header) so we should
go with the POSIX version that's most likely to be set. (We could
probably make a warning if the included header doesn't match the
expected value).

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D159118
2023-08-30 16:16:34 -05:00
..
AOR_v20.02 [NFC][Py Reformat] Reformat python files in the rest of the dirs 2023-05-25 11:17:05 +02:00
benchmarks [test][libc] Fix aligned_alloc argument 2023-08-07 16:36:20 -07:00
cmake/modules [libc] Add missing ${LIBC_INCLUDE_DIR} to object rule 2023-08-29 05:22:14 +00:00
config [libc] Implement the 'clock()' function on the GPU 2023-08-30 16:16:34 -05:00
docs [libc] Implement the 'clock()' function on the GPU 2023-08-30 16:16:34 -05:00
examples Reland "[CMake] Bumps minimum version to 3.20.0. 2023-05-27 12:51:21 +02:00
fuzzing [libc] Add fuzzing for printf floats 2023-08-15 16:23:24 -07:00
include [libc] Implement the 'clock()' function on the GPU 2023-08-30 16:16:34 -05:00
lib [libc] Build two different static archives libc.a and libm.a under full build. 2023-01-31 21:45:08 +00:00
spec [libc][math] Implement double precision exp10 function correctly rounded for all rounding modes. 2023-08-30 08:43:50 -04:00
src [libc] Implement the 'clock()' function on the GPU 2023-08-30 16:16:34 -05:00
startup [libc] Fix set_thread_ptr call in rv32 start up code 2023-08-30 11:30:56 -03:00
test [libc] Fix test case that expects time_t to be a 32-bit type 2023-08-30 11:24:19 -03:00
utils [libc] Remove MAX_LANE_SIZE definition from the RPC server 2023-08-23 12:09:30 -05:00
.clang-tidy [libc][NFC] Clean up clang-tidy warnings for src/__support and src/math. 2023-03-15 18:47:31 -04:00
.gitignore
CMakeLists.txt [libc] _INCLUDE_SCUDO: check for compiler-rt in enabled RUNTIMES too 2023-07-27 05:11:54 +01:00
common_libc_tuners.cmake [libc][NFC] Make tuning macros start with LIBC_COPT_ 2023-02-15 10:00:16 +00:00
LICENSE.TXT
README.txt

LLVM libc
=========

This directory and its subdirectories contain source code for llvm-libc,
a retargetable implementation of the C standard library.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.