[llvm-branch-commits] [libc] [libc][math][c23] Add tanhf16 C23 math function (PR #106006)

2024-08-25 Thread via llvm-branch-commits

https://github.com/overmighty created 
https://github.com/llvm/llvm-project/pull/106006

Part of #95250.

>From eadda81a46d6b3bdf44574467deb3d94add102ac Mon Sep 17 00:00:00 2001
From: OverMighty 
Date: Sun, 25 Aug 2024 22:02:09 +0200
Subject: [PATCH] [libc][math][c23] Add tanhf16 C23 math function

Part of #95250.
---
 libc/config/gpu/entrypoints.txt   |   1 +
 libc/config/linux/x86_64/entrypoints.txt  |   1 +
 libc/docs/math/index.rst  |   2 +-
 libc/spec/stdc.td |   1 +
 libc/src/math/CMakeLists.txt  |   1 +
 libc/src/math/generic/CMakeLists.txt  |  22 
 libc/src/math/generic/tanhf16.cpp | 144 ++
 libc/src/math/tanhf16.h   |  21 
 libc/test/src/math/CMakeLists.txt |  11 ++
 libc/test/src/math/smoke/CMakeLists.txt   |  12 ++
 libc/test/src/math/smoke/tanhf16_test.cpp | 131 
 libc/test/src/math/tanhf16_test.cpp   |  40 ++
 12 files changed, 386 insertions(+), 1 deletion(-)
 create mode 100644 libc/src/math/generic/tanhf16.cpp
 create mode 100644 libc/src/math/tanhf16.h
 create mode 100644 libc/test/src/math/smoke/tanhf16_test.cpp
 create mode 100644 libc/test/src/math/tanhf16_test.cpp

diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index 7fdebe9322c283..b206bb7c936f39 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -551,6 +551,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
 libc.src.math.setpayloadf16
 libc.src.math.setpayloadsigf16
 libc.src.math.sinhf16
+libc.src.math.tanhf16
 libc.src.math.totalorderf16
 libc.src.math.totalordermagf16
 libc.src.math.truncf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 5b984c4bcd501d..b702a7ff482a5c 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -662,6 +662,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
 libc.src.math.setpayloadf16
 libc.src.math.setpayloadsigf16
 libc.src.math.sinhf16
+libc.src.math.tanhf16
 libc.src.math.totalorderf16
 libc.src.math.totalordermagf16
 libc.src.math.truncf16
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 6f17d4fa022c9a..de88f14426799f 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -344,7 +344,7 @@ Higher Math Functions
 
+---+--+-++--++++
 | tan   | |check|  | |check| ||
  || 7.12.4.7   | F.10.1.7  
 |
 
+---+--+-++--++++
-| tanh  | |check|  | ||
  || 7.12.5.6   | F.10.2.6  
 |
+| tanh  | |check|  | || 
|check|  || 7.12.5.6   | 
F.10.2.6   |
 
+---+--+-++--++++
 | tanpi |  | ||
  || 7.12.4.14  | F.10.1.14 
 |
 
+---+--+-++--++++
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 71c0c0364eecdf..043762bb227456 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -712,6 +712,7 @@ def StdC : StandardSpec<"stdc"> {
   GuardedFunctionSpec<"sinhf16", RetValSpec, 
[ArgSpec], "LIBC_TYPES_HAS_FLOAT16">,
 
   FunctionSpec<"tanhf", RetValSpec, [ArgSpec]>,
+  GuardedFunctionSpec<"tanhf16", RetValSpec, 
[ArgSpec], "LIBC_TYPES_HAS_FLOAT16">,
 
   FunctionSpec<"acosf", RetValSpec, [ArgSpec]>,
 
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index a9b866a31411e5..be05903d4a1c6e 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -483,6 +483,7 @@ add_math_entrypoint_object(tanf)
 
 add_math_entrypoint_object(tanh)
 add_math_entrypoint_object(tanhf)
+add_math_entrypoint_object(tanhf16)
 
 add_math_entrypoint_object(tgamma)
 add_math_entrypoint_object(tgammaf)
diff --git a/libc/src/math/generic/CMakeLists.txt 
b/libc/src/math/generic/CMakeLists.txt
index 12188eaf344f77..9534d17426486b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src

[llvm-branch-commits] [libc] [libc][math][c23] Add tanhf16 C23 math function (PR #106006)

2024-08-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libc

Author: OverMighty (overmighty)


Changes

Part of #95250.

---
Full diff: https://github.com/llvm/llvm-project/pull/106006.diff


12 Files Affected:

- (modified) libc/config/gpu/entrypoints.txt (+1) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+1) 
- (modified) libc/docs/math/index.rst (+1-1) 
- (modified) libc/spec/stdc.td (+1) 
- (modified) libc/src/math/CMakeLists.txt (+1) 
- (modified) libc/src/math/generic/CMakeLists.txt (+22) 
- (added) libc/src/math/generic/tanhf16.cpp (+144) 
- (added) libc/src/math/tanhf16.h (+21) 
- (modified) libc/test/src/math/CMakeLists.txt (+11) 
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+12) 
- (added) libc/test/src/math/smoke/tanhf16_test.cpp (+131) 
- (added) libc/test/src/math/tanhf16_test.cpp (+40) 


``diff
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index 7fdebe9322c283..b206bb7c936f39 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -551,6 +551,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
 libc.src.math.setpayloadf16
 libc.src.math.setpayloadsigf16
 libc.src.math.sinhf16
+libc.src.math.tanhf16
 libc.src.math.totalorderf16
 libc.src.math.totalordermagf16
 libc.src.math.truncf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 5b984c4bcd501d..b702a7ff482a5c 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -662,6 +662,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
 libc.src.math.setpayloadf16
 libc.src.math.setpayloadsigf16
 libc.src.math.sinhf16
+libc.src.math.tanhf16
 libc.src.math.totalorderf16
 libc.src.math.totalordermagf16
 libc.src.math.truncf16
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 6f17d4fa022c9a..de88f14426799f 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -344,7 +344,7 @@ Higher Math Functions
 
+---+--+-++--++++
 | tan   | |check|  | |check| ||
  || 7.12.4.7   | F.10.1.7  
 |
 
+---+--+-++--++++
-| tanh  | |check|  | ||
  || 7.12.5.6   | F.10.2.6  
 |
+| tanh  | |check|  | || 
|check|  || 7.12.5.6   | 
F.10.2.6   |
 
+---+--+-++--++++
 | tanpi |  | ||
  || 7.12.4.14  | F.10.1.14 
 |
 
+---+--+-++--++++
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 71c0c0364eecdf..043762bb227456 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -712,6 +712,7 @@ def StdC : StandardSpec<"stdc"> {
   GuardedFunctionSpec<"sinhf16", RetValSpec, 
[ArgSpec], "LIBC_TYPES_HAS_FLOAT16">,
 
   FunctionSpec<"tanhf", RetValSpec, [ArgSpec]>,
+  GuardedFunctionSpec<"tanhf16", RetValSpec, 
[ArgSpec], "LIBC_TYPES_HAS_FLOAT16">,
 
   FunctionSpec<"acosf", RetValSpec, [ArgSpec]>,
 
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index a9b866a31411e5..be05903d4a1c6e 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -483,6 +483,7 @@ add_math_entrypoint_object(tanf)
 
 add_math_entrypoint_object(tanh)
 add_math_entrypoint_object(tanhf)
+add_math_entrypoint_object(tanhf16)
 
 add_math_entrypoint_object(tgamma)
 add_math_entrypoint_object(tgammaf)
diff --git a/libc/src/math/generic/CMakeLists.txt 
b/libc/src/math/generic/CMakeLists.txt
index 12188eaf344f77..9534d17426486b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4154,6 +4154,28 @@ add_entrypoint_object(
 -O3
 )
 
+add_entrypoint_object(
+  tanhf16
+  SRCS
+tanhf16.cpp
+  HDRS
+../tanhf16.h
+  DEPENDS
+.expxf16
+libc.hdr.fenv_macros
+libc.src.__support.CPP.array
+libc.src.__support.FPUtil.except_value_utils
+libc.src.__support.FPUtil.fenv_impl
+libc.src.__support.FPUtil.fp_bits
+libc.src.__support.FPUtil.m

[llvm-branch-commits] [llvm] release/19.x: [MIPS] Optimize sortRelocs for o32 (PR #106008)

2024-08-25 Thread Alex Rønne Petersen via llvm-branch-commits

https://github.com/alexrp created 
https://github.com/llvm/llvm-project/pull/106008

Manual backport of #104723.

From 9a72d8b12202d27c4229ff9ccab0f0cdb6b6f583 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sun, 18 Aug 2024 11:24:44 -0700
Subject: [PATCH 1/3] [MIPS] Remove expensive LLVM_DEBUG relocation dump

The input is usually ordered by offset, so inspecting the output is
sufficient. The super expensive relocation dump is not conventional.
---
 .../Mips/MCTargetDesc/MipsELFObjectWriter.cpp | 32 ++-
 1 file changed, 2 insertions(+), 30 deletions(-)

diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp 
b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index 4d6a00c14a3575..1f047020d96c80 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -47,13 +47,6 @@ struct MipsRelocationEntry {
   }
 };
 
-#ifndef NDEBUG
-raw_ostream &operator<<(raw_ostream &OS, const MipsRelocationEntry &RHS) {
-  RHS.print(OS);
-  return OS;
-}
-#endif
-
 class MipsELFObjectWriter : public MCELFObjectTargetWriter {
 public:
   MipsELFObjectWriter(uint8_t OSABI, bool HasRelocationAddend, bool Is64);
@@ -115,17 +108,11 @@ static InputIt find_best(InputIt First, InputIt Last, 
UnaryPredicate Predicate,
   for (InputIt I = First; I != Last; ++I) {
 unsigned Matched = Predicate(*I);
 if (Matched != FindBest_NoMatch) {
-  LLVM_DEBUG(dbgs() << std::distance(First, I) << " is a match (";
- I->print(dbgs()); dbgs() << ")\n");
-  if (Best == Last || BetterThan(*I, *Best)) {
-LLVM_DEBUG(dbgs() << ".. and it beats the last one\n");
+  if (Best == Last || BetterThan(*I, *Best))
 Best = I;
-  }
 }
-if (Matched == FindBest_PerfectMatch) {
-  LLVM_DEBUG(dbgs() << ".. and it is unbeatable\n");
+if (Matched == FindBest_PerfectMatch)
   break;
-}
   }
 
   return Best;
@@ -201,15 +188,6 @@ static bool compareMatchingRelocs(const 
MipsRelocationEntry &Candidate,
   return PreviousBest.Matched && !Candidate.Matched;
 }
 
-#ifndef NDEBUG
-/// Print all the relocations.
-template 
-static void dumpRelocs(const char *Prefix, const Container &Relocs) {
-  for (const auto &R : Relocs)
-dbgs() << Prefix << R << "\n";
-}
-#endif
-
 MipsELFObjectWriter::MipsELFObjectWriter(uint8_t OSABI,
  bool HasRelocationAddend, bool Is64)
 : MCELFObjectTargetWriter(Is64, OSABI, ELF::EM_MIPS, HasRelocationAddend) 
{}
@@ -448,8 +426,6 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
   std::list Sorted;
   std::list Remainder;
 
-  LLVM_DEBUG(dumpRelocs("R: ", Relocs));
-
   // Separate the movable relocations (AHL relocations using the high bits) 
from
   // the immobile relocations (everything else). This does not preserve 
high/low
   // matches that already existed in the input.
@@ -459,8 +435,6 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
});
 
   for (auto &R : Remainder) {
-LLVM_DEBUG(dbgs() << "Matching: " << R << "\n");
-
 unsigned MatchingType = getMatchingLoType(R);
 assert(MatchingType != ELF::R_MIPS_NONE &&
"Wrong list for reloc that doesn't need a match");
@@ -494,8 +468,6 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
 Sorted.insert(InsertionPoint, R)->Matched = true;
   }
 
-  LLVM_DEBUG(dumpRelocs("S: ", Sorted));
-
   assert(Relocs.size() == Sorted.size() && "Some relocs were not consumed");
 
   // Overwrite the original vector with the sorted elements.

From f139a3296123eb567c158fd1219b33e2263cc5f7 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sun, 18 Aug 2024 15:47:38 -0700
Subject: [PATCH 2/3] [MC] Remove ELFRelocationEntry::OriginalAddend

For MIPS's o32 ABI (REL), https://reviews.llvm.org/D19718 introduced
`OriginalAddend` to find the matching R_MIPS_LO16 relocation for
R_MIPS_GOT16 when STT_SECTION conversion is applicable.

lw $2, %lo(local1)
lui $2, %got(local1)

However, we could just store the original `Addend` in
`ELFRelocationEntry` and remove `OriginalAddend`.

Note: The relocation ordering algorithm in
https://reviews.llvm.org/D19718 is inefficient (#104562), which will be
addressed by another patch.
---
 llvm/include/llvm/MC/MCELFObjectWriter.h|  9 +++--
 llvm/lib/MC/ELFObjectWriter.cpp | 17 ++---
 .../Mips/MCTargetDesc/MipsELFObjectWriter.cpp   |  9 -
 3 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/llvm/include/llvm/MC/MCELFObjectWriter.h 
b/llvm/include/llvm/MC/MCELFObjectWriter.h
index 9b74cbc3d3a520..d48840c0f89877 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -38,18 +38,15 @@ struct ELFRelocationEntry {
   unsigned Type;   // The type of the relocation.
   uint64_t Addend; // The addend to use.
   const MCSymbolELF *OriginalSymbol; // The original 

[llvm-branch-commits] [llvm] release/19.x: [MIPS] Optimize sortRelocs for o32 (PR #106008)

2024-08-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: Alex Rønne Petersen (alexrp)


Changes

Manual backport of #104723.

---
Full diff: https://github.com/llvm/llvm-project/pull/106008.diff


4 Files Affected:

- (modified) llvm/include/llvm/MC/MCELFObjectWriter.h (+3-8) 
- (modified) llvm/lib/MC/ELFObjectWriter.cpp (+6-11) 
- (modified) llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp 
(+43-117) 
- (modified) llvm/test/MC/Mips/sort-relocation-table.s (+3-3) 


``diff
diff --git a/llvm/include/llvm/MC/MCELFObjectWriter.h 
b/llvm/include/llvm/MC/MCELFObjectWriter.h
index 9b74cbc3d3a520..cbb010fa2fd802 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -37,19 +37,14 @@ struct ELFRelocationEntry {
   const MCSymbolELF *Symbol; // The symbol to relocate with.
   unsigned Type;   // The type of the relocation.
   uint64_t Addend; // The addend to use.
-  const MCSymbolELF *OriginalSymbol; // The original value of Symbol if we 
changed it.
-  uint64_t OriginalAddend; // The original value of addend.
 
   ELFRelocationEntry(uint64_t Offset, const MCSymbolELF *Symbol, unsigned Type,
- uint64_t Addend, const MCSymbolELF *OriginalSymbol,
- uint64_t OriginalAddend)
-  : Offset(Offset), Symbol(Symbol), Type(Type), Addend(Addend),
-OriginalSymbol(OriginalSymbol), OriginalAddend(OriginalAddend) {}
+ uint64_t Addend)
+  : Offset(Offset), Symbol(Symbol), Type(Type), Addend(Addend) {}
 
   void print(raw_ostream &Out) const {
 Out << "Off=" << Offset << ", Sym=" << Symbol << ", Type=" << Type
-<< ", Addend=" << Addend << ", OriginalSymbol=" << OriginalSymbol
-<< ", OriginalAddend=" << OriginalAddend;
+<< ", Addend=" << Addend;
   }
 
   LLVM_DUMP_METHOD void dump() const { print(errs()); }
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index f958905a26aa42..8e8705500126e7 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1393,22 +1393,17 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
   bool RelocateWithSymbol =
   shouldRelocateWithSymbol(Asm, Target, SymA, C, Type) ||
   (Parent->getType() == ELF::SHT_LLVM_CALL_GRAPH_PROFILE);
-  uint64_t Addend = 0;
-
-  FixedValue = !RelocateWithSymbol && SymA && !SymA->isUndefined()
-   ? C + Asm.getSymbolOffset(*SymA)
-   : C;
-  if (usesRela(TO, FixupSection)) {
-Addend = FixedValue;
-FixedValue = 0;
-  }
+  uint64_t Addend = !RelocateWithSymbol && SymA && !SymA->isUndefined()
+? C + Asm.getSymbolOffset(*SymA)
+: C;
+  FixedValue = usesRela(TO, FixupSection) ? 0 : Addend;
 
   if (!RelocateWithSymbol) {
 const auto *SectionSymbol =
 SecA ? cast(SecA->getBeginSymbol()) : nullptr;
 if (SectionSymbol)
   SectionSymbol->setUsedInReloc();
-ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend, SymA, C);
+ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend);
 Relocations[&FixupSection].push_back(Rec);
 return;
   }
@@ -1423,7 +1418,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
 else
   RenamedSymA->setUsedInReloc();
   }
-  ELFRelocationEntry Rec(FixupOffset, RenamedSymA, Type, Addend, SymA, C);
+  ELFRelocationEntry Rec(FixupOffset, RenamedSymA, Type, Addend);
   Relocations[&FixupSection].push_back(Rec);
 }
 
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp 
b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index 4d6a00c14a3575..faf9772ab75756 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -40,20 +40,8 @@ struct MipsRelocationEntry {
   bool Matched = false;   ///< Is this relocation part of a match.
 
   MipsRelocationEntry(const ELFRelocationEntry &R) : R(R) {}
-
-  void print(raw_ostream &Out) const {
-R.print(Out);
-Out << ", Matched=" << Matched;
-  }
 };
 
-#ifndef NDEBUG
-raw_ostream &operator<<(raw_ostream &OS, const MipsRelocationEntry &RHS) {
-  RHS.print(OS);
-  return OS;
-}
-#endif
-
 class MipsELFObjectWriter : public MCELFObjectTargetWriter {
 public:
   MipsELFObjectWriter(uint8_t OSABI, bool HasRelocationAddend, bool Is64);
@@ -115,17 +103,11 @@ static InputIt find_best(InputIt First, InputIt Last, 
UnaryPredicate Predicate,
   for (InputIt I = First; I != Last; ++I) {
 unsigned Matched = Predicate(*I);
 if (Matched != FindBest_NoMatch) {
-  LLVM_DEBUG(dbgs() << std::distance(First, I) << " is a match (";
- I->print(dbgs()); dbgs() << ")\n");
-  if (Best == Last || BetterThan(*I, *Best)) {
-LLVM_DEBUG(dbgs() << ".. and it beats the last one\n");
+  if (Best == Last || BetterThan(*I, *Best))
 Best = I;
-  }
 }
-if (Matched == FindBest_PerfectMatch) 

[llvm-branch-commits] [llvm] release/19.x: [MIPS] Optimize sortRelocs for o32 (PR #106008)

2024-08-25 Thread Alex Rønne Petersen via llvm-branch-commits

alexrp wrote:

cc @MaskRay @brad0

https://github.com/llvm/llvm-project/pull/106008
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [libc][math][c23] Add exp10m1f16 C23 math function (PR #105706)

2024-08-25 Thread via llvm-branch-commits


@@ -606,6 +606,8 @@ def StdC : StandardSpec<"stdc"> {
   FunctionSpec<"exp10f", RetValSpec, [ArgSpec]>,
   GuardedFunctionSpec<"exp10f16", RetValSpec, 
[ArgSpec], "LIBC_TYPES_HAS_FLOAT16">,
 
+  GuardedFunctionSpec<"exp10m1f16", RetValSpec, 
[ArgSpec], "LIBC_TYPES_HAS_FLOAT16">,

lntue wrote:

also update new header gen.

https://github.com/llvm/llvm-project/pull/105706
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] [libc][math][c23] Add exp10m1f16 C23 math function (PR #105706)

2024-08-25 Thread via llvm-branch-commits


@@ -0,0 +1,162 @@
+//===-- Half-precision 10^x - 1 function 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "src/math/exp10m1f16.h"
+#include "expxf16.h"
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/rounding_mode.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/cpu_features.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+static constexpr fputil::ExceptValues EXP10M1F16_EXCEPTS_LO = {{
+// (input, RZ output, RU offset, RD offset, RN offset)
+// x = 0x1.5c4p-4, exp10m1f16(x) = 0x1.bacp-3 (RZ)
+{0x2d71U, 0x32ebU, 1U, 0U, 0U},
+// x = -0x1.5ep-13, exp10m1f16(x) = -0x1.92cp-12 (RZ)
+{0x8978U, 0x8e4bU, 0U, 1U, 0U},
+// x = -0x1.e2p-10, exp10m1f16(x) = -0x1.14cp-8 (RZ)
+{0x9788U, 0x9c53U, 0U, 1U, 0U},
+}};
+
+#ifdef LIBC_TARGET_CPU_HAS_FMA
+static constexpr size_t N_EXP10M1F16_EXCEPTS_HI = 3;
+#else
+static constexpr size_t N_EXP10M1F16_EXCEPTS_HI = 6;
+#endif
+
+static constexpr fputil::ExceptValues
+EXP10M1F16_EXCEPTS_HI = {{
+// (input, RZ output, RU offset, RD offset, RN offset)
+// x = 0x1.8f4p-2, exp10m1f16(x) = 0x1.744p+0 (RZ)
+{0x363dU, 0x3dd1U, 1U, 0U, 0U},
+// x = 0x1.95cp-2, exp10m1f16(x) = 0x1.7d8p+0 (RZ)
+{0x3657U, 0x3df6U, 1U, 0U, 0U},
+// x = 0x1.d04p-2, exp10m1f16(x) = 0x1.d7p+0 (RZ)
+{0x3741U, 0x3f5cU, 1U, 0U, 1U},
+#ifndef LIBC_TARGET_CPU_HAS_FMA
+// x = 0x1.0cp+1, exp10m1f16(x) = 0x1.ec4p+6 (RZ)
+{0x4030U, 0x57b1U, 1U, 0U, 1U},
+// x = 0x1.1b8p+1, exp10m1f16(x) = 0x1.45cp+7 (RZ)
+{0x406eU, 0x5917U, 1U, 0U, 1U},
+// x = 0x1.2f4p+2, exp10m1f16(x) = 0x1.ab8p+15 (RZ)
+{0x44bdU, 0x7aaeU, 1U, 0U, 1U},
+#endif
+}};
+
+LLVM_LIBC_FUNCTION(float16, exp10m1f16, (float16 x)) {
+  using FPBits = fputil::FPBits;
+  FPBits x_bits(x);
+
+  uint16_t x_u = x_bits.uintval();
+  uint16_t x_abs = x_u & 0x7fffU;
+
+  // When |x| <= 2^(-3), or |x| >= 11 * log10(2), or x is NaN.
+  if (LIBC_UNLIKELY(x_abs <= 0x3000U || x_abs >= 0x429fU)) {
+// exp10m1(NaN) = NaN
+if (x_bits.is_nan()) {
+  if (x_bits.is_signaling_nan()) {
+fputil::raise_except_if_required(FE_INVALID);
+return FPBits::quiet_nan().get_val();
+  }
+
+  return x;
+}
+
+// When x >= 16 * log10(2).
+if (x_u >= 0x44d1U && x_bits.is_pos()) {
+  // exp10m1(+inf) = +inf
+  if (x_bits.is_inf())
+return FPBits::inf().get_val();
+
+  switch (fputil::quick_get_round()) {
+  case FE_TONEAREST:
+  case FE_UPWARD:
+fputil::set_errno_if_required(ERANGE);
+fputil::raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
+return FPBits::inf().get_val();
+  default:
+return FPBits::max_normal().get_val();
+  }
+}
+
+// When x < -11 * log10(2).
+if (x_u > 0xc29fU) {
+  // exp10m1(-inf) = -1
+  if (x_bits.is_inf())
+return FPBits::one(Sign::NEG).get_val();
+
+  // When x >= -0x1.ce4p+1, round(10^x - 1, HP, RN) = -0x1.ffcp-1.
+  if (x_u <= 0xc339U) {
+return fputil::round_result_slightly_down(
+static_cast(-0x1.ffcp-1));
+  }
+
+  // When x < -0x1.ce4p+1, round(10^x - 1, HP, RN) = -1.
+  switch (fputil::quick_get_round()) {
+  case FE_TONEAREST:
+  case FE_DOWNWARD:
+return FPBits::one(Sign::NEG).get_val();
+  default:
+return static_cast(-0x1.ffcp-1);
+  }
+}
+
+// When |x| <= 2^(-3).
+if (x_abs <= 0x3000U) {
+  if (auto r = EXP10M1F16_EXCEPTS_LO.lookup(x_u);
+  LIBC_UNLIKELY(r.has_value()))
+return r.value();
+
+  float xf = x;
+  // Degree-5 minimax polynomial generated by Sollya with the following
+  // commands:
+  //   > display = hexadecimal;
+  //   > P = fpminimax((10^x - 1)/x, 4, [|SG...|], [-2^-3, 2^-3]);
+  //   > x * P;
+  return static_cast(
+  xf * fputil::polyeval(xf, 0x1.26bb1cp+1f, 0x1.5351c8p+1f,
+0x1.04704p+1f, 0x1.2ce084p+0f, 
0x1.14a6bep-1f));
+}
+  }
+
+  // When x is 1, 2, or 3. These are hard-to-round cases with exact results.
+  // 10^4 - 1 = 9'999 is not exactly representable as a float16, but luckily 
the

lntue wrote:

It's actually not luck, because the relative error of `9'999` to the

[llvm-branch-commits] [llvm] release/19.x: [MIPS] Optimize sortRelocs for o32 (PR #106008)

2024-08-25 Thread Brad Smith via llvm-branch-commits

https://github.com/brad0 milestoned 
https://github.com/llvm/llvm-project/pull/106008
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/19.x: [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (#102131) (PR #106043)

2024-08-25 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/106043

Backport e6974daa

Requested by: @zyn0217

>From f40c547eb78c91a9b35ae4ccefbf00c2983038e7 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 26 Aug 2024 14:30:26 +0800
Subject: [PATCH] [Clang][Concepts] Fix the constraint equivalence checking
 involving parameter packs (#102131)

We established an instantiation scope in order for constraint
equivalence checking to properly map the uninstantiated parameters.

That mechanism mapped even packs to themselves. Consequently, parameter
packs e.g. appearing in a function call, were not expanded. So they
would end up becoming `SubstTemplateTypeParmPackType`s that circularly
depend on the canonical declaration of the function template, which is
not yet determined, hence the spurious error.

No release note as I plan to backport it to 19.

Fixes https://github.com/llvm/llvm-project/issues/101735

-

Co-authored-by: cor3ntin 
(cherry picked from commit e6974daa7bc100c8b88057d50f3ec3eca7282243)
---
 clang/lib/Sema/SemaConcept.cpp| 26 +--
 .../SemaTemplate/concepts-out-of-line-def.cpp | 23 
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index c34d32002b5ad7..244f6ef2f53faa 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -969,8 +969,30 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
   // equivalence.
   LocalInstantiationScope ScopeForParameters(S);
   if (auto *FD = DeclInfo.getDecl()->getAsFunction())
-for (auto *PVD : FD->parameters())
-  ScopeForParameters.InstantiatedLocal(PVD, PVD);
+for (auto *PVD : FD->parameters()) {
+  if (!PVD->isParameterPack()) {
+ScopeForParameters.InstantiatedLocal(PVD, PVD);
+continue;
+  }
+  // This is hacky: we're mapping the parameter pack to a size-of-1 
argument
+  // to avoid building SubstTemplateTypeParmPackTypes for
+  // PackExpansionTypes. The SubstTemplateTypeParmPackType node would
+  // otherwise reference the AssociatedDecl of the template arguments, 
which
+  // is, in this case, the template declaration.
+  //
+  // However, as we are in the process of comparing potential
+  // re-declarations, the canonical declaration is the declaration itself 
at
+  // this point. So if we didn't expand these packs, we would end up with 
an
+  // incorrect profile difference because we will be profiling the
+  // canonical types!
+  //
+  // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so
+  // that we can eliminate the Scope in the cases where the declarations 
are
+  // not necessarily instantiated. It would also benefit the noexcept
+  // specifier comparison.
+  ScopeForParameters.MakeInstantiatedLocalArgPack(PVD);
+  ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD);
+}
 
   std::optional ThisScope;
 
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index 0142efcdc3ee86..333187b0d74ad6 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -599,3 +599,26 @@ template 
 unsigned long DerivedCollection::index() {}
 
 } // namespace GH72557
+
+namespace GH101735 {
+
+template 
+concept True = true;
+
+template 
+class A {
+  template 
+  void method(Ts&... ts)
+requires requires (T t) {
+  { t.method(static_cast(ts)...) } -> True;
+};
+};
+
+template 
+template 
+void A::method(Ts&... ts)
+  requires requires (T t) {
+{ t.method(static_cast(ts)...) } -> True;
+  } {}
+
+}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/19.x: [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (#102131) (PR #106043)

2024-08-25 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/106043
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/19.x: [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (#102131) (PR #106043)

2024-08-25 Thread via llvm-branch-commits

llvmbot wrote:

@zyn0217 What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/106043
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/19.x: [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (#102131) (PR #106043)

2024-08-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport e6974daa

Requested by: @zyn0217

---
Full diff: https://github.com/llvm/llvm-project/pull/106043.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaConcept.cpp (+24-2) 
- (modified) clang/test/SemaTemplate/concepts-out-of-line-def.cpp (+23) 


``diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index c34d32002b5ad7..244f6ef2f53faa 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -969,8 +969,30 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
   // equivalence.
   LocalInstantiationScope ScopeForParameters(S);
   if (auto *FD = DeclInfo.getDecl()->getAsFunction())
-for (auto *PVD : FD->parameters())
-  ScopeForParameters.InstantiatedLocal(PVD, PVD);
+for (auto *PVD : FD->parameters()) {
+  if (!PVD->isParameterPack()) {
+ScopeForParameters.InstantiatedLocal(PVD, PVD);
+continue;
+  }
+  // This is hacky: we're mapping the parameter pack to a size-of-1 
argument
+  // to avoid building SubstTemplateTypeParmPackTypes for
+  // PackExpansionTypes. The SubstTemplateTypeParmPackType node would
+  // otherwise reference the AssociatedDecl of the template arguments, 
which
+  // is, in this case, the template declaration.
+  //
+  // However, as we are in the process of comparing potential
+  // re-declarations, the canonical declaration is the declaration itself 
at
+  // this point. So if we didn't expand these packs, we would end up with 
an
+  // incorrect profile difference because we will be profiling the
+  // canonical types!
+  //
+  // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so
+  // that we can eliminate the Scope in the cases where the declarations 
are
+  // not necessarily instantiated. It would also benefit the noexcept
+  // specifier comparison.
+  ScopeForParameters.MakeInstantiatedLocalArgPack(PVD);
+  ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD);
+}
 
   std::optional ThisScope;
 
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index 0142efcdc3ee86..333187b0d74ad6 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -599,3 +599,26 @@ template 
 unsigned long DerivedCollection::index() {}
 
 } // namespace GH72557
+
+namespace GH101735 {
+
+template 
+concept True = true;
+
+template 
+class A {
+  template 
+  void method(Ts&... ts)
+requires requires (T t) {
+  { t.method(static_cast(ts)...) } -> True;
+};
+};
+
+template 
+template 
+void A::method(Ts&... ts)
+  requires requires (T t) {
+{ t.method(static_cast(ts)...) } -> True;
+  } {}
+
+}

``




https://github.com/llvm/llvm-project/pull/106043
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits