diff options
author | dcherednik <dcherednik@ydb.tech> | 2022-10-26 16:40:35 +0300 |
---|---|---|
committer | dcherednik <dcherednik@ydb.tech> | 2022-10-26 16:40:35 +0300 |
commit | b981cca279190176740c3bf5c5b4fd03be51b599 (patch) | |
tree | f5ec6210fdce0e976cbbe4dc8ae78bb6509adf49 /contrib/libs/cxxsupp/builtins | |
parent | 6dc0de995652f7eeecdbdb88dc98b00bb0653a2f (diff) | |
download | ydb-b981cca279190176740c3bf5c5b4fd03be51b599.tar.gz |
Enable linux-arm platform.
Diffstat (limited to 'contrib/libs/cxxsupp/builtins')
-rw-r--r-- | contrib/libs/cxxsupp/builtins/CMakeLists.linux-aarch64.txt | 62 | ||||
-rw-r--r-- | contrib/libs/cxxsupp/builtins/CMakeLists.txt | 4 | ||||
-rw-r--r-- | contrib/libs/cxxsupp/builtins/clear_cache.c | 159 | ||||
-rw-r--r-- | contrib/libs/cxxsupp/builtins/multc3.c | 68 |
4 files changed, 292 insertions, 1 deletions
diff --git a/contrib/libs/cxxsupp/builtins/CMakeLists.linux-aarch64.txt b/contrib/libs/cxxsupp/builtins/CMakeLists.linux-aarch64.txt new file mode 100644 index 0000000000..d2753ebe29 --- /dev/null +++ b/contrib/libs/cxxsupp/builtins/CMakeLists.linux-aarch64.txt @@ -0,0 +1,62 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(libs-cxxsupp-builtins) +target_compile_options(libs-cxxsupp-builtins PRIVATE + -Wno-everything +) +target_sources(libs-cxxsupp-builtins PRIVATE + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/addtf3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/ashlti3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/clzti2.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/comparetf2.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/divdc3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/divsc3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/divtf3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/divti3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/divxc3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/extenddftf2.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/extendsftf2.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixdfti.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixsfti.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixtfdi.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixtfsi.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixunsdfti.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixunssfti.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixunstfdi.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixunstfsi.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixunstfti.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/fixunsxfti.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/floatditf.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/floatsitf.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/floattidf.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/floattisf.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/floatunditf.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/floatunsitf.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/floatuntidf.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/floatuntisf.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/gcc_personality_v0.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/int_util.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/lshrti3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/modti3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/muldc3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/muloti4.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/mulsc3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/multf3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/mulxc3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/popcountdi2.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/subtf3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/trunctfdf2.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/trunctfsf2.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/udivmodti4.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/udivti3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/umodti3.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/clear_cache.c + ${CMAKE_SOURCE_DIR}/contrib/libs/cxxsupp/builtins/multc3.c +) diff --git a/contrib/libs/cxxsupp/builtins/CMakeLists.txt b/contrib/libs/cxxsupp/builtins/CMakeLists.txt index 79468a5d8d..3e0811fb22 100644 --- a/contrib/libs/cxxsupp/builtins/CMakeLists.txt +++ b/contrib/libs/cxxsupp/builtins/CMakeLists.txt @@ -6,7 +6,9 @@ # original buildsystem will not be accepted. -if (APPLE) +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux-aarch64.txt) +elseif (APPLE) include(CMakeLists.darwin.txt) elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID) include(CMakeLists.linux.txt) diff --git a/contrib/libs/cxxsupp/builtins/clear_cache.c b/contrib/libs/cxxsupp/builtins/clear_cache.c new file mode 100644 index 0000000000..8eec068939 --- /dev/null +++ b/contrib/libs/cxxsupp/builtins/clear_cache.c @@ -0,0 +1,159 @@ +/* ===-- clear_cache.c - Implement __clear_cache ---------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_lib.h" +#include <stddef.h> + +#if __APPLE__ + #include <libkern/OSCacheControl.h> +#endif +#if (defined(__FreeBSD__) || defined(__Bitrig__)) && defined(__arm__) + #include <sys/types.h> + #include <machine/sysarch.h> +#endif + +#if defined(__NetBSD__) && defined(__arm__) + #include <machine/sysarch.h> +#endif + +#if defined(__mips__) + #include <sys/cachectl.h> + #include <sys/syscall.h> + #include <unistd.h> + #if defined(__ANDROID__) && defined(__LP64__) + /* + * clear_mips_cache - Invalidates instruction cache for Mips. + */ + static void clear_mips_cache(const void* Addr, size_t Size) { + asm volatile ( + ".set push\n" + ".set noreorder\n" + ".set noat\n" + "beq %[Size], $zero, 20f\n" /* If size == 0, branch around. */ + "nop\n" + "daddu %[Size], %[Addr], %[Size]\n" /* Calculate end address + 1 */ + "rdhwr $v0, $1\n" /* Get step size for SYNCI. + $1 is $HW_SYNCI_Step */ + "beq $v0, $zero, 20f\n" /* If no caches require + synchronization, branch + around. */ + "nop\n" + "10:\n" + "synci 0(%[Addr])\n" /* Synchronize all caches around + address. */ + "daddu %[Addr], %[Addr], $v0\n" /* Add step size. */ + "sltu $at, %[Addr], %[Size]\n" /* Compare current with end + address. */ + "bne $at, $zero, 10b\n" /* Branch if more to do. */ + "nop\n" + "sync\n" /* Clear memory hazards. */ + "20:\n" + "bal 30f\n" + "nop\n" + "30:\n" + "daddiu $ra, $ra, 12\n" /* $ra has a value of $pc here. + Add offset of 12 to point to the + instruction after the last nop. + */ + "jr.hb $ra\n" /* Return, clearing instruction + hazards. */ + "nop\n" + ".set pop\n" + : [Addr] "+r"(Addr), [Size] "+r"(Size) + :: "at", "ra", "v0", "memory" + ); + } + #endif +#endif + +#if defined(__ANDROID__) && defined(__arm__) + #include <asm/unistd.h> +#endif + +/* + * The compiler generates calls to __clear_cache() when creating + * trampoline functions on the stack for use with nested functions. + * It is expected to invalidate the instruction cache for the + * specified range. + */ + +void __clear_cache(void *start, void *end) { +#if __i386__ || __x86_64__ +/* + * Intel processors have a unified instruction and data cache + * so there is nothing to do + */ +#elif defined(__arm__) && !defined(__APPLE__) + #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__Bitrig__) + struct arm_sync_icache_args arg; + + arg.addr = (uintptr_t)start; + arg.len = (uintptr_t)end - (uintptr_t)start; + + sysarch(ARM_SYNC_ICACHE, &arg); + #elif defined(__ANDROID__) + int start_reg __asm("r0") = (int) (intptr_t) start; + const register int end_reg __asm("r1") = (int) (intptr_t) end; + const register int flags __asm("r2") = 0; + const register int syscall_nr __asm("r7") = __ARM_NR_cacheflush; + __asm __volatile("svc 0x0" : "=r"(start_reg) + : "r"(syscall_nr), "r"(start_reg), "r"(end_reg), "r"(flags) : "r0"); + if (start_reg != 0) { + compilerrt_abort(); + } + #else + compilerrt_abort(); + #endif +#elif defined(__mips__) + const uintptr_t start_int = (uintptr_t) start; + const uintptr_t end_int = (uintptr_t) end; + #if defined(__ANDROID__) && defined(__LP64__) + // Call synci implementation for short address range. + const uintptr_t address_range_limit = 256; + if ((end_int - start_int) <= address_range_limit) { + clear_mips_cache(start, (end_int - start_int)); + } else { + syscall(__NR_cacheflush, start, (end_int - start_int), BCACHE); + } + #else + syscall(__NR_cacheflush, start, (end_int - start_int), BCACHE); + #endif +#elif defined(__aarch64__) && !defined(__APPLE__) + uint64_t xstart = (uint64_t)(uintptr_t) start; + uint64_t xend = (uint64_t)(uintptr_t) end; + uint64_t addr; + + // Get Cache Type Info + uint64_t ctr_el0; + __asm __volatile("mrs %0, ctr_el0" : "=r"(ctr_el0)); + + /* + * dc & ic instructions must use 64bit registers so we don't use + * uintptr_t in case this runs in an IPL32 environment. + */ + const size_t dcache_line_size = 4 << ((ctr_el0 >> 16) & 15); + for (addr = xstart; addr < xend; addr += dcache_line_size) + __asm __volatile("dc cvau, %0" :: "r"(addr)); + __asm __volatile("dsb ish"); + + const size_t icache_line_size = 4 << ((ctr_el0 >> 0) & 15); + for (addr = xstart; addr < xend; addr += icache_line_size) + __asm __volatile("ic ivau, %0" :: "r"(addr)); + __asm __volatile("isb sy"); +#else + #if __APPLE__ + /* On Darwin, sys_icache_invalidate() provides this functionality */ + sys_icache_invalidate(start, end-start); + #else + compilerrt_abort(); + #endif +#endif +} + diff --git a/contrib/libs/cxxsupp/builtins/multc3.c b/contrib/libs/cxxsupp/builtins/multc3.c new file mode 100644 index 0000000000..0518bc2569 --- /dev/null +++ b/contrib/libs/cxxsupp/builtins/multc3.c @@ -0,0 +1,68 @@ +/* ===-- multc3.c - Implement __multc3 -------------------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + * + * This file implements __multc3 for the compiler_rt library. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_lib.h" +#include "int_math.h" + +/* Returns: the product of a + ib and c + id */ + +COMPILER_RT_ABI long double _Complex +__multc3(long double a, long double b, long double c, long double d) +{ + long double ac = a * c; + long double bd = b * d; + long double ad = a * d; + long double bc = b * c; + long double _Complex z; + __real__ z = ac - bd; + __imag__ z = ad + bc; + if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { + int recalc = 0; + if (crt_isinf(a) || crt_isinf(b)) { + a = crt_copysignl(crt_isinf(a) ? 1 : 0, a); + b = crt_copysignl(crt_isinf(b) ? 1 : 0, b); + if (crt_isnan(c)) + c = crt_copysignl(0, c); + if (crt_isnan(d)) + d = crt_copysignl(0, d); + recalc = 1; + } + if (crt_isinf(c) || crt_isinf(d)) { + c = crt_copysignl(crt_isinf(c) ? 1 : 0, c); + d = crt_copysignl(crt_isinf(d) ? 1 : 0, d); + if (crt_isnan(a)) + a = crt_copysignl(0, a); + if (crt_isnan(b)) + b = crt_copysignl(0, b); + recalc = 1; + } + if (!recalc && (crt_isinf(ac) || crt_isinf(bd) || + crt_isinf(ad) || crt_isinf(bc))) { + if (crt_isnan(a)) + a = crt_copysignl(0, a); + if (crt_isnan(b)) + b = crt_copysignl(0, b); + if (crt_isnan(c)) + c = crt_copysignl(0, c); + if (crt_isnan(d)) + d = crt_copysignl(0, d); + recalc = 1; + } + if (recalc) { + __real__ z = CRT_INFINITY * (a * c - b * d); + __imag__ z = CRT_INFINITY * (a * d + b * c); + } + } + return z; +} |