File: | build/source/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp |
Warning: | line 1721, column 24 The result of the right shift is undefined due to shifting by '4294967295', which is greater or equal to the width of type 'uint64_t' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===-- SystemZInstrInfo.cpp - SystemZ instruction information ------------===// | |||
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 | // | |||
9 | // This file contains the SystemZ implementation of the TargetInstrInfo class. | |||
10 | // | |||
11 | //===----------------------------------------------------------------------===// | |||
12 | ||||
13 | #include "SystemZInstrInfo.h" | |||
14 | #include "MCTargetDesc/SystemZMCTargetDesc.h" | |||
15 | #include "SystemZ.h" | |||
16 | #include "SystemZInstrBuilder.h" | |||
17 | #include "SystemZSubtarget.h" | |||
18 | #include "llvm/ADT/Statistic.h" | |||
19 | #include "llvm/CodeGen/LiveInterval.h" | |||
20 | #include "llvm/CodeGen/LiveIntervals.h" | |||
21 | #include "llvm/CodeGen/LivePhysRegs.h" | |||
22 | #include "llvm/CodeGen/LiveVariables.h" | |||
23 | #include "llvm/CodeGen/MachineBasicBlock.h" | |||
24 | #include "llvm/CodeGen/MachineFrameInfo.h" | |||
25 | #include "llvm/CodeGen/MachineFunction.h" | |||
26 | #include "llvm/CodeGen/MachineInstr.h" | |||
27 | #include "llvm/CodeGen/MachineMemOperand.h" | |||
28 | #include "llvm/CodeGen/MachineOperand.h" | |||
29 | #include "llvm/CodeGen/MachineRegisterInfo.h" | |||
30 | #include "llvm/CodeGen/SlotIndexes.h" | |||
31 | #include "llvm/CodeGen/StackMaps.h" | |||
32 | #include "llvm/CodeGen/TargetInstrInfo.h" | |||
33 | #include "llvm/CodeGen/TargetSubtargetInfo.h" | |||
34 | #include "llvm/CodeGen/VirtRegMap.h" | |||
35 | #include "llvm/MC/MCInstrDesc.h" | |||
36 | #include "llvm/MC/MCRegisterInfo.h" | |||
37 | #include "llvm/Support/BranchProbability.h" | |||
38 | #include "llvm/Support/ErrorHandling.h" | |||
39 | #include "llvm/Support/MathExtras.h" | |||
40 | #include "llvm/Target/TargetMachine.h" | |||
41 | #include <cassert> | |||
42 | #include <cstdint> | |||
43 | #include <iterator> | |||
44 | ||||
45 | using namespace llvm; | |||
46 | ||||
47 | #define GET_INSTRINFO_CTOR_DTOR | |||
48 | #define GET_INSTRMAP_INFO | |||
49 | #include "SystemZGenInstrInfo.inc" | |||
50 | ||||
51 | #define DEBUG_TYPE"systemz-II" "systemz-II" | |||
52 | ||||
53 | // Return a mask with Count low bits set. | |||
54 | static uint64_t allOnes(unsigned int Count) { | |||
55 | return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1; | |||
56 | } | |||
57 | ||||
58 | // Pin the vtable to this file. | |||
59 | void SystemZInstrInfo::anchor() {} | |||
60 | ||||
61 | SystemZInstrInfo::SystemZInstrInfo(SystemZSubtarget &sti) | |||
62 | : SystemZGenInstrInfo(SystemZ::ADJCALLSTACKDOWN, SystemZ::ADJCALLSTACKUP), | |||
63 | RI(sti.getSpecialRegisters()->getReturnFunctionAddressRegister()), | |||
64 | STI(sti) {} | |||
65 | ||||
66 | // MI is a 128-bit load or store. Split it into two 64-bit loads or stores, | |||
67 | // each having the opcode given by NewOpcode. | |||
68 | void SystemZInstrInfo::splitMove(MachineBasicBlock::iterator MI, | |||
69 | unsigned NewOpcode) const { | |||
70 | MachineBasicBlock *MBB = MI->getParent(); | |||
71 | MachineFunction &MF = *MBB->getParent(); | |||
72 | ||||
73 | // Get two load or store instructions. Use the original instruction for one | |||
74 | // of them (arbitrarily the second here) and create a clone for the other. | |||
75 | MachineInstr *EarlierMI = MF.CloneMachineInstr(&*MI); | |||
76 | MBB->insert(MI, EarlierMI); | |||
77 | ||||
78 | // Set up the two 64-bit registers and remember super reg and its flags. | |||
79 | MachineOperand &HighRegOp = EarlierMI->getOperand(0); | |||
80 | MachineOperand &LowRegOp = MI->getOperand(0); | |||
81 | Register Reg128 = LowRegOp.getReg(); | |||
82 | unsigned Reg128Killed = getKillRegState(LowRegOp.isKill()); | |||
83 | unsigned Reg128Undef = getUndefRegState(LowRegOp.isUndef()); | |||
84 | HighRegOp.setReg(RI.getSubReg(HighRegOp.getReg(), SystemZ::subreg_h64)); | |||
85 | LowRegOp.setReg(RI.getSubReg(LowRegOp.getReg(), SystemZ::subreg_l64)); | |||
86 | ||||
87 | if (MI->mayStore()) { | |||
88 | // Add implicit uses of the super register in case one of the subregs is | |||
89 | // undefined. We could track liveness and skip storing an undefined | |||
90 | // subreg, but this is hopefully rare (discovered with llvm-stress). | |||
91 | // If Reg128 was killed, set kill flag on MI. | |||
92 | unsigned Reg128UndefImpl = (Reg128Undef | RegState::Implicit); | |||
93 | MachineInstrBuilder(MF, EarlierMI).addReg(Reg128, Reg128UndefImpl); | |||
94 | MachineInstrBuilder(MF, MI).addReg(Reg128, (Reg128UndefImpl | Reg128Killed)); | |||
95 | } | |||
96 | ||||
97 | // The address in the first (high) instruction is already correct. | |||
98 | // Adjust the offset in the second (low) instruction. | |||
99 | MachineOperand &HighOffsetOp = EarlierMI->getOperand(2); | |||
100 | MachineOperand &LowOffsetOp = MI->getOperand(2); | |||
101 | LowOffsetOp.setImm(LowOffsetOp.getImm() + 8); | |||
102 | ||||
103 | // Clear the kill flags on the registers in the first instruction. | |||
104 | if (EarlierMI->getOperand(0).isReg() && EarlierMI->getOperand(0).isUse()) | |||
105 | EarlierMI->getOperand(0).setIsKill(false); | |||
106 | EarlierMI->getOperand(1).setIsKill(false); | |||
107 | EarlierMI->getOperand(3).setIsKill(false); | |||
108 | ||||
109 | // Set the opcodes. | |||
110 | unsigned HighOpcode = getOpcodeForOffset(NewOpcode, HighOffsetOp.getImm()); | |||
111 | unsigned LowOpcode = getOpcodeForOffset(NewOpcode, LowOffsetOp.getImm()); | |||
112 | assert(HighOpcode && LowOpcode && "Both offsets should be in range")(static_cast <bool> (HighOpcode && LowOpcode && "Both offsets should be in range") ? void (0) : __assert_fail ("HighOpcode && LowOpcode && \"Both offsets should be in range\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 112, __extension__ __PRETTY_FUNCTION__)); | |||
113 | ||||
114 | EarlierMI->setDesc(get(HighOpcode)); | |||
115 | MI->setDesc(get(LowOpcode)); | |||
116 | } | |||
117 | ||||
118 | // Split ADJDYNALLOC instruction MI. | |||
119 | void SystemZInstrInfo::splitAdjDynAlloc(MachineBasicBlock::iterator MI) const { | |||
120 | MachineBasicBlock *MBB = MI->getParent(); | |||
121 | MachineFunction &MF = *MBB->getParent(); | |||
122 | MachineFrameInfo &MFFrame = MF.getFrameInfo(); | |||
123 | MachineOperand &OffsetMO = MI->getOperand(2); | |||
124 | SystemZCallingConventionRegisters *Regs = STI.getSpecialRegisters(); | |||
125 | ||||
126 | uint64_t Offset = (MFFrame.getMaxCallFrameSize() + | |||
127 | Regs->getCallFrameSize() + | |||
128 | Regs->getStackPointerBias() + | |||
129 | OffsetMO.getImm()); | |||
130 | unsigned NewOpcode = getOpcodeForOffset(SystemZ::LA, Offset); | |||
131 | assert(NewOpcode && "No support for huge argument lists yet")(static_cast <bool> (NewOpcode && "No support for huge argument lists yet" ) ? void (0) : __assert_fail ("NewOpcode && \"No support for huge argument lists yet\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 131, __extension__ __PRETTY_FUNCTION__)); | |||
132 | MI->setDesc(get(NewOpcode)); | |||
133 | OffsetMO.setImm(Offset); | |||
134 | } | |||
135 | ||||
136 | // MI is an RI-style pseudo instruction. Replace it with LowOpcode | |||
137 | // if the first operand is a low GR32 and HighOpcode if the first operand | |||
138 | // is a high GR32. ConvertHigh is true if LowOpcode takes a signed operand | |||
139 | // and HighOpcode takes an unsigned 32-bit operand. In those cases, | |||
140 | // MI has the same kind of operand as LowOpcode, so needs to be converted | |||
141 | // if HighOpcode is used. | |||
142 | void SystemZInstrInfo::expandRIPseudo(MachineInstr &MI, unsigned LowOpcode, | |||
143 | unsigned HighOpcode, | |||
144 | bool ConvertHigh) const { | |||
145 | Register Reg = MI.getOperand(0).getReg(); | |||
146 | bool IsHigh = SystemZ::isHighReg(Reg); | |||
147 | MI.setDesc(get(IsHigh ? HighOpcode : LowOpcode)); | |||
148 | if (IsHigh && ConvertHigh) | |||
149 | MI.getOperand(1).setImm(uint32_t(MI.getOperand(1).getImm())); | |||
150 | } | |||
151 | ||||
152 | // MI is a three-operand RIE-style pseudo instruction. Replace it with | |||
153 | // LowOpcodeK if the registers are both low GR32s, otherwise use a move | |||
154 | // followed by HighOpcode or LowOpcode, depending on whether the target | |||
155 | // is a high or low GR32. | |||
156 | void SystemZInstrInfo::expandRIEPseudo(MachineInstr &MI, unsigned LowOpcode, | |||
157 | unsigned LowOpcodeK, | |||
158 | unsigned HighOpcode) const { | |||
159 | Register DestReg = MI.getOperand(0).getReg(); | |||
160 | Register SrcReg = MI.getOperand(1).getReg(); | |||
161 | bool DestIsHigh = SystemZ::isHighReg(DestReg); | |||
162 | bool SrcIsHigh = SystemZ::isHighReg(SrcReg); | |||
163 | if (!DestIsHigh && !SrcIsHigh) | |||
164 | MI.setDesc(get(LowOpcodeK)); | |||
165 | else { | |||
166 | if (DestReg != SrcReg) { | |||
167 | emitGRX32Move(*MI.getParent(), MI, MI.getDebugLoc(), DestReg, SrcReg, | |||
168 | SystemZ::LR, 32, MI.getOperand(1).isKill(), | |||
169 | MI.getOperand(1).isUndef()); | |||
170 | MI.getOperand(1).setReg(DestReg); | |||
171 | } | |||
172 | MI.setDesc(get(DestIsHigh ? HighOpcode : LowOpcode)); | |||
173 | MI.tieOperands(0, 1); | |||
174 | } | |||
175 | } | |||
176 | ||||
177 | // MI is an RXY-style pseudo instruction. Replace it with LowOpcode | |||
178 | // if the first operand is a low GR32 and HighOpcode if the first operand | |||
179 | // is a high GR32. | |||
180 | void SystemZInstrInfo::expandRXYPseudo(MachineInstr &MI, unsigned LowOpcode, | |||
181 | unsigned HighOpcode) const { | |||
182 | Register Reg = MI.getOperand(0).getReg(); | |||
183 | unsigned Opcode = getOpcodeForOffset( | |||
184 | SystemZ::isHighReg(Reg) ? HighOpcode : LowOpcode, | |||
185 | MI.getOperand(2).getImm()); | |||
186 | MI.setDesc(get(Opcode)); | |||
187 | } | |||
188 | ||||
189 | // MI is a load-on-condition pseudo instruction with a single register | |||
190 | // (source or destination) operand. Replace it with LowOpcode if the | |||
191 | // register is a low GR32 and HighOpcode if the register is a high GR32. | |||
192 | void SystemZInstrInfo::expandLOCPseudo(MachineInstr &MI, unsigned LowOpcode, | |||
193 | unsigned HighOpcode) const { | |||
194 | Register Reg = MI.getOperand(0).getReg(); | |||
195 | unsigned Opcode = SystemZ::isHighReg(Reg) ? HighOpcode : LowOpcode; | |||
196 | MI.setDesc(get(Opcode)); | |||
197 | } | |||
198 | ||||
199 | // MI is an RR-style pseudo instruction that zero-extends the low Size bits | |||
200 | // of one GRX32 into another. Replace it with LowOpcode if both operands | |||
201 | // are low registers, otherwise use RISB[LH]G. | |||
202 | void SystemZInstrInfo::expandZExtPseudo(MachineInstr &MI, unsigned LowOpcode, | |||
203 | unsigned Size) const { | |||
204 | MachineInstrBuilder MIB = | |||
205 | emitGRX32Move(*MI.getParent(), MI, MI.getDebugLoc(), | |||
206 | MI.getOperand(0).getReg(), MI.getOperand(1).getReg(), LowOpcode, | |||
207 | Size, MI.getOperand(1).isKill(), MI.getOperand(1).isUndef()); | |||
208 | ||||
209 | // Keep the remaining operands as-is. | |||
210 | for (const MachineOperand &MO : llvm::drop_begin(MI.operands(), 2)) | |||
211 | MIB.add(MO); | |||
212 | ||||
213 | MI.eraseFromParent(); | |||
214 | } | |||
215 | ||||
216 | void SystemZInstrInfo::expandLoadStackGuard(MachineInstr *MI) const { | |||
217 | MachineBasicBlock *MBB = MI->getParent(); | |||
218 | MachineFunction &MF = *MBB->getParent(); | |||
219 | const Register Reg64 = MI->getOperand(0).getReg(); | |||
220 | const Register Reg32 = RI.getSubReg(Reg64, SystemZ::subreg_l32); | |||
221 | ||||
222 | // EAR can only load the low subregister so us a shift for %a0 to produce | |||
223 | // the GR containing %a0 and %a1. | |||
224 | ||||
225 | // ear <reg>, %a0 | |||
226 | BuildMI(*MBB, MI, MI->getDebugLoc(), get(SystemZ::EAR), Reg32) | |||
227 | .addReg(SystemZ::A0) | |||
228 | .addReg(Reg64, RegState::ImplicitDefine); | |||
229 | ||||
230 | // sllg <reg>, <reg>, 32 | |||
231 | BuildMI(*MBB, MI, MI->getDebugLoc(), get(SystemZ::SLLG), Reg64) | |||
232 | .addReg(Reg64) | |||
233 | .addReg(0) | |||
234 | .addImm(32); | |||
235 | ||||
236 | // ear <reg>, %a1 | |||
237 | BuildMI(*MBB, MI, MI->getDebugLoc(), get(SystemZ::EAR), Reg32) | |||
238 | .addReg(SystemZ::A1); | |||
239 | ||||
240 | // lg <reg>, 40(<reg>) | |||
241 | MI->setDesc(get(SystemZ::LG)); | |||
242 | MachineInstrBuilder(MF, MI).addReg(Reg64).addImm(40).addReg(0); | |||
243 | } | |||
244 | ||||
245 | // Emit a zero-extending move from 32-bit GPR SrcReg to 32-bit GPR | |||
246 | // DestReg before MBBI in MBB. Use LowLowOpcode when both DestReg and SrcReg | |||
247 | // are low registers, otherwise use RISB[LH]G. Size is the number of bits | |||
248 | // taken from the low end of SrcReg (8 for LLCR, 16 for LLHR and 32 for LR). | |||
249 | // KillSrc is true if this move is the last use of SrcReg. | |||
250 | MachineInstrBuilder | |||
251 | SystemZInstrInfo::emitGRX32Move(MachineBasicBlock &MBB, | |||
252 | MachineBasicBlock::iterator MBBI, | |||
253 | const DebugLoc &DL, unsigned DestReg, | |||
254 | unsigned SrcReg, unsigned LowLowOpcode, | |||
255 | unsigned Size, bool KillSrc, | |||
256 | bool UndefSrc) const { | |||
257 | unsigned Opcode; | |||
258 | bool DestIsHigh = SystemZ::isHighReg(DestReg); | |||
259 | bool SrcIsHigh = SystemZ::isHighReg(SrcReg); | |||
260 | if (DestIsHigh && SrcIsHigh) | |||
261 | Opcode = SystemZ::RISBHH; | |||
262 | else if (DestIsHigh && !SrcIsHigh) | |||
263 | Opcode = SystemZ::RISBHL; | |||
264 | else if (!DestIsHigh && SrcIsHigh) | |||
265 | Opcode = SystemZ::RISBLH; | |||
266 | else { | |||
267 | return BuildMI(MBB, MBBI, DL, get(LowLowOpcode), DestReg) | |||
268 | .addReg(SrcReg, getKillRegState(KillSrc) | getUndefRegState(UndefSrc)); | |||
269 | } | |||
270 | unsigned Rotate = (DestIsHigh != SrcIsHigh ? 32 : 0); | |||
271 | return BuildMI(MBB, MBBI, DL, get(Opcode), DestReg) | |||
272 | .addReg(DestReg, RegState::Undef) | |||
273 | .addReg(SrcReg, getKillRegState(KillSrc) | getUndefRegState(UndefSrc)) | |||
274 | .addImm(32 - Size).addImm(128 + 31).addImm(Rotate); | |||
275 | } | |||
276 | ||||
277 | MachineInstr *SystemZInstrInfo::commuteInstructionImpl(MachineInstr &MI, | |||
278 | bool NewMI, | |||
279 | unsigned OpIdx1, | |||
280 | unsigned OpIdx2) const { | |||
281 | auto cloneIfNew = [NewMI](MachineInstr &MI) -> MachineInstr & { | |||
282 | if (NewMI) | |||
283 | return *MI.getParent()->getParent()->CloneMachineInstr(&MI); | |||
284 | return MI; | |||
285 | }; | |||
286 | ||||
287 | switch (MI.getOpcode()) { | |||
288 | case SystemZ::SELRMux: | |||
289 | case SystemZ::SELFHR: | |||
290 | case SystemZ::SELR: | |||
291 | case SystemZ::SELGR: | |||
292 | case SystemZ::LOCRMux: | |||
293 | case SystemZ::LOCFHR: | |||
294 | case SystemZ::LOCR: | |||
295 | case SystemZ::LOCGR: { | |||
296 | auto &WorkingMI = cloneIfNew(MI); | |||
297 | // Invert condition. | |||
298 | unsigned CCValid = WorkingMI.getOperand(3).getImm(); | |||
299 | unsigned CCMask = WorkingMI.getOperand(4).getImm(); | |||
300 | WorkingMI.getOperand(4).setImm(CCMask ^ CCValid); | |||
301 | return TargetInstrInfo::commuteInstructionImpl(WorkingMI, /*NewMI=*/false, | |||
302 | OpIdx1, OpIdx2); | |||
303 | } | |||
304 | default: | |||
305 | return TargetInstrInfo::commuteInstructionImpl(MI, NewMI, OpIdx1, OpIdx2); | |||
306 | } | |||
307 | } | |||
308 | ||||
309 | // If MI is a simple load or store for a frame object, return the register | |||
310 | // it loads or stores and set FrameIndex to the index of the frame object. | |||
311 | // Return 0 otherwise. | |||
312 | // | |||
313 | // Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores. | |||
314 | static int isSimpleMove(const MachineInstr &MI, int &FrameIndex, | |||
315 | unsigned Flag) { | |||
316 | const MCInstrDesc &MCID = MI.getDesc(); | |||
317 | if ((MCID.TSFlags & Flag) && MI.getOperand(1).isFI() && | |||
318 | MI.getOperand(2).getImm() == 0 && MI.getOperand(3).getReg() == 0) { | |||
319 | FrameIndex = MI.getOperand(1).getIndex(); | |||
320 | return MI.getOperand(0).getReg(); | |||
321 | } | |||
322 | return 0; | |||
323 | } | |||
324 | ||||
325 | unsigned SystemZInstrInfo::isLoadFromStackSlot(const MachineInstr &MI, | |||
326 | int &FrameIndex) const { | |||
327 | return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXLoad); | |||
328 | } | |||
329 | ||||
330 | unsigned SystemZInstrInfo::isStoreToStackSlot(const MachineInstr &MI, | |||
331 | int &FrameIndex) const { | |||
332 | return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXStore); | |||
333 | } | |||
334 | ||||
335 | bool SystemZInstrInfo::isStackSlotCopy(const MachineInstr &MI, | |||
336 | int &DestFrameIndex, | |||
337 | int &SrcFrameIndex) const { | |||
338 | // Check for MVC 0(Length,FI1),0(FI2) | |||
339 | const MachineFrameInfo &MFI = MI.getParent()->getParent()->getFrameInfo(); | |||
340 | if (MI.getOpcode() != SystemZ::MVC || !MI.getOperand(0).isFI() || | |||
341 | MI.getOperand(1).getImm() != 0 || !MI.getOperand(3).isFI() || | |||
342 | MI.getOperand(4).getImm() != 0) | |||
343 | return false; | |||
344 | ||||
345 | // Check that Length covers the full slots. | |||
346 | int64_t Length = MI.getOperand(2).getImm(); | |||
347 | unsigned FI1 = MI.getOperand(0).getIndex(); | |||
348 | unsigned FI2 = MI.getOperand(3).getIndex(); | |||
349 | if (MFI.getObjectSize(FI1) != Length || | |||
350 | MFI.getObjectSize(FI2) != Length) | |||
351 | return false; | |||
352 | ||||
353 | DestFrameIndex = FI1; | |||
354 | SrcFrameIndex = FI2; | |||
355 | return true; | |||
356 | } | |||
357 | ||||
358 | bool SystemZInstrInfo::analyzeBranch(MachineBasicBlock &MBB, | |||
359 | MachineBasicBlock *&TBB, | |||
360 | MachineBasicBlock *&FBB, | |||
361 | SmallVectorImpl<MachineOperand> &Cond, | |||
362 | bool AllowModify) const { | |||
363 | // Most of the code and comments here are boilerplate. | |||
364 | ||||
365 | // Start from the bottom of the block and work up, examining the | |||
366 | // terminator instructions. | |||
367 | MachineBasicBlock::iterator I = MBB.end(); | |||
368 | while (I != MBB.begin()) { | |||
369 | --I; | |||
370 | if (I->isDebugInstr()) | |||
371 | continue; | |||
372 | ||||
373 | // Working from the bottom, when we see a non-terminator instruction, we're | |||
374 | // done. | |||
375 | if (!isUnpredicatedTerminator(*I)) | |||
376 | break; | |||
377 | ||||
378 | // A terminator that isn't a branch can't easily be handled by this | |||
379 | // analysis. | |||
380 | if (!I->isBranch()) | |||
381 | return true; | |||
382 | ||||
383 | // Can't handle indirect branches. | |||
384 | SystemZII::Branch Branch(getBranchInfo(*I)); | |||
385 | if (!Branch.hasMBBTarget()) | |||
386 | return true; | |||
387 | ||||
388 | // Punt on compound branches. | |||
389 | if (Branch.Type != SystemZII::BranchNormal) | |||
390 | return true; | |||
391 | ||||
392 | if (Branch.CCMask == SystemZ::CCMASK_ANY) { | |||
393 | // Handle unconditional branches. | |||
394 | if (!AllowModify) { | |||
395 | TBB = Branch.getMBBTarget(); | |||
396 | continue; | |||
397 | } | |||
398 | ||||
399 | // If the block has any instructions after a JMP, delete them. | |||
400 | MBB.erase(std::next(I), MBB.end()); | |||
401 | ||||
402 | Cond.clear(); | |||
403 | FBB = nullptr; | |||
404 | ||||
405 | // Delete the JMP if it's equivalent to a fall-through. | |||
406 | if (MBB.isLayoutSuccessor(Branch.getMBBTarget())) { | |||
407 | TBB = nullptr; | |||
408 | I->eraseFromParent(); | |||
409 | I = MBB.end(); | |||
410 | continue; | |||
411 | } | |||
412 | ||||
413 | // TBB is used to indicate the unconditinal destination. | |||
414 | TBB = Branch.getMBBTarget(); | |||
415 | continue; | |||
416 | } | |||
417 | ||||
418 | // Working from the bottom, handle the first conditional branch. | |||
419 | if (Cond.empty()) { | |||
420 | // FIXME: add X86-style branch swap | |||
421 | FBB = TBB; | |||
422 | TBB = Branch.getMBBTarget(); | |||
423 | Cond.push_back(MachineOperand::CreateImm(Branch.CCValid)); | |||
424 | Cond.push_back(MachineOperand::CreateImm(Branch.CCMask)); | |||
425 | continue; | |||
426 | } | |||
427 | ||||
428 | // Handle subsequent conditional branches. | |||
429 | assert(Cond.size() == 2 && TBB && "Should have seen a conditional branch")(static_cast <bool> (Cond.size() == 2 && TBB && "Should have seen a conditional branch") ? void (0) : __assert_fail ("Cond.size() == 2 && TBB && \"Should have seen a conditional branch\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 429, __extension__ __PRETTY_FUNCTION__)); | |||
430 | ||||
431 | // Only handle the case where all conditional branches branch to the same | |||
432 | // destination. | |||
433 | if (TBB != Branch.getMBBTarget()) | |||
434 | return true; | |||
435 | ||||
436 | // If the conditions are the same, we can leave them alone. | |||
437 | unsigned OldCCValid = Cond[0].getImm(); | |||
438 | unsigned OldCCMask = Cond[1].getImm(); | |||
439 | if (OldCCValid == Branch.CCValid && OldCCMask == Branch.CCMask) | |||
440 | continue; | |||
441 | ||||
442 | // FIXME: Try combining conditions like X86 does. Should be easy on Z! | |||
443 | return false; | |||
444 | } | |||
445 | ||||
446 | return false; | |||
447 | } | |||
448 | ||||
449 | unsigned SystemZInstrInfo::removeBranch(MachineBasicBlock &MBB, | |||
450 | int *BytesRemoved) const { | |||
451 | assert(!BytesRemoved && "code size not handled")(static_cast <bool> (!BytesRemoved && "code size not handled" ) ? void (0) : __assert_fail ("!BytesRemoved && \"code size not handled\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 451, __extension__ __PRETTY_FUNCTION__)); | |||
452 | ||||
453 | // Most of the code and comments here are boilerplate. | |||
454 | MachineBasicBlock::iterator I = MBB.end(); | |||
455 | unsigned Count = 0; | |||
456 | ||||
457 | while (I != MBB.begin()) { | |||
458 | --I; | |||
459 | if (I->isDebugInstr()) | |||
460 | continue; | |||
461 | if (!I->isBranch()) | |||
462 | break; | |||
463 | if (!getBranchInfo(*I).hasMBBTarget()) | |||
464 | break; | |||
465 | // Remove the branch. | |||
466 | I->eraseFromParent(); | |||
467 | I = MBB.end(); | |||
468 | ++Count; | |||
469 | } | |||
470 | ||||
471 | return Count; | |||
472 | } | |||
473 | ||||
474 | bool SystemZInstrInfo:: | |||
475 | reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { | |||
476 | assert(Cond.size() == 2 && "Invalid condition")(static_cast <bool> (Cond.size() == 2 && "Invalid condition" ) ? void (0) : __assert_fail ("Cond.size() == 2 && \"Invalid condition\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 476, __extension__ __PRETTY_FUNCTION__)); | |||
477 | Cond[1].setImm(Cond[1].getImm() ^ Cond[0].getImm()); | |||
478 | return false; | |||
479 | } | |||
480 | ||||
481 | unsigned SystemZInstrInfo::insertBranch(MachineBasicBlock &MBB, | |||
482 | MachineBasicBlock *TBB, | |||
483 | MachineBasicBlock *FBB, | |||
484 | ArrayRef<MachineOperand> Cond, | |||
485 | const DebugLoc &DL, | |||
486 | int *BytesAdded) const { | |||
487 | // In this function we output 32-bit branches, which should always | |||
488 | // have enough range. They can be shortened and relaxed by later code | |||
489 | // in the pipeline, if desired. | |||
490 | ||||
491 | // Shouldn't be a fall through. | |||
492 | assert(TBB && "insertBranch must not be told to insert a fallthrough")(static_cast <bool> (TBB && "insertBranch must not be told to insert a fallthrough" ) ? void (0) : __assert_fail ("TBB && \"insertBranch must not be told to insert a fallthrough\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 492, __extension__ __PRETTY_FUNCTION__)); | |||
493 | assert((Cond.size() == 2 || Cond.size() == 0) &&(static_cast <bool> ((Cond.size() == 2 || Cond.size() == 0) && "SystemZ branch conditions have one component!" ) ? void (0) : __assert_fail ("(Cond.size() == 2 || Cond.size() == 0) && \"SystemZ branch conditions have one component!\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 494, __extension__ __PRETTY_FUNCTION__)) | |||
494 | "SystemZ branch conditions have one component!")(static_cast <bool> ((Cond.size() == 2 || Cond.size() == 0) && "SystemZ branch conditions have one component!" ) ? void (0) : __assert_fail ("(Cond.size() == 2 || Cond.size() == 0) && \"SystemZ branch conditions have one component!\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 494, __extension__ __PRETTY_FUNCTION__)); | |||
495 | assert(!BytesAdded && "code size not handled")(static_cast <bool> (!BytesAdded && "code size not handled" ) ? void (0) : __assert_fail ("!BytesAdded && \"code size not handled\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 495, __extension__ __PRETTY_FUNCTION__)); | |||
496 | ||||
497 | if (Cond.empty()) { | |||
498 | // Unconditional branch? | |||
499 | assert(!FBB && "Unconditional branch with multiple successors!")(static_cast <bool> (!FBB && "Unconditional branch with multiple successors!" ) ? void (0) : __assert_fail ("!FBB && \"Unconditional branch with multiple successors!\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 499, __extension__ __PRETTY_FUNCTION__)); | |||
500 | BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(TBB); | |||
501 | return 1; | |||
502 | } | |||
503 | ||||
504 | // Conditional branch. | |||
505 | unsigned Count = 0; | |||
506 | unsigned CCValid = Cond[0].getImm(); | |||
507 | unsigned CCMask = Cond[1].getImm(); | |||
508 | BuildMI(&MBB, DL, get(SystemZ::BRC)) | |||
509 | .addImm(CCValid).addImm(CCMask).addMBB(TBB); | |||
510 | ++Count; | |||
511 | ||||
512 | if (FBB) { | |||
513 | // Two-way Conditional branch. Insert the second branch. | |||
514 | BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(FBB); | |||
515 | ++Count; | |||
516 | } | |||
517 | return Count; | |||
518 | } | |||
519 | ||||
520 | bool SystemZInstrInfo::analyzeCompare(const MachineInstr &MI, Register &SrcReg, | |||
521 | Register &SrcReg2, int64_t &Mask, | |||
522 | int64_t &Value) const { | |||
523 | assert(MI.isCompare() && "Caller should have checked for a comparison")(static_cast <bool> (MI.isCompare() && "Caller should have checked for a comparison" ) ? void (0) : __assert_fail ("MI.isCompare() && \"Caller should have checked for a comparison\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 523, __extension__ __PRETTY_FUNCTION__)); | |||
524 | ||||
525 | if (MI.getNumExplicitOperands() == 2 && MI.getOperand(0).isReg() && | |||
526 | MI.getOperand(1).isImm()) { | |||
527 | SrcReg = MI.getOperand(0).getReg(); | |||
528 | SrcReg2 = 0; | |||
529 | Value = MI.getOperand(1).getImm(); | |||
530 | Mask = ~0; | |||
531 | return true; | |||
532 | } | |||
533 | ||||
534 | return false; | |||
535 | } | |||
536 | ||||
537 | bool SystemZInstrInfo::canInsertSelect(const MachineBasicBlock &MBB, | |||
538 | ArrayRef<MachineOperand> Pred, | |||
539 | Register DstReg, Register TrueReg, | |||
540 | Register FalseReg, int &CondCycles, | |||
541 | int &TrueCycles, | |||
542 | int &FalseCycles) const { | |||
543 | // Not all subtargets have LOCR instructions. | |||
544 | if (!STI.hasLoadStoreOnCond()) | |||
545 | return false; | |||
546 | if (Pred.size() != 2) | |||
547 | return false; | |||
548 | ||||
549 | // Check register classes. | |||
550 | const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); | |||
551 | const TargetRegisterClass *RC = | |||
552 | RI.getCommonSubClass(MRI.getRegClass(TrueReg), MRI.getRegClass(FalseReg)); | |||
553 | if (!RC) | |||
554 | return false; | |||
555 | ||||
556 | // We have LOCR instructions for 32 and 64 bit general purpose registers. | |||
557 | if ((STI.hasLoadStoreOnCond2() && | |||
558 | SystemZ::GRX32BitRegClass.hasSubClassEq(RC)) || | |||
559 | SystemZ::GR32BitRegClass.hasSubClassEq(RC) || | |||
560 | SystemZ::GR64BitRegClass.hasSubClassEq(RC)) { | |||
561 | CondCycles = 2; | |||
562 | TrueCycles = 2; | |||
563 | FalseCycles = 2; | |||
564 | return true; | |||
565 | } | |||
566 | ||||
567 | // Can't do anything else. | |||
568 | return false; | |||
569 | } | |||
570 | ||||
571 | void SystemZInstrInfo::insertSelect(MachineBasicBlock &MBB, | |||
572 | MachineBasicBlock::iterator I, | |||
573 | const DebugLoc &DL, Register DstReg, | |||
574 | ArrayRef<MachineOperand> Pred, | |||
575 | Register TrueReg, | |||
576 | Register FalseReg) const { | |||
577 | MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); | |||
578 | const TargetRegisterClass *RC = MRI.getRegClass(DstReg); | |||
579 | ||||
580 | assert(Pred.size() == 2 && "Invalid condition")(static_cast <bool> (Pred.size() == 2 && "Invalid condition" ) ? void (0) : __assert_fail ("Pred.size() == 2 && \"Invalid condition\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 580, __extension__ __PRETTY_FUNCTION__)); | |||
581 | unsigned CCValid = Pred[0].getImm(); | |||
582 | unsigned CCMask = Pred[1].getImm(); | |||
583 | ||||
584 | unsigned Opc; | |||
585 | if (SystemZ::GRX32BitRegClass.hasSubClassEq(RC)) { | |||
586 | if (STI.hasMiscellaneousExtensions3()) | |||
587 | Opc = SystemZ::SELRMux; | |||
588 | else if (STI.hasLoadStoreOnCond2()) | |||
589 | Opc = SystemZ::LOCRMux; | |||
590 | else { | |||
591 | Opc = SystemZ::LOCR; | |||
592 | MRI.constrainRegClass(DstReg, &SystemZ::GR32BitRegClass); | |||
593 | Register TReg = MRI.createVirtualRegister(&SystemZ::GR32BitRegClass); | |||
594 | Register FReg = MRI.createVirtualRegister(&SystemZ::GR32BitRegClass); | |||
595 | BuildMI(MBB, I, DL, get(TargetOpcode::COPY), TReg).addReg(TrueReg); | |||
596 | BuildMI(MBB, I, DL, get(TargetOpcode::COPY), FReg).addReg(FalseReg); | |||
597 | TrueReg = TReg; | |||
598 | FalseReg = FReg; | |||
599 | } | |||
600 | } else if (SystemZ::GR64BitRegClass.hasSubClassEq(RC)) { | |||
601 | if (STI.hasMiscellaneousExtensions3()) | |||
602 | Opc = SystemZ::SELGR; | |||
603 | else | |||
604 | Opc = SystemZ::LOCGR; | |||
605 | } else | |||
606 | llvm_unreachable("Invalid register class")::llvm::llvm_unreachable_internal("Invalid register class", "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp" , 606); | |||
607 | ||||
608 | BuildMI(MBB, I, DL, get(Opc), DstReg) | |||
609 | .addReg(FalseReg).addReg(TrueReg) | |||
610 | .addImm(CCValid).addImm(CCMask); | |||
611 | } | |||
612 | ||||
613 | bool SystemZInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, | |||
614 | Register Reg, | |||
615 | MachineRegisterInfo *MRI) const { | |||
616 | unsigned DefOpc = DefMI.getOpcode(); | |||
617 | if (DefOpc != SystemZ::LHIMux && DefOpc != SystemZ::LHI && | |||
618 | DefOpc != SystemZ::LGHI) | |||
619 | return false; | |||
620 | if (DefMI.getOperand(0).getReg() != Reg) | |||
621 | return false; | |||
622 | int32_t ImmVal = (int32_t)DefMI.getOperand(1).getImm(); | |||
623 | ||||
624 | unsigned UseOpc = UseMI.getOpcode(); | |||
625 | unsigned NewUseOpc; | |||
626 | unsigned UseIdx; | |||
627 | int CommuteIdx = -1; | |||
628 | bool TieOps = false; | |||
629 | switch (UseOpc) { | |||
630 | case SystemZ::SELRMux: | |||
631 | TieOps = true; | |||
632 | [[fallthrough]]; | |||
633 | case SystemZ::LOCRMux: | |||
634 | if (!STI.hasLoadStoreOnCond2()) | |||
635 | return false; | |||
636 | NewUseOpc = SystemZ::LOCHIMux; | |||
637 | if (UseMI.getOperand(2).getReg() == Reg) | |||
638 | UseIdx = 2; | |||
639 | else if (UseMI.getOperand(1).getReg() == Reg) | |||
640 | UseIdx = 2, CommuteIdx = 1; | |||
641 | else | |||
642 | return false; | |||
643 | break; | |||
644 | case SystemZ::SELGR: | |||
645 | TieOps = true; | |||
646 | [[fallthrough]]; | |||
647 | case SystemZ::LOCGR: | |||
648 | if (!STI.hasLoadStoreOnCond2()) | |||
649 | return false; | |||
650 | NewUseOpc = SystemZ::LOCGHI; | |||
651 | if (UseMI.getOperand(2).getReg() == Reg) | |||
652 | UseIdx = 2; | |||
653 | else if (UseMI.getOperand(1).getReg() == Reg) | |||
654 | UseIdx = 2, CommuteIdx = 1; | |||
655 | else | |||
656 | return false; | |||
657 | break; | |||
658 | default: | |||
659 | return false; | |||
660 | } | |||
661 | ||||
662 | if (CommuteIdx != -1) | |||
663 | if (!commuteInstruction(UseMI, false, CommuteIdx, UseIdx)) | |||
664 | return false; | |||
665 | ||||
666 | bool DeleteDef = MRI->hasOneNonDBGUse(Reg); | |||
667 | UseMI.setDesc(get(NewUseOpc)); | |||
668 | if (TieOps) | |||
669 | UseMI.tieOperands(0, 1); | |||
670 | UseMI.getOperand(UseIdx).ChangeToImmediate(ImmVal); | |||
671 | if (DeleteDef) | |||
672 | DefMI.eraseFromParent(); | |||
673 | ||||
674 | return true; | |||
675 | } | |||
676 | ||||
677 | bool SystemZInstrInfo::isPredicable(const MachineInstr &MI) const { | |||
678 | unsigned Opcode = MI.getOpcode(); | |||
679 | if (Opcode == SystemZ::Return || | |||
680 | Opcode == SystemZ::Return_XPLINK || | |||
681 | Opcode == SystemZ::Trap || | |||
682 | Opcode == SystemZ::CallJG || | |||
683 | Opcode == SystemZ::CallBR) | |||
684 | return true; | |||
685 | return false; | |||
686 | } | |||
687 | ||||
688 | bool SystemZInstrInfo:: | |||
689 | isProfitableToIfCvt(MachineBasicBlock &MBB, | |||
690 | unsigned NumCycles, unsigned ExtraPredCycles, | |||
691 | BranchProbability Probability) const { | |||
692 | // Avoid using conditional returns at the end of a loop (since then | |||
693 | // we'd need to emit an unconditional branch to the beginning anyway, | |||
694 | // making the loop body longer). This doesn't apply for low-probability | |||
695 | // loops (eg. compare-and-swap retry), so just decide based on branch | |||
696 | // probability instead of looping structure. | |||
697 | // However, since Compare and Trap instructions cost the same as a regular | |||
698 | // Compare instruction, we should allow the if conversion to convert this | |||
699 | // into a Conditional Compare regardless of the branch probability. | |||
700 | if (MBB.getLastNonDebugInstr()->getOpcode() != SystemZ::Trap && | |||
701 | MBB.succ_empty() && Probability < BranchProbability(1, 8)) | |||
702 | return false; | |||
703 | // For now only convert single instructions. | |||
704 | return NumCycles == 1; | |||
705 | } | |||
706 | ||||
707 | bool SystemZInstrInfo:: | |||
708 | isProfitableToIfCvt(MachineBasicBlock &TMBB, | |||
709 | unsigned NumCyclesT, unsigned ExtraPredCyclesT, | |||
710 | MachineBasicBlock &FMBB, | |||
711 | unsigned NumCyclesF, unsigned ExtraPredCyclesF, | |||
712 | BranchProbability Probability) const { | |||
713 | // For now avoid converting mutually-exclusive cases. | |||
714 | return false; | |||
715 | } | |||
716 | ||||
717 | bool SystemZInstrInfo:: | |||
718 | isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, | |||
719 | BranchProbability Probability) const { | |||
720 | // For now only duplicate single instructions. | |||
721 | return NumCycles == 1; | |||
722 | } | |||
723 | ||||
724 | bool SystemZInstrInfo::PredicateInstruction( | |||
725 | MachineInstr &MI, ArrayRef<MachineOperand> Pred) const { | |||
726 | assert(Pred.size() == 2 && "Invalid condition")(static_cast <bool> (Pred.size() == 2 && "Invalid condition" ) ? void (0) : __assert_fail ("Pred.size() == 2 && \"Invalid condition\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 726, __extension__ __PRETTY_FUNCTION__)); | |||
727 | unsigned CCValid = Pred[0].getImm(); | |||
728 | unsigned CCMask = Pred[1].getImm(); | |||
729 | assert(CCMask > 0 && CCMask < 15 && "Invalid predicate")(static_cast <bool> (CCMask > 0 && CCMask < 15 && "Invalid predicate") ? void (0) : __assert_fail ("CCMask > 0 && CCMask < 15 && \"Invalid predicate\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 729, __extension__ __PRETTY_FUNCTION__)); | |||
730 | unsigned Opcode = MI.getOpcode(); | |||
731 | if (Opcode == SystemZ::Trap) { | |||
732 | MI.setDesc(get(SystemZ::CondTrap)); | |||
733 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) | |||
734 | .addImm(CCValid).addImm(CCMask) | |||
735 | .addReg(SystemZ::CC, RegState::Implicit); | |||
736 | return true; | |||
737 | } | |||
738 | if (Opcode == SystemZ::Return || Opcode == SystemZ::Return_XPLINK) { | |||
739 | MI.setDesc(get(Opcode == SystemZ::Return ? SystemZ::CondReturn | |||
740 | : SystemZ::CondReturn_XPLINK)); | |||
741 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) | |||
742 | .addImm(CCValid) | |||
743 | .addImm(CCMask) | |||
744 | .addReg(SystemZ::CC, RegState::Implicit); | |||
745 | return true; | |||
746 | } | |||
747 | if (Opcode == SystemZ::CallJG) { | |||
748 | MachineOperand FirstOp = MI.getOperand(0); | |||
749 | const uint32_t *RegMask = MI.getOperand(1).getRegMask(); | |||
750 | MI.removeOperand(1); | |||
751 | MI.removeOperand(0); | |||
752 | MI.setDesc(get(SystemZ::CallBRCL)); | |||
753 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) | |||
754 | .addImm(CCValid) | |||
755 | .addImm(CCMask) | |||
756 | .add(FirstOp) | |||
757 | .addRegMask(RegMask) | |||
758 | .addReg(SystemZ::CC, RegState::Implicit); | |||
759 | return true; | |||
760 | } | |||
761 | if (Opcode == SystemZ::CallBR) { | |||
762 | MachineOperand Target = MI.getOperand(0); | |||
763 | const uint32_t *RegMask = MI.getOperand(1).getRegMask(); | |||
764 | MI.removeOperand(1); | |||
765 | MI.removeOperand(0); | |||
766 | MI.setDesc(get(SystemZ::CallBCR)); | |||
767 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) | |||
768 | .addImm(CCValid).addImm(CCMask) | |||
769 | .add(Target) | |||
770 | .addRegMask(RegMask) | |||
771 | .addReg(SystemZ::CC, RegState::Implicit); | |||
772 | return true; | |||
773 | } | |||
774 | return false; | |||
775 | } | |||
776 | ||||
777 | void SystemZInstrInfo::copyPhysReg(MachineBasicBlock &MBB, | |||
778 | MachineBasicBlock::iterator MBBI, | |||
779 | const DebugLoc &DL, MCRegister DestReg, | |||
780 | MCRegister SrcReg, bool KillSrc) const { | |||
781 | // Split 128-bit GPR moves into two 64-bit moves. Add implicit uses of the | |||
782 | // super register in case one of the subregs is undefined. | |||
783 | // This handles ADDR128 too. | |||
784 | if (SystemZ::GR128BitRegClass.contains(DestReg, SrcReg)) { | |||
785 | copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_h64), | |||
786 | RI.getSubReg(SrcReg, SystemZ::subreg_h64), KillSrc); | |||
787 | MachineInstrBuilder(*MBB.getParent(), std::prev(MBBI)) | |||
788 | .addReg(SrcReg, RegState::Implicit); | |||
789 | copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_l64), | |||
790 | RI.getSubReg(SrcReg, SystemZ::subreg_l64), KillSrc); | |||
791 | MachineInstrBuilder(*MBB.getParent(), std::prev(MBBI)) | |||
792 | .addReg(SrcReg, (getKillRegState(KillSrc) | RegState::Implicit)); | |||
793 | return; | |||
794 | } | |||
795 | ||||
796 | if (SystemZ::GRX32BitRegClass.contains(DestReg, SrcReg)) { | |||
797 | emitGRX32Move(MBB, MBBI, DL, DestReg, SrcReg, SystemZ::LR, 32, KillSrc, | |||
798 | false); | |||
799 | return; | |||
800 | } | |||
801 | ||||
802 | // Move 128-bit floating-point values between VR128 and FP128. | |||
803 | if (SystemZ::VR128BitRegClass.contains(DestReg) && | |||
804 | SystemZ::FP128BitRegClass.contains(SrcReg)) { | |||
805 | MCRegister SrcRegHi = | |||
806 | RI.getMatchingSuperReg(RI.getSubReg(SrcReg, SystemZ::subreg_h64), | |||
807 | SystemZ::subreg_h64, &SystemZ::VR128BitRegClass); | |||
808 | MCRegister SrcRegLo = | |||
809 | RI.getMatchingSuperReg(RI.getSubReg(SrcReg, SystemZ::subreg_l64), | |||
810 | SystemZ::subreg_h64, &SystemZ::VR128BitRegClass); | |||
811 | ||||
812 | BuildMI(MBB, MBBI, DL, get(SystemZ::VMRHG), DestReg) | |||
813 | .addReg(SrcRegHi, getKillRegState(KillSrc)) | |||
814 | .addReg(SrcRegLo, getKillRegState(KillSrc)); | |||
815 | return; | |||
816 | } | |||
817 | if (SystemZ::FP128BitRegClass.contains(DestReg) && | |||
818 | SystemZ::VR128BitRegClass.contains(SrcReg)) { | |||
819 | MCRegister DestRegHi = | |||
820 | RI.getMatchingSuperReg(RI.getSubReg(DestReg, SystemZ::subreg_h64), | |||
821 | SystemZ::subreg_h64, &SystemZ::VR128BitRegClass); | |||
822 | MCRegister DestRegLo = | |||
823 | RI.getMatchingSuperReg(RI.getSubReg(DestReg, SystemZ::subreg_l64), | |||
824 | SystemZ::subreg_h64, &SystemZ::VR128BitRegClass); | |||
825 | ||||
826 | if (DestRegHi != SrcReg) | |||
827 | copyPhysReg(MBB, MBBI, DL, DestRegHi, SrcReg, false); | |||
828 | BuildMI(MBB, MBBI, DL, get(SystemZ::VREPG), DestRegLo) | |||
829 | .addReg(SrcReg, getKillRegState(KillSrc)).addImm(1); | |||
830 | return; | |||
831 | } | |||
832 | ||||
833 | // Move CC value from a GR32. | |||
834 | if (DestReg == SystemZ::CC) { | |||
835 | unsigned Opcode = | |||
836 | SystemZ::GR32BitRegClass.contains(SrcReg) ? SystemZ::TMLH : SystemZ::TMHH; | |||
837 | BuildMI(MBB, MBBI, DL, get(Opcode)) | |||
838 | .addReg(SrcReg, getKillRegState(KillSrc)) | |||
839 | .addImm(3 << (SystemZ::IPM_CC - 16)); | |||
840 | return; | |||
841 | } | |||
842 | ||||
843 | // Everything else needs only one instruction. | |||
844 | unsigned Opcode; | |||
845 | if (SystemZ::GR64BitRegClass.contains(DestReg, SrcReg)) | |||
846 | Opcode = SystemZ::LGR; | |||
847 | else if (SystemZ::FP32BitRegClass.contains(DestReg, SrcReg)) | |||
848 | // For z13 we prefer LDR over LER to avoid partial register dependencies. | |||
849 | Opcode = STI.hasVector() ? SystemZ::LDR32 : SystemZ::LER; | |||
850 | else if (SystemZ::FP64BitRegClass.contains(DestReg, SrcReg)) | |||
851 | Opcode = SystemZ::LDR; | |||
852 | else if (SystemZ::FP128BitRegClass.contains(DestReg, SrcReg)) | |||
853 | Opcode = SystemZ::LXR; | |||
854 | else if (SystemZ::VR32BitRegClass.contains(DestReg, SrcReg)) | |||
855 | Opcode = SystemZ::VLR32; | |||
856 | else if (SystemZ::VR64BitRegClass.contains(DestReg, SrcReg)) | |||
857 | Opcode = SystemZ::VLR64; | |||
858 | else if (SystemZ::VR128BitRegClass.contains(DestReg, SrcReg)) | |||
859 | Opcode = SystemZ::VLR; | |||
860 | else if (SystemZ::AR32BitRegClass.contains(DestReg, SrcReg)) | |||
861 | Opcode = SystemZ::CPYA; | |||
862 | else | |||
863 | llvm_unreachable("Impossible reg-to-reg copy")::llvm::llvm_unreachable_internal("Impossible reg-to-reg copy" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 863); | |||
864 | ||||
865 | BuildMI(MBB, MBBI, DL, get(Opcode), DestReg) | |||
866 | .addReg(SrcReg, getKillRegState(KillSrc)); | |||
867 | } | |||
868 | ||||
869 | void SystemZInstrInfo::storeRegToStackSlot( | |||
870 | MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, | |||
871 | bool isKill, int FrameIdx, const TargetRegisterClass *RC, | |||
872 | const TargetRegisterInfo *TRI, Register VReg) const { | |||
873 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); | |||
874 | ||||
875 | // Callers may expect a single instruction, so keep 128-bit moves | |||
876 | // together for now and lower them after register allocation. | |||
877 | unsigned LoadOpcode, StoreOpcode; | |||
878 | getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode); | |||
879 | addFrameReference(BuildMI(MBB, MBBI, DL, get(StoreOpcode)) | |||
880 | .addReg(SrcReg, getKillRegState(isKill)), | |||
881 | FrameIdx); | |||
882 | } | |||
883 | ||||
884 | void SystemZInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, | |||
885 | MachineBasicBlock::iterator MBBI, | |||
886 | Register DestReg, int FrameIdx, | |||
887 | const TargetRegisterClass *RC, | |||
888 | const TargetRegisterInfo *TRI, | |||
889 | Register VReg) const { | |||
890 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); | |||
891 | ||||
892 | // Callers may expect a single instruction, so keep 128-bit moves | |||
893 | // together for now and lower them after register allocation. | |||
894 | unsigned LoadOpcode, StoreOpcode; | |||
895 | getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode); | |||
896 | addFrameReference(BuildMI(MBB, MBBI, DL, get(LoadOpcode), DestReg), | |||
897 | FrameIdx); | |||
898 | } | |||
899 | ||||
900 | // Return true if MI is a simple load or store with a 12-bit displacement | |||
901 | // and no index. Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores. | |||
902 | static bool isSimpleBD12Move(const MachineInstr *MI, unsigned Flag) { | |||
903 | const MCInstrDesc &MCID = MI->getDesc(); | |||
904 | return ((MCID.TSFlags & Flag) && | |||
905 | isUInt<12>(MI->getOperand(2).getImm()) && | |||
906 | MI->getOperand(3).getReg() == 0); | |||
907 | } | |||
908 | ||||
909 | namespace { | |||
910 | ||||
911 | struct LogicOp { | |||
912 | LogicOp() = default; | |||
913 | LogicOp(unsigned regSize, unsigned immLSB, unsigned immSize) | |||
914 | : RegSize(regSize), ImmLSB(immLSB), ImmSize(immSize) {} | |||
915 | ||||
916 | explicit operator bool() const { return RegSize; } | |||
917 | ||||
918 | unsigned RegSize = 0; | |||
919 | unsigned ImmLSB = 0; | |||
920 | unsigned ImmSize = 0; | |||
921 | }; | |||
922 | ||||
923 | } // end anonymous namespace | |||
924 | ||||
925 | static LogicOp interpretAndImmediate(unsigned Opcode) { | |||
926 | switch (Opcode) { | |||
927 | case SystemZ::NILMux: return LogicOp(32, 0, 16); | |||
928 | case SystemZ::NIHMux: return LogicOp(32, 16, 16); | |||
929 | case SystemZ::NILL64: return LogicOp(64, 0, 16); | |||
930 | case SystemZ::NILH64: return LogicOp(64, 16, 16); | |||
931 | case SystemZ::NIHL64: return LogicOp(64, 32, 16); | |||
932 | case SystemZ::NIHH64: return LogicOp(64, 48, 16); | |||
933 | case SystemZ::NIFMux: return LogicOp(32, 0, 32); | |||
934 | case SystemZ::NILF64: return LogicOp(64, 0, 32); | |||
935 | case SystemZ::NIHF64: return LogicOp(64, 32, 32); | |||
936 | default: return LogicOp(); | |||
937 | } | |||
938 | } | |||
939 | ||||
940 | static void transferDeadCC(MachineInstr *OldMI, MachineInstr *NewMI) { | |||
941 | if (OldMI->registerDefIsDead(SystemZ::CC)) { | |||
942 | MachineOperand *CCDef = NewMI->findRegisterDefOperand(SystemZ::CC); | |||
943 | if (CCDef != nullptr) | |||
944 | CCDef->setIsDead(true); | |||
945 | } | |||
946 | } | |||
947 | ||||
948 | static void transferMIFlag(MachineInstr *OldMI, MachineInstr *NewMI, | |||
949 | MachineInstr::MIFlag Flag) { | |||
950 | if (OldMI->getFlag(Flag)) | |||
951 | NewMI->setFlag(Flag); | |||
952 | } | |||
953 | ||||
954 | MachineInstr * | |||
955 | SystemZInstrInfo::convertToThreeAddress(MachineInstr &MI, LiveVariables *LV, | |||
956 | LiveIntervals *LIS) const { | |||
957 | MachineBasicBlock *MBB = MI.getParent(); | |||
958 | ||||
959 | // Try to convert an AND into an RISBG-type instruction. | |||
960 | // TODO: It might be beneficial to select RISBG and shorten to AND instead. | |||
961 | if (LogicOp And = interpretAndImmediate(MI.getOpcode())) { | |||
| ||||
962 | uint64_t Imm = MI.getOperand(2).getImm() << And.ImmLSB; | |||
963 | // AND IMMEDIATE leaves the other bits of the register unchanged. | |||
964 | Imm |= allOnes(And.RegSize) & ~(allOnes(And.ImmSize) << And.ImmLSB); | |||
965 | unsigned Start, End; | |||
966 | if (isRxSBGMask(Imm, And.RegSize, Start, End)) { | |||
967 | unsigned NewOpcode; | |||
968 | if (And.RegSize == 64) { | |||
969 | NewOpcode = SystemZ::RISBG; | |||
970 | // Prefer RISBGN if available, since it does not clobber CC. | |||
971 | if (STI.hasMiscellaneousExtensions()) | |||
972 | NewOpcode = SystemZ::RISBGN; | |||
973 | } else { | |||
974 | NewOpcode = SystemZ::RISBMux; | |||
975 | Start &= 31; | |||
976 | End &= 31; | |||
977 | } | |||
978 | MachineOperand &Dest = MI.getOperand(0); | |||
979 | MachineOperand &Src = MI.getOperand(1); | |||
980 | MachineInstrBuilder MIB = | |||
981 | BuildMI(*MBB, MI, MI.getDebugLoc(), get(NewOpcode)) | |||
982 | .add(Dest) | |||
983 | .addReg(0) | |||
984 | .addReg(Src.getReg(), getKillRegState(Src.isKill()), | |||
985 | Src.getSubReg()) | |||
986 | .addImm(Start) | |||
987 | .addImm(End + 128) | |||
988 | .addImm(0); | |||
989 | if (LV) { | |||
990 | unsigned NumOps = MI.getNumOperands(); | |||
991 | for (unsigned I = 1; I < NumOps; ++I) { | |||
992 | MachineOperand &Op = MI.getOperand(I); | |||
993 | if (Op.isReg() && Op.isKill()) | |||
994 | LV->replaceKillInstruction(Op.getReg(), MI, *MIB); | |||
995 | } | |||
996 | } | |||
997 | if (LIS) | |||
998 | LIS->ReplaceMachineInstrInMaps(MI, *MIB); | |||
999 | transferDeadCC(&MI, MIB); | |||
1000 | return MIB; | |||
1001 | } | |||
1002 | } | |||
1003 | return nullptr; | |||
1004 | } | |||
1005 | ||||
1006 | MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl( | |||
1007 | MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops, | |||
1008 | MachineBasicBlock::iterator InsertPt, int FrameIndex, | |||
1009 | LiveIntervals *LIS, VirtRegMap *VRM) const { | |||
1010 | const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); | |||
1011 | MachineRegisterInfo &MRI = MF.getRegInfo(); | |||
1012 | const MachineFrameInfo &MFI = MF.getFrameInfo(); | |||
1013 | unsigned Size = MFI.getObjectSize(FrameIndex); | |||
1014 | unsigned Opcode = MI.getOpcode(); | |||
1015 | ||||
1016 | // Check CC liveness if new instruction introduces a dead def of CC. | |||
1017 | MCRegUnitIterator CCUnit(MCRegister::from(SystemZ::CC), TRI); | |||
1018 | SlotIndex MISlot = SlotIndex(); | |||
1019 | LiveRange *CCLiveRange = nullptr; | |||
1020 | bool CCLiveAtMI = true; | |||
1021 | if (LIS) { | |||
1022 | MISlot = LIS->getSlotIndexes()->getInstructionIndex(MI).getRegSlot(); | |||
1023 | CCLiveRange = &LIS->getRegUnit(*CCUnit); | |||
1024 | CCLiveAtMI = CCLiveRange->liveAt(MISlot); | |||
1025 | } | |||
1026 | ++CCUnit; | |||
1027 | assert(!CCUnit.isValid() && "CC only has one reg unit.")(static_cast <bool> (!CCUnit.isValid() && "CC only has one reg unit." ) ? void (0) : __assert_fail ("!CCUnit.isValid() && \"CC only has one reg unit.\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1027, __extension__ __PRETTY_FUNCTION__)); | |||
1028 | ||||
1029 | if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) { | |||
1030 | if (!CCLiveAtMI && (Opcode == SystemZ::LA || Opcode == SystemZ::LAY) && | |||
1031 | isInt<8>(MI.getOperand(2).getImm()) && !MI.getOperand(3).getReg()) { | |||
1032 | // LA(Y) %reg, CONST(%reg) -> AGSI %mem, CONST | |||
1033 | MachineInstr *BuiltMI = BuildMI(*InsertPt->getParent(), InsertPt, | |||
1034 | MI.getDebugLoc(), get(SystemZ::AGSI)) | |||
1035 | .addFrameIndex(FrameIndex) | |||
1036 | .addImm(0) | |||
1037 | .addImm(MI.getOperand(2).getImm()); | |||
1038 | BuiltMI->findRegisterDefOperand(SystemZ::CC)->setIsDead(true); | |||
1039 | CCLiveRange->createDeadDef(MISlot, LIS->getVNInfoAllocator()); | |||
1040 | return BuiltMI; | |||
1041 | } | |||
1042 | return nullptr; | |||
1043 | } | |||
1044 | ||||
1045 | // All other cases require a single operand. | |||
1046 | if (Ops.size() != 1) | |||
1047 | return nullptr; | |||
1048 | ||||
1049 | unsigned OpNum = Ops[0]; | |||
1050 | assert(Size * 8 ==(static_cast <bool> (Size * 8 == TRI->getRegSizeInBits (*MF.getRegInfo() .getRegClass(MI.getOperand(OpNum).getReg()) ) && "Invalid size combination") ? void (0) : __assert_fail ("Size * 8 == TRI->getRegSizeInBits(*MF.getRegInfo() .getRegClass(MI.getOperand(OpNum).getReg())) && \"Invalid size combination\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1053, __extension__ __PRETTY_FUNCTION__)) | |||
1051 | TRI->getRegSizeInBits(*MF.getRegInfo()(static_cast <bool> (Size * 8 == TRI->getRegSizeInBits (*MF.getRegInfo() .getRegClass(MI.getOperand(OpNum).getReg()) ) && "Invalid size combination") ? void (0) : __assert_fail ("Size * 8 == TRI->getRegSizeInBits(*MF.getRegInfo() .getRegClass(MI.getOperand(OpNum).getReg())) && \"Invalid size combination\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1053, __extension__ __PRETTY_FUNCTION__)) | |||
1052 | .getRegClass(MI.getOperand(OpNum).getReg())) &&(static_cast <bool> (Size * 8 == TRI->getRegSizeInBits (*MF.getRegInfo() .getRegClass(MI.getOperand(OpNum).getReg()) ) && "Invalid size combination") ? void (0) : __assert_fail ("Size * 8 == TRI->getRegSizeInBits(*MF.getRegInfo() .getRegClass(MI.getOperand(OpNum).getReg())) && \"Invalid size combination\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1053, __extension__ __PRETTY_FUNCTION__)) | |||
1053 | "Invalid size combination")(static_cast <bool> (Size * 8 == TRI->getRegSizeInBits (*MF.getRegInfo() .getRegClass(MI.getOperand(OpNum).getReg()) ) && "Invalid size combination") ? void (0) : __assert_fail ("Size * 8 == TRI->getRegSizeInBits(*MF.getRegInfo() .getRegClass(MI.getOperand(OpNum).getReg())) && \"Invalid size combination\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1053, __extension__ __PRETTY_FUNCTION__)); | |||
1054 | ||||
1055 | if ((Opcode == SystemZ::AHI || Opcode == SystemZ::AGHI) && OpNum == 0 && | |||
1056 | isInt<8>(MI.getOperand(2).getImm())) { | |||
1057 | // A(G)HI %reg, CONST -> A(G)SI %mem, CONST | |||
1058 | Opcode = (Opcode == SystemZ::AHI ? SystemZ::ASI : SystemZ::AGSI); | |||
1059 | MachineInstr *BuiltMI = | |||
1060 | BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), get(Opcode)) | |||
1061 | .addFrameIndex(FrameIndex) | |||
1062 | .addImm(0) | |||
1063 | .addImm(MI.getOperand(2).getImm()); | |||
1064 | transferDeadCC(&MI, BuiltMI); | |||
1065 | transferMIFlag(&MI, BuiltMI, MachineInstr::NoSWrap); | |||
1066 | return BuiltMI; | |||
1067 | } | |||
1068 | ||||
1069 | if ((Opcode == SystemZ::ALFI && OpNum == 0 && | |||
1070 | isInt<8>((int32_t)MI.getOperand(2).getImm())) || | |||
1071 | (Opcode == SystemZ::ALGFI && OpNum == 0 && | |||
1072 | isInt<8>((int64_t)MI.getOperand(2).getImm()))) { | |||
1073 | // AL(G)FI %reg, CONST -> AL(G)SI %mem, CONST | |||
1074 | Opcode = (Opcode == SystemZ::ALFI ? SystemZ::ALSI : SystemZ::ALGSI); | |||
1075 | MachineInstr *BuiltMI = | |||
1076 | BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), get(Opcode)) | |||
1077 | .addFrameIndex(FrameIndex) | |||
1078 | .addImm(0) | |||
1079 | .addImm((int8_t)MI.getOperand(2).getImm()); | |||
1080 | transferDeadCC(&MI, BuiltMI); | |||
1081 | return BuiltMI; | |||
1082 | } | |||
1083 | ||||
1084 | if ((Opcode == SystemZ::SLFI && OpNum == 0 && | |||
1085 | isInt<8>((int32_t)-MI.getOperand(2).getImm())) || | |||
1086 | (Opcode == SystemZ::SLGFI && OpNum == 0 && | |||
1087 | isInt<8>((int64_t)-MI.getOperand(2).getImm()))) { | |||
1088 | // SL(G)FI %reg, CONST -> AL(G)SI %mem, -CONST | |||
1089 | Opcode = (Opcode == SystemZ::SLFI ? SystemZ::ALSI : SystemZ::ALGSI); | |||
1090 | MachineInstr *BuiltMI = | |||
1091 | BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), get(Opcode)) | |||
1092 | .addFrameIndex(FrameIndex) | |||
1093 | .addImm(0) | |||
1094 | .addImm((int8_t)-MI.getOperand(2).getImm()); | |||
1095 | transferDeadCC(&MI, BuiltMI); | |||
1096 | return BuiltMI; | |||
1097 | } | |||
1098 | ||||
1099 | unsigned MemImmOpc = 0; | |||
1100 | switch (Opcode) { | |||
1101 | case SystemZ::LHIMux: | |||
1102 | case SystemZ::LHI: MemImmOpc = SystemZ::MVHI; break; | |||
1103 | case SystemZ::LGHI: MemImmOpc = SystemZ::MVGHI; break; | |||
1104 | case SystemZ::CHIMux: | |||
1105 | case SystemZ::CHI: MemImmOpc = SystemZ::CHSI; break; | |||
1106 | case SystemZ::CGHI: MemImmOpc = SystemZ::CGHSI; break; | |||
1107 | case SystemZ::CLFIMux: | |||
1108 | case SystemZ::CLFI: | |||
1109 | if (isUInt<16>(MI.getOperand(1).getImm())) | |||
1110 | MemImmOpc = SystemZ::CLFHSI; | |||
1111 | break; | |||
1112 | case SystemZ::CLGFI: | |||
1113 | if (isUInt<16>(MI.getOperand(1).getImm())) | |||
1114 | MemImmOpc = SystemZ::CLGHSI; | |||
1115 | break; | |||
1116 | default: break; | |||
1117 | } | |||
1118 | if (MemImmOpc) | |||
1119 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), | |||
1120 | get(MemImmOpc)) | |||
1121 | .addFrameIndex(FrameIndex) | |||
1122 | .addImm(0) | |||
1123 | .addImm(MI.getOperand(1).getImm()); | |||
1124 | ||||
1125 | if (Opcode == SystemZ::LGDR || Opcode == SystemZ::LDGR) { | |||
1126 | bool Op0IsGPR = (Opcode == SystemZ::LGDR); | |||
1127 | bool Op1IsGPR = (Opcode == SystemZ::LDGR); | |||
1128 | // If we're spilling the destination of an LDGR or LGDR, store the | |||
1129 | // source register instead. | |||
1130 | if (OpNum == 0) { | |||
1131 | unsigned StoreOpcode = Op1IsGPR ? SystemZ::STG : SystemZ::STD; | |||
1132 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), | |||
1133 | get(StoreOpcode)) | |||
1134 | .add(MI.getOperand(1)) | |||
1135 | .addFrameIndex(FrameIndex) | |||
1136 | .addImm(0) | |||
1137 | .addReg(0); | |||
1138 | } | |||
1139 | // If we're spilling the source of an LDGR or LGDR, load the | |||
1140 | // destination register instead. | |||
1141 | if (OpNum == 1) { | |||
1142 | unsigned LoadOpcode = Op0IsGPR ? SystemZ::LG : SystemZ::LD; | |||
1143 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), | |||
1144 | get(LoadOpcode)) | |||
1145 | .add(MI.getOperand(0)) | |||
1146 | .addFrameIndex(FrameIndex) | |||
1147 | .addImm(0) | |||
1148 | .addReg(0); | |||
1149 | } | |||
1150 | } | |||
1151 | ||||
1152 | // Look for cases where the source of a simple store or the destination | |||
1153 | // of a simple load is being spilled. Try to use MVC instead. | |||
1154 | // | |||
1155 | // Although MVC is in practice a fast choice in these cases, it is still | |||
1156 | // logically a bytewise copy. This means that we cannot use it if the | |||
1157 | // load or store is volatile. We also wouldn't be able to use MVC if | |||
1158 | // the two memories partially overlap, but that case cannot occur here, | |||
1159 | // because we know that one of the memories is a full frame index. | |||
1160 | // | |||
1161 | // For performance reasons, we also want to avoid using MVC if the addresses | |||
1162 | // might be equal. We don't worry about that case here, because spill slot | |||
1163 | // coloring happens later, and because we have special code to remove | |||
1164 | // MVCs that turn out to be redundant. | |||
1165 | if (OpNum == 0 && MI.hasOneMemOperand()) { | |||
1166 | MachineMemOperand *MMO = *MI.memoperands_begin(); | |||
1167 | if (MMO->getSize() == Size && !MMO->isVolatile() && !MMO->isAtomic()) { | |||
1168 | // Handle conversion of loads. | |||
1169 | if (isSimpleBD12Move(&MI, SystemZII::SimpleBDXLoad)) { | |||
1170 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), | |||
1171 | get(SystemZ::MVC)) | |||
1172 | .addFrameIndex(FrameIndex) | |||
1173 | .addImm(0) | |||
1174 | .addImm(Size) | |||
1175 | .add(MI.getOperand(1)) | |||
1176 | .addImm(MI.getOperand(2).getImm()) | |||
1177 | .addMemOperand(MMO); | |||
1178 | } | |||
1179 | // Handle conversion of stores. | |||
1180 | if (isSimpleBD12Move(&MI, SystemZII::SimpleBDXStore)) { | |||
1181 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), | |||
1182 | get(SystemZ::MVC)) | |||
1183 | .add(MI.getOperand(1)) | |||
1184 | .addImm(MI.getOperand(2).getImm()) | |||
1185 | .addImm(Size) | |||
1186 | .addFrameIndex(FrameIndex) | |||
1187 | .addImm(0) | |||
1188 | .addMemOperand(MMO); | |||
1189 | } | |||
1190 | } | |||
1191 | } | |||
1192 | ||||
1193 | // If the spilled operand is the final one or the instruction is | |||
1194 | // commutable, try to change <INSN>R into <INSN>. Don't introduce a def of | |||
1195 | // CC if it is live and MI does not define it. | |||
1196 | unsigned NumOps = MI.getNumExplicitOperands(); | |||
1197 | int MemOpcode = SystemZ::getMemOpcode(Opcode); | |||
1198 | if (MemOpcode == -1 || | |||
1199 | (CCLiveAtMI && !MI.definesRegister(SystemZ::CC) && | |||
1200 | get(MemOpcode).hasImplicitDefOfPhysReg(SystemZ::CC))) | |||
1201 | return nullptr; | |||
1202 | ||||
1203 | // Check if all other vregs have a usable allocation in the case of vector | |||
1204 | // to FP conversion. | |||
1205 | const MCInstrDesc &MCID = MI.getDesc(); | |||
1206 | for (unsigned I = 0, E = MCID.getNumOperands(); I != E; ++I) { | |||
1207 | const MCOperandInfo &MCOI = MCID.OpInfo[I]; | |||
1208 | if (MCOI.OperandType != MCOI::OPERAND_REGISTER || I == OpNum) | |||
1209 | continue; | |||
1210 | const TargetRegisterClass *RC = TRI->getRegClass(MCOI.RegClass); | |||
1211 | if (RC == &SystemZ::VR32BitRegClass || RC == &SystemZ::VR64BitRegClass) { | |||
1212 | Register Reg = MI.getOperand(I).getReg(); | |||
1213 | Register PhysReg = Register::isVirtualRegister(Reg) | |||
1214 | ? (VRM ? Register(VRM->getPhys(Reg)) : Register()) | |||
1215 | : Reg; | |||
1216 | if (!PhysReg || | |||
1217 | !(SystemZ::FP32BitRegClass.contains(PhysReg) || | |||
1218 | SystemZ::FP64BitRegClass.contains(PhysReg) || | |||
1219 | SystemZ::VF128BitRegClass.contains(PhysReg))) | |||
1220 | return nullptr; | |||
1221 | } | |||
1222 | } | |||
1223 | // Fused multiply and add/sub need to have the same dst and accumulator reg. | |||
1224 | bool FusedFPOp = (Opcode == SystemZ::WFMADB || Opcode == SystemZ::WFMASB || | |||
1225 | Opcode == SystemZ::WFMSDB || Opcode == SystemZ::WFMSSB); | |||
1226 | if (FusedFPOp) { | |||
1227 | Register DstReg = VRM->getPhys(MI.getOperand(0).getReg()); | |||
1228 | Register AccReg = VRM->getPhys(MI.getOperand(3).getReg()); | |||
1229 | if (OpNum == 0 || OpNum == 3 || DstReg != AccReg) | |||
1230 | return nullptr; | |||
1231 | } | |||
1232 | ||||
1233 | // Try to swap compare operands if possible. | |||
1234 | bool NeedsCommute = false; | |||
1235 | if ((MI.getOpcode() == SystemZ::CR || MI.getOpcode() == SystemZ::CGR || | |||
1236 | MI.getOpcode() == SystemZ::CLR || MI.getOpcode() == SystemZ::CLGR || | |||
1237 | MI.getOpcode() == SystemZ::WFCDB || MI.getOpcode() == SystemZ::WFCSB || | |||
1238 | MI.getOpcode() == SystemZ::WFKDB || MI.getOpcode() == SystemZ::WFKSB) && | |||
1239 | OpNum == 0 && prepareCompareSwapOperands(MI)) | |||
1240 | NeedsCommute = true; | |||
1241 | ||||
1242 | bool CCOperands = false; | |||
1243 | if (MI.getOpcode() == SystemZ::LOCRMux || MI.getOpcode() == SystemZ::LOCGR || | |||
1244 | MI.getOpcode() == SystemZ::SELRMux || MI.getOpcode() == SystemZ::SELGR) { | |||
1245 | assert(MI.getNumOperands() == 6 && NumOps == 5 &&(static_cast <bool> (MI.getNumOperands() == 6 && NumOps == 5 && "LOCR/SELR instruction operands corrupt?" ) ? void (0) : __assert_fail ("MI.getNumOperands() == 6 && NumOps == 5 && \"LOCR/SELR instruction operands corrupt?\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1246, __extension__ __PRETTY_FUNCTION__)) | |||
1246 | "LOCR/SELR instruction operands corrupt?")(static_cast <bool> (MI.getNumOperands() == 6 && NumOps == 5 && "LOCR/SELR instruction operands corrupt?" ) ? void (0) : __assert_fail ("MI.getNumOperands() == 6 && NumOps == 5 && \"LOCR/SELR instruction operands corrupt?\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1246, __extension__ __PRETTY_FUNCTION__)); | |||
1247 | NumOps -= 2; | |||
1248 | CCOperands = true; | |||
1249 | } | |||
1250 | ||||
1251 | // See if this is a 3-address instruction that is convertible to 2-address | |||
1252 | // and suitable for folding below. Only try this with virtual registers | |||
1253 | // and a provided VRM (during regalloc). | |||
1254 | if (NumOps == 3 && SystemZ::getTargetMemOpcode(MemOpcode) != -1) { | |||
1255 | if (VRM == nullptr) | |||
1256 | return nullptr; | |||
1257 | else { | |||
1258 | Register DstReg = MI.getOperand(0).getReg(); | |||
1259 | Register DstPhys = | |||
1260 | (Register::isVirtualRegister(DstReg) ? Register(VRM->getPhys(DstReg)) | |||
1261 | : DstReg); | |||
1262 | Register SrcReg = (OpNum == 2 ? MI.getOperand(1).getReg() | |||
1263 | : ((OpNum == 1 && MI.isCommutable()) | |||
1264 | ? MI.getOperand(2).getReg() | |||
1265 | : Register())); | |||
1266 | if (DstPhys && !SystemZ::GRH32BitRegClass.contains(DstPhys) && SrcReg && | |||
1267 | Register::isVirtualRegister(SrcReg) && | |||
1268 | DstPhys == VRM->getPhys(SrcReg)) | |||
1269 | NeedsCommute = (OpNum == 1); | |||
1270 | else | |||
1271 | return nullptr; | |||
1272 | } | |||
1273 | } | |||
1274 | ||||
1275 | if ((OpNum == NumOps - 1) || NeedsCommute || FusedFPOp) { | |||
1276 | const MCInstrDesc &MemDesc = get(MemOpcode); | |||
1277 | uint64_t AccessBytes = SystemZII::getAccessSize(MemDesc.TSFlags); | |||
1278 | assert(AccessBytes != 0 && "Size of access should be known")(static_cast <bool> (AccessBytes != 0 && "Size of access should be known" ) ? void (0) : __assert_fail ("AccessBytes != 0 && \"Size of access should be known\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1278, __extension__ __PRETTY_FUNCTION__)); | |||
1279 | assert(AccessBytes <= Size && "Access outside the frame index")(static_cast <bool> (AccessBytes <= Size && "Access outside the frame index" ) ? void (0) : __assert_fail ("AccessBytes <= Size && \"Access outside the frame index\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1279, __extension__ __PRETTY_FUNCTION__)); | |||
1280 | uint64_t Offset = Size - AccessBytes; | |||
1281 | MachineInstrBuilder MIB = BuildMI(*InsertPt->getParent(), InsertPt, | |||
1282 | MI.getDebugLoc(), get(MemOpcode)); | |||
1283 | if (MI.isCompare()) { | |||
1284 | assert(NumOps == 2 && "Expected 2 register operands for a compare.")(static_cast <bool> (NumOps == 2 && "Expected 2 register operands for a compare." ) ? void (0) : __assert_fail ("NumOps == 2 && \"Expected 2 register operands for a compare.\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1284, __extension__ __PRETTY_FUNCTION__)); | |||
1285 | MIB.add(MI.getOperand(NeedsCommute ? 1 : 0)); | |||
1286 | } | |||
1287 | else if (FusedFPOp) { | |||
1288 | MIB.add(MI.getOperand(0)); | |||
1289 | MIB.add(MI.getOperand(3)); | |||
1290 | MIB.add(MI.getOperand(OpNum == 1 ? 2 : 1)); | |||
1291 | } | |||
1292 | else { | |||
1293 | MIB.add(MI.getOperand(0)); | |||
1294 | if (NeedsCommute) | |||
1295 | MIB.add(MI.getOperand(2)); | |||
1296 | else | |||
1297 | for (unsigned I = 1; I < OpNum; ++I) | |||
1298 | MIB.add(MI.getOperand(I)); | |||
1299 | } | |||
1300 | MIB.addFrameIndex(FrameIndex).addImm(Offset); | |||
1301 | if (MemDesc.TSFlags & SystemZII::HasIndex) | |||
1302 | MIB.addReg(0); | |||
1303 | if (CCOperands) { | |||
1304 | unsigned CCValid = MI.getOperand(NumOps).getImm(); | |||
1305 | unsigned CCMask = MI.getOperand(NumOps + 1).getImm(); | |||
1306 | MIB.addImm(CCValid); | |||
1307 | MIB.addImm(NeedsCommute ? CCMask ^ CCValid : CCMask); | |||
1308 | } | |||
1309 | if (MIB->definesRegister(SystemZ::CC) && | |||
1310 | (!MI.definesRegister(SystemZ::CC) || | |||
1311 | MI.registerDefIsDead(SystemZ::CC))) { | |||
1312 | MIB->addRegisterDead(SystemZ::CC, TRI); | |||
1313 | if (CCLiveRange) | |||
1314 | CCLiveRange->createDeadDef(MISlot, LIS->getVNInfoAllocator()); | |||
1315 | } | |||
1316 | // Constrain the register classes if converted from a vector opcode. The | |||
1317 | // allocated regs are in an FP reg-class per previous check above. | |||
1318 | for (const MachineOperand &MO : MIB->operands()) | |||
1319 | if (MO.isReg() && Register::isVirtualRegister(MO.getReg())) { | |||
1320 | Register Reg = MO.getReg(); | |||
1321 | if (MRI.getRegClass(Reg) == &SystemZ::VR32BitRegClass) | |||
1322 | MRI.setRegClass(Reg, &SystemZ::FP32BitRegClass); | |||
1323 | else if (MRI.getRegClass(Reg) == &SystemZ::VR64BitRegClass) | |||
1324 | MRI.setRegClass(Reg, &SystemZ::FP64BitRegClass); | |||
1325 | else if (MRI.getRegClass(Reg) == &SystemZ::VR128BitRegClass) | |||
1326 | MRI.setRegClass(Reg, &SystemZ::VF128BitRegClass); | |||
1327 | } | |||
1328 | ||||
1329 | transferDeadCC(&MI, MIB); | |||
1330 | transferMIFlag(&MI, MIB, MachineInstr::NoSWrap); | |||
1331 | transferMIFlag(&MI, MIB, MachineInstr::NoFPExcept); | |||
1332 | return MIB; | |||
1333 | } | |||
1334 | ||||
1335 | return nullptr; | |||
1336 | } | |||
1337 | ||||
1338 | MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl( | |||
1339 | MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops, | |||
1340 | MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI, | |||
1341 | LiveIntervals *LIS) const { | |||
1342 | return nullptr; | |||
1343 | } | |||
1344 | ||||
1345 | bool SystemZInstrInfo::expandPostRAPseudo(MachineInstr &MI) const { | |||
1346 | switch (MI.getOpcode()) { | |||
1347 | case SystemZ::L128: | |||
1348 | splitMove(MI, SystemZ::LG); | |||
1349 | return true; | |||
1350 | ||||
1351 | case SystemZ::ST128: | |||
1352 | splitMove(MI, SystemZ::STG); | |||
1353 | return true; | |||
1354 | ||||
1355 | case SystemZ::LX: | |||
1356 | splitMove(MI, SystemZ::LD); | |||
1357 | return true; | |||
1358 | ||||
1359 | case SystemZ::STX: | |||
1360 | splitMove(MI, SystemZ::STD); | |||
1361 | return true; | |||
1362 | ||||
1363 | case SystemZ::LBMux: | |||
1364 | expandRXYPseudo(MI, SystemZ::LB, SystemZ::LBH); | |||
1365 | return true; | |||
1366 | ||||
1367 | case SystemZ::LHMux: | |||
1368 | expandRXYPseudo(MI, SystemZ::LH, SystemZ::LHH); | |||
1369 | return true; | |||
1370 | ||||
1371 | case SystemZ::LLCRMux: | |||
1372 | expandZExtPseudo(MI, SystemZ::LLCR, 8); | |||
1373 | return true; | |||
1374 | ||||
1375 | case SystemZ::LLHRMux: | |||
1376 | expandZExtPseudo(MI, SystemZ::LLHR, 16); | |||
1377 | return true; | |||
1378 | ||||
1379 | case SystemZ::LLCMux: | |||
1380 | expandRXYPseudo(MI, SystemZ::LLC, SystemZ::LLCH); | |||
1381 | return true; | |||
1382 | ||||
1383 | case SystemZ::LLHMux: | |||
1384 | expandRXYPseudo(MI, SystemZ::LLH, SystemZ::LLHH); | |||
1385 | return true; | |||
1386 | ||||
1387 | case SystemZ::LMux: | |||
1388 | expandRXYPseudo(MI, SystemZ::L, SystemZ::LFH); | |||
1389 | return true; | |||
1390 | ||||
1391 | case SystemZ::LOCMux: | |||
1392 | expandLOCPseudo(MI, SystemZ::LOC, SystemZ::LOCFH); | |||
1393 | return true; | |||
1394 | ||||
1395 | case SystemZ::LOCHIMux: | |||
1396 | expandLOCPseudo(MI, SystemZ::LOCHI, SystemZ::LOCHHI); | |||
1397 | return true; | |||
1398 | ||||
1399 | case SystemZ::STCMux: | |||
1400 | expandRXYPseudo(MI, SystemZ::STC, SystemZ::STCH); | |||
1401 | return true; | |||
1402 | ||||
1403 | case SystemZ::STHMux: | |||
1404 | expandRXYPseudo(MI, SystemZ::STH, SystemZ::STHH); | |||
1405 | return true; | |||
1406 | ||||
1407 | case SystemZ::STMux: | |||
1408 | expandRXYPseudo(MI, SystemZ::ST, SystemZ::STFH); | |||
1409 | return true; | |||
1410 | ||||
1411 | case SystemZ::STOCMux: | |||
1412 | expandLOCPseudo(MI, SystemZ::STOC, SystemZ::STOCFH); | |||
1413 | return true; | |||
1414 | ||||
1415 | case SystemZ::LHIMux: | |||
1416 | expandRIPseudo(MI, SystemZ::LHI, SystemZ::IIHF, true); | |||
1417 | return true; | |||
1418 | ||||
1419 | case SystemZ::IIFMux: | |||
1420 | expandRIPseudo(MI, SystemZ::IILF, SystemZ::IIHF, false); | |||
1421 | return true; | |||
1422 | ||||
1423 | case SystemZ::IILMux: | |||
1424 | expandRIPseudo(MI, SystemZ::IILL, SystemZ::IIHL, false); | |||
1425 | return true; | |||
1426 | ||||
1427 | case SystemZ::IIHMux: | |||
1428 | expandRIPseudo(MI, SystemZ::IILH, SystemZ::IIHH, false); | |||
1429 | return true; | |||
1430 | ||||
1431 | case SystemZ::NIFMux: | |||
1432 | expandRIPseudo(MI, SystemZ::NILF, SystemZ::NIHF, false); | |||
1433 | return true; | |||
1434 | ||||
1435 | case SystemZ::NILMux: | |||
1436 | expandRIPseudo(MI, SystemZ::NILL, SystemZ::NIHL, false); | |||
1437 | return true; | |||
1438 | ||||
1439 | case SystemZ::NIHMux: | |||
1440 | expandRIPseudo(MI, SystemZ::NILH, SystemZ::NIHH, false); | |||
1441 | return true; | |||
1442 | ||||
1443 | case SystemZ::OIFMux: | |||
1444 | expandRIPseudo(MI, SystemZ::OILF, SystemZ::OIHF, false); | |||
1445 | return true; | |||
1446 | ||||
1447 | case SystemZ::OILMux: | |||
1448 | expandRIPseudo(MI, SystemZ::OILL, SystemZ::OIHL, false); | |||
1449 | return true; | |||
1450 | ||||
1451 | case SystemZ::OIHMux: | |||
1452 | expandRIPseudo(MI, SystemZ::OILH, SystemZ::OIHH, false); | |||
1453 | return true; | |||
1454 | ||||
1455 | case SystemZ::XIFMux: | |||
1456 | expandRIPseudo(MI, SystemZ::XILF, SystemZ::XIHF, false); | |||
1457 | return true; | |||
1458 | ||||
1459 | case SystemZ::TMLMux: | |||
1460 | expandRIPseudo(MI, SystemZ::TMLL, SystemZ::TMHL, false); | |||
1461 | return true; | |||
1462 | ||||
1463 | case SystemZ::TMHMux: | |||
1464 | expandRIPseudo(MI, SystemZ::TMLH, SystemZ::TMHH, false); | |||
1465 | return true; | |||
1466 | ||||
1467 | case SystemZ::AHIMux: | |||
1468 | expandRIPseudo(MI, SystemZ::AHI, SystemZ::AIH, false); | |||
1469 | return true; | |||
1470 | ||||
1471 | case SystemZ::AHIMuxK: | |||
1472 | expandRIEPseudo(MI, SystemZ::AHI, SystemZ::AHIK, SystemZ::AIH); | |||
1473 | return true; | |||
1474 | ||||
1475 | case SystemZ::AFIMux: | |||
1476 | expandRIPseudo(MI, SystemZ::AFI, SystemZ::AIH, false); | |||
1477 | return true; | |||
1478 | ||||
1479 | case SystemZ::CHIMux: | |||
1480 | expandRIPseudo(MI, SystemZ::CHI, SystemZ::CIH, false); | |||
1481 | return true; | |||
1482 | ||||
1483 | case SystemZ::CFIMux: | |||
1484 | expandRIPseudo(MI, SystemZ::CFI, SystemZ::CIH, false); | |||
1485 | return true; | |||
1486 | ||||
1487 | case SystemZ::CLFIMux: | |||
1488 | expandRIPseudo(MI, SystemZ::CLFI, SystemZ::CLIH, false); | |||
1489 | return true; | |||
1490 | ||||
1491 | case SystemZ::CMux: | |||
1492 | expandRXYPseudo(MI, SystemZ::C, SystemZ::CHF); | |||
1493 | return true; | |||
1494 | ||||
1495 | case SystemZ::CLMux: | |||
1496 | expandRXYPseudo(MI, SystemZ::CL, SystemZ::CLHF); | |||
1497 | return true; | |||
1498 | ||||
1499 | case SystemZ::RISBMux: { | |||
1500 | bool DestIsHigh = SystemZ::isHighReg(MI.getOperand(0).getReg()); | |||
1501 | bool SrcIsHigh = SystemZ::isHighReg(MI.getOperand(2).getReg()); | |||
1502 | if (SrcIsHigh == DestIsHigh) | |||
1503 | MI.setDesc(get(DestIsHigh ? SystemZ::RISBHH : SystemZ::RISBLL)); | |||
1504 | else { | |||
1505 | MI.setDesc(get(DestIsHigh ? SystemZ::RISBHL : SystemZ::RISBLH)); | |||
1506 | MI.getOperand(5).setImm(MI.getOperand(5).getImm() ^ 32); | |||
1507 | } | |||
1508 | return true; | |||
1509 | } | |||
1510 | ||||
1511 | case SystemZ::ADJDYNALLOC: | |||
1512 | splitAdjDynAlloc(MI); | |||
1513 | return true; | |||
1514 | ||||
1515 | case TargetOpcode::LOAD_STACK_GUARD: | |||
1516 | expandLoadStackGuard(&MI); | |||
1517 | return true; | |||
1518 | ||||
1519 | default: | |||
1520 | return false; | |||
1521 | } | |||
1522 | } | |||
1523 | ||||
1524 | unsigned SystemZInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const { | |||
1525 | if (MI.isInlineAsm()) { | |||
1526 | const MachineFunction *MF = MI.getParent()->getParent(); | |||
1527 | const char *AsmStr = MI.getOperand(0).getSymbolName(); | |||
1528 | return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo()); | |||
1529 | } | |||
1530 | else if (MI.getOpcode() == SystemZ::PATCHPOINT) | |||
1531 | return PatchPointOpers(&MI).getNumPatchBytes(); | |||
1532 | else if (MI.getOpcode() == SystemZ::STACKMAP) | |||
1533 | return MI.getOperand(1).getImm(); | |||
1534 | else if (MI.getOpcode() == SystemZ::FENTRY_CALL) | |||
1535 | return 6; | |||
1536 | ||||
1537 | return MI.getDesc().getSize(); | |||
1538 | } | |||
1539 | ||||
1540 | SystemZII::Branch | |||
1541 | SystemZInstrInfo::getBranchInfo(const MachineInstr &MI) const { | |||
1542 | switch (MI.getOpcode()) { | |||
1543 | case SystemZ::BR: | |||
1544 | case SystemZ::BI: | |||
1545 | case SystemZ::J: | |||
1546 | case SystemZ::JG: | |||
1547 | return SystemZII::Branch(SystemZII::BranchNormal, SystemZ::CCMASK_ANY, | |||
1548 | SystemZ::CCMASK_ANY, &MI.getOperand(0)); | |||
1549 | ||||
1550 | case SystemZ::BRC: | |||
1551 | case SystemZ::BRCL: | |||
1552 | return SystemZII::Branch(SystemZII::BranchNormal, MI.getOperand(0).getImm(), | |||
1553 | MI.getOperand(1).getImm(), &MI.getOperand(2)); | |||
1554 | ||||
1555 | case SystemZ::BRCT: | |||
1556 | case SystemZ::BRCTH: | |||
1557 | return SystemZII::Branch(SystemZII::BranchCT, SystemZ::CCMASK_ICMP, | |||
1558 | SystemZ::CCMASK_CMP_NE, &MI.getOperand(2)); | |||
1559 | ||||
1560 | case SystemZ::BRCTG: | |||
1561 | return SystemZII::Branch(SystemZII::BranchCTG, SystemZ::CCMASK_ICMP, | |||
1562 | SystemZ::CCMASK_CMP_NE, &MI.getOperand(2)); | |||
1563 | ||||
1564 | case SystemZ::CIJ: | |||
1565 | case SystemZ::CRJ: | |||
1566 | return SystemZII::Branch(SystemZII::BranchC, SystemZ::CCMASK_ICMP, | |||
1567 | MI.getOperand(2).getImm(), &MI.getOperand(3)); | |||
1568 | ||||
1569 | case SystemZ::CLIJ: | |||
1570 | case SystemZ::CLRJ: | |||
1571 | return SystemZII::Branch(SystemZII::BranchCL, SystemZ::CCMASK_ICMP, | |||
1572 | MI.getOperand(2).getImm(), &MI.getOperand(3)); | |||
1573 | ||||
1574 | case SystemZ::CGIJ: | |||
1575 | case SystemZ::CGRJ: | |||
1576 | return SystemZII::Branch(SystemZII::BranchCG, SystemZ::CCMASK_ICMP, | |||
1577 | MI.getOperand(2).getImm(), &MI.getOperand(3)); | |||
1578 | ||||
1579 | case SystemZ::CLGIJ: | |||
1580 | case SystemZ::CLGRJ: | |||
1581 | return SystemZII::Branch(SystemZII::BranchCLG, SystemZ::CCMASK_ICMP, | |||
1582 | MI.getOperand(2).getImm(), &MI.getOperand(3)); | |||
1583 | ||||
1584 | case SystemZ::INLINEASM_BR: | |||
1585 | // Don't try to analyze asm goto, so pass nullptr as branch target argument. | |||
1586 | return SystemZII::Branch(SystemZII::AsmGoto, 0, 0, nullptr); | |||
1587 | ||||
1588 | default: | |||
1589 | llvm_unreachable("Unrecognized branch opcode")::llvm::llvm_unreachable_internal("Unrecognized branch opcode" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1589); | |||
1590 | } | |||
1591 | } | |||
1592 | ||||
1593 | void SystemZInstrInfo::getLoadStoreOpcodes(const TargetRegisterClass *RC, | |||
1594 | unsigned &LoadOpcode, | |||
1595 | unsigned &StoreOpcode) const { | |||
1596 | if (RC == &SystemZ::GR32BitRegClass || RC == &SystemZ::ADDR32BitRegClass) { | |||
1597 | LoadOpcode = SystemZ::L; | |||
1598 | StoreOpcode = SystemZ::ST; | |||
1599 | } else if (RC == &SystemZ::GRH32BitRegClass) { | |||
1600 | LoadOpcode = SystemZ::LFH; | |||
1601 | StoreOpcode = SystemZ::STFH; | |||
1602 | } else if (RC == &SystemZ::GRX32BitRegClass) { | |||
1603 | LoadOpcode = SystemZ::LMux; | |||
1604 | StoreOpcode = SystemZ::STMux; | |||
1605 | } else if (RC == &SystemZ::GR64BitRegClass || | |||
1606 | RC == &SystemZ::ADDR64BitRegClass) { | |||
1607 | LoadOpcode = SystemZ::LG; | |||
1608 | StoreOpcode = SystemZ::STG; | |||
1609 | } else if (RC == &SystemZ::GR128BitRegClass || | |||
1610 | RC == &SystemZ::ADDR128BitRegClass) { | |||
1611 | LoadOpcode = SystemZ::L128; | |||
1612 | StoreOpcode = SystemZ::ST128; | |||
1613 | } else if (RC == &SystemZ::FP32BitRegClass) { | |||
1614 | LoadOpcode = SystemZ::LE; | |||
1615 | StoreOpcode = SystemZ::STE; | |||
1616 | } else if (RC == &SystemZ::FP64BitRegClass) { | |||
1617 | LoadOpcode = SystemZ::LD; | |||
1618 | StoreOpcode = SystemZ::STD; | |||
1619 | } else if (RC == &SystemZ::FP128BitRegClass) { | |||
1620 | LoadOpcode = SystemZ::LX; | |||
1621 | StoreOpcode = SystemZ::STX; | |||
1622 | } else if (RC == &SystemZ::VR32BitRegClass) { | |||
1623 | LoadOpcode = SystemZ::VL32; | |||
1624 | StoreOpcode = SystemZ::VST32; | |||
1625 | } else if (RC == &SystemZ::VR64BitRegClass) { | |||
1626 | LoadOpcode = SystemZ::VL64; | |||
1627 | StoreOpcode = SystemZ::VST64; | |||
1628 | } else if (RC == &SystemZ::VF128BitRegClass || | |||
1629 | RC == &SystemZ::VR128BitRegClass) { | |||
1630 | LoadOpcode = SystemZ::VL; | |||
1631 | StoreOpcode = SystemZ::VST; | |||
1632 | } else | |||
1633 | llvm_unreachable("Unsupported regclass to load or store")::llvm::llvm_unreachable_internal("Unsupported regclass to load or store" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1633); | |||
1634 | } | |||
1635 | ||||
1636 | unsigned SystemZInstrInfo::getOpcodeForOffset(unsigned Opcode, | |||
1637 | int64_t Offset, | |||
1638 | const MachineInstr *MI) const { | |||
1639 | const MCInstrDesc &MCID = get(Opcode); | |||
1640 | int64_t Offset2 = (MCID.TSFlags & SystemZII::Is128Bit ? Offset + 8 : Offset); | |||
1641 | if (isUInt<12>(Offset) && isUInt<12>(Offset2)) { | |||
1642 | // Get the instruction to use for unsigned 12-bit displacements. | |||
1643 | int Disp12Opcode = SystemZ::getDisp12Opcode(Opcode); | |||
1644 | if (Disp12Opcode >= 0) | |||
1645 | return Disp12Opcode; | |||
1646 | ||||
1647 | // All address-related instructions can use unsigned 12-bit | |||
1648 | // displacements. | |||
1649 | return Opcode; | |||
1650 | } | |||
1651 | if (isInt<20>(Offset) && isInt<20>(Offset2)) { | |||
1652 | // Get the instruction to use for signed 20-bit displacements. | |||
1653 | int Disp20Opcode = SystemZ::getDisp20Opcode(Opcode); | |||
1654 | if (Disp20Opcode >= 0) | |||
1655 | return Disp20Opcode; | |||
1656 | ||||
1657 | // Check whether Opcode allows signed 20-bit displacements. | |||
1658 | if (MCID.TSFlags & SystemZII::Has20BitOffset) | |||
1659 | return Opcode; | |||
1660 | ||||
1661 | // If a VR32/VR64 reg ended up in an FP register, use the FP opcode. | |||
1662 | if (MI && MI->getOperand(0).isReg()) { | |||
1663 | Register Reg = MI->getOperand(0).getReg(); | |||
1664 | if (Reg.isPhysical() && SystemZMC::getFirstReg(Reg) < 16) { | |||
1665 | switch (Opcode) { | |||
1666 | case SystemZ::VL32: | |||
1667 | return SystemZ::LEY; | |||
1668 | case SystemZ::VST32: | |||
1669 | return SystemZ::STEY; | |||
1670 | case SystemZ::VL64: | |||
1671 | return SystemZ::LDY; | |||
1672 | case SystemZ::VST64: | |||
1673 | return SystemZ::STDY; | |||
1674 | default: break; | |||
1675 | } | |||
1676 | } | |||
1677 | } | |||
1678 | } | |||
1679 | return 0; | |||
1680 | } | |||
1681 | ||||
1682 | bool SystemZInstrInfo::hasDisplacementPairInsn(unsigned Opcode) const { | |||
1683 | const MCInstrDesc &MCID = get(Opcode); | |||
1684 | if (MCID.TSFlags & SystemZII::Has20BitOffset) | |||
1685 | return SystemZ::getDisp12Opcode(Opcode) >= 0; | |||
1686 | return SystemZ::getDisp20Opcode(Opcode) >= 0; | |||
1687 | } | |||
1688 | ||||
1689 | unsigned SystemZInstrInfo::getLoadAndTest(unsigned Opcode) const { | |||
1690 | switch (Opcode) { | |||
1691 | case SystemZ::L: return SystemZ::LT; | |||
1692 | case SystemZ::LY: return SystemZ::LT; | |||
1693 | case SystemZ::LG: return SystemZ::LTG; | |||
1694 | case SystemZ::LGF: return SystemZ::LTGF; | |||
1695 | case SystemZ::LR: return SystemZ::LTR; | |||
1696 | case SystemZ::LGFR: return SystemZ::LTGFR; | |||
1697 | case SystemZ::LGR: return SystemZ::LTGR; | |||
1698 | case SystemZ::LER: return SystemZ::LTEBR; | |||
1699 | case SystemZ::LDR: return SystemZ::LTDBR; | |||
1700 | case SystemZ::LXR: return SystemZ::LTXBR; | |||
1701 | case SystemZ::LCDFR: return SystemZ::LCDBR; | |||
1702 | case SystemZ::LPDFR: return SystemZ::LPDBR; | |||
1703 | case SystemZ::LNDFR: return SystemZ::LNDBR; | |||
1704 | case SystemZ::LCDFR_32: return SystemZ::LCEBR; | |||
1705 | case SystemZ::LPDFR_32: return SystemZ::LPEBR; | |||
1706 | case SystemZ::LNDFR_32: return SystemZ::LNEBR; | |||
1707 | // On zEC12 we prefer to use RISBGN. But if there is a chance to | |||
1708 | // actually use the condition code, we may turn it back into RISGB. | |||
1709 | // Note that RISBG is not really a "load-and-test" instruction, | |||
1710 | // but sets the same condition code values, so is OK to use here. | |||
1711 | case SystemZ::RISBGN: return SystemZ::RISBG; | |||
1712 | default: return 0; | |||
1713 | } | |||
1714 | } | |||
1715 | ||||
1716 | // Return true if Mask matches the regexp 0*1+0*, given that zero masks | |||
1717 | // have already been filtered out. Store the first set bit in LSB and | |||
1718 | // the number of set bits in Length if so. | |||
1719 | static bool isStringOfOnes(uint64_t Mask, unsigned &LSB, unsigned &Length) { | |||
1720 | unsigned First = findFirstSet(Mask); | |||
1721 | uint64_t Top = (Mask >> First) + 1; | |||
| ||||
1722 | if ((Top & -Top) == Top) { | |||
1723 | LSB = First; | |||
1724 | Length = findFirstSet(Top); | |||
1725 | return true; | |||
1726 | } | |||
1727 | return false; | |||
1728 | } | |||
1729 | ||||
1730 | bool SystemZInstrInfo::isRxSBGMask(uint64_t Mask, unsigned BitSize, | |||
1731 | unsigned &Start, unsigned &End) const { | |||
1732 | // Reject trivial all-zero masks. | |||
1733 | Mask &= allOnes(BitSize); | |||
1734 | if (Mask == 0) | |||
1735 | return false; | |||
1736 | ||||
1737 | // Handle the 1+0+ or 0+1+0* cases. Start then specifies the index of | |||
1738 | // the msb and End specifies the index of the lsb. | |||
1739 | unsigned LSB, Length; | |||
1740 | if (isStringOfOnes(Mask, LSB, Length)) { | |||
1741 | Start = 63 - (LSB + Length - 1); | |||
1742 | End = 63 - LSB; | |||
1743 | return true; | |||
1744 | } | |||
1745 | ||||
1746 | // Handle the wrap-around 1+0+1+ cases. Start then specifies the msb | |||
1747 | // of the low 1s and End specifies the lsb of the high 1s. | |||
1748 | if (isStringOfOnes(Mask ^ allOnes(BitSize), LSB, Length)) { | |||
1749 | assert(LSB > 0 && "Bottom bit must be set")(static_cast <bool> (LSB > 0 && "Bottom bit must be set" ) ? void (0) : __assert_fail ("LSB > 0 && \"Bottom bit must be set\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1749, __extension__ __PRETTY_FUNCTION__)); | |||
1750 | assert(LSB + Length < BitSize && "Top bit must be set")(static_cast <bool> (LSB + Length < BitSize && "Top bit must be set") ? void (0) : __assert_fail ("LSB + Length < BitSize && \"Top bit must be set\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1750, __extension__ __PRETTY_FUNCTION__)); | |||
1751 | Start = 63 - (LSB - 1); | |||
1752 | End = 63 - (LSB + Length); | |||
1753 | return true; | |||
1754 | } | |||
1755 | ||||
1756 | return false; | |||
1757 | } | |||
1758 | ||||
1759 | unsigned SystemZInstrInfo::getFusedCompare(unsigned Opcode, | |||
1760 | SystemZII::FusedCompareType Type, | |||
1761 | const MachineInstr *MI) const { | |||
1762 | switch (Opcode) { | |||
1763 | case SystemZ::CHI: | |||
1764 | case SystemZ::CGHI: | |||
1765 | if (!(MI && isInt<8>(MI->getOperand(1).getImm()))) | |||
1766 | return 0; | |||
1767 | break; | |||
1768 | case SystemZ::CLFI: | |||
1769 | case SystemZ::CLGFI: | |||
1770 | if (!(MI && isUInt<8>(MI->getOperand(1).getImm()))) | |||
1771 | return 0; | |||
1772 | break; | |||
1773 | case SystemZ::CL: | |||
1774 | case SystemZ::CLG: | |||
1775 | if (!STI.hasMiscellaneousExtensions()) | |||
1776 | return 0; | |||
1777 | if (!(MI && MI->getOperand(3).getReg() == 0)) | |||
1778 | return 0; | |||
1779 | break; | |||
1780 | } | |||
1781 | switch (Type) { | |||
1782 | case SystemZII::CompareAndBranch: | |||
1783 | switch (Opcode) { | |||
1784 | case SystemZ::CR: | |||
1785 | return SystemZ::CRJ; | |||
1786 | case SystemZ::CGR: | |||
1787 | return SystemZ::CGRJ; | |||
1788 | case SystemZ::CHI: | |||
1789 | return SystemZ::CIJ; | |||
1790 | case SystemZ::CGHI: | |||
1791 | return SystemZ::CGIJ; | |||
1792 | case SystemZ::CLR: | |||
1793 | return SystemZ::CLRJ; | |||
1794 | case SystemZ::CLGR: | |||
1795 | return SystemZ::CLGRJ; | |||
1796 | case SystemZ::CLFI: | |||
1797 | return SystemZ::CLIJ; | |||
1798 | case SystemZ::CLGFI: | |||
1799 | return SystemZ::CLGIJ; | |||
1800 | default: | |||
1801 | return 0; | |||
1802 | } | |||
1803 | case SystemZII::CompareAndReturn: | |||
1804 | switch (Opcode) { | |||
1805 | case SystemZ::CR: | |||
1806 | return SystemZ::CRBReturn; | |||
1807 | case SystemZ::CGR: | |||
1808 | return SystemZ::CGRBReturn; | |||
1809 | case SystemZ::CHI: | |||
1810 | return SystemZ::CIBReturn; | |||
1811 | case SystemZ::CGHI: | |||
1812 | return SystemZ::CGIBReturn; | |||
1813 | case SystemZ::CLR: | |||
1814 | return SystemZ::CLRBReturn; | |||
1815 | case SystemZ::CLGR: | |||
1816 | return SystemZ::CLGRBReturn; | |||
1817 | case SystemZ::CLFI: | |||
1818 | return SystemZ::CLIBReturn; | |||
1819 | case SystemZ::CLGFI: | |||
1820 | return SystemZ::CLGIBReturn; | |||
1821 | default: | |||
1822 | return 0; | |||
1823 | } | |||
1824 | case SystemZII::CompareAndSibcall: | |||
1825 | switch (Opcode) { | |||
1826 | case SystemZ::CR: | |||
1827 | return SystemZ::CRBCall; | |||
1828 | case SystemZ::CGR: | |||
1829 | return SystemZ::CGRBCall; | |||
1830 | case SystemZ::CHI: | |||
1831 | return SystemZ::CIBCall; | |||
1832 | case SystemZ::CGHI: | |||
1833 | return SystemZ::CGIBCall; | |||
1834 | case SystemZ::CLR: | |||
1835 | return SystemZ::CLRBCall; | |||
1836 | case SystemZ::CLGR: | |||
1837 | return SystemZ::CLGRBCall; | |||
1838 | case SystemZ::CLFI: | |||
1839 | return SystemZ::CLIBCall; | |||
1840 | case SystemZ::CLGFI: | |||
1841 | return SystemZ::CLGIBCall; | |||
1842 | default: | |||
1843 | return 0; | |||
1844 | } | |||
1845 | case SystemZII::CompareAndTrap: | |||
1846 | switch (Opcode) { | |||
1847 | case SystemZ::CR: | |||
1848 | return SystemZ::CRT; | |||
1849 | case SystemZ::CGR: | |||
1850 | return SystemZ::CGRT; | |||
1851 | case SystemZ::CHI: | |||
1852 | return SystemZ::CIT; | |||
1853 | case SystemZ::CGHI: | |||
1854 | return SystemZ::CGIT; | |||
1855 | case SystemZ::CLR: | |||
1856 | return SystemZ::CLRT; | |||
1857 | case SystemZ::CLGR: | |||
1858 | return SystemZ::CLGRT; | |||
1859 | case SystemZ::CLFI: | |||
1860 | return SystemZ::CLFIT; | |||
1861 | case SystemZ::CLGFI: | |||
1862 | return SystemZ::CLGIT; | |||
1863 | case SystemZ::CL: | |||
1864 | return SystemZ::CLT; | |||
1865 | case SystemZ::CLG: | |||
1866 | return SystemZ::CLGT; | |||
1867 | default: | |||
1868 | return 0; | |||
1869 | } | |||
1870 | } | |||
1871 | return 0; | |||
1872 | } | |||
1873 | ||||
1874 | bool SystemZInstrInfo:: | |||
1875 | prepareCompareSwapOperands(MachineBasicBlock::iterator const MBBI) const { | |||
1876 | assert(MBBI->isCompare() && MBBI->getOperand(0).isReg() &&(static_cast <bool> (MBBI->isCompare() && MBBI ->getOperand(0).isReg() && MBBI->getOperand(1). isReg() && !MBBI->mayLoad() && "Not a compare reg/reg." ) ? void (0) : __assert_fail ("MBBI->isCompare() && MBBI->getOperand(0).isReg() && MBBI->getOperand(1).isReg() && !MBBI->mayLoad() && \"Not a compare reg/reg.\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1878, __extension__ __PRETTY_FUNCTION__)) | |||
1877 | MBBI->getOperand(1).isReg() && !MBBI->mayLoad() &&(static_cast <bool> (MBBI->isCompare() && MBBI ->getOperand(0).isReg() && MBBI->getOperand(1). isReg() && !MBBI->mayLoad() && "Not a compare reg/reg." ) ? void (0) : __assert_fail ("MBBI->isCompare() && MBBI->getOperand(0).isReg() && MBBI->getOperand(1).isReg() && !MBBI->mayLoad() && \"Not a compare reg/reg.\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1878, __extension__ __PRETTY_FUNCTION__)) | |||
1878 | "Not a compare reg/reg.")(static_cast <bool> (MBBI->isCompare() && MBBI ->getOperand(0).isReg() && MBBI->getOperand(1). isReg() && !MBBI->mayLoad() && "Not a compare reg/reg." ) ? void (0) : __assert_fail ("MBBI->isCompare() && MBBI->getOperand(0).isReg() && MBBI->getOperand(1).isReg() && !MBBI->mayLoad() && \"Not a compare reg/reg.\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1878, __extension__ __PRETTY_FUNCTION__)); | |||
1879 | ||||
1880 | MachineBasicBlock *MBB = MBBI->getParent(); | |||
1881 | bool CCLive = true; | |||
1882 | SmallVector<MachineInstr *, 4> CCUsers; | |||
1883 | for (MachineInstr &MI : llvm::make_range(std::next(MBBI), MBB->end())) { | |||
1884 | if (MI.readsRegister(SystemZ::CC)) { | |||
1885 | unsigned Flags = MI.getDesc().TSFlags; | |||
1886 | if ((Flags & SystemZII::CCMaskFirst) || (Flags & SystemZII::CCMaskLast)) | |||
1887 | CCUsers.push_back(&MI); | |||
1888 | else | |||
1889 | return false; | |||
1890 | } | |||
1891 | if (MI.definesRegister(SystemZ::CC)) { | |||
1892 | CCLive = false; | |||
1893 | break; | |||
1894 | } | |||
1895 | } | |||
1896 | if (CCLive) { | |||
1897 | LivePhysRegs LiveRegs(*MBB->getParent()->getSubtarget().getRegisterInfo()); | |||
1898 | LiveRegs.addLiveOuts(*MBB); | |||
1899 | if (LiveRegs.contains(SystemZ::CC)) | |||
1900 | return false; | |||
1901 | } | |||
1902 | ||||
1903 | // Update all CC users. | |||
1904 | for (unsigned Idx = 0; Idx < CCUsers.size(); ++Idx) { | |||
1905 | unsigned Flags = CCUsers[Idx]->getDesc().TSFlags; | |||
1906 | unsigned FirstOpNum = ((Flags & SystemZII::CCMaskFirst) ? | |||
1907 | 0 : CCUsers[Idx]->getNumExplicitOperands() - 2); | |||
1908 | MachineOperand &CCMaskMO = CCUsers[Idx]->getOperand(FirstOpNum + 1); | |||
1909 | unsigned NewCCMask = SystemZ::reverseCCMask(CCMaskMO.getImm()); | |||
1910 | CCMaskMO.setImm(NewCCMask); | |||
1911 | } | |||
1912 | ||||
1913 | return true; | |||
1914 | } | |||
1915 | ||||
1916 | unsigned SystemZ::reverseCCMask(unsigned CCMask) { | |||
1917 | return ((CCMask & SystemZ::CCMASK_CMP_EQ) | | |||
1918 | (CCMask & SystemZ::CCMASK_CMP_GT ? SystemZ::CCMASK_CMP_LT : 0) | | |||
1919 | (CCMask & SystemZ::CCMASK_CMP_LT ? SystemZ::CCMASK_CMP_GT : 0) | | |||
1920 | (CCMask & SystemZ::CCMASK_CMP_UO)); | |||
1921 | } | |||
1922 | ||||
1923 | MachineBasicBlock *SystemZ::emitBlockAfter(MachineBasicBlock *MBB) { | |||
1924 | MachineFunction &MF = *MBB->getParent(); | |||
1925 | MachineBasicBlock *NewMBB = MF.CreateMachineBasicBlock(MBB->getBasicBlock()); | |||
1926 | MF.insert(std::next(MachineFunction::iterator(MBB)), NewMBB); | |||
1927 | return NewMBB; | |||
1928 | } | |||
1929 | ||||
1930 | MachineBasicBlock *SystemZ::splitBlockAfter(MachineBasicBlock::iterator MI, | |||
1931 | MachineBasicBlock *MBB) { | |||
1932 | MachineBasicBlock *NewMBB = emitBlockAfter(MBB); | |||
1933 | NewMBB->splice(NewMBB->begin(), MBB, | |||
1934 | std::next(MachineBasicBlock::iterator(MI)), MBB->end()); | |||
1935 | NewMBB->transferSuccessorsAndUpdatePHIs(MBB); | |||
1936 | return NewMBB; | |||
1937 | } | |||
1938 | ||||
1939 | MachineBasicBlock *SystemZ::splitBlockBefore(MachineBasicBlock::iterator MI, | |||
1940 | MachineBasicBlock *MBB) { | |||
1941 | MachineBasicBlock *NewMBB = emitBlockAfter(MBB); | |||
1942 | NewMBB->splice(NewMBB->begin(), MBB, MI, MBB->end()); | |||
1943 | NewMBB->transferSuccessorsAndUpdatePHIs(MBB); | |||
1944 | return NewMBB; | |||
1945 | } | |||
1946 | ||||
1947 | unsigned SystemZInstrInfo::getLoadAndTrap(unsigned Opcode) const { | |||
1948 | if (!STI.hasLoadAndTrap()) | |||
1949 | return 0; | |||
1950 | switch (Opcode) { | |||
1951 | case SystemZ::L: | |||
1952 | case SystemZ::LY: | |||
1953 | return SystemZ::LAT; | |||
1954 | case SystemZ::LG: | |||
1955 | return SystemZ::LGAT; | |||
1956 | case SystemZ::LFH: | |||
1957 | return SystemZ::LFHAT; | |||
1958 | case SystemZ::LLGF: | |||
1959 | return SystemZ::LLGFAT; | |||
1960 | case SystemZ::LLGT: | |||
1961 | return SystemZ::LLGTAT; | |||
1962 | } | |||
1963 | return 0; | |||
1964 | } | |||
1965 | ||||
1966 | void SystemZInstrInfo::loadImmediate(MachineBasicBlock &MBB, | |||
1967 | MachineBasicBlock::iterator MBBI, | |||
1968 | unsigned Reg, uint64_t Value) const { | |||
1969 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); | |||
1970 | unsigned Opcode = 0; | |||
1971 | if (isInt<16>(Value)) | |||
1972 | Opcode = SystemZ::LGHI; | |||
1973 | else if (SystemZ::isImmLL(Value)) | |||
1974 | Opcode = SystemZ::LLILL; | |||
1975 | else if (SystemZ::isImmLH(Value)) { | |||
1976 | Opcode = SystemZ::LLILH; | |||
1977 | Value >>= 16; | |||
1978 | } | |||
1979 | else if (isInt<32>(Value)) | |||
1980 | Opcode = SystemZ::LGFI; | |||
1981 | if (Opcode) { | |||
1982 | BuildMI(MBB, MBBI, DL, get(Opcode), Reg).addImm(Value); | |||
1983 | return; | |||
1984 | } | |||
1985 | ||||
1986 | MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); | |||
1987 | assert (MRI.isSSA() && "Huge values only handled before reg-alloc .")(static_cast <bool> (MRI.isSSA() && "Huge values only handled before reg-alloc ." ) ? void (0) : __assert_fail ("MRI.isSSA() && \"Huge values only handled before reg-alloc .\"" , "llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp", 1987, __extension__ __PRETTY_FUNCTION__)); | |||
1988 | Register Reg0 = MRI.createVirtualRegister(&SystemZ::GR64BitRegClass); | |||
1989 | Register Reg1 = MRI.createVirtualRegister(&SystemZ::GR64BitRegClass); | |||
1990 | BuildMI(MBB, MBBI, DL, get(SystemZ::IMPLICIT_DEF), Reg0); | |||
1991 | BuildMI(MBB, MBBI, DL, get(SystemZ::IIHF64), Reg1) | |||
1992 | .addReg(Reg0).addImm(Value >> 32); | |||
1993 | BuildMI(MBB, MBBI, DL, get(SystemZ::IILF64), Reg) | |||
1994 | .addReg(Reg1).addImm(Value & ((uint64_t(1) << 32) - 1)); | |||
1995 | } | |||
1996 | ||||
1997 | bool SystemZInstrInfo::verifyInstruction(const MachineInstr &MI, | |||
1998 | StringRef &ErrInfo) const { | |||
1999 | const MCInstrDesc &MCID = MI.getDesc(); | |||
2000 | for (unsigned I = 0, E = MI.getNumOperands(); I != E; ++I) { | |||
2001 | if (I >= MCID.getNumOperands()) | |||
2002 | break; | |||
2003 | const MachineOperand &Op = MI.getOperand(I); | |||
2004 | const MCOperandInfo &MCOI = MCID.OpInfo[I]; | |||
2005 | // Addressing modes have register and immediate operands. Op should be a | |||
2006 | // register (or frame index) operand if MCOI.RegClass contains a valid | |||
2007 | // register class, or an immediate otherwise. | |||
2008 | if (MCOI.OperandType == MCOI::OPERAND_MEMORY && | |||
2009 | ((MCOI.RegClass != -1 && !Op.isReg() && !Op.isFI()) || | |||
2010 | (MCOI.RegClass == -1 && !Op.isImm()))) { | |||
2011 | ErrInfo = "Addressing mode operands corrupt!"; | |||
2012 | return false; | |||
2013 | } | |||
2014 | } | |||
2015 | ||||
2016 | return true; | |||
2017 | } | |||
2018 | ||||
2019 | bool SystemZInstrInfo:: | |||
2020 | areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, | |||
2021 | const MachineInstr &MIb) const { | |||
2022 | ||||
2023 | if (!MIa.hasOneMemOperand() || !MIb.hasOneMemOperand()) | |||
2024 | return false; | |||
2025 | ||||
2026 | // If mem-operands show that the same address Value is used by both | |||
2027 | // instructions, check for non-overlapping offsets and widths. Not | |||
2028 | // sure if a register based analysis would be an improvement... | |||
2029 | ||||
2030 | MachineMemOperand *MMOa = *MIa.memoperands_begin(); | |||
2031 | MachineMemOperand *MMOb = *MIb.memoperands_begin(); | |||
2032 | const Value *VALa = MMOa->getValue(); | |||
2033 | const Value *VALb = MMOb->getValue(); | |||
2034 | bool SameVal = (VALa && VALb && (VALa == VALb)); | |||
2035 | if (!SameVal) { | |||
2036 | const PseudoSourceValue *PSVa = MMOa->getPseudoValue(); | |||
2037 | const PseudoSourceValue *PSVb = MMOb->getPseudoValue(); | |||
2038 | if (PSVa && PSVb && (PSVa == PSVb)) | |||
2039 | SameVal = true; | |||
2040 | } | |||
2041 | if (SameVal) { | |||
2042 | int OffsetA = MMOa->getOffset(), OffsetB = MMOb->getOffset(); | |||
2043 | int WidthA = MMOa->getSize(), WidthB = MMOb->getSize(); | |||
2044 | int LowOffset = OffsetA < OffsetB ? OffsetA : OffsetB; | |||
2045 | int HighOffset = OffsetA < OffsetB ? OffsetB : OffsetA; | |||
2046 | int LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB; | |||
2047 | if (LowOffset + LowWidth <= HighOffset) | |||
2048 | return true; | |||
2049 | } | |||
2050 | ||||
2051 | return false; | |||
2052 | } |
1 | //===-- llvm/Support/MathExtras.h - Useful math functions -------*- 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 | // | ||||||
9 | // This file contains some functions that are useful for math stuff. | ||||||
10 | // | ||||||
11 | //===----------------------------------------------------------------------===// | ||||||
12 | |||||||
13 | #ifndef LLVM_SUPPORT_MATHEXTRAS_H | ||||||
14 | #define LLVM_SUPPORT_MATHEXTRAS_H | ||||||
15 | |||||||
16 | #include "llvm/ADT/bit.h" | ||||||
17 | #include "llvm/Support/Compiler.h" | ||||||
18 | #include <cassert> | ||||||
19 | #include <climits> | ||||||
20 | #include <cstdint> | ||||||
21 | #include <cstring> | ||||||
22 | #include <limits> | ||||||
23 | #include <type_traits> | ||||||
24 | |||||||
25 | #ifdef _MSC_VER | ||||||
26 | // Declare these intrinsics manually rather including intrin.h. It's very | ||||||
27 | // expensive, and MathExtras.h is popular. | ||||||
28 | // #include <intrin.h> | ||||||
29 | extern "C" { | ||||||
30 | unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask); | ||||||
31 | unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask); | ||||||
32 | unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask); | ||||||
33 | unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask); | ||||||
34 | } | ||||||
35 | #endif | ||||||
36 | |||||||
37 | namespace llvm { | ||||||
38 | |||||||
39 | /// The behavior an operation has on an input of 0. | ||||||
40 | enum ZeroBehavior { | ||||||
41 | /// The returned value is undefined. | ||||||
42 | ZB_Undefined, | ||||||
43 | /// The returned value is numeric_limits<T>::max() | ||||||
44 | ZB_Max, | ||||||
45 | /// The returned value is numeric_limits<T>::digits | ||||||
46 | ZB_Width | ||||||
47 | }; | ||||||
48 | |||||||
49 | /// Mathematical constants. | ||||||
50 | namespace numbers { | ||||||
51 | // TODO: Track C++20 std::numbers. | ||||||
52 | // TODO: Favor using the hexadecimal FP constants (requires C++17). | ||||||
53 | constexpr double e = 2.7182818284590452354, // (0x1.5bf0a8b145749P+1) https://oeis.org/A001113 | ||||||
54 | egamma = .57721566490153286061, // (0x1.2788cfc6fb619P-1) https://oeis.org/A001620 | ||||||
55 | ln2 = .69314718055994530942, // (0x1.62e42fefa39efP-1) https://oeis.org/A002162 | ||||||
56 | ln10 = 2.3025850929940456840, // (0x1.24bb1bbb55516P+1) https://oeis.org/A002392 | ||||||
57 | log2e = 1.4426950408889634074, // (0x1.71547652b82feP+0) | ||||||
58 | log10e = .43429448190325182765, // (0x1.bcb7b1526e50eP-2) | ||||||
59 | pi = 3.1415926535897932385, // (0x1.921fb54442d18P+1) https://oeis.org/A000796 | ||||||
60 | inv_pi = .31830988618379067154, // (0x1.45f306bc9c883P-2) https://oeis.org/A049541 | ||||||
61 | sqrtpi = 1.7724538509055160273, // (0x1.c5bf891b4ef6bP+0) https://oeis.org/A002161 | ||||||
62 | inv_sqrtpi = .56418958354775628695, // (0x1.20dd750429b6dP-1) https://oeis.org/A087197 | ||||||
63 | sqrt2 = 1.4142135623730950488, // (0x1.6a09e667f3bcdP+0) https://oeis.org/A00219 | ||||||
64 | inv_sqrt2 = .70710678118654752440, // (0x1.6a09e667f3bcdP-1) | ||||||
65 | sqrt3 = 1.7320508075688772935, // (0x1.bb67ae8584caaP+0) https://oeis.org/A002194 | ||||||
66 | inv_sqrt3 = .57735026918962576451, // (0x1.279a74590331cP-1) | ||||||
67 | phi = 1.6180339887498948482; // (0x1.9e3779b97f4a8P+0) https://oeis.org/A001622 | ||||||
68 | constexpr float ef = 2.71828183F, // (0x1.5bf0a8P+1) https://oeis.org/A001113 | ||||||
69 | egammaf = .577215665F, // (0x1.2788d0P-1) https://oeis.org/A001620 | ||||||
70 | ln2f = .693147181F, // (0x1.62e430P-1) https://oeis.org/A002162 | ||||||
71 | ln10f = 2.30258509F, // (0x1.26bb1cP+1) https://oeis.org/A002392 | ||||||
72 | log2ef = 1.44269504F, // (0x1.715476P+0) | ||||||
73 | log10ef = .434294482F, // (0x1.bcb7b2P-2) | ||||||
74 | pif = 3.14159265F, // (0x1.921fb6P+1) https://oeis.org/A000796 | ||||||
75 | inv_pif = .318309886F, // (0x1.45f306P-2) https://oeis.org/A049541 | ||||||
76 | sqrtpif = 1.77245385F, // (0x1.c5bf8aP+0) https://oeis.org/A002161 | ||||||
77 | inv_sqrtpif = .564189584F, // (0x1.20dd76P-1) https://oeis.org/A087197 | ||||||
78 | sqrt2f = 1.41421356F, // (0x1.6a09e6P+0) https://oeis.org/A002193 | ||||||
79 | inv_sqrt2f = .707106781F, // (0x1.6a09e6P-1) | ||||||
80 | sqrt3f = 1.73205081F, // (0x1.bb67aeP+0) https://oeis.org/A002194 | ||||||
81 | inv_sqrt3f = .577350269F, // (0x1.279a74P-1) | ||||||
82 | phif = 1.61803399F; // (0x1.9e377aP+0) https://oeis.org/A001622 | ||||||
83 | } // namespace numbers | ||||||
84 | |||||||
85 | namespace detail { | ||||||
86 | template <typename T, std::size_t SizeOfT> struct TrailingZerosCounter { | ||||||
87 | static unsigned count(T Val, ZeroBehavior) { | ||||||
88 | if (!Val) | ||||||
89 | return std::numeric_limits<T>::digits; | ||||||
90 | if (Val & 0x1) | ||||||
91 | return 0; | ||||||
92 | |||||||
93 | // Bisection method. | ||||||
94 | unsigned ZeroBits = 0; | ||||||
95 | T Shift = std::numeric_limits<T>::digits >> 1; | ||||||
96 | T Mask = std::numeric_limits<T>::max() >> Shift; | ||||||
97 | while (Shift) { | ||||||
98 | if ((Val & Mask) == 0) { | ||||||
99 | Val >>= Shift; | ||||||
100 | ZeroBits |= Shift; | ||||||
101 | } | ||||||
102 | Shift >>= 1; | ||||||
103 | Mask >>= Shift; | ||||||
104 | } | ||||||
105 | return ZeroBits; | ||||||
106 | } | ||||||
107 | }; | ||||||
108 | |||||||
109 | #if defined(__GNUC__4) || defined(_MSC_VER) | ||||||
110 | template <typename T> struct TrailingZerosCounter<T, 4> { | ||||||
111 | static unsigned count(T Val, ZeroBehavior ZB) { | ||||||
112 | if (ZB != ZB_Undefined && Val == 0) | ||||||
113 | return 32; | ||||||
114 | |||||||
115 | #if __has_builtin(__builtin_ctz)1 || defined(__GNUC__4) | ||||||
116 | return __builtin_ctz(Val); | ||||||
117 | #elif defined(_MSC_VER) | ||||||
118 | unsigned long Index; | ||||||
119 | _BitScanForward(&Index, Val); | ||||||
120 | return Index; | ||||||
121 | #endif | ||||||
122 | } | ||||||
123 | }; | ||||||
124 | |||||||
125 | #if !defined(_MSC_VER) || defined(_M_X64) | ||||||
126 | template <typename T> struct TrailingZerosCounter<T, 8> { | ||||||
127 | static unsigned count(T Val, ZeroBehavior ZB) { | ||||||
128 | if (ZB != ZB_Undefined && Val == 0) | ||||||
129 | return 64; | ||||||
130 | |||||||
131 | #if __has_builtin(__builtin_ctzll)1 || defined(__GNUC__4) | ||||||
132 | return __builtin_ctzll(Val); | ||||||
133 | #elif defined(_MSC_VER) | ||||||
134 | unsigned long Index; | ||||||
135 | _BitScanForward64(&Index, Val); | ||||||
136 | return Index; | ||||||
137 | #endif | ||||||
138 | } | ||||||
139 | }; | ||||||
140 | #endif | ||||||
141 | #endif | ||||||
142 | } // namespace detail | ||||||
143 | |||||||
144 | /// Count number of 0's from the least significant bit to the most | ||||||
145 | /// stopping at the first 1. | ||||||
146 | /// | ||||||
147 | /// Only unsigned integral types are allowed. | ||||||
148 | /// | ||||||
149 | /// \param ZB the behavior on an input of 0. Only ZB_Width and ZB_Undefined are | ||||||
150 | /// valid arguments. | ||||||
151 | template <typename T> | ||||||
152 | unsigned countTrailingZeros(T Val, ZeroBehavior ZB = ZB_Width) { | ||||||
153 | static_assert(std::is_unsigned_v<T>, | ||||||
154 | "Only unsigned integral types are allowed."); | ||||||
155 | return llvm::detail::TrailingZerosCounter<T, sizeof(T)>::count(Val, ZB); | ||||||
156 | } | ||||||
157 | |||||||
158 | namespace detail { | ||||||
159 | template <typename T, std::size_t SizeOfT> struct LeadingZerosCounter { | ||||||
160 | static unsigned count(T Val, ZeroBehavior) { | ||||||
161 | if (!Val) | ||||||
162 | return std::numeric_limits<T>::digits; | ||||||
163 | |||||||
164 | // Bisection method. | ||||||
165 | unsigned ZeroBits = 0; | ||||||
166 | for (T Shift = std::numeric_limits<T>::digits >> 1; Shift; Shift >>= 1) { | ||||||
167 | T Tmp = Val >> Shift; | ||||||
168 | if (Tmp) | ||||||
169 | Val = Tmp; | ||||||
170 | else | ||||||
171 | ZeroBits |= Shift; | ||||||
172 | } | ||||||
173 | return ZeroBits; | ||||||
174 | } | ||||||
175 | }; | ||||||
176 | |||||||
177 | #if defined(__GNUC__4) || defined(_MSC_VER) | ||||||
178 | template <typename T> struct LeadingZerosCounter<T, 4> { | ||||||
179 | static unsigned count(T Val, ZeroBehavior ZB) { | ||||||
180 | if (ZB != ZB_Undefined && Val == 0) | ||||||
181 | return 32; | ||||||
182 | |||||||
183 | #if __has_builtin(__builtin_clz)1 || defined(__GNUC__4) | ||||||
184 | return __builtin_clz(Val); | ||||||
185 | #elif defined(_MSC_VER) | ||||||
186 | unsigned long Index; | ||||||
187 | _BitScanReverse(&Index, Val); | ||||||
188 | return Index ^ 31; | ||||||
189 | #endif | ||||||
190 | } | ||||||
191 | }; | ||||||
192 | |||||||
193 | #if !defined(_MSC_VER) || defined(_M_X64) | ||||||
194 | template <typename T> struct LeadingZerosCounter<T, 8> { | ||||||
195 | static unsigned count(T Val, ZeroBehavior ZB) { | ||||||
196 | if (ZB != ZB_Undefined && Val == 0) | ||||||
197 | return 64; | ||||||
198 | |||||||
199 | #if __has_builtin(__builtin_clzll)1 || defined(__GNUC__4) | ||||||
200 | return __builtin_clzll(Val); | ||||||
201 | #elif defined(_MSC_VER) | ||||||
202 | unsigned long Index; | ||||||
203 | _BitScanReverse64(&Index, Val); | ||||||
204 | return Index ^ 63; | ||||||
205 | #endif | ||||||
206 | } | ||||||
207 | }; | ||||||
208 | #endif | ||||||
209 | #endif | ||||||
210 | } // namespace detail | ||||||
211 | |||||||
212 | /// Count number of 0's from the most significant bit to the least | ||||||
213 | /// stopping at the first 1. | ||||||
214 | /// | ||||||
215 | /// Only unsigned integral types are allowed. | ||||||
216 | /// | ||||||
217 | /// \param ZB the behavior on an input of 0. Only ZB_Width and ZB_Undefined are | ||||||
218 | /// valid arguments. | ||||||
219 | template <typename T> | ||||||
220 | unsigned countLeadingZeros(T Val, ZeroBehavior ZB = ZB_Width) { | ||||||
221 | static_assert(std::is_unsigned_v<T>, | ||||||
222 | "Only unsigned integral types are allowed."); | ||||||
223 | return llvm::detail::LeadingZerosCounter<T, sizeof(T)>::count(Val, ZB); | ||||||
224 | } | ||||||
225 | |||||||
226 | /// Get the index of the first set bit starting from the least | ||||||
227 | /// significant bit. | ||||||
228 | /// | ||||||
229 | /// Only unsigned integral types are allowed. | ||||||
230 | /// | ||||||
231 | /// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are | ||||||
232 | /// valid arguments. | ||||||
233 | template <typename T> T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) { | ||||||
234 | if (ZB
| ||||||
235 | return std::numeric_limits<T>::max(); | ||||||
236 | |||||||
237 | return countTrailingZeros(Val, ZB_Undefined); | ||||||
238 | } | ||||||
239 | |||||||
240 | /// Create a bitmask with the N right-most bits set to 1, and all other | ||||||
241 | /// bits set to 0. Only unsigned types are allowed. | ||||||
242 | template <typename T> T maskTrailingOnes(unsigned N) { | ||||||
243 | static_assert(std::is_unsigned<T>::value, "Invalid type!"); | ||||||
244 | const unsigned Bits = CHAR_BIT8 * sizeof(T); | ||||||
245 | assert(N <= Bits && "Invalid bit index")(static_cast <bool> (N <= Bits && "Invalid bit index" ) ? void (0) : __assert_fail ("N <= Bits && \"Invalid bit index\"" , "llvm/include/llvm/Support/MathExtras.h", 245, __extension__ __PRETTY_FUNCTION__)); | ||||||
246 | return N == 0 ? 0 : (T(-1) >> (Bits - N)); | ||||||
247 | } | ||||||
248 | |||||||
249 | /// Create a bitmask with the N left-most bits set to 1, and all other | ||||||
250 | /// bits set to 0. Only unsigned types are allowed. | ||||||
251 | template <typename T> T maskLeadingOnes(unsigned N) { | ||||||
252 | return ~maskTrailingOnes<T>(CHAR_BIT8 * sizeof(T) - N); | ||||||
253 | } | ||||||
254 | |||||||
255 | /// Create a bitmask with the N right-most bits set to 0, and all other | ||||||
256 | /// bits set to 1. Only unsigned types are allowed. | ||||||
257 | template <typename T> T maskTrailingZeros(unsigned N) { | ||||||
258 | return maskLeadingOnes<T>(CHAR_BIT8 * sizeof(T) - N); | ||||||
259 | } | ||||||
260 | |||||||
261 | /// Create a bitmask with the N left-most bits set to 0, and all other | ||||||
262 | /// bits set to 1. Only unsigned types are allowed. | ||||||
263 | template <typename T> T maskLeadingZeros(unsigned N) { | ||||||
264 | return maskTrailingOnes<T>(CHAR_BIT8 * sizeof(T) - N); | ||||||
265 | } | ||||||
266 | |||||||
267 | /// Get the index of the last set bit starting from the least | ||||||
268 | /// significant bit. | ||||||
269 | /// | ||||||
270 | /// Only unsigned integral types are allowed. | ||||||
271 | /// | ||||||
272 | /// \param ZB the behavior on an input of 0. Only ZB_Max and ZB_Undefined are | ||||||
273 | /// valid arguments. | ||||||
274 | template <typename T> T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) { | ||||||
275 | if (ZB == ZB_Max && Val == 0) | ||||||
276 | return std::numeric_limits<T>::max(); | ||||||
277 | |||||||
278 | // Use ^ instead of - because both gcc and llvm can remove the associated ^ | ||||||
279 | // in the __builtin_clz intrinsic on x86. | ||||||
280 | return countLeadingZeros(Val, ZB_Undefined) ^ | ||||||
281 | (std::numeric_limits<T>::digits - 1); | ||||||
282 | } | ||||||
283 | |||||||
284 | /// Macro compressed bit reversal table for 256 bits. | ||||||
285 | /// | ||||||
286 | /// http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable | ||||||
287 | static const unsigned char BitReverseTable256[256] = { | ||||||
288 | #define R2(n) n, n + 2 * 64, n + 1 * 64, n + 3 * 64 | ||||||
289 | #define R4(n) R2(n), R2(n + 2 * 16), R2(n + 1 * 16), R2(n + 3 * 16) | ||||||
290 | #define R6(n) R4(n), R4(n + 2 * 4), R4(n + 1 * 4), R4(n + 3 * 4) | ||||||
291 | R6(0), R6(2), R6(1), R6(3) | ||||||
292 | #undef R2 | ||||||
293 | #undef R4 | ||||||
294 | #undef R6 | ||||||
295 | }; | ||||||
296 | |||||||
297 | /// Reverse the bits in \p Val. | ||||||
298 | template <typename T> T reverseBits(T Val) { | ||||||
299 | #if __has_builtin(__builtin_bitreverse8)1 | ||||||
300 | if constexpr (std::is_same_v<T, uint8_t>) | ||||||
301 | return __builtin_bitreverse8(Val); | ||||||
302 | #endif | ||||||
303 | #if __has_builtin(__builtin_bitreverse16)1 | ||||||
304 | if constexpr (std::is_same_v<T, uint16_t>) | ||||||
305 | return __builtin_bitreverse16(Val); | ||||||
306 | #endif | ||||||
307 | #if __has_builtin(__builtin_bitreverse32)1 | ||||||
308 | if constexpr (std::is_same_v<T, uint32_t>) | ||||||
309 | return __builtin_bitreverse32(Val); | ||||||
310 | #endif | ||||||
311 | #if __has_builtin(__builtin_bitreverse64)1 | ||||||
312 | if constexpr (std::is_same_v<T, uint64_t>) | ||||||
313 | return __builtin_bitreverse64(Val); | ||||||
314 | #endif | ||||||
315 | |||||||
316 | unsigned char in[sizeof(Val)]; | ||||||
317 | unsigned char out[sizeof(Val)]; | ||||||
318 | std::memcpy(in, &Val, sizeof(Val)); | ||||||
319 | for (unsigned i = 0; i < sizeof(Val); ++i) | ||||||
320 | out[(sizeof(Val) - i) - 1] = BitReverseTable256[in[i]]; | ||||||
321 | std::memcpy(&Val, out, sizeof(Val)); | ||||||
322 | return Val; | ||||||
323 | } | ||||||
324 | |||||||
325 | // NOTE: The following support functions use the _32/_64 extensions instead of | ||||||
326 | // type overloading so that signed and unsigned integers can be used without | ||||||
327 | // ambiguity. | ||||||
328 | |||||||
329 | /// Return the high 32 bits of a 64 bit value. | ||||||
330 | constexpr inline uint32_t Hi_32(uint64_t Value) { | ||||||
331 | return static_cast<uint32_t>(Value >> 32); | ||||||
332 | } | ||||||
333 | |||||||
334 | /// Return the low 32 bits of a 64 bit value. | ||||||
335 | constexpr inline uint32_t Lo_32(uint64_t Value) { | ||||||
336 | return static_cast<uint32_t>(Value); | ||||||
337 | } | ||||||
338 | |||||||
339 | /// Make a 64-bit integer from a high / low pair of 32-bit integers. | ||||||
340 | constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) { | ||||||
341 | return ((uint64_t)High << 32) | (uint64_t)Low; | ||||||
342 | } | ||||||
343 | |||||||
344 | /// Checks if an integer fits into the given bit width. | ||||||
345 | template <unsigned N> constexpr inline bool isInt(int64_t x) { | ||||||
346 | if constexpr (N == 8) | ||||||
347 | return static_cast<int8_t>(x) == x; | ||||||
348 | if constexpr (N == 16) | ||||||
349 | return static_cast<int16_t>(x) == x; | ||||||
350 | if constexpr (N == 32) | ||||||
351 | return static_cast<int32_t>(x) == x; | ||||||
352 | if constexpr (N < 64) | ||||||
353 | return -(INT64_C(1)1L << (N - 1)) <= x && x < (INT64_C(1)1L << (N - 1)); | ||||||
354 | (void)x; // MSVC v19.25 warns that x is unused. | ||||||
355 | return true; | ||||||
356 | } | ||||||
357 | |||||||
358 | /// Checks if a signed integer is an N bit number shifted left by S. | ||||||
359 | template <unsigned N, unsigned S> | ||||||
360 | constexpr inline bool isShiftedInt(int64_t x) { | ||||||
361 | static_assert( | ||||||
362 | N > 0, "isShiftedInt<0> doesn't make sense (refers to a 0-bit number."); | ||||||
363 | static_assert(N + S <= 64, "isShiftedInt<N, S> with N + S > 64 is too wide."); | ||||||
364 | return isInt<N + S>(x) && (x % (UINT64_C(1)1UL << S) == 0); | ||||||
365 | } | ||||||
366 | |||||||
367 | /// Checks if an unsigned integer fits into the given bit width. | ||||||
368 | template <unsigned N> constexpr inline bool isUInt(uint64_t x) { | ||||||
369 | static_assert(N > 0, "isUInt<0> doesn't make sense"); | ||||||
370 | if constexpr (N == 8) | ||||||
371 | return static_cast<uint8_t>(x) == x; | ||||||
372 | if constexpr (N == 16) | ||||||
373 | return static_cast<uint16_t>(x) == x; | ||||||
374 | if constexpr (N == 32) | ||||||
375 | return static_cast<uint32_t>(x) == x; | ||||||
376 | if constexpr (N < 64) | ||||||
377 | return x < (UINT64_C(1)1UL << (N)); | ||||||
378 | (void)x; // MSVC v19.25 warns that x is unused. | ||||||
379 | return true; | ||||||
380 | } | ||||||
381 | |||||||
382 | /// Checks if a unsigned integer is an N bit number shifted left by S. | ||||||
383 | template <unsigned N, unsigned S> | ||||||
384 | constexpr inline bool isShiftedUInt(uint64_t x) { | ||||||
385 | static_assert( | ||||||
386 | N > 0, "isShiftedUInt<0> doesn't make sense (refers to a 0-bit number)"); | ||||||
387 | static_assert(N + S <= 64, | ||||||
388 | "isShiftedUInt<N, S> with N + S > 64 is too wide."); | ||||||
389 | // Per the two static_asserts above, S must be strictly less than 64. So | ||||||
390 | // 1 << S is not undefined behavior. | ||||||
391 | return isUInt<N + S>(x) && (x % (UINT64_C(1)1UL << S) == 0); | ||||||
392 | } | ||||||
393 | |||||||
394 | /// Gets the maximum value for a N-bit unsigned integer. | ||||||
395 | inline uint64_t maxUIntN(uint64_t N) { | ||||||
396 | assert(N > 0 && N <= 64 && "integer width out of range")(static_cast <bool> (N > 0 && N <= 64 && "integer width out of range") ? void (0) : __assert_fail ("N > 0 && N <= 64 && \"integer width out of range\"" , "llvm/include/llvm/Support/MathExtras.h", 396, __extension__ __PRETTY_FUNCTION__)); | ||||||
397 | |||||||
398 | // uint64_t(1) << 64 is undefined behavior, so we can't do | ||||||
399 | // (uint64_t(1) << N) - 1 | ||||||
400 | // without checking first that N != 64. But this works and doesn't have a | ||||||
401 | // branch. | ||||||
402 | return UINT64_MAX(18446744073709551615UL) >> (64 - N); | ||||||
403 | } | ||||||
404 | |||||||
405 | /// Gets the minimum value for a N-bit signed integer. | ||||||
406 | inline int64_t minIntN(int64_t N) { | ||||||
407 | assert(N > 0 && N <= 64 && "integer width out of range")(static_cast <bool> (N > 0 && N <= 64 && "integer width out of range") ? void (0) : __assert_fail ("N > 0 && N <= 64 && \"integer width out of range\"" , "llvm/include/llvm/Support/MathExtras.h", 407, __extension__ __PRETTY_FUNCTION__)); | ||||||
408 | |||||||
409 | return UINT64_C(1)1UL + ~(UINT64_C(1)1UL << (N - 1)); | ||||||
410 | } | ||||||
411 | |||||||
412 | /// Gets the maximum value for a N-bit signed integer. | ||||||
413 | inline int64_t maxIntN(int64_t N) { | ||||||
414 | assert(N > 0 && N <= 64 && "integer width out of range")(static_cast <bool> (N > 0 && N <= 64 && "integer width out of range") ? void (0) : __assert_fail ("N > 0 && N <= 64 && \"integer width out of range\"" , "llvm/include/llvm/Support/MathExtras.h", 414, __extension__ __PRETTY_FUNCTION__)); | ||||||
415 | |||||||
416 | // This relies on two's complement wraparound when N == 64, so we convert to | ||||||
417 | // int64_t only at the very end to avoid UB. | ||||||
418 | return (UINT64_C(1)1UL << (N - 1)) - 1; | ||||||
419 | } | ||||||
420 | |||||||
421 | /// Checks if an unsigned integer fits into the given (dynamic) bit width. | ||||||
422 | inline bool isUIntN(unsigned N, uint64_t x) { | ||||||
423 | return N >= 64 || x <= maxUIntN(N); | ||||||
424 | } | ||||||
425 | |||||||
426 | /// Checks if an signed integer fits into the given (dynamic) bit width. | ||||||
427 | inline bool isIntN(unsigned N, int64_t x) { | ||||||
428 | return N >= 64 || (minIntN(N) <= x && x <= maxIntN(N)); | ||||||
429 | } | ||||||
430 | |||||||
431 | /// Return true if the argument is a non-empty sequence of ones starting at the | ||||||
432 | /// least significant bit with the remainder zero (32 bit version). | ||||||
433 | /// Ex. isMask_32(0x0000FFFFU) == true. | ||||||
434 | constexpr inline bool isMask_32(uint32_t Value) { | ||||||
435 | return Value && ((Value + 1) & Value) == 0; | ||||||
436 | } | ||||||
437 | |||||||
438 | /// Return true if the argument is a non-empty sequence of ones starting at the | ||||||
439 | /// least significant bit with the remainder zero (64 bit version). | ||||||
440 | constexpr inline bool isMask_64(uint64_t Value) { | ||||||
441 | return Value && ((Value + 1) & Value) == 0; | ||||||
442 | } | ||||||
443 | |||||||
444 | /// Return true if the argument contains a non-empty sequence of ones with the | ||||||
445 | /// remainder zero (32 bit version.) Ex. isShiftedMask_32(0x0000FF00U) == true. | ||||||
446 | constexpr inline bool isShiftedMask_32(uint32_t Value) { | ||||||
447 | return Value && isMask_32((Value - 1) | Value); | ||||||
448 | } | ||||||
449 | |||||||
450 | /// Return true if the argument contains a non-empty sequence of ones with the | ||||||
451 | /// remainder zero (64 bit version.) | ||||||
452 | constexpr inline bool isShiftedMask_64(uint64_t Value) { | ||||||
453 | return Value && isMask_64((Value - 1) | Value); | ||||||
454 | } | ||||||
455 | |||||||
456 | /// Return true if the argument is a power of two > 0. | ||||||
457 | /// Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.) | ||||||
458 | constexpr inline bool isPowerOf2_32(uint32_t Value) { | ||||||
459 | return llvm::has_single_bit(Value); | ||||||
460 | } | ||||||
461 | |||||||
462 | /// Return true if the argument is a power of two > 0 (64 bit edition.) | ||||||
463 | constexpr inline bool isPowerOf2_64(uint64_t Value) { | ||||||
464 | return llvm::has_single_bit(Value); | ||||||
465 | } | ||||||
466 | |||||||
467 | /// Count the number of ones from the most significant bit to the first | ||||||
468 | /// zero bit. | ||||||
469 | /// | ||||||
470 | /// Ex. countLeadingOnes(0xFF0FFF00) == 8. | ||||||
471 | /// Only unsigned integral types are allowed. | ||||||
472 | /// | ||||||
473 | /// \param ZB the behavior on an input of all ones. Only ZB_Width and | ||||||
474 | /// ZB_Undefined are valid arguments. | ||||||
475 | template <typename T> | ||||||
476 | unsigned countLeadingOnes(T Value, ZeroBehavior ZB = ZB_Width) { | ||||||
477 | static_assert(std::is_unsigned_v<T>, | ||||||
478 | "Only unsigned integral types are allowed."); | ||||||
479 | return countLeadingZeros<T>(~Value, ZB); | ||||||
480 | } | ||||||
481 | |||||||
482 | /// Count the number of ones from the least significant bit to the first | ||||||
483 | /// zero bit. | ||||||
484 | /// | ||||||
485 | /// Ex. countTrailingOnes(0x00FF00FF) == 8. | ||||||
486 | /// Only unsigned integral types are allowed. | ||||||
487 | /// | ||||||
488 | /// \param ZB the behavior on an input of all ones. Only ZB_Width and | ||||||
489 | /// ZB_Undefined are valid arguments. | ||||||
490 | template <typename T> | ||||||
491 | unsigned countTrailingOnes(T Value, ZeroBehavior ZB = ZB_Width) { | ||||||
492 | static_assert(std::is_unsigned_v<T>, | ||||||
493 | "Only unsigned integral types are allowed."); | ||||||
494 | return countTrailingZeros<T>(~Value, ZB); | ||||||
495 | } | ||||||
496 | |||||||
497 | /// Count the number of set bits in a value. | ||||||
498 | /// Ex. countPopulation(0xF000F000) = 8 | ||||||
499 | /// Returns 0 if the word is zero. | ||||||
500 | template <typename T> | ||||||
501 | inline unsigned countPopulation(T Value) { | ||||||
502 | static_assert(std::is_unsigned_v<T>, | ||||||
503 | "Only unsigned integral types are allowed."); | ||||||
504 | return (unsigned)llvm::popcount(Value); | ||||||
505 | } | ||||||
506 | |||||||
507 | /// Return true if the argument contains a non-empty sequence of ones with the | ||||||
508 | /// remainder zero (32 bit version.) Ex. isShiftedMask_32(0x0000FF00U) == true. | ||||||
509 | /// If true, \p MaskIdx will specify the index of the lowest set bit and \p | ||||||
510 | /// MaskLen is updated to specify the length of the mask, else neither are | ||||||
511 | /// updated. | ||||||
512 | inline bool isShiftedMask_32(uint32_t Value, unsigned &MaskIdx, | ||||||
513 | unsigned &MaskLen) { | ||||||
514 | if (!isShiftedMask_32(Value)) | ||||||
515 | return false; | ||||||
516 | MaskIdx = countTrailingZeros(Value); | ||||||
517 | MaskLen = countPopulation(Value); | ||||||
518 | return true; | ||||||
519 | } | ||||||
520 | |||||||
521 | /// Return true if the argument contains a non-empty sequence of ones with the | ||||||
522 | /// remainder zero (64 bit version.) If true, \p MaskIdx will specify the index | ||||||
523 | /// of the lowest set bit and \p MaskLen is updated to specify the length of the | ||||||
524 | /// mask, else neither are updated. | ||||||
525 | inline bool isShiftedMask_64(uint64_t Value, unsigned &MaskIdx, | ||||||
526 | unsigned &MaskLen) { | ||||||
527 | if (!isShiftedMask_64(Value)) | ||||||
528 | return false; | ||||||
529 | MaskIdx = countTrailingZeros(Value); | ||||||
530 | MaskLen = countPopulation(Value); | ||||||
531 | return true; | ||||||
532 | } | ||||||
533 | |||||||
534 | /// Compile time Log2. | ||||||
535 | /// Valid only for positive powers of two. | ||||||
536 | template <size_t kValue> constexpr inline size_t CTLog2() { | ||||||
537 | static_assert(kValue > 0 && llvm::isPowerOf2_64(kValue), | ||||||
538 | "Value is not a valid power of 2"); | ||||||
539 | return 1 + CTLog2<kValue / 2>(); | ||||||
540 | } | ||||||
541 | |||||||
542 | template <> constexpr inline size_t CTLog2<1>() { return 0; } | ||||||
543 | |||||||
544 | /// Return the floor log base 2 of the specified value, -1 if the value is zero. | ||||||
545 | /// (32 bit edition.) | ||||||
546 | /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2 | ||||||
547 | inline unsigned Log2_32(uint32_t Value) { | ||||||
548 | return 31 - countLeadingZeros(Value); | ||||||
549 | } | ||||||
550 | |||||||
551 | /// Return the floor log base 2 of the specified value, -1 if the value is zero. | ||||||
552 | /// (64 bit edition.) | ||||||
553 | inline unsigned Log2_64(uint64_t Value) { | ||||||
554 | return 63 - countLeadingZeros(Value); | ||||||
555 | } | ||||||
556 | |||||||
557 | /// Return the ceil log base 2 of the specified value, 32 if the value is zero. | ||||||
558 | /// (32 bit edition). | ||||||
559 | /// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3 | ||||||
560 | inline unsigned Log2_32_Ceil(uint32_t Value) { | ||||||
561 | return 32 - countLeadingZeros(Value - 1); | ||||||
562 | } | ||||||
563 | |||||||
564 | /// Return the ceil log base 2 of the specified value, 64 if the value is zero. | ||||||
565 | /// (64 bit edition.) | ||||||
566 | inline unsigned Log2_64_Ceil(uint64_t Value) { | ||||||
567 | return 64 - countLeadingZeros(Value - 1); | ||||||
568 | } | ||||||
569 | |||||||
570 | /// This function takes a 64-bit integer and returns the bit equivalent double. | ||||||
571 | inline double BitsToDouble(uint64_t Bits) { | ||||||
572 | static_assert(sizeof(uint64_t) == sizeof(double), "Unexpected type sizes"); | ||||||
573 | return llvm::bit_cast<double>(Bits); | ||||||
574 | } | ||||||
575 | |||||||
576 | /// This function takes a 32-bit integer and returns the bit equivalent float. | ||||||
577 | inline float BitsToFloat(uint32_t Bits) { | ||||||
578 | static_assert(sizeof(uint32_t) == sizeof(float), "Unexpected type sizes"); | ||||||
579 | return llvm::bit_cast<float>(Bits); | ||||||
580 | } | ||||||
581 | |||||||
582 | /// This function takes a double and returns the bit equivalent 64-bit integer. | ||||||
583 | /// Note that copying doubles around changes the bits of NaNs on some hosts, | ||||||
584 | /// notably x86, so this routine cannot be used if these bits are needed. | ||||||
585 | inline uint64_t DoubleToBits(double Double) { | ||||||
586 | static_assert(sizeof(uint64_t) == sizeof(double), "Unexpected type sizes"); | ||||||
587 | return llvm::bit_cast<uint64_t>(Double); | ||||||
588 | } | ||||||
589 | |||||||
590 | /// This function takes a float and returns the bit equivalent 32-bit integer. | ||||||
591 | /// Note that copying floats around changes the bits of NaNs on some hosts, | ||||||
592 | /// notably x86, so this routine cannot be used if these bits are needed. | ||||||
593 | inline uint32_t FloatToBits(float Float) { | ||||||
594 | static_assert(sizeof(uint32_t) == sizeof(float), "Unexpected type sizes"); | ||||||
595 | return llvm::bit_cast<uint32_t>(Float); | ||||||
596 | } | ||||||
597 | |||||||
598 | /// A and B are either alignments or offsets. Return the minimum alignment that | ||||||
599 | /// may be assumed after adding the two together. | ||||||
600 | constexpr inline uint64_t MinAlign(uint64_t A, uint64_t B) { | ||||||
601 | // The largest power of 2 that divides both A and B. | ||||||
602 | // | ||||||
603 | // Replace "-Value" by "1+~Value" in the following commented code to avoid | ||||||
604 | // MSVC warning C4146 | ||||||
605 | // return (A | B) & -(A | B); | ||||||
606 | return (A | B) & (1 + ~(A | B)); | ||||||
607 | } | ||||||
608 | |||||||
609 | /// Returns the next power of two (in 64-bits) that is strictly greater than A. | ||||||
610 | /// Returns zero on overflow. | ||||||
611 | constexpr inline uint64_t NextPowerOf2(uint64_t A) { | ||||||
612 | A |= (A >> 1); | ||||||
613 | A |= (A >> 2); | ||||||
614 | A |= (A >> 4); | ||||||
615 | A |= (A >> 8); | ||||||
616 | A |= (A >> 16); | ||||||
617 | A |= (A >> 32); | ||||||
618 | return A + 1; | ||||||
619 | } | ||||||
620 | |||||||
621 | /// Returns the power of two which is less than or equal to the given value. | ||||||
622 | /// Essentially, it is a floor operation across the domain of powers of two. | ||||||
623 | inline uint64_t PowerOf2Floor(uint64_t A) { | ||||||
624 | if (!A) return 0; | ||||||
625 | return 1ull << (63 - countLeadingZeros(A, ZB_Undefined)); | ||||||
626 | } | ||||||
627 | |||||||
628 | /// Returns the power of two which is greater than or equal to the given value. | ||||||
629 | /// Essentially, it is a ceil operation across the domain of powers of two. | ||||||
630 | inline uint64_t PowerOf2Ceil(uint64_t A) { | ||||||
631 | if (!A) | ||||||
632 | return 0; | ||||||
633 | return NextPowerOf2(A - 1); | ||||||
634 | } | ||||||
635 | |||||||
636 | /// Returns the next integer (mod 2**64) that is greater than or equal to | ||||||
637 | /// \p Value and is a multiple of \p Align. \p Align must be non-zero. | ||||||
638 | /// | ||||||
639 | /// Examples: | ||||||
640 | /// \code | ||||||
641 | /// alignTo(5, 8) = 8 | ||||||
642 | /// alignTo(17, 8) = 24 | ||||||
643 | /// alignTo(~0LL, 8) = 0 | ||||||
644 | /// alignTo(321, 255) = 510 | ||||||
645 | /// \endcode | ||||||
646 | inline uint64_t alignTo(uint64_t Value, uint64_t Align) { | ||||||
647 | assert(Align != 0u && "Align can't be 0.")(static_cast <bool> (Align != 0u && "Align can't be 0." ) ? void (0) : __assert_fail ("Align != 0u && \"Align can't be 0.\"" , "llvm/include/llvm/Support/MathExtras.h", 647, __extension__ __PRETTY_FUNCTION__)); | ||||||
648 | return (Value + Align - 1) / Align * Align; | ||||||
649 | } | ||||||
650 | |||||||
651 | inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) { | ||||||
652 | assert(Align != 0 && (Align & (Align - 1)) == 0 &&(static_cast <bool> (Align != 0 && (Align & (Align - 1)) == 0 && "Align must be a power of 2") ? void (0) : __assert_fail ("Align != 0 && (Align & (Align - 1)) == 0 && \"Align must be a power of 2\"" , "llvm/include/llvm/Support/MathExtras.h", 653, __extension__ __PRETTY_FUNCTION__)) | ||||||
653 | "Align must be a power of 2")(static_cast <bool> (Align != 0 && (Align & (Align - 1)) == 0 && "Align must be a power of 2") ? void (0) : __assert_fail ("Align != 0 && (Align & (Align - 1)) == 0 && \"Align must be a power of 2\"" , "llvm/include/llvm/Support/MathExtras.h", 653, __extension__ __PRETTY_FUNCTION__)); | ||||||
654 | return (Value + Align - 1) & -Align; | ||||||
655 | } | ||||||
656 | |||||||
657 | /// If non-zero \p Skew is specified, the return value will be a minimal integer | ||||||
658 | /// that is greater than or equal to \p Size and equal to \p A * N + \p Skew for | ||||||
659 | /// some integer N. If \p Skew is larger than \p A, its value is adjusted to '\p | ||||||
660 | /// Skew mod \p A'. \p Align must be non-zero. | ||||||
661 | /// | ||||||
662 | /// Examples: | ||||||
663 | /// \code | ||||||
664 | /// alignTo(5, 8, 7) = 7 | ||||||
665 | /// alignTo(17, 8, 1) = 17 | ||||||
666 | /// alignTo(~0LL, 8, 3) = 3 | ||||||
667 | /// alignTo(321, 255, 42) = 552 | ||||||
668 | /// \endcode | ||||||
669 | inline uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew) { | ||||||
670 | assert(Align != 0u && "Align can't be 0.")(static_cast <bool> (Align != 0u && "Align can't be 0." ) ? void (0) : __assert_fail ("Align != 0u && \"Align can't be 0.\"" , "llvm/include/llvm/Support/MathExtras.h", 670, __extension__ __PRETTY_FUNCTION__)); | ||||||
671 | Skew %= Align; | ||||||
672 | return alignTo(Value - Skew, Align) + Skew; | ||||||
673 | } | ||||||
674 | |||||||
675 | /// Returns the next integer (mod 2**64) that is greater than or equal to | ||||||
676 | /// \p Value and is a multiple of \c Align. \c Align must be non-zero. | ||||||
677 | template <uint64_t Align> constexpr inline uint64_t alignTo(uint64_t Value) { | ||||||
678 | static_assert(Align != 0u, "Align must be non-zero"); | ||||||
679 | return (Value + Align - 1) / Align * Align; | ||||||
680 | } | ||||||
681 | |||||||
682 | /// Returns the integer ceil(Numerator / Denominator). | ||||||
683 | inline uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator) { | ||||||
684 | return alignTo(Numerator, Denominator) / Denominator; | ||||||
685 | } | ||||||
686 | |||||||
687 | /// Returns the integer nearest(Numerator / Denominator). | ||||||
688 | inline uint64_t divideNearest(uint64_t Numerator, uint64_t Denominator) { | ||||||
689 | return (Numerator + (Denominator / 2)) / Denominator; | ||||||
690 | } | ||||||
691 | |||||||
692 | /// Returns the largest uint64_t less than or equal to \p Value and is | ||||||
693 | /// \p Skew mod \p Align. \p Align must be non-zero | ||||||
694 | inline uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew = 0) { | ||||||
695 | assert(Align != 0u && "Align can't be 0.")(static_cast <bool> (Align != 0u && "Align can't be 0." ) ? void (0) : __assert_fail ("Align != 0u && \"Align can't be 0.\"" , "llvm/include/llvm/Support/MathExtras.h", 695, __extension__ __PRETTY_FUNCTION__)); | ||||||
696 | Skew %= Align; | ||||||
697 | return (Value - Skew) / Align * Align + Skew; | ||||||
698 | } | ||||||
699 | |||||||
700 | /// Sign-extend the number in the bottom B bits of X to a 32-bit integer. | ||||||
701 | /// Requires 0 < B <= 32. | ||||||
702 | template <unsigned B> constexpr inline int32_t SignExtend32(uint32_t X) { | ||||||
703 | static_assert(B > 0, "Bit width can't be 0."); | ||||||
704 | static_assert(B <= 32, "Bit width out of range."); | ||||||
705 | return int32_t(X << (32 - B)) >> (32 - B); | ||||||
706 | } | ||||||
707 | |||||||
708 | /// Sign-extend the number in the bottom B bits of X to a 32-bit integer. | ||||||
709 | /// Requires 0 < B <= 32. | ||||||
710 | inline int32_t SignExtend32(uint32_t X, unsigned B) { | ||||||
711 | assert(B > 0 && "Bit width can't be 0.")(static_cast <bool> (B > 0 && "Bit width can't be 0." ) ? void (0) : __assert_fail ("B > 0 && \"Bit width can't be 0.\"" , "llvm/include/llvm/Support/MathExtras.h", 711, __extension__ __PRETTY_FUNCTION__)); | ||||||
712 | assert(B <= 32 && "Bit width out of range.")(static_cast <bool> (B <= 32 && "Bit width out of range." ) ? void (0) : __assert_fail ("B <= 32 && \"Bit width out of range.\"" , "llvm/include/llvm/Support/MathExtras.h", 712, __extension__ __PRETTY_FUNCTION__)); | ||||||
713 | return int32_t(X << (32 - B)) >> (32 - B); | ||||||
714 | } | ||||||
715 | |||||||
716 | /// Sign-extend the number in the bottom B bits of X to a 64-bit integer. | ||||||
717 | /// Requires 0 < B <= 64. | ||||||
718 | template <unsigned B> constexpr inline int64_t SignExtend64(uint64_t x) { | ||||||
719 | static_assert(B > 0, "Bit width can't be 0."); | ||||||
720 | static_assert(B <= 64, "Bit width out of range."); | ||||||
721 | return int64_t(x << (64 - B)) >> (64 - B); | ||||||
722 | } | ||||||
723 | |||||||
724 | /// Sign-extend the number in the bottom B bits of X to a 64-bit integer. | ||||||
725 | /// Requires 0 < B <= 64. | ||||||
726 | inline int64_t SignExtend64(uint64_t X, unsigned B) { | ||||||
727 | assert(B > 0 && "Bit width can't be 0.")(static_cast <bool> (B > 0 && "Bit width can't be 0." ) ? void (0) : __assert_fail ("B > 0 && \"Bit width can't be 0.\"" , "llvm/include/llvm/Support/MathExtras.h", 727, __extension__ __PRETTY_FUNCTION__)); | ||||||
728 | assert(B <= 64 && "Bit width out of range.")(static_cast <bool> (B <= 64 && "Bit width out of range." ) ? void (0) : __assert_fail ("B <= 64 && \"Bit width out of range.\"" , "llvm/include/llvm/Support/MathExtras.h", 728, __extension__ __PRETTY_FUNCTION__)); | ||||||
729 | return int64_t(X << (64 - B)) >> (64 - B); | ||||||
730 | } | ||||||
731 | |||||||
732 | /// Subtract two unsigned integers, X and Y, of type T and return the absolute | ||||||
733 | /// value of the result. | ||||||
734 | template <typename T> | ||||||
735 | std::enable_if_t<std::is_unsigned<T>::value, T> AbsoluteDifference(T X, T Y) { | ||||||
736 | return X > Y ? (X - Y) : (Y - X); | ||||||
737 | } | ||||||
738 | |||||||
739 | /// Add two unsigned integers, X and Y, of type T. Clamp the result to the | ||||||
740 | /// maximum representable value of T on overflow. ResultOverflowed indicates if | ||||||
741 | /// the result is larger than the maximum representable value of type T. | ||||||
742 | template <typename T> | ||||||
743 | std::enable_if_t<std::is_unsigned<T>::value, T> | ||||||
744 | SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) { | ||||||
745 | bool Dummy; | ||||||
746 | bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy; | ||||||
747 | // Hacker's Delight, p. 29 | ||||||
748 | T Z = X + Y; | ||||||
749 | Overflowed = (Z < X || Z < Y); | ||||||
750 | if (Overflowed) | ||||||
751 | return std::numeric_limits<T>::max(); | ||||||
752 | else | ||||||
753 | return Z; | ||||||
754 | } | ||||||
755 | |||||||
756 | /// Add multiple unsigned integers of type T. Clamp the result to the | ||||||
757 | /// maximum representable value of T on overflow. | ||||||
758 | template <class T, class... Ts> | ||||||
759 | std::enable_if_t<std::is_unsigned_v<T>, T> SaturatingAdd(T X, T Y, T Z, | ||||||
760 | Ts... Args) { | ||||||
761 | bool Overflowed = false; | ||||||
762 | T XY = SaturatingAdd(X, Y, &Overflowed); | ||||||
763 | if (Overflowed) | ||||||
764 | return SaturatingAdd(std::numeric_limits<T>::max(), T(1), Args...); | ||||||
765 | return SaturatingAdd(XY, Z, Args...); | ||||||
766 | } | ||||||
767 | |||||||
768 | /// Multiply two unsigned integers, X and Y, of type T. Clamp the result to the | ||||||
769 | /// maximum representable value of T on overflow. ResultOverflowed indicates if | ||||||
770 | /// the result is larger than the maximum representable value of type T. | ||||||
771 | template <typename T> | ||||||
772 | std::enable_if_t<std::is_unsigned<T>::value, T> | ||||||
773 | SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) { | ||||||
774 | bool Dummy; | ||||||
775 | bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy; | ||||||
776 | |||||||
777 | // Hacker's Delight, p. 30 has a different algorithm, but we don't use that | ||||||
778 | // because it fails for uint16_t (where multiplication can have undefined | ||||||
779 | // behavior due to promotion to int), and requires a division in addition | ||||||
780 | // to the multiplication. | ||||||
781 | |||||||
782 | Overflowed = false; | ||||||
783 | |||||||
784 | // Log2(Z) would be either Log2Z or Log2Z + 1. | ||||||
785 | // Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z | ||||||
786 | // will necessarily be less than Log2Max as desired. | ||||||
787 | int Log2Z = Log2_64(X) + Log2_64(Y); | ||||||
788 | const T Max = std::numeric_limits<T>::max(); | ||||||
789 | int Log2Max = Log2_64(Max); | ||||||
790 | if (Log2Z < Log2Max) { | ||||||
791 | return X * Y; | ||||||
792 | } | ||||||
793 | if (Log2Z > Log2Max) { | ||||||
794 | Overflowed = true; | ||||||
795 | return Max; | ||||||
796 | } | ||||||
797 | |||||||
798 | // We're going to use the top bit, and maybe overflow one | ||||||
799 | // bit past it. Multiply all but the bottom bit then add | ||||||
800 | // that on at the end. | ||||||
801 | T Z = (X >> 1) * Y; | ||||||
802 | if (Z & ~(Max >> 1)) { | ||||||
803 | Overflowed = true; | ||||||
804 | return Max; | ||||||
805 | } | ||||||
806 | Z <<= 1; | ||||||
807 | if (X & 1) | ||||||
808 | return SaturatingAdd(Z, Y, ResultOverflowed); | ||||||
809 | |||||||
810 | return Z; | ||||||
811 | } | ||||||
812 | |||||||
813 | /// Multiply two unsigned integers, X and Y, and add the unsigned integer, A to | ||||||
814 | /// the product. Clamp the result to the maximum representable value of T on | ||||||
815 | /// overflow. ResultOverflowed indicates if the result is larger than the | ||||||
816 | /// maximum representable value of type T. | ||||||
817 | template <typename T> | ||||||
818 | std::enable_if_t<std::is_unsigned<T>::value, T> | ||||||
819 | SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed = nullptr) { | ||||||
820 | bool Dummy; | ||||||
821 | bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy; | ||||||
822 | |||||||
823 | T Product = SaturatingMultiply(X, Y, &Overflowed); | ||||||
824 | if (Overflowed) | ||||||
825 | return Product; | ||||||
826 | |||||||
827 | return SaturatingAdd(A, Product, &Overflowed); | ||||||
828 | } | ||||||
829 | |||||||
830 | /// Use this rather than HUGE_VALF; the latter causes warnings on MSVC. | ||||||
831 | extern const float huge_valf; | ||||||
832 | |||||||
833 | |||||||
834 | /// Add two signed integers, computing the two's complement truncated result, | ||||||
835 | /// returning true if overflow occurred. | ||||||
836 | template <typename T> | ||||||
837 | std::enable_if_t<std::is_signed<T>::value, T> AddOverflow(T X, T Y, T &Result) { | ||||||
838 | #if __has_builtin(__builtin_add_overflow)1 | ||||||
839 | return __builtin_add_overflow(X, Y, &Result); | ||||||
840 | #else | ||||||
841 | // Perform the unsigned addition. | ||||||
842 | using U = std::make_unsigned_t<T>; | ||||||
843 | const U UX = static_cast<U>(X); | ||||||
844 | const U UY = static_cast<U>(Y); | ||||||
845 | const U UResult = UX + UY; | ||||||
846 | |||||||
847 | // Convert to signed. | ||||||
848 | Result = static_cast<T>(UResult); | ||||||
849 | |||||||
850 | // Adding two positive numbers should result in a positive number. | ||||||
851 | if (X > 0 && Y > 0) | ||||||
852 | return Result <= 0; | ||||||
853 | // Adding two negatives should result in a negative number. | ||||||
854 | if (X < 0 && Y < 0) | ||||||
855 | return Result >= 0; | ||||||
856 | return false; | ||||||
857 | #endif | ||||||
858 | } | ||||||
859 | |||||||
860 | /// Subtract two signed integers, computing the two's complement truncated | ||||||
861 | /// result, returning true if an overflow ocurred. | ||||||
862 | template <typename T> | ||||||
863 | std::enable_if_t<std::is_signed<T>::value, T> SubOverflow(T X, T Y, T &Result) { | ||||||
864 | #if __has_builtin(__builtin_sub_overflow)1 | ||||||
865 | return __builtin_sub_overflow(X, Y, &Result); | ||||||
866 | #else | ||||||
867 | // Perform the unsigned addition. | ||||||
868 | using U = std::make_unsigned_t<T>; | ||||||
869 | const U UX = static_cast<U>(X); | ||||||
870 | const U UY = static_cast<U>(Y); | ||||||
871 | const U UResult = UX - UY; | ||||||
872 | |||||||
873 | // Convert to signed. | ||||||
874 | Result = static_cast<T>(UResult); | ||||||
875 | |||||||
876 | // Subtracting a positive number from a negative results in a negative number. | ||||||
877 | if (X <= 0 && Y > 0) | ||||||
878 | return Result >= 0; | ||||||
879 | // Subtracting a negative number from a positive results in a positive number. | ||||||
880 | if (X >= 0 && Y < 0) | ||||||
881 | return Result <= 0; | ||||||
882 | return false; | ||||||
883 | #endif | ||||||
884 | } | ||||||
885 | |||||||
886 | /// Multiply two signed integers, computing the two's complement truncated | ||||||
887 | /// result, returning true if an overflow ocurred. | ||||||
888 | template <typename T> | ||||||
889 | std::enable_if_t<std::is_signed<T>::value, T> MulOverflow(T X, T Y, T &Result) { | ||||||
890 | // Perform the unsigned multiplication on absolute values. | ||||||
891 | using U = std::make_unsigned_t<T>; | ||||||
892 | const U UX = X < 0 ? (0 - static_cast<U>(X)) : static_cast<U>(X); | ||||||
893 | const U UY = Y < 0 ? (0 - static_cast<U>(Y)) : static_cast<U>(Y); | ||||||
894 | const U UResult = UX * UY; | ||||||
895 | |||||||
896 | // Convert to signed. | ||||||
897 | const bool IsNegative = (X < 0) ^ (Y < 0); | ||||||
898 | Result = IsNegative ? (0 - UResult) : UResult; | ||||||
899 | |||||||
900 | // If any of the args was 0, result is 0 and no overflow occurs. | ||||||
901 | if (UX == 0 || UY == 0) | ||||||
902 | return false; | ||||||
903 | |||||||
904 | // UX and UY are in [1, 2^n], where n is the number of digits. | ||||||
905 | // Check how the max allowed absolute value (2^n for negative, 2^(n-1) for | ||||||
906 | // positive) divided by an argument compares to the other. | ||||||
907 | if (IsNegative) | ||||||
908 | return UX > (static_cast<U>(std::numeric_limits<T>::max()) + U(1)) / UY; | ||||||
909 | else | ||||||
910 | return UX > (static_cast<U>(std::numeric_limits<T>::max())) / UY; | ||||||
911 | } | ||||||
912 | |||||||
913 | } // End llvm namespace | ||||||
914 | |||||||
915 | #endif |
1 | // The template and inlines for the numeric_limits classes. -*- C++ -*- |
2 | |
3 | // Copyright (C) 1999-2020 Free Software Foundation, Inc. |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free |
6 | // software; you can redistribute it and/or modify it under the |
7 | // terms of the GNU General Public License as published by the |
8 | // Free Software Foundation; either version 3, or (at your option) |
9 | // any later version. |
10 | |
11 | // This library is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
15 | |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version |
18 | // 3.1, as published by the Free Software Foundation. |
19 | |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
23 | // <http://www.gnu.org/licenses/>. |
24 | |
25 | /** @file include/limits |
26 | * This is a Standard C++ Library header. |
27 | */ |
28 | |
29 | // Note: this is not a conforming implementation. |
30 | // Written by Gabriel Dos Reis <gdr@codesourcery.com> |
31 | |
32 | // |
33 | // ISO 14882:1998 |
34 | // 18.2.1 |
35 | // |
36 | |
37 | #ifndef _GLIBCXX_NUMERIC_LIMITS1 |
38 | #define _GLIBCXX_NUMERIC_LIMITS1 1 |
39 | |
40 | #pragma GCC system_header |
41 | |
42 | #include <bits/c++config.h> |
43 | |
44 | // |
45 | // The numeric_limits<> traits document implementation-defined aspects |
46 | // of fundamental arithmetic data types (integers and floating points). |
47 | // From Standard C++ point of view, there are 14 such types: |
48 | // * integers |
49 | // bool (1) |
50 | // char, signed char, unsigned char, wchar_t (4) |
51 | // short, unsigned short (2) |
52 | // int, unsigned (2) |
53 | // long, unsigned long (2) |
54 | // |
55 | // * floating points |
56 | // float (1) |
57 | // double (1) |
58 | // long double (1) |
59 | // |
60 | // GNU C++ understands (where supported by the host C-library) |
61 | // * integer |
62 | // long long, unsigned long long (2) |
63 | // |
64 | // which brings us to 16 fundamental arithmetic data types in GNU C++. |
65 | // |
66 | // |
67 | // Since a numeric_limits<> is a bit tricky to get right, we rely on |
68 | // an interface composed of macros which should be defined in config/os |
69 | // or config/cpu when they differ from the generic (read arbitrary) |
70 | // definitions given here. |
71 | // |
72 | |
73 | // These values can be overridden in the target configuration file. |
74 | // The default values are appropriate for many 32-bit targets. |
75 | |
76 | // GCC only intrinsically supports modulo integral types. The only remaining |
77 | // integral exceptional values is division by zero. Only targets that do not |
78 | // signal division by zero in some "hard to ignore" way should use false. |
79 | #ifndef __glibcxx_integral_trapstrue |
80 | # define __glibcxx_integral_trapstrue true |
81 | #endif |
82 | |
83 | // float |
84 | // |
85 | |
86 | // Default values. Should be overridden in configuration files if necessary. |
87 | |
88 | #ifndef __glibcxx_float_has_denorm_loss |
89 | # define __glibcxx_float_has_denorm_loss false |
90 | #endif |
91 | #ifndef __glibcxx_float_traps |
92 | # define __glibcxx_float_traps false |
93 | #endif |
94 | #ifndef __glibcxx_float_tinyness_before |
95 | # define __glibcxx_float_tinyness_before false |
96 | #endif |
97 | |
98 | // double |
99 | |
100 | // Default values. Should be overridden in configuration files if necessary. |
101 | |
102 | #ifndef __glibcxx_double_has_denorm_loss |
103 | # define __glibcxx_double_has_denorm_loss false |
104 | #endif |
105 | #ifndef __glibcxx_double_traps |
106 | # define __glibcxx_double_traps false |
107 | #endif |
108 | #ifndef __glibcxx_double_tinyness_before |
109 | # define __glibcxx_double_tinyness_before false |
110 | #endif |
111 | |
112 | // long double |
113 | |
114 | // Default values. Should be overridden in configuration files if necessary. |
115 | |
116 | #ifndef __glibcxx_long_double_has_denorm_loss |
117 | # define __glibcxx_long_double_has_denorm_loss false |
118 | #endif |
119 | #ifndef __glibcxx_long_double_traps |
120 | # define __glibcxx_long_double_traps false |
121 | #endif |
122 | #ifndef __glibcxx_long_double_tinyness_before |
123 | # define __glibcxx_long_double_tinyness_before false |
124 | #endif |
125 | |
126 | // You should not need to define any macros below this point. |
127 | |
128 | #define __glibcxx_signed_b(T,B)((T)(-1) < 0) ((T)(-1) < 0) |
129 | |
130 | #define __glibcxx_min_b(T,B)(((T)(-1) < 0) ? -(((T)(-1) < 0) ? (((((T)1 << (( B - ((T)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(T)0) - 1 : (T)0) \ |
131 | (__glibcxx_signed_b (T,B)((T)(-1) < 0) ? -__glibcxx_max_b (T,B)(((T)(-1) < 0) ? (((((T)1 << ((B - ((T)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(T)0) - 1 : (T)0) |
132 | |
133 | #define __glibcxx_max_b(T,B)(((T)(-1) < 0) ? (((((T)1 << ((B - ((T)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(T)0) \ |
134 | (__glibcxx_signed_b (T,B)((T)(-1) < 0) ? \ |
135 | (((((T)1 << (__glibcxx_digits_b (T,B)(B - ((T)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(T)0) |
136 | |
137 | #define __glibcxx_digits_b(T,B)(B - ((T)(-1) < 0)) \ |
138 | (B - __glibcxx_signed_b (T,B)((T)(-1) < 0)) |
139 | |
140 | // The fraction 643/2136 approximates log10(2) to 7 significant digits. |
141 | #define __glibcxx_digits10_b(T,B)((B - ((T)(-1) < 0)) * 643L / 2136) \ |
142 | (__glibcxx_digits_b (T,B)(B - ((T)(-1) < 0)) * 643L / 2136) |
143 | |
144 | #define __glibcxx_signed(T) \ |
145 | __glibcxx_signed_b (T, sizeof(T) * __CHAR_BIT__)((T)(-1) < 0) |
146 | #define __glibcxx_min(T) \ |
147 | __glibcxx_min_b (T, sizeof(T) * __CHAR_BIT__)(((T)(-1) < 0) ? -(((T)(-1) < 0) ? (((((T)1 << (( sizeof(T) * 8 - ((T)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(T)0) - 1 : (T)0) |
148 | #define __glibcxx_max(T) \ |
149 | __glibcxx_max_b (T, sizeof(T) * __CHAR_BIT__)(((T)(-1) < 0) ? (((((T)1 << ((sizeof(T) * 8 - ((T)( -1) < 0)) - 1)) - 1) << 1) + 1) : ~(T)0) |
150 | #define __glibcxx_digits(T) \ |
151 | __glibcxx_digits_b (T, sizeof(T) * __CHAR_BIT__)(sizeof(T) * 8 - ((T)(-1) < 0)) |
152 | #define __glibcxx_digits10(T) \ |
153 | __glibcxx_digits10_b (T, sizeof(T) * __CHAR_BIT__)((sizeof(T) * 8 - ((T)(-1) < 0)) * 643L / 2136) |
154 | |
155 | #define __glibcxx_max_digits10(T) \ |
156 | (2 + (T) * 643L / 2136) |
157 | |
158 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
159 | { |
160 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
161 | |
162 | /** |
163 | * @brief Describes the rounding style for floating-point types. |
164 | * |
165 | * This is used in the std::numeric_limits class. |
166 | */ |
167 | enum float_round_style |
168 | { |
169 | round_indeterminate = -1, /// Intermediate. |
170 | round_toward_zero = 0, /// To zero. |
171 | round_to_nearest = 1, /// To the nearest representable value. |
172 | round_toward_infinity = 2, /// To infinity. |
173 | round_toward_neg_infinity = 3 /// To negative infinity. |
174 | }; |
175 | |
176 | /** |
177 | * @brief Describes the denormalization for floating-point types. |
178 | * |
179 | * These values represent the presence or absence of a variable number |
180 | * of exponent bits. This type is used in the std::numeric_limits class. |
181 | */ |
182 | enum float_denorm_style |
183 | { |
184 | /// Indeterminate at compile time whether denormalized values are allowed. |
185 | denorm_indeterminate = -1, |
186 | /// The type does not allow denormalized values. |
187 | denorm_absent = 0, |
188 | /// The type allows denormalized values. |
189 | denorm_present = 1 |
190 | }; |
191 | |
192 | /** |
193 | * @brief Part of std::numeric_limits. |
194 | * |
195 | * The @c static @c const members are usable as integral constant |
196 | * expressions. |
197 | * |
198 | * @note This is a separate class for purposes of efficiency; you |
199 | * should only access these members as part of an instantiation |
200 | * of the std::numeric_limits class. |
201 | */ |
202 | struct __numeric_limits_base |
203 | { |
204 | /** This will be true for all fundamental types (which have |
205 | specializations), and false for everything else. */ |
206 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = false; |
207 | |
208 | /** The number of @c radix digits that be represented without change: for |
209 | integer types, the number of non-sign bits in the mantissa; for |
210 | floating types, the number of @c radix digits in the mantissa. */ |
211 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = 0; |
212 | |
213 | /** The number of base 10 digits that can be represented without change. */ |
214 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = 0; |
215 | |
216 | #if __cplusplus201703L >= 201103L |
217 | /** The number of base 10 digits required to ensure that values which |
218 | differ are always differentiated. */ |
219 | static constexpr int max_digits10 = 0; |
220 | #endif |
221 | |
222 | /** True if the type is signed. */ |
223 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = false; |
224 | |
225 | /** True if the type is integer. */ |
226 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = false; |
227 | |
228 | /** True if the type uses an exact representation. All integer types are |
229 | exact, but not all exact types are integer. For example, rational and |
230 | fixed-exponent representations are exact but not integer. */ |
231 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = false; |
232 | |
233 | /** For integer types, specifies the base of the representation. For |
234 | floating types, specifies the base of the exponent representation. */ |
235 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 0; |
236 | |
237 | /** The minimum negative integer such that @c radix raised to the power of |
238 | (one less than that integer) is a normalized floating point number. */ |
239 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
240 | |
241 | /** The minimum negative integer such that 10 raised to that power is in |
242 | the range of normalized floating point numbers. */ |
243 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
244 | |
245 | /** The maximum positive integer such that @c radix raised to the power of |
246 | (one less than that integer) is a representable finite floating point |
247 | number. */ |
248 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
249 | |
250 | /** The maximum positive integer such that 10 raised to that power is in |
251 | the range of representable finite floating point numbers. */ |
252 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
253 | |
254 | /** True if the type has a representation for positive infinity. */ |
255 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
256 | |
257 | /** True if the type has a representation for a quiet (non-signaling) |
258 | Not a Number. */ |
259 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
260 | |
261 | /** True if the type has a representation for a signaling |
262 | Not a Number. */ |
263 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
264 | |
265 | /** See std::float_denorm_style for more information. */ |
266 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm = denorm_absent; |
267 | |
268 | /** True if loss of accuracy is detected as a denormalization loss, |
269 | rather than as an inexact result. */ |
270 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
271 | |
272 | /** True if-and-only-if the type adheres to the IEC 559 standard, also |
273 | known as IEEE 754. (Only makes sense for floating point types.) */ |
274 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
275 | |
276 | /** True if the set of values representable by the type is |
277 | finite. All built-in types are bounded, this member would be |
278 | false for arbitrary precision types. */ |
279 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = false; |
280 | |
281 | /** True if the type is @e modulo. A type is modulo if, for any |
282 | operation involving +, -, or * on values of that type whose |
283 | result would fall outside the range [min(),max()], the value |
284 | returned differs from the true value by an integer multiple of |
285 | max() - min() + 1. On most machines, this is false for floating |
286 | types, true for unsigned integers, and true for signed integers. |
287 | See PR22200 about signed integers. */ |
288 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
289 | |
290 | /** True if trapping is implemented for this type. */ |
291 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = false; |
292 | |
293 | /** True if tininess is detected before rounding. (see IEC 559) */ |
294 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
295 | |
296 | /** See std::float_round_style for more information. This is only |
297 | meaningful for floating types; integer types will all be |
298 | round_toward_zero. */ |
299 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style = |
300 | round_toward_zero; |
301 | }; |
302 | |
303 | /** |
304 | * @brief Properties of fundamental types. |
305 | * |
306 | * This class allows a program to obtain information about the |
307 | * representation of a fundamental type on a given platform. For |
308 | * non-fundamental types, the functions will return 0 and the data |
309 | * members will all be @c false. |
310 | */ |
311 | template<typename _Tp> |
312 | struct numeric_limits : public __numeric_limits_base |
313 | { |
314 | /** The minimum finite value, or for floating types with |
315 | denormalization, the minimum positive normalized value. */ |
316 | static _GLIBCXX_CONSTEXPRconstexpr _Tp |
317 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return _Tp(); } |
318 | |
319 | /** The maximum finite value. */ |
320 | static _GLIBCXX_CONSTEXPRconstexpr _Tp |
321 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return _Tp(); } |
322 | |
323 | #if __cplusplus201703L >= 201103L |
324 | /** A finite value x such that there is no other finite value y |
325 | * where y < x. */ |
326 | static constexpr _Tp |
327 | lowest() noexcept { return _Tp(); } |
328 | #endif |
329 | |
330 | /** The @e machine @e epsilon: the difference between 1 and the least |
331 | value greater than 1 that is representable. */ |
332 | static _GLIBCXX_CONSTEXPRconstexpr _Tp |
333 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return _Tp(); } |
334 | |
335 | /** The maximum rounding error measurement (see LIA-1). */ |
336 | static _GLIBCXX_CONSTEXPRconstexpr _Tp |
337 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return _Tp(); } |
338 | |
339 | /** The representation of positive infinity, if @c has_infinity. */ |
340 | static _GLIBCXX_CONSTEXPRconstexpr _Tp |
341 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return _Tp(); } |
342 | |
343 | /** The representation of a quiet Not a Number, |
344 | if @c has_quiet_NaN. */ |
345 | static _GLIBCXX_CONSTEXPRconstexpr _Tp |
346 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return _Tp(); } |
347 | |
348 | /** The representation of a signaling Not a Number, if |
349 | @c has_signaling_NaN. */ |
350 | static _GLIBCXX_CONSTEXPRconstexpr _Tp |
351 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return _Tp(); } |
352 | |
353 | /** The minimum positive denormalized value. For types where |
354 | @c has_denorm is false, this is the minimum positive normalized |
355 | value. */ |
356 | static _GLIBCXX_CONSTEXPRconstexpr _Tp |
357 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return _Tp(); } |
358 | }; |
359 | |
360 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
361 | // 559. numeric_limits<const T> |
362 | |
363 | template<typename _Tp> |
364 | struct numeric_limits<const _Tp> |
365 | : public numeric_limits<_Tp> { }; |
366 | |
367 | template<typename _Tp> |
368 | struct numeric_limits<volatile _Tp> |
369 | : public numeric_limits<_Tp> { }; |
370 | |
371 | template<typename _Tp> |
372 | struct numeric_limits<const volatile _Tp> |
373 | : public numeric_limits<_Tp> { }; |
374 | |
375 | // Now there follow 16 explicit specializations. Yes, 16. Make sure |
376 | // you get the count right. (18 in C++11 mode, with char16_t and char32_t.) |
377 | // (+1 if char8_t is enabled.) |
378 | |
379 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
380 | // 184. numeric_limits<bool> wording problems |
381 | |
382 | /// numeric_limits<bool> specialization. |
383 | template<> |
384 | struct numeric_limits<bool> |
385 | { |
386 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
387 | |
388 | static _GLIBCXX_CONSTEXPRconstexpr bool |
389 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return false; } |
390 | |
391 | static _GLIBCXX_CONSTEXPRconstexpr bool |
392 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return true; } |
393 | |
394 | #if __cplusplus201703L >= 201103L |
395 | static constexpr bool |
396 | lowest() noexcept { return min(); } |
397 | #endif |
398 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = 1; |
399 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = 0; |
400 | #if __cplusplus201703L >= 201103L |
401 | static constexpr int max_digits10 = 0; |
402 | #endif |
403 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = false; |
404 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
405 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
406 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
407 | |
408 | static _GLIBCXX_CONSTEXPRconstexpr bool |
409 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return false; } |
410 | |
411 | static _GLIBCXX_CONSTEXPRconstexpr bool |
412 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return false; } |
413 | |
414 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
415 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
416 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
417 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
418 | |
419 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
420 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
421 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
422 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
423 | = denorm_absent; |
424 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
425 | |
426 | static _GLIBCXX_CONSTEXPRconstexpr bool |
427 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return false; } |
428 | |
429 | static _GLIBCXX_CONSTEXPRconstexpr bool |
430 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return false; } |
431 | |
432 | static _GLIBCXX_CONSTEXPRconstexpr bool |
433 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return false; } |
434 | |
435 | static _GLIBCXX_CONSTEXPRconstexpr bool |
436 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return false; } |
437 | |
438 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
439 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
440 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
441 | |
442 | // It is not clear what it means for a boolean type to trap. |
443 | // This is a DR on the LWG issue list. Here, I use integer |
444 | // promotion semantics. |
445 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
446 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
447 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
448 | = round_toward_zero; |
449 | }; |
450 | |
451 | /// numeric_limits<char> specialization. |
452 | template<> |
453 | struct numeric_limits<char> |
454 | { |
455 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
456 | |
457 | static _GLIBCXX_CONSTEXPRconstexpr char |
458 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __glibcxx_min(char); } |
459 | |
460 | static _GLIBCXX_CONSTEXPRconstexpr char |
461 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __glibcxx_max(char); } |
462 | |
463 | #if __cplusplus201703L >= 201103L |
464 | static constexpr char |
465 | lowest() noexcept { return min(); } |
466 | #endif |
467 | |
468 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __glibcxx_digits (char); |
469 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = __glibcxx_digits10 (char); |
470 | #if __cplusplus201703L >= 201103L |
471 | static constexpr int max_digits10 = 0; |
472 | #endif |
473 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = __glibcxx_signed (char); |
474 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
475 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
476 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
477 | |
478 | static _GLIBCXX_CONSTEXPRconstexpr char |
479 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
480 | |
481 | static _GLIBCXX_CONSTEXPRconstexpr char |
482 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
483 | |
484 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
485 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
486 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
487 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
488 | |
489 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
490 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
491 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
492 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
493 | = denorm_absent; |
494 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
495 | |
496 | static _GLIBCXX_CONSTEXPRconstexpr |
497 | char infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return char(); } |
498 | |
499 | static _GLIBCXX_CONSTEXPRconstexpr char |
500 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return char(); } |
501 | |
502 | static _GLIBCXX_CONSTEXPRconstexpr char |
503 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return char(); } |
504 | |
505 | static _GLIBCXX_CONSTEXPRconstexpr char |
506 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<char>(0); } |
507 | |
508 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
509 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
510 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = !is_signed; |
511 | |
512 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
513 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
514 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
515 | = round_toward_zero; |
516 | }; |
517 | |
518 | /// numeric_limits<signed char> specialization. |
519 | template<> |
520 | struct numeric_limits<signed char> |
521 | { |
522 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
523 | |
524 | static _GLIBCXX_CONSTEXPRconstexpr signed char |
525 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return -__SCHAR_MAX__127 - 1; } |
526 | |
527 | static _GLIBCXX_CONSTEXPRconstexpr signed char |
528 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __SCHAR_MAX__127; } |
529 | |
530 | #if __cplusplus201703L >= 201103L |
531 | static constexpr signed char |
532 | lowest() noexcept { return min(); } |
533 | #endif |
534 | |
535 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __glibcxx_digits (signed char); |
536 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 |
537 | = __glibcxx_digits10 (signed char); |
538 | #if __cplusplus201703L >= 201103L |
539 | static constexpr int max_digits10 = 0; |
540 | #endif |
541 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; |
542 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
543 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
544 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
545 | |
546 | static _GLIBCXX_CONSTEXPRconstexpr signed char |
547 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
548 | |
549 | static _GLIBCXX_CONSTEXPRconstexpr signed char |
550 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
551 | |
552 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
553 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
554 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
555 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
556 | |
557 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
558 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
559 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
560 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
561 | = denorm_absent; |
562 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
563 | |
564 | static _GLIBCXX_CONSTEXPRconstexpr signed char |
565 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<signed char>(0); } |
566 | |
567 | static _GLIBCXX_CONSTEXPRconstexpr signed char |
568 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<signed char>(0); } |
569 | |
570 | static _GLIBCXX_CONSTEXPRconstexpr signed char |
571 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
572 | { return static_cast<signed char>(0); } |
573 | |
574 | static _GLIBCXX_CONSTEXPRconstexpr signed char |
575 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept |
576 | { return static_cast<signed char>(0); } |
577 | |
578 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
579 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
580 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
581 | |
582 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
583 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
584 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
585 | = round_toward_zero; |
586 | }; |
587 | |
588 | /// numeric_limits<unsigned char> specialization. |
589 | template<> |
590 | struct numeric_limits<unsigned char> |
591 | { |
592 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
593 | |
594 | static _GLIBCXX_CONSTEXPRconstexpr unsigned char |
595 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
596 | |
597 | static _GLIBCXX_CONSTEXPRconstexpr unsigned char |
598 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __SCHAR_MAX__127 * 2U + 1; } |
599 | |
600 | #if __cplusplus201703L >= 201103L |
601 | static constexpr unsigned char |
602 | lowest() noexcept { return min(); } |
603 | #endif |
604 | |
605 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits |
606 | = __glibcxx_digits (unsigned char); |
607 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 |
608 | = __glibcxx_digits10 (unsigned char); |
609 | #if __cplusplus201703L >= 201103L |
610 | static constexpr int max_digits10 = 0; |
611 | #endif |
612 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = false; |
613 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
614 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
615 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
616 | |
617 | static _GLIBCXX_CONSTEXPRconstexpr unsigned char |
618 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
619 | |
620 | static _GLIBCXX_CONSTEXPRconstexpr unsigned char |
621 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
622 | |
623 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
624 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
625 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
626 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
627 | |
628 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
629 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
630 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
631 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
632 | = denorm_absent; |
633 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
634 | |
635 | static _GLIBCXX_CONSTEXPRconstexpr unsigned char |
636 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept |
637 | { return static_cast<unsigned char>(0); } |
638 | |
639 | static _GLIBCXX_CONSTEXPRconstexpr unsigned char |
640 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
641 | { return static_cast<unsigned char>(0); } |
642 | |
643 | static _GLIBCXX_CONSTEXPRconstexpr unsigned char |
644 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
645 | { return static_cast<unsigned char>(0); } |
646 | |
647 | static _GLIBCXX_CONSTEXPRconstexpr unsigned char |
648 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept |
649 | { return static_cast<unsigned char>(0); } |
650 | |
651 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
652 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
653 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = true; |
654 | |
655 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
656 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
657 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
658 | = round_toward_zero; |
659 | }; |
660 | |
661 | /// numeric_limits<wchar_t> specialization. |
662 | template<> |
663 | struct numeric_limits<wchar_t> |
664 | { |
665 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
666 | |
667 | static _GLIBCXX_CONSTEXPRconstexpr wchar_t |
668 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __glibcxx_min (wchar_t); } |
669 | |
670 | static _GLIBCXX_CONSTEXPRconstexpr wchar_t |
671 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __glibcxx_max (wchar_t); } |
672 | |
673 | #if __cplusplus201703L >= 201103L |
674 | static constexpr wchar_t |
675 | lowest() noexcept { return min(); } |
676 | #endif |
677 | |
678 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __glibcxx_digits (wchar_t); |
679 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 |
680 | = __glibcxx_digits10 (wchar_t); |
681 | #if __cplusplus201703L >= 201103L |
682 | static constexpr int max_digits10 = 0; |
683 | #endif |
684 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = __glibcxx_signed (wchar_t); |
685 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
686 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
687 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
688 | |
689 | static _GLIBCXX_CONSTEXPRconstexpr wchar_t |
690 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
691 | |
692 | static _GLIBCXX_CONSTEXPRconstexpr wchar_t |
693 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
694 | |
695 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
696 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
697 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
698 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
699 | |
700 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
701 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
702 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
703 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
704 | = denorm_absent; |
705 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
706 | |
707 | static _GLIBCXX_CONSTEXPRconstexpr wchar_t |
708 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return wchar_t(); } |
709 | |
710 | static _GLIBCXX_CONSTEXPRconstexpr wchar_t |
711 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return wchar_t(); } |
712 | |
713 | static _GLIBCXX_CONSTEXPRconstexpr wchar_t |
714 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return wchar_t(); } |
715 | |
716 | static _GLIBCXX_CONSTEXPRconstexpr wchar_t |
717 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return wchar_t(); } |
718 | |
719 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
720 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
721 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = !is_signed; |
722 | |
723 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
724 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
725 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
726 | = round_toward_zero; |
727 | }; |
728 | |
729 | #if _GLIBCXX_USE_CHAR8_T |
730 | /// numeric_limits<char8_t> specialization. |
731 | template<> |
732 | struct numeric_limits<char8_t> |
733 | { |
734 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
735 | |
736 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
737 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __glibcxx_min (char8_t); } |
738 | |
739 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
740 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __glibcxx_max (char8_t); } |
741 | |
742 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
743 | lowest() _GLIBCXX_USE_NOEXCEPTnoexcept { return min(); } |
744 | |
745 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __glibcxx_digits (char8_t); |
746 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = __glibcxx_digits10 (char8_t); |
747 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_digits10 = 0; |
748 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = __glibcxx_signed (char8_t); |
749 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
750 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
751 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
752 | |
753 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
754 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
755 | |
756 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
757 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
758 | |
759 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
760 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
761 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
762 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
763 | |
764 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
765 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
766 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
767 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
768 | = denorm_absent; |
769 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
770 | |
771 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
772 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return char8_t(); } |
773 | |
774 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
775 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return char8_t(); } |
776 | |
777 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
778 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return char8_t(); } |
779 | |
780 | static _GLIBCXX_CONSTEXPRconstexpr char8_t |
781 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return char8_t(); } |
782 | |
783 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
784 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
785 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = !is_signed; |
786 | |
787 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
788 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
789 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
790 | = round_toward_zero; |
791 | }; |
792 | #endif |
793 | |
794 | #if __cplusplus201703L >= 201103L |
795 | /// numeric_limits<char16_t> specialization. |
796 | template<> |
797 | struct numeric_limits<char16_t> |
798 | { |
799 | static constexpr bool is_specialized = true; |
800 | |
801 | static constexpr char16_t |
802 | min() noexcept { return __glibcxx_min (char16_t); } |
803 | |
804 | static constexpr char16_t |
805 | max() noexcept { return __glibcxx_max (char16_t); } |
806 | |
807 | static constexpr char16_t |
808 | lowest() noexcept { return min(); } |
809 | |
810 | static constexpr int digits = __glibcxx_digits (char16_t); |
811 | static constexpr int digits10 = __glibcxx_digits10 (char16_t); |
812 | static constexpr int max_digits10 = 0; |
813 | static constexpr bool is_signed = __glibcxx_signed (char16_t); |
814 | static constexpr bool is_integer = true; |
815 | static constexpr bool is_exact = true; |
816 | static constexpr int radix = 2; |
817 | |
818 | static constexpr char16_t |
819 | epsilon() noexcept { return 0; } |
820 | |
821 | static constexpr char16_t |
822 | round_error() noexcept { return 0; } |
823 | |
824 | static constexpr int min_exponent = 0; |
825 | static constexpr int min_exponent10 = 0; |
826 | static constexpr int max_exponent = 0; |
827 | static constexpr int max_exponent10 = 0; |
828 | |
829 | static constexpr bool has_infinity = false; |
830 | static constexpr bool has_quiet_NaN = false; |
831 | static constexpr bool has_signaling_NaN = false; |
832 | static constexpr float_denorm_style has_denorm = denorm_absent; |
833 | static constexpr bool has_denorm_loss = false; |
834 | |
835 | static constexpr char16_t |
836 | infinity() noexcept { return char16_t(); } |
837 | |
838 | static constexpr char16_t |
839 | quiet_NaN() noexcept { return char16_t(); } |
840 | |
841 | static constexpr char16_t |
842 | signaling_NaN() noexcept { return char16_t(); } |
843 | |
844 | static constexpr char16_t |
845 | denorm_min() noexcept { return char16_t(); } |
846 | |
847 | static constexpr bool is_iec559 = false; |
848 | static constexpr bool is_bounded = true; |
849 | static constexpr bool is_modulo = !is_signed; |
850 | |
851 | static constexpr bool traps = __glibcxx_integral_trapstrue; |
852 | static constexpr bool tinyness_before = false; |
853 | static constexpr float_round_style round_style = round_toward_zero; |
854 | }; |
855 | |
856 | /// numeric_limits<char32_t> specialization. |
857 | template<> |
858 | struct numeric_limits<char32_t> |
859 | { |
860 | static constexpr bool is_specialized = true; |
861 | |
862 | static constexpr char32_t |
863 | min() noexcept { return __glibcxx_min (char32_t); } |
864 | |
865 | static constexpr char32_t |
866 | max() noexcept { return __glibcxx_max (char32_t); } |
867 | |
868 | static constexpr char32_t |
869 | lowest() noexcept { return min(); } |
870 | |
871 | static constexpr int digits = __glibcxx_digits (char32_t); |
872 | static constexpr int digits10 = __glibcxx_digits10 (char32_t); |
873 | static constexpr int max_digits10 = 0; |
874 | static constexpr bool is_signed = __glibcxx_signed (char32_t); |
875 | static constexpr bool is_integer = true; |
876 | static constexpr bool is_exact = true; |
877 | static constexpr int radix = 2; |
878 | |
879 | static constexpr char32_t |
880 | epsilon() noexcept { return 0; } |
881 | |
882 | static constexpr char32_t |
883 | round_error() noexcept { return 0; } |
884 | |
885 | static constexpr int min_exponent = 0; |
886 | static constexpr int min_exponent10 = 0; |
887 | static constexpr int max_exponent = 0; |
888 | static constexpr int max_exponent10 = 0; |
889 | |
890 | static constexpr bool has_infinity = false; |
891 | static constexpr bool has_quiet_NaN = false; |
892 | static constexpr bool has_signaling_NaN = false; |
893 | static constexpr float_denorm_style has_denorm = denorm_absent; |
894 | static constexpr bool has_denorm_loss = false; |
895 | |
896 | static constexpr char32_t |
897 | infinity() noexcept { return char32_t(); } |
898 | |
899 | static constexpr char32_t |
900 | quiet_NaN() noexcept { return char32_t(); } |
901 | |
902 | static constexpr char32_t |
903 | signaling_NaN() noexcept { return char32_t(); } |
904 | |
905 | static constexpr char32_t |
906 | denorm_min() noexcept { return char32_t(); } |
907 | |
908 | static constexpr bool is_iec559 = false; |
909 | static constexpr bool is_bounded = true; |
910 | static constexpr bool is_modulo = !is_signed; |
911 | |
912 | static constexpr bool traps = __glibcxx_integral_trapstrue; |
913 | static constexpr bool tinyness_before = false; |
914 | static constexpr float_round_style round_style = round_toward_zero; |
915 | }; |
916 | #endif |
917 | |
918 | /// numeric_limits<short> specialization. |
919 | template<> |
920 | struct numeric_limits<short> |
921 | { |
922 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
923 | |
924 | static _GLIBCXX_CONSTEXPRconstexpr short |
925 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return -__SHRT_MAX__32767 - 1; } |
926 | |
927 | static _GLIBCXX_CONSTEXPRconstexpr short |
928 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __SHRT_MAX__32767; } |
929 | |
930 | #if __cplusplus201703L >= 201103L |
931 | static constexpr short |
932 | lowest() noexcept { return min(); } |
933 | #endif |
934 | |
935 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __glibcxx_digits (short); |
936 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = __glibcxx_digits10 (short); |
937 | #if __cplusplus201703L >= 201103L |
938 | static constexpr int max_digits10 = 0; |
939 | #endif |
940 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; |
941 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
942 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
943 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
944 | |
945 | static _GLIBCXX_CONSTEXPRconstexpr short |
946 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
947 | |
948 | static _GLIBCXX_CONSTEXPRconstexpr short |
949 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
950 | |
951 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
952 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
953 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
954 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
955 | |
956 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
957 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
958 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
959 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
960 | = denorm_absent; |
961 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
962 | |
963 | static _GLIBCXX_CONSTEXPRconstexpr short |
964 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return short(); } |
965 | |
966 | static _GLIBCXX_CONSTEXPRconstexpr short |
967 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return short(); } |
968 | |
969 | static _GLIBCXX_CONSTEXPRconstexpr short |
970 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return short(); } |
971 | |
972 | static _GLIBCXX_CONSTEXPRconstexpr short |
973 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return short(); } |
974 | |
975 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
976 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
977 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
978 | |
979 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
980 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
981 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
982 | = round_toward_zero; |
983 | }; |
984 | |
985 | /// numeric_limits<unsigned short> specialization. |
986 | template<> |
987 | struct numeric_limits<unsigned short> |
988 | { |
989 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
990 | |
991 | static _GLIBCXX_CONSTEXPRconstexpr unsigned short |
992 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
993 | |
994 | static _GLIBCXX_CONSTEXPRconstexpr unsigned short |
995 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __SHRT_MAX__32767 * 2U + 1; } |
996 | |
997 | #if __cplusplus201703L >= 201103L |
998 | static constexpr unsigned short |
999 | lowest() noexcept { return min(); } |
1000 | #endif |
1001 | |
1002 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits |
1003 | = __glibcxx_digits (unsigned short); |
1004 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 |
1005 | = __glibcxx_digits10 (unsigned short); |
1006 | #if __cplusplus201703L >= 201103L |
1007 | static constexpr int max_digits10 = 0; |
1008 | #endif |
1009 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = false; |
1010 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
1011 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
1012 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
1013 | |
1014 | static _GLIBCXX_CONSTEXPRconstexpr unsigned short |
1015 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1016 | |
1017 | static _GLIBCXX_CONSTEXPRconstexpr unsigned short |
1018 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1019 | |
1020 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
1021 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
1022 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
1023 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
1024 | |
1025 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
1026 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
1027 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
1028 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1029 | = denorm_absent; |
1030 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
1031 | |
1032 | static _GLIBCXX_CONSTEXPRconstexpr unsigned short |
1033 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept |
1034 | { return static_cast<unsigned short>(0); } |
1035 | |
1036 | static _GLIBCXX_CONSTEXPRconstexpr unsigned short |
1037 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1038 | { return static_cast<unsigned short>(0); } |
1039 | |
1040 | static _GLIBCXX_CONSTEXPRconstexpr unsigned short |
1041 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1042 | { return static_cast<unsigned short>(0); } |
1043 | |
1044 | static _GLIBCXX_CONSTEXPRconstexpr unsigned short |
1045 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept |
1046 | { return static_cast<unsigned short>(0); } |
1047 | |
1048 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
1049 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1050 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = true; |
1051 | |
1052 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
1053 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
1054 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1055 | = round_toward_zero; |
1056 | }; |
1057 | |
1058 | /// numeric_limits<int> specialization. |
1059 | template<> |
1060 | struct numeric_limits<int> |
1061 | { |
1062 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1063 | |
1064 | static _GLIBCXX_CONSTEXPRconstexpr int |
1065 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return -__INT_MAX__2147483647 - 1; } |
1066 | |
1067 | static _GLIBCXX_CONSTEXPRconstexpr int |
1068 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __INT_MAX__2147483647; } |
1069 | |
1070 | #if __cplusplus201703L >= 201103L |
1071 | static constexpr int |
1072 | lowest() noexcept { return min(); } |
1073 | #endif |
1074 | |
1075 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __glibcxx_digits (int); |
1076 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = __glibcxx_digits10 (int); |
1077 | #if __cplusplus201703L >= 201103L |
1078 | static constexpr int max_digits10 = 0; |
1079 | #endif |
1080 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; |
1081 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
1082 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
1083 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
1084 | |
1085 | static _GLIBCXX_CONSTEXPRconstexpr int |
1086 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1087 | |
1088 | static _GLIBCXX_CONSTEXPRconstexpr int |
1089 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1090 | |
1091 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
1092 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
1093 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
1094 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
1095 | |
1096 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
1097 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
1098 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
1099 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1100 | = denorm_absent; |
1101 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
1102 | |
1103 | static _GLIBCXX_CONSTEXPRconstexpr int |
1104 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<int>(0); } |
1105 | |
1106 | static _GLIBCXX_CONSTEXPRconstexpr int |
1107 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<int>(0); } |
1108 | |
1109 | static _GLIBCXX_CONSTEXPRconstexpr int |
1110 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<int>(0); } |
1111 | |
1112 | static _GLIBCXX_CONSTEXPRconstexpr int |
1113 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<int>(0); } |
1114 | |
1115 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
1116 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1117 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
1118 | |
1119 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
1120 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
1121 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1122 | = round_toward_zero; |
1123 | }; |
1124 | |
1125 | /// numeric_limits<unsigned int> specialization. |
1126 | template<> |
1127 | struct numeric_limits<unsigned int> |
1128 | { |
1129 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1130 | |
1131 | static _GLIBCXX_CONSTEXPRconstexpr unsigned int |
1132 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1133 | |
1134 | static _GLIBCXX_CONSTEXPRconstexpr unsigned int |
1135 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __INT_MAX__2147483647 * 2U + 1; } |
1136 | |
1137 | #if __cplusplus201703L >= 201103L |
1138 | static constexpr unsigned int |
1139 | lowest() noexcept { return min(); } |
1140 | #endif |
1141 | |
1142 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits |
1143 | = __glibcxx_digits (unsigned int); |
1144 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 |
1145 | = __glibcxx_digits10 (unsigned int); |
1146 | #if __cplusplus201703L >= 201103L |
1147 | static constexpr int max_digits10 = 0; |
1148 | #endif |
1149 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = false; |
1150 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
1151 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
1152 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
1153 | |
1154 | static _GLIBCXX_CONSTEXPRconstexpr unsigned int |
1155 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1156 | |
1157 | static _GLIBCXX_CONSTEXPRconstexpr unsigned int |
1158 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1159 | |
1160 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
1161 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
1162 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
1163 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
1164 | |
1165 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
1166 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
1167 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
1168 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1169 | = denorm_absent; |
1170 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
1171 | |
1172 | static _GLIBCXX_CONSTEXPRconstexpr unsigned int |
1173 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<unsigned int>(0); } |
1174 | |
1175 | static _GLIBCXX_CONSTEXPRconstexpr unsigned int |
1176 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1177 | { return static_cast<unsigned int>(0); } |
1178 | |
1179 | static _GLIBCXX_CONSTEXPRconstexpr unsigned int |
1180 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1181 | { return static_cast<unsigned int>(0); } |
1182 | |
1183 | static _GLIBCXX_CONSTEXPRconstexpr unsigned int |
1184 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept |
1185 | { return static_cast<unsigned int>(0); } |
1186 | |
1187 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
1188 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1189 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = true; |
1190 | |
1191 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
1192 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
1193 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1194 | = round_toward_zero; |
1195 | }; |
1196 | |
1197 | /// numeric_limits<long> specialization. |
1198 | template<> |
1199 | struct numeric_limits<long> |
1200 | { |
1201 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1202 | |
1203 | static _GLIBCXX_CONSTEXPRconstexpr long |
1204 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return -__LONG_MAX__9223372036854775807L - 1; } |
1205 | |
1206 | static _GLIBCXX_CONSTEXPRconstexpr long |
1207 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __LONG_MAX__9223372036854775807L; } |
1208 | |
1209 | #if __cplusplus201703L >= 201103L |
1210 | static constexpr long |
1211 | lowest() noexcept { return min(); } |
1212 | #endif |
1213 | |
1214 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __glibcxx_digits (long); |
1215 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = __glibcxx_digits10 (long); |
1216 | #if __cplusplus201703L >= 201103L |
1217 | static constexpr int max_digits10 = 0; |
1218 | #endif |
1219 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; |
1220 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
1221 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
1222 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
1223 | |
1224 | static _GLIBCXX_CONSTEXPRconstexpr long |
1225 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1226 | |
1227 | static _GLIBCXX_CONSTEXPRconstexpr long |
1228 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1229 | |
1230 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
1231 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
1232 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
1233 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
1234 | |
1235 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
1236 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
1237 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
1238 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1239 | = denorm_absent; |
1240 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
1241 | |
1242 | static _GLIBCXX_CONSTEXPRconstexpr long |
1243 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<long>(0); } |
1244 | |
1245 | static _GLIBCXX_CONSTEXPRconstexpr long |
1246 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<long>(0); } |
1247 | |
1248 | static _GLIBCXX_CONSTEXPRconstexpr long |
1249 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<long>(0); } |
1250 | |
1251 | static _GLIBCXX_CONSTEXPRconstexpr long |
1252 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<long>(0); } |
1253 | |
1254 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
1255 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1256 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
1257 | |
1258 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
1259 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
1260 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1261 | = round_toward_zero; |
1262 | }; |
1263 | |
1264 | /// numeric_limits<unsigned long> specialization. |
1265 | template<> |
1266 | struct numeric_limits<unsigned long> |
1267 | { |
1268 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1269 | |
1270 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long |
1271 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1272 | |
1273 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long |
1274 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __LONG_MAX__9223372036854775807L * 2UL + 1; } |
1275 | |
1276 | #if __cplusplus201703L >= 201103L |
1277 | static constexpr unsigned long |
1278 | lowest() noexcept { return min(); } |
1279 | #endif |
1280 | |
1281 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits |
1282 | = __glibcxx_digits (unsigned long); |
1283 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 |
1284 | = __glibcxx_digits10 (unsigned long); |
1285 | #if __cplusplus201703L >= 201103L |
1286 | static constexpr int max_digits10 = 0; |
1287 | #endif |
1288 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = false; |
1289 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
1290 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
1291 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
1292 | |
1293 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long |
1294 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1295 | |
1296 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long |
1297 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1298 | |
1299 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
1300 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
1301 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
1302 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
1303 | |
1304 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
1305 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
1306 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
1307 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1308 | = denorm_absent; |
1309 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
1310 | |
1311 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long |
1312 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept |
1313 | { return static_cast<unsigned long>(0); } |
1314 | |
1315 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long |
1316 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1317 | { return static_cast<unsigned long>(0); } |
1318 | |
1319 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long |
1320 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1321 | { return static_cast<unsigned long>(0); } |
1322 | |
1323 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long |
1324 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept |
1325 | { return static_cast<unsigned long>(0); } |
1326 | |
1327 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
1328 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1329 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = true; |
1330 | |
1331 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
1332 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
1333 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1334 | = round_toward_zero; |
1335 | }; |
1336 | |
1337 | /// numeric_limits<long long> specialization. |
1338 | template<> |
1339 | struct numeric_limits<long long> |
1340 | { |
1341 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1342 | |
1343 | static _GLIBCXX_CONSTEXPRconstexpr long long |
1344 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return -__LONG_LONG_MAX__9223372036854775807LL - 1; } |
1345 | |
1346 | static _GLIBCXX_CONSTEXPRconstexpr long long |
1347 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __LONG_LONG_MAX__9223372036854775807LL; } |
1348 | |
1349 | #if __cplusplus201703L >= 201103L |
1350 | static constexpr long long |
1351 | lowest() noexcept { return min(); } |
1352 | #endif |
1353 | |
1354 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits |
1355 | = __glibcxx_digits (long long); |
1356 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 |
1357 | = __glibcxx_digits10 (long long); |
1358 | #if __cplusplus201703L >= 201103L |
1359 | static constexpr int max_digits10 = 0; |
1360 | #endif |
1361 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; |
1362 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
1363 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
1364 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
1365 | |
1366 | static _GLIBCXX_CONSTEXPRconstexpr long long |
1367 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1368 | |
1369 | static _GLIBCXX_CONSTEXPRconstexpr long long |
1370 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1371 | |
1372 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
1373 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
1374 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
1375 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
1376 | |
1377 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
1378 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
1379 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
1380 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1381 | = denorm_absent; |
1382 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
1383 | |
1384 | static _GLIBCXX_CONSTEXPRconstexpr long long |
1385 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<long long>(0); } |
1386 | |
1387 | static _GLIBCXX_CONSTEXPRconstexpr long long |
1388 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<long long>(0); } |
1389 | |
1390 | static _GLIBCXX_CONSTEXPRconstexpr long long |
1391 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1392 | { return static_cast<long long>(0); } |
1393 | |
1394 | static _GLIBCXX_CONSTEXPRconstexpr long long |
1395 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return static_cast<long long>(0); } |
1396 | |
1397 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
1398 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1399 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
1400 | |
1401 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
1402 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
1403 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1404 | = round_toward_zero; |
1405 | }; |
1406 | |
1407 | /// numeric_limits<unsigned long long> specialization. |
1408 | template<> |
1409 | struct numeric_limits<unsigned long long> |
1410 | { |
1411 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1412 | |
1413 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long long |
1414 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1415 | |
1416 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long long |
1417 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __LONG_LONG_MAX__9223372036854775807LL * 2ULL + 1; } |
1418 | |
1419 | #if __cplusplus201703L >= 201103L |
1420 | static constexpr unsigned long long |
1421 | lowest() noexcept { return min(); } |
1422 | #endif |
1423 | |
1424 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits |
1425 | = __glibcxx_digits (unsigned long long); |
1426 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 |
1427 | = __glibcxx_digits10 (unsigned long long); |
1428 | #if __cplusplus201703L >= 201103L |
1429 | static constexpr int max_digits10 = 0; |
1430 | #endif |
1431 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = false; |
1432 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; |
1433 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; |
1434 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; |
1435 | |
1436 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long long |
1437 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1438 | |
1439 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long long |
1440 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } |
1441 | |
1442 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; |
1443 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; |
1444 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; |
1445 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; |
1446 | |
1447 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; |
1448 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; |
1449 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; |
1450 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1451 | = denorm_absent; |
1452 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; |
1453 | |
1454 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long long |
1455 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept |
1456 | { return static_cast<unsigned long long>(0); } |
1457 | |
1458 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long long |
1459 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1460 | { return static_cast<unsigned long long>(0); } |
1461 | |
1462 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long long |
1463 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept |
1464 | { return static_cast<unsigned long long>(0); } |
1465 | |
1466 | static _GLIBCXX_CONSTEXPRconstexpr unsigned long long |
1467 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept |
1468 | { return static_cast<unsigned long long>(0); } |
1469 | |
1470 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; |
1471 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1472 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = true; |
1473 | |
1474 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; |
1475 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; |
1476 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1477 | = round_toward_zero; |
1478 | }; |
1479 | |
1480 | #define __INT_N(TYPE, BITSIZE, EXT, UEXT) \ |
1481 | template<> \ |
1482 | struct numeric_limits<TYPE> \ |
1483 | { \ |
1484 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; \ |
1485 | \ |
1486 | static _GLIBCXX_CONSTEXPRconstexpr TYPE \ |
1487 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __glibcxx_min_b (TYPE, BITSIZE)(((TYPE)(-1) < 0) ? -(((TYPE)(-1) < 0) ? (((((TYPE)1 << ((BITSIZE - ((TYPE)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(TYPE)0) - 1 : (TYPE)0); } \ |
1488 | \ |
1489 | static _GLIBCXX_CONSTEXPRconstexpr TYPE \ |
1490 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __glibcxx_max_b (TYPE, BITSIZE)(((TYPE)(-1) < 0) ? (((((TYPE)1 << ((BITSIZE - ((TYPE )(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(TYPE)0); } \ |
1491 | \ |
1492 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits \ |
1493 | = BITSIZE - 1; \ |
1494 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 \ |
1495 | = (BITSIZE - 1) * 643L / 2136; \ |
1496 | \ |
1497 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; \ |
1498 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; \ |
1499 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; \ |
1500 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; \ |
1501 | \ |
1502 | static _GLIBCXX_CONSTEXPRconstexpr TYPE \ |
1503 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } \ |
1504 | \ |
1505 | static _GLIBCXX_CONSTEXPRconstexpr TYPE \ |
1506 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } \ |
1507 | \ |
1508 | EXT \ |
1509 | \ |
1510 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; \ |
1511 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; \ |
1512 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; \ |
1513 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; \ |
1514 | \ |
1515 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; \ |
1516 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; \ |
1517 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; \ |
1518 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm \ |
1519 | = denorm_absent; \ |
1520 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; \ |
1521 | \ |
1522 | static _GLIBCXX_CONSTEXPRconstexpr TYPE \ |
1523 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1524 | { return static_cast<TYPE>(0); } \ |
1525 | \ |
1526 | static _GLIBCXX_CONSTEXPRconstexpr TYPE \ |
1527 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1528 | { return static_cast<TYPE>(0); } \ |
1529 | \ |
1530 | static _GLIBCXX_CONSTEXPRconstexpr TYPE \ |
1531 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1532 | { return static_cast<TYPE>(0); } \ |
1533 | \ |
1534 | static _GLIBCXX_CONSTEXPRconstexpr TYPE \ |
1535 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1536 | { return static_cast<TYPE>(0); } \ |
1537 | \ |
1538 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; \ |
1539 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; \ |
1540 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; \ |
1541 | \ |
1542 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps \ |
1543 | = __glibcxx_integral_trapstrue; \ |
1544 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; \ |
1545 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style \ |
1546 | = round_toward_zero; \ |
1547 | }; \ |
1548 | \ |
1549 | template<> \ |
1550 | struct numeric_limits<unsigned TYPE> \ |
1551 | { \ |
1552 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; \ |
1553 | \ |
1554 | static _GLIBCXX_CONSTEXPRconstexpr unsigned TYPE \ |
1555 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } \ |
1556 | \ |
1557 | static _GLIBCXX_CONSTEXPRconstexpr unsigned TYPE \ |
1558 | max() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1559 | { return __glibcxx_max_b (unsigned TYPE, BITSIZE)(((unsigned TYPE)(-1) < 0) ? (((((unsigned TYPE)1 << ((BITSIZE - ((unsigned TYPE)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(unsigned TYPE)0); } \ |
1560 | \ |
1561 | UEXT \ |
1562 | \ |
1563 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits \ |
1564 | = BITSIZE; \ |
1565 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 \ |
1566 | = BITSIZE * 643L / 2136; \ |
1567 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = false; \ |
1568 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = true; \ |
1569 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = true; \ |
1570 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = 2; \ |
1571 | \ |
1572 | static _GLIBCXX_CONSTEXPRconstexpr unsigned TYPE \ |
1573 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } \ |
1574 | \ |
1575 | static _GLIBCXX_CONSTEXPRconstexpr unsigned TYPE \ |
1576 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0; } \ |
1577 | \ |
1578 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = 0; \ |
1579 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = 0; \ |
1580 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = 0; \ |
1581 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = 0; \ |
1582 | \ |
1583 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = false; \ |
1584 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = false; \ |
1585 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = false; \ |
1586 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm \ |
1587 | = denorm_absent; \ |
1588 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss = false; \ |
1589 | \ |
1590 | static _GLIBCXX_CONSTEXPRconstexpr unsigned TYPE \ |
1591 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1592 | { return static_cast<unsigned TYPE>(0); } \ |
1593 | \ |
1594 | static _GLIBCXX_CONSTEXPRconstexpr unsigned TYPE \ |
1595 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1596 | { return static_cast<unsigned TYPE>(0); } \ |
1597 | \ |
1598 | static _GLIBCXX_CONSTEXPRconstexpr unsigned TYPE \ |
1599 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1600 | { return static_cast<unsigned TYPE>(0); } \ |
1601 | \ |
1602 | static _GLIBCXX_CONSTEXPRconstexpr unsigned TYPE \ |
1603 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept \ |
1604 | { return static_cast<unsigned TYPE>(0); } \ |
1605 | \ |
1606 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 = false; \ |
1607 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; \ |
1608 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = true; \ |
1609 | \ |
1610 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_integral_trapstrue; \ |
1611 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = false; \ |
1612 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style \ |
1613 | = round_toward_zero; \ |
1614 | }; |
1615 | |
1616 | #if __cplusplus201703L >= 201103L |
1617 | |
1618 | #define __INT_N_201103(TYPE) \ |
1619 | static constexpr TYPE \ |
1620 | lowest() noexcept { return min(); } \ |
1621 | static constexpr int max_digits10 = 0; |
1622 | |
1623 | #define __INT_N_U201103(TYPE) \ |
1624 | static constexpr unsigned TYPE \ |
1625 | lowest() noexcept { return min(); } \ |
1626 | static constexpr int max_digits10 = 0; |
1627 | |
1628 | #else |
1629 | #define __INT_N_201103(TYPE) |
1630 | #define __INT_N_U201103(TYPE) |
1631 | #endif |
1632 | |
1633 | #if !defined(__STRICT_ANSI__1) |
1634 | #ifdef __GLIBCXX_TYPE_INT_N_0 |
1635 | __INT_N(__GLIBCXX_TYPE_INT_N_0, __GLIBCXX_BITSIZE_INT_N_0, |
1636 | __INT_N_201103 (__GLIBCXX_TYPE_INT_N_0), __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_0)) |
1637 | #endif |
1638 | #ifdef __GLIBCXX_TYPE_INT_N_1 |
1639 | __INT_N (__GLIBCXX_TYPE_INT_N_1, __GLIBCXX_BITSIZE_INT_N_1, |
1640 | __INT_N_201103 (__GLIBCXX_TYPE_INT_N_1), __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_1)) |
1641 | #endif |
1642 | #ifdef __GLIBCXX_TYPE_INT_N_2 |
1643 | __INT_N (__GLIBCXX_TYPE_INT_N_2, __GLIBCXX_BITSIZE_INT_N_2, |
1644 | __INT_N_201103 (__GLIBCXX_TYPE_INT_N_2), __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_2)) |
1645 | #endif |
1646 | #ifdef __GLIBCXX_TYPE_INT_N_3 |
1647 | __INT_N (__GLIBCXX_TYPE_INT_N_3, __GLIBCXX_BITSIZE_INT_N_3, |
1648 | __INT_N_201103 (__GLIBCXX_TYPE_INT_N_3), __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_3)) |
1649 | #endif |
1650 | |
1651 | #elif defined __STRICT_ANSI__1 && defined __SIZEOF_INT128__16 |
1652 | __INT_N(__int128, 128, |
1653 | __INT_N_201103 (__int128), |
1654 | __INT_N_U201103 (__int128)) |
1655 | #endif |
1656 | |
1657 | #undef __INT_N |
1658 | #undef __INT_N_201103 |
1659 | #undef __INT_N_U201103 |
1660 | |
1661 | |
1662 | /// numeric_limits<float> specialization. |
1663 | template<> |
1664 | struct numeric_limits<float> |
1665 | { |
1666 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1667 | |
1668 | static _GLIBCXX_CONSTEXPRconstexpr float |
1669 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __FLT_MIN__1.17549435e-38F; } |
1670 | |
1671 | static _GLIBCXX_CONSTEXPRconstexpr float |
1672 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __FLT_MAX__3.40282347e+38F; } |
1673 | |
1674 | #if __cplusplus201703L >= 201103L |
1675 | static constexpr float |
1676 | lowest() noexcept { return -__FLT_MAX__3.40282347e+38F; } |
1677 | #endif |
1678 | |
1679 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __FLT_MANT_DIG__24; |
1680 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = __FLT_DIG__6; |
1681 | #if __cplusplus201703L >= 201103L |
1682 | static constexpr int max_digits10 |
1683 | = __glibcxx_max_digits10 (__FLT_MANT_DIG__24); |
1684 | #endif |
1685 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; |
1686 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = false; |
1687 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = false; |
1688 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = __FLT_RADIX__2; |
1689 | |
1690 | static _GLIBCXX_CONSTEXPRconstexpr float |
1691 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return __FLT_EPSILON__1.19209290e-7F; } |
1692 | |
1693 | static _GLIBCXX_CONSTEXPRconstexpr float |
1694 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0.5F; } |
1695 | |
1696 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = __FLT_MIN_EXP__(-125); |
1697 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = __FLT_MIN_10_EXP__(-37); |
1698 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = __FLT_MAX_EXP__128; |
1699 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = __FLT_MAX_10_EXP__38; |
1700 | |
1701 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = __FLT_HAS_INFINITY__1; |
1702 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = __FLT_HAS_QUIET_NAN__1; |
1703 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = has_quiet_NaN; |
1704 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1705 | = bool(__FLT_HAS_DENORM__1) ? denorm_present : denorm_absent; |
1706 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss |
1707 | = __glibcxx_float_has_denorm_loss; |
1708 | |
1709 | static _GLIBCXX_CONSTEXPRconstexpr float |
1710 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_huge_valf(); } |
1711 | |
1712 | static _GLIBCXX_CONSTEXPRconstexpr float |
1713 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_nanf(""); } |
1714 | |
1715 | static _GLIBCXX_CONSTEXPRconstexpr float |
1716 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_nansf(""); } |
1717 | |
1718 | static _GLIBCXX_CONSTEXPRconstexpr float |
1719 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __FLT_DENORM_MIN__1.40129846e-45F; } |
1720 | |
1721 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 |
1722 | = has_infinity && has_quiet_NaN && has_denorm == denorm_present; |
1723 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1724 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
1725 | |
1726 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_float_traps; |
1727 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before |
1728 | = __glibcxx_float_tinyness_before; |
1729 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1730 | = round_to_nearest; |
1731 | }; |
1732 | |
1733 | #undef __glibcxx_float_has_denorm_loss |
1734 | #undef __glibcxx_float_traps |
1735 | #undef __glibcxx_float_tinyness_before |
1736 | |
1737 | /// numeric_limits<double> specialization. |
1738 | template<> |
1739 | struct numeric_limits<double> |
1740 | { |
1741 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1742 | |
1743 | static _GLIBCXX_CONSTEXPRconstexpr double |
1744 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __DBL_MIN__2.2250738585072014e-308; } |
1745 | |
1746 | static _GLIBCXX_CONSTEXPRconstexpr double |
1747 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __DBL_MAX__1.7976931348623157e+308; } |
1748 | |
1749 | #if __cplusplus201703L >= 201103L |
1750 | static constexpr double |
1751 | lowest() noexcept { return -__DBL_MAX__1.7976931348623157e+308; } |
1752 | #endif |
1753 | |
1754 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __DBL_MANT_DIG__53; |
1755 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = __DBL_DIG__15; |
1756 | #if __cplusplus201703L >= 201103L |
1757 | static constexpr int max_digits10 |
1758 | = __glibcxx_max_digits10 (__DBL_MANT_DIG__53); |
1759 | #endif |
1760 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; |
1761 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = false; |
1762 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = false; |
1763 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = __FLT_RADIX__2; |
1764 | |
1765 | static _GLIBCXX_CONSTEXPRconstexpr double |
1766 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return __DBL_EPSILON__2.2204460492503131e-16; } |
1767 | |
1768 | static _GLIBCXX_CONSTEXPRconstexpr double |
1769 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0.5; } |
1770 | |
1771 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = __DBL_MIN_EXP__(-1021); |
1772 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = __DBL_MIN_10_EXP__(-307); |
1773 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = __DBL_MAX_EXP__1024; |
1774 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = __DBL_MAX_10_EXP__308; |
1775 | |
1776 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = __DBL_HAS_INFINITY__1; |
1777 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = __DBL_HAS_QUIET_NAN__1; |
1778 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = has_quiet_NaN; |
1779 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1780 | = bool(__DBL_HAS_DENORM__1) ? denorm_present : denorm_absent; |
1781 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss |
1782 | = __glibcxx_double_has_denorm_loss; |
1783 | |
1784 | static _GLIBCXX_CONSTEXPRconstexpr double |
1785 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_huge_val(); } |
1786 | |
1787 | static _GLIBCXX_CONSTEXPRconstexpr double |
1788 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_nan(""); } |
1789 | |
1790 | static _GLIBCXX_CONSTEXPRconstexpr double |
1791 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_nans(""); } |
1792 | |
1793 | static _GLIBCXX_CONSTEXPRconstexpr double |
1794 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __DBL_DENORM_MIN__4.9406564584124654e-324; } |
1795 | |
1796 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 |
1797 | = has_infinity && has_quiet_NaN && has_denorm == denorm_present; |
1798 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1799 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
1800 | |
1801 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_double_traps; |
1802 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before |
1803 | = __glibcxx_double_tinyness_before; |
1804 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style |
1805 | = round_to_nearest; |
1806 | }; |
1807 | |
1808 | #undef __glibcxx_double_has_denorm_loss |
1809 | #undef __glibcxx_double_traps |
1810 | #undef __glibcxx_double_tinyness_before |
1811 | |
1812 | /// numeric_limits<long double> specialization. |
1813 | template<> |
1814 | struct numeric_limits<long double> |
1815 | { |
1816 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_specialized = true; |
1817 | |
1818 | static _GLIBCXX_CONSTEXPRconstexpr long double |
1819 | min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __LDBL_MIN__3.36210314311209350626e-4932L; } |
1820 | |
1821 | static _GLIBCXX_CONSTEXPRconstexpr long double |
1822 | max() _GLIBCXX_USE_NOEXCEPTnoexcept { return __LDBL_MAX__1.18973149535723176502e+4932L; } |
1823 | |
1824 | #if __cplusplus201703L >= 201103L |
1825 | static constexpr long double |
1826 | lowest() noexcept { return -__LDBL_MAX__1.18973149535723176502e+4932L; } |
1827 | #endif |
1828 | |
1829 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits = __LDBL_MANT_DIG__64; |
1830 | static _GLIBCXX_USE_CONSTEXPRconstexpr int digits10 = __LDBL_DIG__18; |
1831 | #if __cplusplus201703L >= 201103L |
1832 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_digits10 |
1833 | = __glibcxx_max_digits10 (__LDBL_MANT_DIG__64); |
1834 | #endif |
1835 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_signed = true; |
1836 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_integer = false; |
1837 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_exact = false; |
1838 | static _GLIBCXX_USE_CONSTEXPRconstexpr int radix = __FLT_RADIX__2; |
1839 | |
1840 | static _GLIBCXX_CONSTEXPRconstexpr long double |
1841 | epsilon() _GLIBCXX_USE_NOEXCEPTnoexcept { return __LDBL_EPSILON__1.08420217248550443401e-19L; } |
1842 | |
1843 | static _GLIBCXX_CONSTEXPRconstexpr long double |
1844 | round_error() _GLIBCXX_USE_NOEXCEPTnoexcept { return 0.5L; } |
1845 | |
1846 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent = __LDBL_MIN_EXP__(-16381); |
1847 | static _GLIBCXX_USE_CONSTEXPRconstexpr int min_exponent10 = __LDBL_MIN_10_EXP__(-4931); |
1848 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent = __LDBL_MAX_EXP__16384; |
1849 | static _GLIBCXX_USE_CONSTEXPRconstexpr int max_exponent10 = __LDBL_MAX_10_EXP__4932; |
1850 | |
1851 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_infinity = __LDBL_HAS_INFINITY__1; |
1852 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_quiet_NaN = __LDBL_HAS_QUIET_NAN__1; |
1853 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_signaling_NaN = has_quiet_NaN; |
1854 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_denorm_style has_denorm |
1855 | = bool(__LDBL_HAS_DENORM__1) ? denorm_present : denorm_absent; |
1856 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool has_denorm_loss |
1857 | = __glibcxx_long_double_has_denorm_loss; |
1858 | |
1859 | static _GLIBCXX_CONSTEXPRconstexpr long double |
1860 | infinity() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_huge_vall(); } |
1861 | |
1862 | static _GLIBCXX_CONSTEXPRconstexpr long double |
1863 | quiet_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_nanl(""); } |
1864 | |
1865 | static _GLIBCXX_CONSTEXPRconstexpr long double |
1866 | signaling_NaN() _GLIBCXX_USE_NOEXCEPTnoexcept { return __builtin_nansl(""); } |
1867 | |
1868 | static _GLIBCXX_CONSTEXPRconstexpr long double |
1869 | denorm_min() _GLIBCXX_USE_NOEXCEPTnoexcept { return __LDBL_DENORM_MIN__3.64519953188247460253e-4951L; } |
1870 | |
1871 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_iec559 |
1872 | = has_infinity && has_quiet_NaN && has_denorm == denorm_present; |
1873 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_bounded = true; |
1874 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool is_modulo = false; |
1875 | |
1876 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool traps = __glibcxx_long_double_traps; |
1877 | static _GLIBCXX_USE_CONSTEXPRconstexpr bool tinyness_before = |
1878 | __glibcxx_long_double_tinyness_before; |
1879 | static _GLIBCXX_USE_CONSTEXPRconstexpr float_round_style round_style = |
1880 | round_to_nearest; |
1881 | }; |
1882 | |
1883 | #undef __glibcxx_long_double_has_denorm_loss |
1884 | #undef __glibcxx_long_double_traps |
1885 | #undef __glibcxx_long_double_tinyness_before |
1886 | |
1887 | _GLIBCXX_END_NAMESPACE_VERSION |
1888 | } // namespace |
1889 | |
1890 | #undef __glibcxx_signed |
1891 | #undef __glibcxx_min |
1892 | #undef __glibcxx_max |
1893 | #undef __glibcxx_digits |
1894 | #undef __glibcxx_digits10 |
1895 | #undef __glibcxx_max_digits10 |
1896 | |
1897 | #endif // _GLIBCXX_NUMERIC_LIMITS |