basicComparisonUInt.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 AsmModuleUInt() {
  21. "use asm";
  22. function LtUInt(x,y) {
  23. x = x|0;
  24. y = y|0;
  25. return ((x>>>0)<(y>>>0))|0;
  26. }
  27. function LeUInt(x,y) {
  28. x = x|0;
  29. y = y|0;
  30. return ((x>>>0)<=(y>>>0))|0;
  31. }
  32. function GtUInt(x,y) {
  33. x = x|0;
  34. y = y|0;
  35. return ((x>>>0)>(y>>>0))|0;
  36. }
  37. function GeUInt(x,y) {
  38. x = x|0;
  39. y = y|0;
  40. return ((x>>>0)>=(y>>>0))|0;
  41. }
  42. function EqUInt(x,y) {
  43. x = x|0;
  44. y = y|0;
  45. return ((x>>>0)==(y>>>0))|0;
  46. }
  47. function NeUInt(x,y) {
  48. x = x|0;
  49. y = y|0;
  50. return ((x>>>0)!=(y>>>0))|0;
  51. }
  52. return {
  53. Lt : LtUInt
  54. ,Le : LeUInt
  55. ,Gt : GtUInt
  56. ,Ge : GeUInt
  57. ,Eq : EqUInt
  58. ,Ne : NeUInt
  59. };
  60. }
  61. var asmModuleUInt = AsmModuleUInt(); // produces AOT-compiled version
  62. print("Comparison for unsigned ints");
  63. for (var i=0; i<all.length; ++i) {
  64. for (var j=0; j<all.length; ++j) {
  65. print("ui a["+i+"](" + all[i] +") < a["+j+"]("+all[j]+") = " + (asmModuleUInt.Lt(all[i],all[j])));
  66. print("ui a["+i+"](" + all[i] +") <= a["+j+"]("+all[j]+") = " + (asmModuleUInt.Le(all[i],all[j])));
  67. print("ui a["+i+"](" + all[i] +") > a["+j+"]("+all[j]+") = " + (asmModuleUInt.Gt(all[i],all[j])));
  68. print("ui a["+i+"](" + all[i] +") >= a["+j+"]("+all[j]+") = " + (asmModuleUInt.Ge(all[i],all[j])));
  69. print("ui a["+i+"](" + all[i] +") == a["+j+"]("+all[j]+") = " + (asmModuleUInt.Eq(all[i],all[j])));
  70. print("ui a["+i+"](" + all[i] +") != a["+j+"]("+all[j]+") = " + (asmModuleUInt.Ne(all[i],all[j])));
  71. }
  72. }