[libclc] Use float sw_fma for spirv*-mesa-mesa3d targets (#199626)

This partially reverts 39f3d72b72, which changes almost all targets to
use __builtin_elementwise_fma.
The same revert was done for clspv in 1d719edd99.

Restore __clc_runtime_has_hw_fma32 so that Mesa can dynamically change
its behavior to enable native fma for specific hardware.

Fixes #198542
This commit is contained in:
Wenju He 2026-05-29 13:28:17 +08:00 committed by GitHub
parent 479818a38c
commit 767f01e091
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 86 additions and 4 deletions

View file

@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef __CLC_INTERNAL_MATH_CLC_RUNTIME_HAS_HW_FMA32_H__
#define __CLC_INTERNAL_MATH_CLC_RUNTIME_HAS_HW_FMA32_H__
#include "clc/internal/clc.h"
_CLC_DECL bool __attribute__((noinline)) __clc_runtime_has_hw_fma32(void);
#endif // __CLC_INTERNAL_MATH_CLC_RUNTIME_HAS_HW_FMA32_H__

View file

@ -9,6 +9,8 @@
#ifndef __CLC_INTERNAL_MATH_CLC_SW_FMA_H__
#define __CLC_INTERNAL_MATH_CLC_SW_FMA_H__
#include "clc/internal/clc.h"
#define __CLC_FUNCTION __clc_sw_fma
#define __CLC_FLOAT_ONLY
#define __CLC_BODY "clc/shared/ternary_decl.inc"

View file

@ -9,6 +9,8 @@
#ifndef __CLC_MATH_CLC_FMA_H__
#define __CLC_MATH_CLC_FMA_H__
#include "clc/internal/clc.h"
#define __CLC_FUNCTION __clc_fma
#define __CLC_BODY "clc/shared/ternary_decl.inc"

View file

@ -6,9 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "clc/internal/clc.h"
#include "clc/math/clc_fma.h"
#include "clc/math/math.h"
#define __CLC_FUNCTION __clc_fma
#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_fma

View file

@ -3,7 +3,10 @@ if(LIBCLC_TARGET_OS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBCLC_TARGET_OS})
endif()
libclc_add_sources(${LIBCLC_CLC_TARGET} FILES
math/clc_fma.cl
math/clc_fmax.cl
math/clc_fmin.cl
math/clc_runtime_has_hw_fma32.cl
math/clc_sw_fma.cl
subnormal_config.cl
)

View file

@ -0,0 +1,15 @@
//===----------------------------------------------------------------------===//
//
// 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 "clc/internal/math/clc_runtime_has_hw_fma32.h"
#include "clc/internal/math/clc_sw_fma.h"
#include "clc/math/clc_fma.h"
#include "clc/math/math.h"
#define __CLC_BODY "clc_fma.inc"
#include "clc/math/gentype.inc"

View file

@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
_CLC_DEF _CLC_OVERLOAD __CLC_GENTYPE __clc_fma(__CLC_GENTYPE a, __CLC_GENTYPE b,
__CLC_GENTYPE c) {
#if __CLC_FPSIZE == 32
if (!__clc_runtime_has_hw_fma32())
return __clc_sw_fma(a, b, c);
#endif
return __builtin_elementwise_fma(a, b, c);
}

View file

@ -0,0 +1,13 @@
//===----------------------------------------------------------------------===//
//
// 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 "clc/internal/math/clc_runtime_has_hw_fma32.h"
bool __attribute__((noinline)) __clc_runtime_has_hw_fma32(void) {
return false;
}

View file

@ -1,4 +1,3 @@
libclc_add_sources(${LIBCLC_CLC_TARGET} FILES
integer/clc_mul_hi.cl
math/clc_sw_fma.cl
)

View file

@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "clc/math/clc_fma.h"
#include "clc/math/math.h"
#define __CLC_FUNCTION fma
#define __CLC_BODY "clc/shared/ternary_def.inc"

View file

@ -4,6 +4,10 @@ if(LIBCLC_TARGET_OS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBCLC_TARGET_OS})
endif()
# Non-Vulkan SPIR-V uses a curated subset of generic builtins.
libclc_add_sources(${LIBCLC_OPENCL_TARGET} FILES
math/fma.cl
)
libclc_add_sources(${LIBCLC_OPENCL_TARGET}
BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../generic
FILES

View file

@ -0,0 +1,15 @@
//===----------------------------------------------------------------------===//
//
// 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 "clc/math/clc_fma.h"
#define __CLC_FLOAT_ONLY
#define __CLC_FUNCTION fma
#define __CLC_BODY "clc/shared/ternary_def.inc"
#include "clc/math/gentype.inc"