11
11
namespace Slang
12
12
{
13
13
14
+ static const char * kHLSLBuiltInPrelude64BitCast = R"(
15
+ uint64_t _slang_asuint64(double x)
16
+ {
17
+ uint32_t low;
18
+ uint32_t high;
19
+ asuint(x, low, high);
20
+ return ((uint64_t)high << 32) | low;
21
+ }
22
+
23
+ double _slang_asdouble(uint64_t x)
24
+ {
25
+ uint32_t low = x & 0xFFFFFFFF;
26
+ uint32_t high = x >> 32;
27
+ return asdouble(low, high);
28
+ }
29
+ )" ;
30
+
14
31
void HLSLSourceEmitter::_emitHLSLDecorationSingleString (
15
32
const char * name,
16
33
IRFunc* entryPoint,
@@ -822,17 +839,12 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
822
839
//
823
840
// There is no current function (it seems)
824
841
// for bit-casting an `int16_t` to a `half`.
825
- //
826
- // TODO: There is an `asdouble` function
827
- // for converting two 32-bit integer values into
828
- // one `double`. We could use that for
829
- // bit casts of 64-bit values with a bit of
830
- // extra work, but doing so might be best
831
- // handled in an IR pass that legalizes
832
- // bit-casts.
833
- //
834
842
m_writer->emit (" asfloat" );
835
843
break ;
844
+ case BaseType::Double:
845
+ ensurePrelude (kHLSLBuiltInPrelude64BitCast );
846
+ m_writer->emit (" _slang_asdouble" );
847
+ break ;
836
848
}
837
849
m_writer->emit (" (" );
838
850
int closeCount = 1 ;
@@ -844,6 +856,8 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
844
856
diagnoseUnhandledInst (inst);
845
857
break ;
846
858
859
+ case BaseType::Int64:
860
+ case BaseType::UInt64 :
847
861
case BaseType::UInt:
848
862
case BaseType::Int:
849
863
case BaseType::Bool:
@@ -860,6 +874,11 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
860
874
m_writer->emit (" asuint16(" );
861
875
closeCount++;
862
876
break ;
877
+ case BaseType::Double:
878
+ ensurePrelude (kHLSLBuiltInPrelude64BitCast );
879
+ m_writer->emit (" _slang_asuint64(" );
880
+ closeCount++;
881
+ break ;
863
882
}
864
883
865
884
emitOperand (inst->getOperand (0 ), getInfo (EmitOp::General));
0 commit comments