@@ -58,8 +58,15 @@ void SPIRVInstPrinter::printOpConstantVarOps(const MCInst *MI,
5858
5959 O << ' ' ;
6060
61+ uint64_t Imm = MI->getOperand (StartIndex).getImm ();
62+
63+ // Handle 64 bit literals.
64+ if (NumVarOps == 2 ) {
65+ Imm |= (MI->getOperand (StartIndex + 1 ).getImm () << 32 );
66+ }
67+
6168 // Handle arbitrary number of 32-bit words for integer literals
62- if (Opcode == SPIRV::OpConstantI) {
69+ if (Opcode == SPIRV::OpConstantI && NumVarOps > 2 ) {
6370 const unsigned TotalBits = NumVarOps * 32 ;
6471 APInt Val (TotalBits, 0 );
6572 for (unsigned i = 0 ; i < NumVarOps; ++i) {
@@ -70,41 +77,35 @@ void SPIRVInstPrinter::printOpConstantVarOps(const MCInst *MI,
7077 return ;
7178 }
7279
73- // Handle float constants (OpConstantF)
74- uint64_t Imm = MI->getOperand (StartIndex).getImm ();
75- if (NumVarOps == 2 ) {
76- Imm |= (MI->getOperand (StartIndex + 1 ).getImm ()) << 32 ;
77- }
80+ // Format and print float values.
81+ if (MI->getOpcode () == SPIRV::OpConstantF && IsBitwidth16 == 0 ) {
82+ APFloat FP = NumVarOps == 1 ? APFloat (APInt (32 , Imm).bitsToFloat ())
83+ : APFloat (APInt (64 , Imm).bitsToDouble ());
84+
85+ // Print infinity and NaN as hex floats.
86+ // TODO: Make sure subnormal numbers are handled correctly as they may also
87+ // require hex float notation.
88+ if (FP.isInfinity ()) {
89+ if (FP.isNegative ())
90+ O << ' -' ;
91+ O << " 0x1p+128" ;
92+ return ;
93+ }
94+ if (FP.isNaN ()) {
95+ O << " 0x1.8p+128" ;
96+ return ;
97+ }
7898
79- // For 16-bit floats, print as integer
80- if (IsBitwidth16) {
81- O << Imm;
82- return ;
83- }
99+ // Format val as a decimal floating point or scientific notation (whichever
100+ // is shorter), with enough digits of precision to produce the exact value.
101+ O << format (" %.*g" , std::numeric_limits<double >::max_digits10,
102+ FP.convertToDouble ());
84103
85- // Format and print float values
86- APFloat FP = NumVarOps == 1 ? APFloat (APInt (32 , Imm).bitsToFloat ())
87- : APFloat (APInt (64 , Imm).bitsToDouble ());
88-
89- // Print infinity and NaN as hex floats.
90- // TODO: Make sure subnormal numbers are handled correctly as they may also
91- // require hex float notation.
92- if (FP.isInfinity ()) {
93- if (FP.isNegative ())
94- O << ' -' ;
95- O << " 0x1p+128" ;
96- return ;
97- }
98-
99- if (FP.isNaN ()) {
100- O << " 0x1.8p+128" ;
101104 return ;
102105 }
103106
104- // Format val as a decimal floating point or scientific notation (whichever
105- // is shorter), with enough digits of precision to produce the exact value.
106- O << format (" %.*g" , std::numeric_limits<double >::max_digits10,
107- FP.convertToDouble ());
107+ // Print integer values directly.
108+ O << Imm;
108109}
109110
110111void SPIRVInstPrinter::recordOpExtInstImport (const MCInst *MI) {
0 commit comments