Commit Graph

110 Commits

Author SHA1 Message Date
Pirama Arumuga Nainar 4a39e80809 Fix incorrect truncation at the overflow boundary
Summary:
This patch fixes incorrect truncation when the input wider value is
exactly 2^dstBits.  For that value, the overflow to infinity is not
correctly handled.  The fix is to replace a strict '>' with '>='.

Currently,
__truncdfsf2(340282366900000000000000000000000000000.0) returns infinity
__truncdfsf2(340282366920938463463374607431768211456.0) returns 0
__truncdfsf2(400000000000000000000000000000000000000.0) returns infinity

Likewise, __truncdfhf2 and __truncsfhf2 (and consequently gnu_f2h_ieee)
are discontinuous at 65536.0.

This patch adds tests for all three cases, along with adding a missing
header include to fp_test.h.

Reviewers: joerg, ab, srhines

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D10594

llvm-svn: 240450
2015-06-23 20:24:53 +00:00
Saleem Abdulrasool a3b3952ccd builtins: mark functions as aapcs on Windows
Windows does not use AAPCS, but rather AAPCS-VFP, and thus the functions which
are assumed to be AAPCS will cause invalid argument setup.  Ensure that the
functions are marked as AAPCS.

llvm-svn: 238056
2015-05-22 21:47:24 +00:00
Ahmed Bougacha 9a43d5be2f [Builtins] Implement f2h/h2f by jumping to trunc/extend.
Follow-up to r237161; seems like we can't use aliases, but we
can do better than duplicating the bodies, especially when that
body, after inlining, isn't as small as it looks.

Better approaches welcome.  Perhaps the best thing is just to have
an #ifndef __APPLE__ over the GNUEABI names, since they're not used
there.

llvm-svn: 237323
2015-05-14 00:50:28 +00:00
Ahmed Bougacha f1ac850e77 [Builtins] Implement half-precision conversions.
Mostly uninteresting, except:
- in __extendXfYf2, when checking if the number is normal, the old
  code relied on the unsignedness of src_rep_t, which is a problem
  when sizeof(src_rep_t) < sizeof(int): the result gets promoted to
  int, the signedness of which breaks the comparison.
  I added an explicit cast; it shouldn't affect other types.
- we can't pass __fp16, so src_t and src_rep_t are the same.
- the gnu_*_ieee symbols are simply duplicated definitions, as aliases
  are problematic on mach-o (where only weak aliases are supported;
  that's not what we want).

Differential Revision: http://reviews.llvm.org/D9693

llvm-svn: 237161
2015-05-12 18:33:42 +00:00
Justin Bogner fa7525935b builtins: Implement the functions from stdatomic.h
Talking to John and Doug, we concluded that these functions from
stdatomic really do belong here in compiler-rt rather than in libc,
since the compiler owns stdatomic.h and these need to refer to
clang-specific builtins. Nonetheless, I've only added these on darwin
for now - other platforms should probably do the same unless their
libc does implement these functions.

llvm-svn: 236805
2015-05-08 05:39:05 +00:00
Derek Schuff de036eb170 Fix float->uint conversion for inputs less than 0
Summary:
The spec for these functions says that they should return 0 in this case but
this regressed in r234148. That revision essentially delegates the conversion
to the hardware, but that has different behavior on different platforms (e.g.
it is wrong on x86).

Also fix a typo in the name of __fixunsdfti

Test Plan: The existing unit tests now pass

Reviewers: joerg, howard.hinnant

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9305

llvm-svn: 236319
2015-05-01 16:02:16 +00:00
Sergey Dmitrouk f3206d6278 Add hard float versions of FP to LL conversions
This adds hard-float implementation for the following builtins:

* __fixdfdi()
* __fixsfdi()
* __fixunsdfdi()
* __fixunssfdi()

The soft-float implementation does never raise floating point
exceptions, which doesn't allow clients to detect floating point
conversion errors.

I must mention that I had to refer to libgcc's implementation to
write these functions.

Related unit-tests of compiler-rt passed with these changes.

Patch was somewhat out-dated, so was updated locally without any
functional changes.

Differential Revision: http://reviews.llvm.org/D5376

llvm-svn: 234148
2015-04-06 11:54:51 +00:00
Joerg Sonnenberger 1aa3faaca2 We want single precision here.
llvm-svn: 232125
2015-03-13 00:18:28 +00:00
Ed Maste 9197c8dad0 Use signed int implementation for __fixint
llvm-svn: 232107
2015-03-12 21:36:10 +00:00
Joerg Sonnenberger c8f5c18714 Be nicer to C90 environments and avoid the declaration of variables in for
header.

From Alexander Esilevich.

llvm-svn: 231975
2015-03-11 22:06:53 +00:00
Joerg Sonnenberger 099de18c42 Always include stddef.h to make sure size_t exists.
From Alexander Esilevich.

llvm-svn: 231972
2015-03-11 21:58:40 +00:00
Joerg Sonnenberger 91bd698eaf Refactor float to integer conversion to share the same code.
80bit Intel/PPC long double is excluded due to lacking support
for the abstraction. Consistently provide saturation logic.
Extend to long double on 128bit IEEE extended platforms.

Initial patch with test cases from GuanHong Liu.
Reviewed by Steve Canon.

Differential Revision: http://reviews.llvm.org/D2804

llvm-svn: 231965
2015-03-11 21:13:56 +00:00
Renato Golin 26af9c9024 Allow compiler-rt build on Bitrig
This is the only patch Bitrig uses for compiler-rt. It adds support
for Bitrig/arm in the clear cache code.

Patch by Patrick Wildt.

llvm-svn: 231012
2015-03-02 21:02:43 +00:00
Petar Jovanovic 9ef0d1c145 [MIPS] Add missing header for syscall
The syscall function itself is declared in <unistd.h>
Compiling compiler-rt with -Werror-implicit-function-declaration will
cause a build failure. This change fixes it.

Differential Revision: http://reviews.llvm.org/D7949

llvm-svn: 230838
2015-02-28 02:32:55 +00:00
Ed Schouten f6d492e683 Use compiler provided endianness definitions if available.
This makes int_endianness.h work on operating systems for which we
haven't written explicit constructs, as long as GCC or Clang are being
used.

llvm-svn: 230208
2015-02-23 09:27:49 +00:00
Petar Jovanovic 08fc9e9158 [mips] Add __clear_cache() definition for non-Android systems
Make sure clear_cache() builtin has an appropriate definition for Linux.
Call syscall(NR_cacheflush, ...).

Differential Revision: http://reviews.llvm.org/D7205

llvm-svn: 228767
2015-02-10 23:36:19 +00:00
Stephen Hines 4e52d78767 Remove invalid const qualifier for r0, since it is written by svc.
Summary: This causes an invalid lvalue error when building for Android.

Reviewers: danalbert

Reviewed By: danalbert

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D7306

llvm-svn: 227907
2015-02-03 01:35:39 +00:00
Petar Jovanovic 605c14807f [MIPS64] Make __clear_cache more optimal
Use synci implementation of clear_cache for short address ranges.
For long address ranges, make a kernel call.

Differential Revision: http://reviews.llvm.org/D6661

llvm-svn: 226567
2015-01-20 15:04:19 +00:00
Evgeniy Stepanov fa1d9f4860 Fix compilation of compiler_rt against libunwind.
libunwind defines _Unwind_GetLanguageSpecificData as returning long
instead of (uint8_t *).

llvm-svn: 226167
2015-01-15 14:27:38 +00:00
Saleem Abdulrasool a7452e434b builtins: avoid duplicating unwind declarations
Use unwind.h to get the declarations for unwinding interfaces.  This header is
already provided by clang and gcc, so this adds no additional dependencies for
building the builtins library.  It avoids the duplication which may drift over
time though.

llvm-svn: 225990
2015-01-14 15:55:17 +00:00
Roman Divacky 0c9c0c5a6d Add FreeBSD support for __clear_cache.
llvm-svn: 225610
2015-01-11 18:21:11 +00:00
Saleem Abdulrasool 5bbc718539 builtins: rely on the compiler for user label prefix
clang does not like the definition of builtins.  In order to work around this,
we use a SUN CC to redefine the generated name.  However, this requires that we
account for the user label prefix.  Rather than hard coding that into the file,
rely on the compiler to tell us the information and use the preprocessor to
generate the name as we do in the assembly routines.  NFC.

llvm-svn: 224597
2014-12-19 18:54:13 +00:00
Petar Jovanovic 7a6f5e47cf Do not define CRT_HAS_128BIT for MIPS64
Do not define it for MIPS64 until its backend supports it.
See the bug report [1] for more information.

[1] http://llvm.org/bugs/show_bug.cgi?id=20098

Differential Revision: http://reviews.llvm.org/D6703

llvm-svn: 224488
2014-12-18 01:21:33 +00:00
Saleem Abdulrasool 1fe0c18914 builtins: cleanup constant data section selection
Each of the object formats use a different directive for selecting the constant
section.  Use a macro to avoid the duplication across a number of files.  Also
correct a small macro mismatch on the Windows case (HIDDEN_DIRECTIVE -> HIDDEN).

Patch by Vadim Chugunov!

llvm-svn: 223910
2014-12-10 02:36:22 +00:00
Bob Wilson ec9a8c8b10 PR21518: Use unsigned arithmetic for trapping add/sub functions.
The code in {add,sub}v.i3 routines does not trap when it should, because
it performs the actual add/subtract operation in signed arithmetic,
rather than unsigned.

Patch by Francois-Xavie Coudert!

llvm-svn: 221826
2014-11-12 23:01:24 +00:00
Saleem Abdulrasool d888169d75 builtins: avoid endian.h in favour of compiler builtins
Use the __BYTE_ORDER__ macro which has been available in GCC since 4.6 and is
available in clang as well.

llvm-svn: 220626
2014-10-25 20:54:51 +00:00
Dan Albert c5d4bc7581 Fix checks for Android.
__ANDROID__ is a define that comes from the toolchain when building
for Android targets. ANDROID has a different meaning. ANDROID is
defined for _every_ Android build, including those done for host
modules. For host modules, we want to build the regular Linux
sanitizers and builtins, not the one for Android devices. This hasn't
been a problem until now because we only just started building the
sanitizers for the host.

llvm-svn: 220203
2014-10-20 15:35:01 +00:00
Bob Wilson ca0a38e0ae Add complex multiply/divide functions to arm64 iOS libclang_rt libraries.
Clang r219557 introduces libcalls to complex multiply/divide functions.
Since these functions are not available in iOS for arm64 devices, add them to
the static libraries.

llvm-svn: 219715
2014-10-14 20:33:36 +00:00
Tim Northover a5a06ad6fc AArch64: add support for ARM64 iOS versions of compiler-rt.
Just a dummy directory and a few sane choices in the Darwin SDK.

rdar://problem/18575597

llvm-svn: 219323
2014-10-08 17:28:37 +00:00
Saleem Abdulrasool 2cf5d82983 builtins: add missed change from previous commit
The macro rework was missing a trailing SEPARATOR for the .thumb_func, resulting
in assembly failures.

llvm-svn: 219183
2014-10-07 03:00:17 +00:00
Saleem Abdulrasool 48d4e4dd35 builtins: rework use of DEFINE_COMPILERRT_THUMB_FUNCTION
This is simply to help clarity of the code.  The functions are built as thumb
only if Thumb2 is available (__ARM_ARCH_ISA_THUMB == 2).  Sink the selection
into the location of the definition and make DEFINE_COMPILERRT_THUMB_FUNCTION
always define a thumb function while DEFINE_COMPILERRT_FUNCTION always selects
the default.

Since the .thumb_func directive is always available (at least on Linux, Windows,
and BSD), sinking the macro right into the macro works just as well.

No functional change intended.

llvm-svn: 219182
2014-10-07 02:39:13 +00:00
Bob Wilson 115547464e Try harder to fix ARM/Linux after r219040.
llvm-svn: 219066
2014-10-04 20:11:10 +00:00
Bob Wilson d2f1281e6c Attempt to fix ARM/Linux after r219040.
llvm-svn: 219064
2014-10-04 18:13:41 +00:00
Steven Wu 84610ba9b3 Fix the armv7 thumb builtins on darwin
The arm builtins converted into thumb in r213481 are not working
on darwin. On apple platforms, .thumb_func directive is required
to generated correct symbols for thumb functions.

<rdar://problem/18523605>

llvm-svn: 219040
2014-10-04 00:18:59 +00:00
Evgeniy Stepanov 0f7ab59adc [sanitizer] Add i686 arch to compiler-rt.
This is needed so we can produce -i686- named libraries for
x86 Android (which is i686-linux-android).

An alternative solution would be keeping the "i386" name internally and
tweaking the OUTPUT_NAME of compiler-rt libraries.

llvm-svn: 218761
2014-10-01 12:55:06 +00:00
Oliver Stannard 609e2e6a6e [compiler-rt] Do not use ldrexd or strexd on v7M
The ldrexd and strexd instructions are undefined for the ARMv7M
architecture, so we cannot use them to implement the
__sync_fetch_and_*_8 builtins. There is no other way to implement
these without OS support, so this patch #ifdef's these functions out
for M-class architectures.

There are no tests as I cannot find any existing tests for these
builtins.

I used the __ARM_ARCH_PROFILE predefine because __ARM_FEATURE_LDREX is
deprecated and not set by clang.

llvm-svn: 218601
2014-09-29 10:23:20 +00:00
Saleem Abdulrasool 8bf8409be8 builtins: 80-column
Re-wrap a couple of lines.  NFC.

llvm-svn: 218096
2014-09-19 01:35:08 +00:00
Saleem Abdulrasool c5ff406f5f builtins: remove definition of __ARM_ARCH
__ARM_ARCH is part of the ACLE specification.  At least clang and GCC have
supported this part of the ACLE for some time now.  Let the compiler provide the
proper definition for the macro rather than try to guess it.

llvm-svn: 218095
2014-09-19 01:34:03 +00:00
Joerg Sonnenberger ed35a3e717 Implement floatsitf, floatunstfsi, which perform
(signed/unsigned)integer to quad-precision conversion.

Submitted by GuanHong Liu.

Differential Revision: http://reviews.llvm.org/D2805

llvm-svn: 217901
2014-09-16 20:34:41 +00:00
Saleem Abdulrasool c89ae72e43 builtins: replace section symbol with reference to spec
Removes a non-ascii character that was committed.

llvm-svn: 217353
2014-09-08 01:49:24 +00:00
Saleem Abdulrasool a0a5873e28 builtins: add AEABI div0 functions
Add the missing AEABI functions that are part of the base platform ABI
specification.  The provided implementation does the bare minimum to avoid
requiring libc headers.  This permits the use of compiler-rt on bare-metal
environments which conform to EABI.

llvm-svn: 217322
2014-09-06 21:34:02 +00:00
Saleem Abdulrasool b6a85b4f6a builtins: remove unnecessary COMPILER_RT_EXPORT
This macro did not do anything at this point, and is not particularly needed for
Windows unless building the builtins as a shared library.  NFC.

llvm-svn: 217321
2014-09-06 21:33:55 +00:00
Saleem Abdulrasool a0d65971d4 builtins: add signature to some assembly routines
Add a helpful description and a signature for the functions implemented in
assembly for the integral math routines.  NFC.

llvm-svn: 215296
2014-08-09 20:17:43 +00:00
Saleem Abdulrasool 6063983c30 builtins: correct __umodsi3, __udivsi3 on ARM
When building the builtins for a modern CPU (idiv support), __umodsi3 was
completely incorrect as it would behave as __udivmosi3, which takes a tertiary
parameter which is a pointer.

__udivsi3 was also incorrect, returning the remainder in r1.  Although this
would not result in any crash or invalid behaviour as r1 is a caller saved
register in AAPCS, this is unnecessary.  Simply perform the division ignoring
the remainder.

llvm-svn: 215295
2014-08-09 20:17:37 +00:00
Saleem Abdulrasool 3a2d6a3096 builtins: make ARM compilation with GAS work again
The LLVM IAS seems to accept wide instructions for add and sub in ARM mode even
though it is not permitted.  This uses a macro to ensure that the wide modifier
is only applied when building in THUMB mode.

This repairs building with GCC/GAS in ARM mode.

llvm-svn: 214046
2014-07-27 02:01:24 +00:00
Saleem Abdulrasool b6690c34cf builtins: move macro definitions into assembly.h
The macro definitions are shared across multiple files.  Define them once in the
assembly.h header rather than redefining it in each file.

llvm-svn: 214045
2014-07-27 02:01:20 +00:00
Saleem Abdulrasool 31306b1571 builtins: whitespace
llvm-svn: 214044
2014-07-27 02:01:15 +00:00
Saleem Abdulrasool b72a2fdd72 builtins: avoid multiple definitions of symbols
The architecture specific implementation of routines would be built and included
along with the generic implementation.  This would result in multiple
definitions of those symbols.

The linker is free to select either of the two.  Most of the time, this
shouldn't be too terrible as the forward iteration should catch the architecture
version due to the ordering.  Rather than relying on the linker and build
infrastructure ordering things in a specific manner, only provide the
architecture version when available.

This reduces the size of compiler-rt, simplifies inspection of the library
implementations, and guarantees that the desired version is selected at a
slightly complex build system.

llvm-svn: 214040
2014-07-26 23:44:22 +00:00
Saleem Abdulrasool 24c68b26d8 builtins: add missed files from previous commits
This adds missed files in SVN r214033 for alignment and corrects a change from
SVN r214034 for fixing compilation with GCC.

llvm-svn: 214039
2014-07-26 23:44:18 +00:00
Saleem Abdulrasool 12ae9a8704 builtins: move the readonly constants into rodata
Place the floating point constants into the read-only data section.  This was
already being done for x86_64, this simply mirrors the behaviour for i686.

llvm-svn: 214034
2014-07-26 21:08:41 +00:00