diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f6a42756fd..62439c86d57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,9 @@ endif() if( ${TARGET_OS} STREQUAL "Linux" ) set(OS "LINUX") set(OSNAME "Linux") +elseif( ${TARGET_OS} STREQUAL "Darwin" ) + set(OS "OSX") + set(OSNAME "macOS") else() message("Unsupported OS: ${TARGET_OS}" ) return() diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 4b775a15334..10db715793f 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -19,6 +19,10 @@ endif () # flang* executables SET(CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS}") +include(CheckSymbolExists) +check_symbol_exists(clock_settime "time.h" HAVE_CLOCK_SETTIME) +configure_file(libflang_config.h.in libflang_config.h) + SET(FTN_INTRINSICS_DESC_INDEP abort3f.c access3f.c @@ -508,10 +512,12 @@ add_dependencies(flang_shared flang_static) target_link_libraries(flang_shared flangrti_shared) # Resolve symbols against libm and librt -if (NOT MSVC) - target_link_libraries(flang_shared m rt) -else() +if (MSVC) set_target_properties(flang_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) +elseif (APPLE) + target_link_libraries(flang_shared m) +else() + target_link_libraries(flang_shared m rt) endif() set(SHARED_LIBRARY FALSE) diff --git a/runtime/flang/global.h b/runtime/flang/global.h index 54b640a6d5f..2c5f3e71f4b 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -80,7 +80,6 @@ typedef char sbool; /* short boolean (for use in large structs) */ #define assert(ex) #endif -extern char *strcpy(); #define STASH(str) (strcpy((char *)malloc(strlen(str) + 1), str)) /* defs used by __fortio_error */ diff --git a/runtime/flang/libflang_config.h.in b/runtime/flang/libflang_config.h.in new file mode 100644 index 00000000000..d36c120282b --- /dev/null +++ b/runtime/flang/libflang_config.h.in @@ -0,0 +1,4 @@ +#ifndef LIBFLANG_CONFIG_H +#define LIBFLANG_CONFIG_H +#cmakedefine HAVE_CLOCK_SETTIME +#endif diff --git a/runtime/flang/stime3f.c b/runtime/flang/stime3f.c index d8a58f9ad89..4864393286d 100644 --- a/runtime/flang/stime3f.c +++ b/runtime/flang/stime3f.c @@ -9,12 +9,13 @@ /* stime3f.c - Implements LIB3F stime subprogram. */ -#ifndef WINNT - +#include "libflang_config.h" #include #include "io3f.h" #include "ent3f.h" +#ifdef HAVE_CLOCK_SETTIME + int ENT3F(STIME, stime)(int *tp) { int i; @@ -27,4 +28,4 @@ int ENT3F(STIME, stime)(int *tp) return i; } -#endif /* !WINNT */ +#endif /* HAVE_CLOCK_SETTIME */ diff --git a/runtime/flangrti/ktrap.c b/runtime/flangrti/ktrap.c index c28debaef2b..573152d65bf 100644 --- a/runtime/flangrti/ktrap.c +++ b/runtime/flangrti/ktrap.c @@ -50,7 +50,11 @@ __ktrap(void) excepts |= FE_UNDERFLOW; if (bv & 0x100) excepts |= FE_INEXACT; +#ifdef TARGET_OSX + __fenv_feenableexcept(excepts); +#else feenableexcept(excepts); /* glibc 2.2 extension to fenv.h */ +#endif } } } diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index 88bb024f983..d8f6488bfe9 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -13,7 +13,7 @@ #else #include #include -#include +#include #include #endif #include diff --git a/runtime/libpgmath/lib/common/CMakeLists.txt b/runtime/libpgmath/lib/common/CMakeLists.txt index cbeaa18e8d0..59454c9de87 100644 --- a/runtime/libpgmath/lib/common/CMakeLists.txt +++ b/runtime/libpgmath/lib/common/CMakeLists.txt @@ -127,7 +127,7 @@ elseif(${LIBPGMATH_SYSTEM_PROCESSOR} MATCHES "ppc64le") mth_128defs_init.c mth_128defs_stats.c) libmath_add_object_library("${MTH_INTRINSICS_SRCS}" "${FLAGS}" "${DEFINITIONS}" "mth_intrinsics") - + set(SRCS kidnnt.c sincos.c @@ -454,7 +454,7 @@ else() libmath_add_object_library("${TARGET_NAME}.c" "${FLAGS}" "${DEFINITIONS}" "${TARGET_NAME}_build") add_dependencies("${TARGET_NAME}_build" ${TARGET_NAME}) endif() - + # Generate tmp-mth_statsdefs.h set(TARGET_NAME "tmp-mth_statsdefs") add_custom_command(OUTPUT ${TARGET_NAME}.h PRE_BUILD @@ -466,6 +466,6 @@ add_dependencies(dispatch ${TARGET_NAME} tmp-mth_alldefs) add_dependencies(dispatch ${TARGET_NAME} tmp-mth_statsdefs) target_include_directories(dispatch BEFORE - PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../${PROCESSOR}/math_tables PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../generic/math_tables) diff --git a/runtime/libpgmath/lib/common/dceil.c b/runtime/libpgmath/lib/common/dceil.c index b1f8675e1d7..5c7ad04b19b 100644 --- a/runtime/libpgmath/lib/common/dceil.c +++ b/runtime/libpgmath/lib/common/dceil.c @@ -6,26 +6,44 @@ */ #include "mthdecls.h" -#if defined(__SSE4_1__) || defined(__AVX__) -#include -#endif -#if defined(__AVX__) +#if defined(TARGET_X8664) +/* + * For X8664, implement both SSE and AVX versions of __mth_i_ceil using ISA + * instruction extensions. + * + * Using inline assembly allows both the SSE and AVX versions of the routine + * to be compiled in a single unit. + * + * The following asm statements is equivalent to: + * return _mm_cvtss_f32(_mm_ceil_ss(_mm_set1_ps(x), _mm_set1_ps(x))); + * But without the need for separate compiliations for SSE4.1 and AVX ISA + * extensions. + */ + double -__mth_i_dceil_avx(double x) +__mth_i_dceil_sse(double x) { - return _mm_cvtsd_f64(_mm_ceil_sd(_mm_set1_pd(x), _mm_set1_pd(x))); + __asm__( + "roundsd $0x2,%0,%0" + :"+x"(x) + ); + return x; } -#elif defined(__SSE4_1__) + double -__mth_i_dceil_sse(double x) +__mth_i_dceil_avx(double x) { - return _mm_cvtsd_f64(_mm_ceil_sd(_mm_set1_pd(x), _mm_set1_pd(x))); + __asm__( + "vroundsd $0x2,%0,%0,%0" + :"+x"(x) + ); + return x; } -#else +#endif + double __mth_i_dceil(double x) { return ceil(x); } -#endif diff --git a/runtime/libpgmath/lib/common/dfloor.c b/runtime/libpgmath/lib/common/dfloor.c index db5c54cbe0f..092b88184e6 100644 --- a/runtime/libpgmath/lib/common/dfloor.c +++ b/runtime/libpgmath/lib/common/dfloor.c @@ -6,26 +6,44 @@ */ #include "mthdecls.h" -#if defined(__SSE4_1__) || defined(__AVX__) -#include -#endif -#if defined(__AVX__) +#if defined(TARGET_X8664) +/* + * For X8664, implement both SSE and AVX versions of __mth_i_dfloor using ISA + * instruction extensions. + * + * Using inline assembly allows both the SSE and AVX versions of the routine + * to be compiled in a single unit. + * + * The following asm statements is equivalent to: + * return _mm_cvtss_f32(_mm_floor_sd(_mm_set1_ps(x), _mm_set1_ps(x))); + * But without the need for separate compiliations for SSE4.1 and AVX ISA + * extensions. + */ + double -__mth_i_dfloor_avx(double x) +__mth_i_dfloor_sse(double x) { - return _mm_cvtsd_f64(_mm_floor_sd(_mm_set1_pd(x), _mm_set1_pd(x))); + __asm__( + "roundsd $0x1,%0,%0" + :"+x"(x) + ); + return x; } -#elif defined(__SSE4_1__) + double -__mth_i_dfloor_sse(double x) +__mth_i_dfloor_avx(double x) { - return _mm_cvtsd_f64(_mm_floor_sd(_mm_set1_pd(x), _mm_set1_pd(x))); + __asm__( + "vroundsd $0x1,%0,%0,%0" + :"+x"(x) + ); + return x; } -#else +#endif + double __mth_i_dfloor(double x) { return floor(x); } -#endif diff --git a/runtime/libpgmath/lib/common/floor.c b/runtime/libpgmath/lib/common/floor.c index 6895671951f..7a813450c00 100644 --- a/runtime/libpgmath/lib/common/floor.c +++ b/runtime/libpgmath/lib/common/floor.c @@ -6,26 +6,44 @@ */ #include "mthdecls.h" -#if defined(__SSE4_1__) || defined(__AVX__) -#include -#endif -#if defined(__AVX__) +#if defined(TARGET_X8664) +/* + * For X8664, implement both SSE and AVX versions of __mth_i_floor using ISA + * instruction extensions. + * + * Using inline assembly allows both the SSE and AVX versions of the routine + * to be compiled in a single unit. + * + * The following asm statements is equivalent to: + * return _mm_cvtss_f32(_mm_floor_ss(_mm_set1_ps(x), _mm_set1_ps(x))); + * But without the need for separate compiliations for SSE4.1 and AVX ISA + * extensions. + */ + float -__mth_i_floor_avx(float x) +__mth_i_floor_sse(float x) { - return _mm_cvtss_f32(_mm_floor_ss(_mm_set1_ps(x), _mm_set1_ps(x))); + __asm__( + "roundss $0x1,%0,%0" + :"+x"(x) + ); + return x; } -#elif defined(__SSE4_1__) + float -__mth_i_floor_sse(float x) +__mth_i_floor_avx(float x) { - return _mm_cvtss_f32(_mm_floor_ss(_mm_set1_ps(x), _mm_set1_ps(x))); + __asm__( + "vroundss $0x1,%0,%0,%0" + :"+x"(x) + ); + return x; } -#else +#endif + float __mth_i_floor(float x) { return floorf(x); } -#endif diff --git a/runtime/libpgmath/lib/x86_64/math_tables/mth_ceildefs.h b/runtime/libpgmath/lib/x86_64/math_tables/mth_ceildefs.h index a1ab3e41859..b2c567cfd56 100644 --- a/runtime/libpgmath/lib/x86_64/math_tables/mth_ceildefs.h +++ b/runtime/libpgmath/lib/x86_64/math_tables/mth_ceildefs.h @@ -5,8 +5,14 @@ * */ -MTHINTRIN(ceil , ss , any , __mth_i_ceil , __mth_i_ceil , __mth_i_ceil ,__math_dispatch_error) -MTHINTRIN(ceil , ds , any , __mth_i_dceil , __mth_i_dceil , __mth_i_dceil ,__math_dispatch_error) +MTHINTRIN(ceil , ss , any , __mth_i_ceil , __mth_i_ceil , __mth_i_ceil ,__math_dispatch_error) +MTHINTRIN(ceil , ds , em64t , __mth_i_dceil , __mth_i_dceil , __mth_i_dceil ,__math_dispatch_error) +MTHINTRIN(ceil , ds , sse4 , __mth_i_dceil_sse , __mth_i_dceil_sse , __mth_i_dceil_sse ,__math_dispatch_error) +MTHINTRIN(ceil , ds , avx , __mth_i_dceil_avx , __mth_i_dceil_avx , __mth_i_dceil_avx ,__math_dispatch_error) +MTHINTRIN(ceil , ds , avxfma4 , __mth_i_dceil_avx , __mth_i_dceil_avx , __mth_i_dceil_avx ,__math_dispatch_error) +MTHINTRIN(ceil , ds , avx2 , __mth_i_dceil_avx , __mth_i_dceil_avx , __mth_i_dceil_avx ,__math_dispatch_error) +MTHINTRIN(ceil , ds , avx512knl , __mth_i_dceil_avx , __mth_i_dceil_avx , __mth_i_dceil_avx ,__math_dispatch_error) +MTHINTRIN(ceil , ds , avx512 , __mth_i_dceil_avx , __mth_i_dceil_avx , __mth_i_dceil_avx ,__math_dispatch_error) MTHINTRIN(ceil , sv4 , any , __gs_ceil_4_f , __gs_ceil_4_r , __gs_ceil_4_p ,__math_dispatch_error) MTHINTRIN(ceil , dv2 , any , __gd_ceil_2_f , __gd_ceil_2_r , __gd_ceil_2_p ,__math_dispatch_error) MTHINTRIN(ceil , sv8 , any , __gs_ceil_8_f , __gs_ceil_8_r , __gs_ceil_8_p ,__math_dispatch_error) diff --git a/runtime/libpgmath/lib/x86_64/math_tables/mth_floordefs.h b/runtime/libpgmath/lib/x86_64/math_tables/mth_floordefs.h index f7fdcc58ba4..dfb80a74bf2 100644 --- a/runtime/libpgmath/lib/x86_64/math_tables/mth_floordefs.h +++ b/runtime/libpgmath/lib/x86_64/math_tables/mth_floordefs.h @@ -5,8 +5,20 @@ * */ -MTHINTRIN(floor , ss , any , __mth_i_floor , __mth_i_floor , __mth_i_floor ,__math_dispatch_error) -MTHINTRIN(floor , ds , any , __mth_i_dfloor , __mth_i_dfloor , __mth_i_dfloor ,__math_dispatch_error) +MTHINTRIN(floor , ss , em64t , __mth_i_floor , __mth_i_floor , __mth_i_floor ,__math_dispatch_error) +MTHINTRIN(floor , ds , em64t , __mth_i_dfloor , __mth_i_dfloor , __mth_i_dfloor ,__math_dispatch_error) +MTHINTRIN(floor , ss , sse4 , __mth_i_floor_sse , __mth_i_floor_sse , __mth_i_floor_sse ,__math_dispatch_error) +MTHINTRIN(floor , ds , sse4 , __mth_i_dfloor_sse , __mth_i_dfloor_sse , __mth_i_dfloor_sse ,__math_dispatch_error) +MTHINTRIN(floor , ss , avx , __mth_i_floor_avx , __mth_i_floor_avx , __mth_i_floor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ds , avx , __mth_i_dfloor_avx , __mth_i_dfloor_avx , __mth_i_dfloor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ss , avxfma4 , __mth_i_floor_avx , __mth_i_floor_avx , __mth_i_floor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ds , avxfma4 , __mth_i_dfloor_avx , __mth_i_dfloor_avx , __mth_i_dfloor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ss , avx2 , __mth_i_floor_avx , __mth_i_floor_avx , __mth_i_floor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ds , avx2 , __mth_i_dfloor_avx , __mth_i_dfloor_avx , __mth_i_dfloor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ss , avx512knl , __mth_i_floor_avx , __mth_i_floor_avx , __mth_i_floor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ds , avx512knl , __mth_i_dfloor_avx , __mth_i_dfloor_avx , __mth_i_dfloor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ss , avx512 , __mth_i_floor_avx , __mth_i_floor_avx , __mth_i_floor_avx ,__math_dispatch_error) +MTHINTRIN(floor , ds , avx512 , __mth_i_dfloor_avx , __mth_i_dfloor_avx , __mth_i_dfloor_avx ,__math_dispatch_error) MTHINTRIN(floor , sv4 , any , __gs_floor_4_f , __gs_floor_4_r , __gs_floor_4_p ,__math_dispatch_error) MTHINTRIN(floor , dv2 , any , __gd_floor_2_f , __gd_floor_2_r , __gd_floor_2_p ,__math_dispatch_error) MTHINTRIN(floor , sv8 , any , __gs_floor_8_f , __gs_floor_8_r , __gs_floor_8_p ,__math_dispatch_error) diff --git a/tools/flang1/flang1exe/gbldefs.h b/tools/flang1/flang1exe/gbldefs.h index 6da96a98e39..e9cfb24b9a4 100644 --- a/tools/flang1/flang1exe/gbldefs.h +++ b/tools/flang1/flang1exe/gbldefs.h @@ -162,7 +162,6 @@ char *mkfname(const char *, const char *, const char *); /* from miscutil.c: */ bool is_xflag_bit(int); void set_xflag(int, INT); void set_yflag(int, INT); -void bzero(void *, size_t); void list_init(FILE *); /* listing.c: */ void list_line(const char *); /* listing.c */ void list_page(void); /* listing.c */