LLVM 18.0.0git
SIModeRegisterDefaults.cpp
Go to the documentation of this file.
1//===-- SIModeRegisterDefaults.cpp ------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11using namespace llvm;
12
14 *this = getDefaultForCallingConv(F.getCallingConv());
15
16 StringRef IEEEAttr = F.getFnAttribute("amdgpu-ieee").getValueAsString();
17 if (!IEEEAttr.empty())
18 IEEE = IEEEAttr == "true";
19
20 StringRef DX10ClampAttr =
21 F.getFnAttribute("amdgpu-dx10-clamp").getValueAsString();
22 if (!DX10ClampAttr.empty())
23 DX10Clamp = DX10ClampAttr == "true";
24
25 StringRef DenormF32Attr =
26 F.getFnAttribute("denormal-fp-math-f32").getValueAsString();
27 if (!DenormF32Attr.empty())
29
30 StringRef DenormAttr =
31 F.getFnAttribute("denormal-fp-math").getValueAsString();
32 if (!DenormAttr.empty()) {
33 DenormalMode DenormMode = parseDenormalFPAttribute(DenormAttr);
34 if (DenormF32Attr.empty())
35 FP32Denormals = DenormMode;
36 FP64FP16Denormals = DenormMode;
37 }
38}
39
40using namespace AMDGPU;
41
42/// Combine f32 and f64 rounding modes into a combined rounding mode value.
43static constexpr uint32_t getModeRegisterRoundMode(uint32_t HWFP32Val,
44 uint32_t HWFP64Val) {
45 return HWFP32Val << F32FltRoundOffset | HWFP64Val << F64FltRoundOffset;
46}
47
48static constexpr uint64_t encodeFltRoundsTable(uint32_t FltRoundsVal,
49 uint32_t HWF32Val,
50 uint32_t HWF64Val) {
51 uint32_t ModeVal = getModeRegisterRoundMode(HWF32Val, HWF64Val);
52 if (FltRoundsVal > TowardNegative)
53 FltRoundsVal -= ExtendedFltRoundOffset;
54
55 uint32_t BitIndex = ModeVal << 2;
56 return static_cast<uint64_t>(FltRoundsVal) << BitIndex;
57}
58
59// Encode FLT_ROUNDS value where the two rounding modes are the same and use a
60// standard value
61static constexpr uint64_t
63 return encodeFltRoundsTable(FltRoundsMode, HWVal, HWVal);
64}
65
66// Convert mode register encoded rounding mode to AMDGPUFltRounds
67static constexpr AMDGPUFltRounds
69 uint32_t TableRead = (FltRoundConversionTable >> (HWMode << 2)) & 0xf;
70 if (TableRead > TowardNegative)
71 TableRead += ExtendedFltRoundOffset;
72 return static_cast<AMDGPUFltRounds>(TableRead);
73}
74
79
88
95
102
104 HWTowardZero) |
109
111 HWTowardZero) |
116
117// Verify evaluation of FltRoundConversionTable
118
119// If both modes are the same, should return the standard values.
121 HWTowardZero, HWTowardZero)) == AMDGPUFltRounds::TowardZero);
124 AMDGPUFltRounds::NearestTiesToEven);
127 AMDGPUFltRounds::TowardPositive);
130 AMDGPUFltRounds::TowardNegative);
131
141
151
161
#define F(x, y, z)
Definition: MD5.cpp:55
#define FP_ROUND_ROUND_TO_INF
Definition: SIDefines.h:1139
#define FP_ROUND_ROUND_TO_NEAREST
Definition: SIDefines.h:1138
#define FP_ROUND_ROUND_TO_ZERO
Definition: SIDefines.h:1141
#define FP_ROUND_ROUND_TO_NEGINF
Definition: SIDefines.h:1140
static constexpr AMDGPUFltRounds decodeIndexFltRoundConversionTable(uint32_t HWMode)
static constexpr uint32_t HWTowardNegative
static constexpr uint64_t encodeFltRoundsTableSame(AMDGPUFltRounds FltRoundsMode, uint32_t HWVal)
static constexpr uint32_t HWTowardPositive
static constexpr uint32_t HWTowardZero
static constexpr uint64_t encodeFltRoundsTable(uint32_t FltRoundsVal, uint32_t HWF32Val, uint32_t HWF64Val)
static constexpr uint32_t HWNearestTiesToEven
static constexpr uint32_t getModeRegisterRoundMode(uint32_t HWFP32Val, uint32_t HWFP64Val)
Combine f32 and f64 rounding modes into a combined rounding mode value.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
static constexpr uint32_t F64FltRoundOffset
Offset in mode register of f64/f16 rounding mode.
static constexpr uint32_t ExtendedFltRoundOffset
Offset of nonstandard values for llvm.get.rounding results from the largest supported mode.
AMDGPUFltRounds
Return values used for llvm.get.rounding.
static constexpr uint32_t F32FltRoundOffset
Offset in mode register of f32 rounding mode.
const uint64_t FltRoundConversionTable
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ TowardNegative
roundTowardNegative.
DenormalMode parseDenormalFPAttribute(StringRef Str)
Returns the denormal mode to use for inputs and outputs.
Represent subnormal handling kind for floating point instruction inputs and outputs.
bool DX10Clamp
Used by the vector ALU to force DX10-style treatment of NaNs: when set, clamp NaN to zero; otherwise,...
DenormalMode FP64FP16Denormals
If this is set, neither input or output denormals are flushed for both f64 and f16/v2f16 instructions...
bool IEEE
Floating point opcodes that support exception flag gathering quiet and propagate signaling NaN inputs...
static SIModeRegisterDefaults getDefaultForCallingConv(CallingConv::ID CC)
DenormalMode FP32Denormals
If this is set, neither input or output denormals are flushed for most f32 instructions.