Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(770)

Side by Side Diff: src/runtime.cc

Issue 652041: IA32: Native access to TranscendentalCache for sin/cos. (Closed)
Patch Set: Updated to head. Removed dead code. Ignore first patch. Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4620 matching lines...) Expand 10 before | Expand all | Expand 10 after
4631 // x is (non-trivial) prefix of y: 4631 // x is (non-trivial) prefix of y:
4632 if (bufy.has_more()) return Smi::FromInt(LESS); 4632 if (bufy.has_more()) return Smi::FromInt(LESS);
4633 // y is prefix of x: 4633 // y is prefix of x:
4634 return Smi::FromInt(bufx.has_more() ? GREATER : EQUAL); 4634 return Smi::FromInt(bufx.has_more() ? GREATER : EQUAL);
4635 } 4635 }
4636 4636
4637 4637
4638 static Object* Runtime_Math_abs(Arguments args) { 4638 static Object* Runtime_Math_abs(Arguments args) {
4639 NoHandleAllocation ha; 4639 NoHandleAllocation ha;
4640 ASSERT(args.length() == 1); 4640 ASSERT(args.length() == 1);
4641 Counters::math_abs.Increment();
4641 4642
4642 CONVERT_DOUBLE_CHECKED(x, args[0]); 4643 CONVERT_DOUBLE_CHECKED(x, args[0]);
4643 return Heap::AllocateHeapNumber(fabs(x)); 4644 return Heap::AllocateHeapNumber(fabs(x));
4644 } 4645 }
4645 4646
4646 4647
4647 static Object* Runtime_Math_acos(Arguments args) { 4648 static Object* Runtime_Math_acos(Arguments args) {
4648 NoHandleAllocation ha; 4649 NoHandleAllocation ha;
4649 ASSERT(args.length() == 1); 4650 ASSERT(args.length() == 1);
4651 Counters::math_acos.Increment();
4650 4652
4651 CONVERT_DOUBLE_CHECKED(x, args[0]); 4653 CONVERT_DOUBLE_CHECKED(x, args[0]);
4652 return TranscendentalCache::Get(TranscendentalCache::ACOS, x); 4654 return TranscendentalCache::Get(TranscendentalCache::ACOS, x);
4653 } 4655 }
4654 4656
4655 4657
4656 static Object* Runtime_Math_asin(Arguments args) { 4658 static Object* Runtime_Math_asin(Arguments args) {
4657 NoHandleAllocation ha; 4659 NoHandleAllocation ha;
4658 ASSERT(args.length() == 1); 4660 ASSERT(args.length() == 1);
4661 Counters::math_asin.Increment();
4659 4662
4660 CONVERT_DOUBLE_CHECKED(x, args[0]); 4663 CONVERT_DOUBLE_CHECKED(x, args[0]);
4661 return TranscendentalCache::Get(TranscendentalCache::ASIN, x); 4664 return TranscendentalCache::Get(TranscendentalCache::ASIN, x);
4662 } 4665 }
4663 4666
4664 4667
4665 static Object* Runtime_Math_atan(Arguments args) { 4668 static Object* Runtime_Math_atan(Arguments args) {
4666 NoHandleAllocation ha; 4669 NoHandleAllocation ha;
4667 ASSERT(args.length() == 1); 4670 ASSERT(args.length() == 1);
4671 Counters::math_atan.Increment();
4668 4672
4669 CONVERT_DOUBLE_CHECKED(x, args[0]); 4673 CONVERT_DOUBLE_CHECKED(x, args[0]);
4670 return TranscendentalCache::Get(TranscendentalCache::ATAN, x); 4674 return TranscendentalCache::Get(TranscendentalCache::ATAN, x);
4671 } 4675 }
4672 4676
4673 4677
4674 static Object* Runtime_Math_atan2(Arguments args) { 4678 static Object* Runtime_Math_atan2(Arguments args) {
4675 NoHandleAllocation ha; 4679 NoHandleAllocation ha;
4676 ASSERT(args.length() == 2); 4680 ASSERT(args.length() == 2);
4681 Counters::math_atan2.Increment();
4677 4682
4678 CONVERT_DOUBLE_CHECKED(x, args[0]); 4683 CONVERT_DOUBLE_CHECKED(x, args[0]);
4679 CONVERT_DOUBLE_CHECKED(y, args[1]); 4684 CONVERT_DOUBLE_CHECKED(y, args[1]);
4680 double result; 4685 double result;
4681 if (isinf(x) && isinf(y)) { 4686 if (isinf(x) && isinf(y)) {
4682 // Make sure that the result in case of two infinite arguments 4687 // Make sure that the result in case of two infinite arguments
4683 // is a multiple of Pi / 4. The sign of the result is determined 4688 // is a multiple of Pi / 4. The sign of the result is determined
4684 // by the first argument (x) and the sign of the second argument 4689 // by the first argument (x) and the sign of the second argument
4685 // determines the multiplier: one or three. 4690 // determines the multiplier: one or three.
4686 static double kPiDividedBy4 = 0.78539816339744830962; 4691 static double kPiDividedBy4 = 0.78539816339744830962;
4687 int multiplier = (x < 0) ? -1 : 1; 4692 int multiplier = (x < 0) ? -1 : 1;
4688 if (y < 0) multiplier *= 3; 4693 if (y < 0) multiplier *= 3;
4689 result = multiplier * kPiDividedBy4; 4694 result = multiplier * kPiDividedBy4;
4690 } else { 4695 } else {
4691 result = atan2(x, y); 4696 result = atan2(x, y);
4692 } 4697 }
4693 return Heap::AllocateHeapNumber(result); 4698 return Heap::AllocateHeapNumber(result);
4694 } 4699 }
4695 4700
4696 4701
4697 static Object* Runtime_Math_ceil(Arguments args) { 4702 static Object* Runtime_Math_ceil(Arguments args) {
4698 NoHandleAllocation ha; 4703 NoHandleAllocation ha;
4699 ASSERT(args.length() == 1); 4704 ASSERT(args.length() == 1);
4705 Counters::math_ceil.Increment();
4700 4706
4701 CONVERT_DOUBLE_CHECKED(x, args[0]); 4707 CONVERT_DOUBLE_CHECKED(x, args[0]);
4702 return Heap::NumberFromDouble(ceiling(x)); 4708 return Heap::NumberFromDouble(ceiling(x));
4703 } 4709 }
4704 4710
4705 4711
4706 static Object* Runtime_Math_cos(Arguments args) { 4712 static Object* Runtime_Math_cos(Arguments args) {
4707 NoHandleAllocation ha; 4713 NoHandleAllocation ha;
4708 ASSERT(args.length() == 1); 4714 ASSERT(args.length() == 1);
4715 Counters::math_cos.Increment();
4709 4716
4710 CONVERT_DOUBLE_CHECKED(x, args[0]); 4717 CONVERT_DOUBLE_CHECKED(x, args[0]);
4711 return TranscendentalCache::Get(TranscendentalCache::COS, x); 4718 return TranscendentalCache::Get(TranscendentalCache::COS, x);
4712 } 4719 }
4713 4720
4714 4721
4715 static Object* Runtime_Math_exp(Arguments args) { 4722 static Object* Runtime_Math_exp(Arguments args) {
4716 NoHandleAllocation ha; 4723 NoHandleAllocation ha;
4717 ASSERT(args.length() == 1); 4724 ASSERT(args.length() == 1);
4725 Counters::math_exp.Increment();
4718 4726
4719 CONVERT_DOUBLE_CHECKED(x, args[0]); 4727 CONVERT_DOUBLE_CHECKED(x, args[0]);
4720 return TranscendentalCache::Get(TranscendentalCache::EXP, x); 4728 return TranscendentalCache::Get(TranscendentalCache::EXP, x);
4721 } 4729 }
4722 4730
4723 4731
4724 static Object* Runtime_Math_floor(Arguments args) { 4732 static Object* Runtime_Math_floor(Arguments args) {
4725 NoHandleAllocation ha; 4733 NoHandleAllocation ha;
4726 ASSERT(args.length() == 1); 4734 ASSERT(args.length() == 1);
4735 Counters::math_floor.Increment();
4727 4736
4728 CONVERT_DOUBLE_CHECKED(x, args[0]); 4737 CONVERT_DOUBLE_CHECKED(x, args[0]);
4729 return Heap::NumberFromDouble(floor(x)); 4738 return Heap::NumberFromDouble(floor(x));
4730 } 4739 }
4731 4740
4732 4741
4733 static Object* Runtime_Math_log(Arguments args) { 4742 static Object* Runtime_Math_log(Arguments args) {
4734 NoHandleAllocation ha; 4743 NoHandleAllocation ha;
4735 ASSERT(args.length() == 1); 4744 ASSERT(args.length() == 1);
4745 Counters::math_log.Increment();
4736 4746
4737 CONVERT_DOUBLE_CHECKED(x, args[0]); 4747 CONVERT_DOUBLE_CHECKED(x, args[0]);
4738 return TranscendentalCache::Get(TranscendentalCache::LOG, x); 4748 return TranscendentalCache::Get(TranscendentalCache::LOG, x);
4739 } 4749 }
4740 4750
4741 4751
4742 // Helper function to compute x^y, where y is known to be an 4752 // Helper function to compute x^y, where y is known to be an
4743 // integer. Uses binary decomposition to limit the number of 4753 // integer. Uses binary decomposition to limit the number of
4744 // multiplications; see the discussion in "Hacker's Delight" by Henry 4754 // multiplications; see the discussion in "Hacker's Delight" by Henry
4745 // S. Warren, Jr., figure 11-6, page 213. 4755 // S. Warren, Jr., figure 11-6, page 213.
(...skipping 20 matching lines...) Expand all
4766 } 4776 }
4767 } 4777 }
4768 m *= m; 4778 m *= m;
4769 } 4779 }
4770 } 4780 }
4771 4781
4772 4782
4773 static Object* Runtime_Math_pow(Arguments args) { 4783 static Object* Runtime_Math_pow(Arguments args) {
4774 NoHandleAllocation ha; 4784 NoHandleAllocation ha;
4775 ASSERT(args.length() == 2); 4785 ASSERT(args.length() == 2);
4786 Counters::math_pow.Increment();
4776 4787
4777 CONVERT_DOUBLE_CHECKED(x, args[0]); 4788 CONVERT_DOUBLE_CHECKED(x, args[0]);
4778 4789
4779 // If the second argument is a smi, it is much faster to call the 4790 // If the second argument is a smi, it is much faster to call the
4780 // custom powi() function than the generic pow(). 4791 // custom powi() function than the generic pow().
4781 if (args[1]->IsSmi()) { 4792 if (args[1]->IsSmi()) {
4782 int y = Smi::cast(args[1])->value(); 4793 int y = Smi::cast(args[1])->value();
4783 return Heap::AllocateHeapNumber(powi(x, y)); 4794 return Heap::AllocateHeapNumber(powi(x, y));
4784 } 4795 }
4785 4796
(...skipping 18 matching lines...) Expand all
4804 return Heap::nan_value(); 4815 return Heap::nan_value();
4805 } else { 4816 } else {
4806 return Heap::AllocateHeapNumber(pow(x, y)); 4817 return Heap::AllocateHeapNumber(pow(x, y));
4807 } 4818 }
4808 } 4819 }
4809 4820
4810 4821
4811 static Object* Runtime_Math_round(Arguments args) { 4822 static Object* Runtime_Math_round(Arguments args) {
4812 NoHandleAllocation ha; 4823 NoHandleAllocation ha;
4813 ASSERT(args.length() == 1); 4824 ASSERT(args.length() == 1);
4825 Counters::math_round.Increment();
4814 4826
4815 CONVERT_DOUBLE_CHECKED(x, args[0]); 4827 CONVERT_DOUBLE_CHECKED(x, args[0]);
4816 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value(); 4828 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value();
4817 double integer = ceil(x); 4829 double integer = ceil(x);
4818 if (integer - x > 0.5) { integer -= 1.0; } 4830 if (integer - x > 0.5) { integer -= 1.0; }
4819 return Heap::NumberFromDouble(integer); 4831 return Heap::NumberFromDouble(integer);
4820 } 4832 }
4821 4833
4822 4834
4823 static Object* Runtime_Math_sin(Arguments args) { 4835 static Object* Runtime_Math_sin(Arguments args) {
4824 NoHandleAllocation ha; 4836 NoHandleAllocation ha;
4825 ASSERT(args.length() == 1); 4837 ASSERT(args.length() == 1);
4838 Counters::math_sin.Increment();
4826 4839
4827 CONVERT_DOUBLE_CHECKED(x, args[0]); 4840 CONVERT_DOUBLE_CHECKED(x, args[0]);
4828 return TranscendentalCache::Get(TranscendentalCache::SIN, x); 4841 return TranscendentalCache::Get(TranscendentalCache::SIN, x);
4829 } 4842 }
4830 4843
4831 4844
4832 static Object* Runtime_Math_sqrt(Arguments args) { 4845 static Object* Runtime_Math_sqrt(Arguments args) {
4833 NoHandleAllocation ha; 4846 NoHandleAllocation ha;
4834 ASSERT(args.length() == 1); 4847 ASSERT(args.length() == 1);
4848 Counters::math_sqrt.Increment();
4835 4849
4836 CONVERT_DOUBLE_CHECKED(x, args[0]); 4850 CONVERT_DOUBLE_CHECKED(x, args[0]);
4837 return Heap::AllocateHeapNumber(sqrt(x)); 4851 return Heap::AllocateHeapNumber(sqrt(x));
4838 } 4852 }
4839 4853
4840 4854
4841 static Object* Runtime_Math_tan(Arguments args) { 4855 static Object* Runtime_Math_tan(Arguments args) {
4842 NoHandleAllocation ha; 4856 NoHandleAllocation ha;
4843 ASSERT(args.length() == 1); 4857 ASSERT(args.length() == 1);
4858 Counters::math_tan.Increment();
4844 4859
4845 CONVERT_DOUBLE_CHECKED(x, args[0]); 4860 CONVERT_DOUBLE_CHECKED(x, args[0]);
4846 return TranscendentalCache::Get(TranscendentalCache::TAN, x); 4861 return TranscendentalCache::Get(TranscendentalCache::TAN, x);
4847 } 4862 }
4848 4863
4849 4864
4850 static Object* Runtime_NewArgumentsFast(Arguments args) { 4865 static Object* Runtime_NewArgumentsFast(Arguments args) {
4851 NoHandleAllocation ha; 4866 NoHandleAllocation ha;
4852 ASSERT(args.length() == 3); 4867 ASSERT(args.length() == 3);
4853 4868
(...skipping 3410 matching lines...) Expand 10 before | Expand all | Expand 10 after
8264 } else { 8279 } else {
8265 // Handle last resort GC and make sure to allow future allocations 8280 // Handle last resort GC and make sure to allow future allocations
8266 // to grow the heap without causing GCs (if possible). 8281 // to grow the heap without causing GCs (if possible).
8267 Counters::gc_last_resort_from_js.Increment(); 8282 Counters::gc_last_resort_from_js.Increment();
8268 Heap::CollectAllGarbage(false); 8283 Heap::CollectAllGarbage(false);
8269 } 8284 }
8270 } 8285 }
8271 8286
8272 8287
8273 } } // namespace v8::internal 8288 } } // namespace v8::internal
OLDNEW
« src/ia32/disasm-ia32.cc ('K') | « src/math.js ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698