[PATCH] D139842: [compiler-rt][X86] add half <-> x86_fp80 conversion builtins

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 07:09:19 PST 2022


t.p.northover created this revision.
Herald added subscribers: Enna1, pengfei, dberris, mcrosier.
Herald added a project: All.
t.p.northover requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

With the recently(ish) added support for `_Float16`, LLVM is now emitting libcalls to convert to and from `long double` (particularly important for the trunc to avoid double-rounding). Latest GCC already seems to include these in libgcc, but compiler-rt hasn't up to now.

It's a bit messy in the implementation files since `x86_fp80` has an explicit digit with the integer part of the significand unlike the other types that have an implicit `1.abcde...` except for denormals. I handled this by converting to an imaginary "normal" 80-bit float when needed.

The extend tests were derived from `half -> float -> x86_fp80` two-step conversion, the truncate tests didn't need changing from the regular float versions since the `_Float16` representation is the same in both cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139842

Files:
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/lib/builtins/extendhfxf2.c
  compiler-rt/lib/builtins/fp_extend.h
  compiler-rt/lib/builtins/fp_extend_impl.inc
  compiler-rt/lib/builtins/fp_lib.h
  compiler-rt/lib/builtins/fp_trunc.h
  compiler-rt/lib/builtins/fp_trunc_impl.inc
  compiler-rt/lib/builtins/truncxfhf2.c
  compiler-rt/test/builtins/Unit/extendhfxf2_test.c
  compiler-rt/test/builtins/Unit/fp_test.h
  compiler-rt/test/builtins/Unit/truncxfhf2_test.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139842.482111.patch
Type: text/x-patch
Size: 21135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221212/0c62e7cd/attachment.bin>


More information about the llvm-commits mailing list