switchBinaryTraverse.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 AsmModuleSwitch() {
  6. "use asm";
  7. function fib(x) {
  8. // we multiply all the cases by 100 so that the
  9. // switch is sparse and doesn't generate a jump table
  10. x = x|0;
  11. switch(x|0) {
  12. case 000: return 1;
  13. case 100: return 1;
  14. case 200: return 2;
  15. case 300: return 3;
  16. case 400: return 5;
  17. case 500: return 8;
  18. case 600: return 13;
  19. case 700: return 21;
  20. case 800: return 34;
  21. case 900: return 55;
  22. }
  23. return -1;
  24. }
  25. return {
  26. fib: fib
  27. };
  28. }
  29. var asmModuleSwitch = AsmModuleSwitch();
  30. WScript.Echo(asmModuleSwitch.fib(000));
  31. WScript.Echo(asmModuleSwitch.fib(100));
  32. WScript.Echo(asmModuleSwitch.fib(200));
  33. WScript.Echo(asmModuleSwitch.fib(300));
  34. WScript.Echo(asmModuleSwitch.fib(400));
  35. WScript.Echo(asmModuleSwitch.fib(500));
  36. WScript.Echo(asmModuleSwitch.fib(600));