float.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/builtins/float.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/builtins/float.carbon
  10. fn Negate(a: f64) -> f64 = "float.negate";
  11. fn TestNegate(a: f64) -> f64 { return Negate(a); }
  12. fn Add(a: f64, b: f64) -> f64 = "float.add";
  13. fn TestAdd(a: f64, b: f64) -> f64 { return Add(a, b); }
  14. fn Sub(a: f64, b: f64) -> f64 = "float.sub";
  15. fn TestSub(a: f64, b: f64) -> f64 { return Sub(a, b); }
  16. fn Mul(a: f64, b: f64) -> f64 = "float.mul";
  17. fn TestMul(a: f64, b: f64) -> f64 { return Mul(a, b); }
  18. fn Div(a: f64, b: f64) -> f64 = "float.div";
  19. fn TestDiv(a: f64, b: f64) -> f64 { return Div(a, b); }
  20. fn Eq(a: f64, b: f64) -> bool = "float.eq";
  21. fn TestEq(a: f64, b: f64) -> bool { return Eq(a, b); }
  22. fn Neq(a: f64, b: f64) -> bool = "float.neq";
  23. fn TestNeq(a: f64, b: f64) -> bool { return Neq(a, b); }
  24. fn Less(a: f64, b: f64) -> bool = "float.less";
  25. fn TestLess(a: f64, b: f64) -> bool { return Less(a, b); }
  26. fn LessEq(a: f64, b: f64) -> bool = "float.less_eq";
  27. fn TestLessEq(a: f64, b: f64) -> bool { return LessEq(a, b); }
  28. fn Greater(a: f64, b: f64) -> bool = "float.greater";
  29. fn TestGreater(a: f64, b: f64) -> bool { return Greater(a, b); }
  30. fn GreaterEq(a: f64, b: f64) -> bool = "float.greater_eq";
  31. fn TestGreaterEq(a: f64, b: f64) -> bool { return GreaterEq(a, b); }
  32. // CHECK:STDOUT: ; ModuleID = 'float.carbon'
  33. // CHECK:STDOUT: source_filename = "float.carbon"
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: define double @_CTestNegate.Main(double %a) !dbg !4 {
  36. // CHECK:STDOUT: entry:
  37. // CHECK:STDOUT: %float.negate = fneg double %a, !dbg !7
  38. // CHECK:STDOUT: ret double %float.negate, !dbg !8
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: define double @_CTestAdd.Main(double %a, double %b) !dbg !9 {
  42. // CHECK:STDOUT: entry:
  43. // CHECK:STDOUT: %float.add = fadd double %a, %b, !dbg !10
  44. // CHECK:STDOUT: ret double %float.add, !dbg !11
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: define double @_CTestSub.Main(double %a, double %b) !dbg !12 {
  48. // CHECK:STDOUT: entry:
  49. // CHECK:STDOUT: %float.sub = fsub double %a, %b, !dbg !13
  50. // CHECK:STDOUT: ret double %float.sub, !dbg !14
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: define double @_CTestMul.Main(double %a, double %b) !dbg !15 {
  54. // CHECK:STDOUT: entry:
  55. // CHECK:STDOUT: %float.mul = fmul double %a, %b, !dbg !16
  56. // CHECK:STDOUT: ret double %float.mul, !dbg !17
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: define double @_CTestDiv.Main(double %a, double %b) !dbg !18 {
  60. // CHECK:STDOUT: entry:
  61. // CHECK:STDOUT: %float.div = fdiv double %a, %b, !dbg !19
  62. // CHECK:STDOUT: ret double %float.div, !dbg !20
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: define i1 @_CTestEq.Main(double %a, double %b) !dbg !21 {
  66. // CHECK:STDOUT: entry:
  67. // CHECK:STDOUT: %float.eq = fcmp oeq double %a, %b, !dbg !22
  68. // CHECK:STDOUT: ret i1 %float.eq, !dbg !23
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: define i1 @_CTestNeq.Main(double %a, double %b) !dbg !24 {
  72. // CHECK:STDOUT: entry:
  73. // CHECK:STDOUT: %float.neq = fcmp one double %a, %b, !dbg !25
  74. // CHECK:STDOUT: ret i1 %float.neq, !dbg !26
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: define i1 @_CTestLess.Main(double %a, double %b) !dbg !27 {
  78. // CHECK:STDOUT: entry:
  79. // CHECK:STDOUT: %float.less = fcmp olt double %a, %b, !dbg !28
  80. // CHECK:STDOUT: ret i1 %float.less, !dbg !29
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: define i1 @_CTestLessEq.Main(double %a, double %b) !dbg !30 {
  84. // CHECK:STDOUT: entry:
  85. // CHECK:STDOUT: %float.less_eq = fcmp ole double %a, %b, !dbg !31
  86. // CHECK:STDOUT: ret i1 %float.less_eq, !dbg !32
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: define i1 @_CTestGreater.Main(double %a, double %b) !dbg !33 {
  90. // CHECK:STDOUT: entry:
  91. // CHECK:STDOUT: %float.greater = fcmp ogt double %a, %b, !dbg !34
  92. // CHECK:STDOUT: ret i1 %float.greater, !dbg !35
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: define i1 @_CTestGreaterEq.Main(double %a, double %b) !dbg !36 {
  96. // CHECK:STDOUT: entry:
  97. // CHECK:STDOUT: %float.greater_eq = fcmp oge double %a, %b, !dbg !37
  98. // CHECK:STDOUT: ret i1 %float.greater_eq, !dbg !38
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  102. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  105. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  106. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  107. // CHECK:STDOUT: !3 = !DIFile(filename: "float.carbon", directory: "")
  108. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "TestNegate", linkageName: "_CTestNegate.Main", scope: null, file: !3, line: 12, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  109. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  110. // CHECK:STDOUT: !6 = !{}
  111. // CHECK:STDOUT: !7 = !DILocation(line: 12, column: 39, scope: !4)
  112. // CHECK:STDOUT: !8 = !DILocation(line: 12, column: 32, scope: !4)
  113. // CHECK:STDOUT: !9 = distinct !DISubprogram(name: "TestAdd", linkageName: "_CTestAdd.Main", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  114. // CHECK:STDOUT: !10 = !DILocation(line: 15, column: 44, scope: !9)
  115. // CHECK:STDOUT: !11 = !DILocation(line: 15, column: 37, scope: !9)
  116. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "TestSub", linkageName: "_CTestSub.Main", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  117. // CHECK:STDOUT: !13 = !DILocation(line: 18, column: 44, scope: !12)
  118. // CHECK:STDOUT: !14 = !DILocation(line: 18, column: 37, scope: !12)
  119. // CHECK:STDOUT: !15 = distinct !DISubprogram(name: "TestMul", linkageName: "_CTestMul.Main", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  120. // CHECK:STDOUT: !16 = !DILocation(line: 21, column: 44, scope: !15)
  121. // CHECK:STDOUT: !17 = !DILocation(line: 21, column: 37, scope: !15)
  122. // CHECK:STDOUT: !18 = distinct !DISubprogram(name: "TestDiv", linkageName: "_CTestDiv.Main", scope: null, file: !3, line: 24, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  123. // CHECK:STDOUT: !19 = !DILocation(line: 24, column: 44, scope: !18)
  124. // CHECK:STDOUT: !20 = !DILocation(line: 24, column: 37, scope: !18)
  125. // CHECK:STDOUT: !21 = distinct !DISubprogram(name: "TestEq", linkageName: "_CTestEq.Main", scope: null, file: !3, line: 27, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  126. // CHECK:STDOUT: !22 = !DILocation(line: 27, column: 44, scope: !21)
  127. // CHECK:STDOUT: !23 = !DILocation(line: 27, column: 37, scope: !21)
  128. // CHECK:STDOUT: !24 = distinct !DISubprogram(name: "TestNeq", linkageName: "_CTestNeq.Main", scope: null, file: !3, line: 30, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  129. // CHECK:STDOUT: !25 = !DILocation(line: 30, column: 45, scope: !24)
  130. // CHECK:STDOUT: !26 = !DILocation(line: 30, column: 38, scope: !24)
  131. // CHECK:STDOUT: !27 = distinct !DISubprogram(name: "TestLess", linkageName: "_CTestLess.Main", scope: null, file: !3, line: 33, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  132. // CHECK:STDOUT: !28 = !DILocation(line: 33, column: 46, scope: !27)
  133. // CHECK:STDOUT: !29 = !DILocation(line: 33, column: 39, scope: !27)
  134. // CHECK:STDOUT: !30 = distinct !DISubprogram(name: "TestLessEq", linkageName: "_CTestLessEq.Main", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  135. // CHECK:STDOUT: !31 = !DILocation(line: 36, column: 48, scope: !30)
  136. // CHECK:STDOUT: !32 = !DILocation(line: 36, column: 41, scope: !30)
  137. // CHECK:STDOUT: !33 = distinct !DISubprogram(name: "TestGreater", linkageName: "_CTestGreater.Main", scope: null, file: !3, line: 39, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  138. // CHECK:STDOUT: !34 = !DILocation(line: 39, column: 49, scope: !33)
  139. // CHECK:STDOUT: !35 = !DILocation(line: 39, column: 42, scope: !33)
  140. // CHECK:STDOUT: !36 = distinct !DISubprogram(name: "TestGreaterEq", linkageName: "_CTestGreaterEq.Main", scope: null, file: !3, line: 42, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  141. // CHECK:STDOUT: !37 = !DILocation(line: 42, column: 51, scope: !36)
  142. // CHECK:STDOUT: !38 = !DILocation(line: 42, column: 44, scope: !36)