From 760e86baf25542c7d0af2cf05eaea5679ff915ce Mon Sep 17 00:00:00 2001 From: zhoujing Date: Thu, 13 Jul 2023 09:21:50 +0800 Subject: [PATCH] [VENTUS][RISCV][fix&feat] Add cl_khr_fp64 support and add missing header file --- build-ventus.sh | 6 +- clang/lib/Basic/Targets/RISCV.h | 1 + libclc/riscv32/lib/compiler-rt/libm.h | 63 ++++++++++++++++++++ libclc/riscv32/lib/compiler-rt/nextafterf.cl | 9 ++- 4 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 libclc/riscv32/lib/compiler-rt/libm.h diff --git a/build-ventus.sh b/build-ventus.sh index 209f14a3270b..b79ac9b64e1f 100755 --- a/build-ventus.sh +++ b/build-ventus.sh @@ -176,10 +176,10 @@ build_libclc() { -DCMAKE_LLAsm_COMPILER_WORKS=ON \ -DCMAKE_CLC_COMPILER_WORKS=ON \ -DCMAKE_CLC_COMPILER_FORCED=ON \ - -DCMAKE_LLAsm_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0" \ - -DCMAKE_CLC_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -I${DIR}/libclc/generic/include" \ + -DCMAKE_LLAsm_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -Dcl_khr_fp64" \ + -DCMAKE_CLC_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -I${DIR}/libclc/generic/include -Dcl_khr_fp64" \ -DLIBCLC_TARGETS_TO_BUILD="riscv32--" \ - -DCMAKE_CXX_FLAGS="-I ${DIR}/llvm/include/ -std=c++17" \ + -DCMAKE_CXX_FLAGS="-I ${DIR}/llvm/include/ -std=c++17 -Dcl_khr_fp64" \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_INSTALL_PREFIX=${VENTUS_INSTALL_PREFIX} \ diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index b5b9434e42d7..21b18b97d31d 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -133,6 +133,7 @@ public: Opts["__opencl_c_3d_image_writes"] = true; Opts["cl_khr_3d_image_writes"] = true; Opts["cl_khr_byte_addressable_store"] = true; + Opts["cl_khr_fp64"] = true; } LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override { diff --git a/libclc/riscv32/lib/compiler-rt/libm.h b/libclc/riscv32/lib/compiler-rt/libm.h new file mode 100644 index 000000000000..d0a3ca510f09 --- /dev/null +++ b/libclc/riscv32/lib/compiler-rt/libm.h @@ -0,0 +1,63 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#ifndef LIBM_H +#define LIBM_H + +#define FE_INVALID 1 +#define __FE_DENORM 2 +#define FE_DIVBYZERO 4 +#define FE_OVERFLOW 8 +#define FE_UNDERFLOW 16 +#define FE_INEXACT 32 + +#define FE_ALL_EXCEPT 63 + +#define FE_TONEAREST 0 +#define FE_DOWNWARD 0x400 +#define FE_UPWARD 0x800 +#define FE_TOWARDZERO 0xc00 + +typedef unsigned short fexcept_t; + +typedef struct { + unsigned short __control_word; + unsigned short __unused1; + unsigned short __status_word; + unsigned short __unused2; + unsigned short __tags; + unsigned short __unused3; + unsigned int __eip; + unsigned short __cs_selector; + unsigned int __opcode; + unsigned int __unused4; + unsigned int __data_offset; + unsigned short __data_selector; + unsigned short __unused5; + unsigned int __mxcsr; +} _fenv_t; + +#define FE_DFL_ENV ((const fenv_t *)-1) +static int feclearexcept(int mask) { return 0; } + +static int feraiseexcept(int mask) { return 0; } + +static int _fetestexcept(int mask) { return 0; } + +static int fegetround(void) { return FE_TONEAREST; } + +static int fesetround(int r) { return 0; } + +static int fegetenv(_fenv_t *envp) { return 0; } + +static int fesetenv(const _fenv_t *envp) { return 0; } + +#endif // LIBM_H diff --git a/libclc/riscv32/lib/compiler-rt/nextafterf.cl b/libclc/riscv32/lib/compiler-rt/nextafterf.cl index bbcdd4af91bd..6ed3f7612419 100644 --- a/libclc/riscv32/lib/compiler-rt/nextafterf.cl +++ b/libclc/riscv32/lib/compiler-rt/nextafterf.cl @@ -16,8 +16,11 @@ // //===----------------------------------------------------------------------===// -#include "types.h" +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + +#include "types.h" float __nextafterf(float x, float y) { int hx, hy, ix, iy; @@ -96,10 +99,6 @@ float __nextafterf(float x, float y) { return x; } -#ifdef cl_khr_fp64 - -#pragma OPENCL EXTENSION cl_khr_fp64 : enable - double __nextafter (double x, double y) {