BasicBranching.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function foo() {}
  6. var all = [ undefined, null,
  7. true, false, new Boolean(true), new Boolean(false),
  8. NaN, +0, -0, 0, 1, 10.0, 10.1, -1, -5, 5,
  9. 124, 248, 654, 987, -1026, +98768.2546, -88754.15478,
  10. 1<<32, -(1<<32), (1<<32)-1, 1<<31, -(1<<31), 1<<25, -1<<25,
  11. Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY,
  12. new Number(NaN), new Number(+0), new Number( -0), new Number(0), new Number(1),
  13. new Number(10.0), new Number(10.1),
  14. new Number(Number.MAX_VALUE), new Number(Number.MIN_VALUE), new Number(Number.NaN),
  15. new Number(Number.POSITIVE_INFINITY), new Number(Number.NEGATIVE_INFINITY),
  16. "", "hello", "hel" + "lo", "+0", "-0", "0", "1", "10.0", "10.1",
  17. new String(""), new String("hello"), new String("he" + "llo"),
  18. new Object(), [1,2,3], new Object(), [1,2,3] , foo
  19. ];
  20. function AsmModule(stdlib) {
  21. "use asm";
  22. var fround = stdlib.Math.fround;
  23. function brInt(x,y) {
  24. x = x|0;
  25. y = y|0;
  26. var i = 0;
  27. if( (y|0) < 0 & (x|0) < 0){
  28. i = 1;
  29. }
  30. else {
  31. if((x|0)>0 | (y|0)>0){
  32. i = 2;
  33. }
  34. else{
  35. i = 3;
  36. }
  37. }
  38. return (i)|0;
  39. }
  40. function brDouble(x,y) {
  41. x = +x;
  42. y = +y;
  43. var i = 0;
  44. if(y<0.0 & x<0.0){
  45. i = 1;
  46. }
  47. else {
  48. if(x>0.0 | y>0.0){
  49. i = 2;
  50. }
  51. else{
  52. i = 3;
  53. }
  54. }
  55. return (i)|0;
  56. }
  57. function brFloat(x,y) {
  58. x = fround(x);
  59. y = fround(y);
  60. var i = 0;
  61. if(y<fround(0.0) & x<fround(0.0)){
  62. i = 1;
  63. }
  64. else {
  65. if(x>fround(0.0) | y>fround(0.0)){
  66. i = 2;
  67. }
  68. else{
  69. i = 3;
  70. }
  71. }
  72. return (i)|0;
  73. }
  74. function brMix(x,y) {
  75. x = x|0;
  76. y = +y;
  77. var i = 0;
  78. if((x|0)>0){
  79. if(y>0.0){
  80. i = 1;
  81. } else {
  82. if(y==0.0){
  83. i = 2;
  84. } else {
  85. i = 3;
  86. }
  87. }
  88. return i|0;
  89. }
  90. else {
  91. if((x|0)==0){
  92. if(y>0.0){
  93. i = 4;
  94. } else {
  95. if(y==0.0){
  96. i = 5;
  97. } else {
  98. i = 6;
  99. }
  100. }
  101. } else { // x < 0
  102. if(y>0.0){
  103. i = 7;
  104. } else {
  105. if(y==0.0){
  106. i = 8;
  107. } else {
  108. i = 9;
  109. }
  110. }
  111. }
  112. return i|0;
  113. }
  114. return (i)|0;
  115. }
  116. return {
  117. brInt : brInt,
  118. brDouble: brDouble,
  119. brFloat : brFloat,
  120. brMix : brMix
  121. };
  122. }
  123. var asmModule = AsmModule({Math:Math});
  124. for (var i=0; i<all.length; ++i) {
  125. print("t1 +a["+i+"](" + all[i] +") = " + (asmModule.brInt (all[i])));
  126. print("t2 +a["+i+"](" + all[i] +") = " + (asmModule.brDouble(all[i])));
  127. print("t2 +a["+i+"](" + all[i] +") = " + (asmModule.brFloat(all[i])));
  128. print("t3 +a["+i+"](" + all[i] +") = " + (asmModule.brMix (all[i])));
  129. }
  130. for (var i=0; i<all.length; ++i) {
  131. for (var j=0; j<all.length; ++j) {
  132. print("t1 a["+i+"](" + all[i] +") , a["+j+"]("+all[j]+") = " + (asmModule.brInt (all[i],all[j])));
  133. print("t2 a["+i+"](" + all[i] +") , a["+j+"]("+all[j]+") = " + (asmModule.brDouble(all[i],all[j])));
  134. print("t2 a["+i+"](" + all[i] +") , a["+j+"]("+all[j]+") = " + (asmModule.brFloat (all[i],all[j])));
  135. print("t3 a["+i+"](" + all[i] +") , a["+j+"]("+all[j]+") = " + (asmModule.brMix (all[i],all[j])));
  136. }
  137. }