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

Side by Side Diff: src/utils.h

Issue 9638018: [v8-dev] Optimise Math.floor(x/y) to use integer division for specific divisor.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/mips/lithium-mips.cc ('k') | src/utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 case 4: bits++; // Fall through. 78 case 4: bits++; // Fall through.
79 case 2: bits++; // Fall through. 79 case 2: bits++; // Fall through.
80 case 1: break; 80 case 1: break;
81 } 81 }
82 ASSERT_EQ(1 << bits, original_x); 82 ASSERT_EQ(1 << bits, original_x);
83 return bits; 83 return bits;
84 return 0; 84 return 0;
85 } 85 }
86 86
87 87
88 // Magic numbers for integer division.
89 // These are kind of 2's complement reciprocal of the divisors.
90 // Details and proofs can be found in:
91 // - Hacker's Delight, Henry S. Warren, Jr.
92 // - The PowerPC Compiler Writer’s Guide
93 // and probably many others.
94 // See details in the implementation of the algorithm in
95 // lithium-codegen-arm.cc : LCodeGen::TryEmitSignedIntegerDivisionByConstant().
96 struct DivMagicNumbers {
97 unsigned M;
98 unsigned s;
99 };
100
101 const DivMagicNumbers InvalidDivMagicNumber= {0, 0};
102 const DivMagicNumbers DivMagicNumberFor3 = {0x55555556, 0};
103 const DivMagicNumbers DivMagicNumberFor5 = {0x66666667, 1};
104 const DivMagicNumbers DivMagicNumberFor7 = {0x92492493, 2};
105 const DivMagicNumbers DivMagicNumberFor9 = {0x38e38e39, 1};
106 const DivMagicNumbers DivMagicNumberFor11 = {0x2e8ba2e9, 1};
107 const DivMagicNumbers DivMagicNumberFor25 = {0x51eb851f, 3};
108 const DivMagicNumbers DivMagicNumberFor125 = {0x10624dd3, 3};
109 const DivMagicNumbers DivMagicNumberFor625 = {0x68db8bad, 8};
110
111 const DivMagicNumbers DivMagicNumberFor(int32_t divisor);
112
113
88 // The C++ standard leaves the semantics of '>>' undefined for 114 // The C++ standard leaves the semantics of '>>' undefined for
89 // negative signed operands. Most implementations do the right thing, 115 // negative signed operands. Most implementations do the right thing,
90 // though. 116 // though.
91 inline int ArithmeticShiftRight(int x, int s) { 117 inline int ArithmeticShiftRight(int x, int s) {
92 return x >> s; 118 return x >> s;
93 } 119 }
94 120
95 121
96 // Compute the 0-relative offset of some absolute value x of type T. 122 // Compute the 0-relative offset of some absolute value x of type T.
97 // This allows conversion of Addresses and integral types into 123 // This allows conversion of Addresses and integral types into
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); 976 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT));
951 return 1 << element; 977 return 1 << element;
952 } 978 }
953 979
954 T bits_; 980 T bits_;
955 }; 981 };
956 982
957 } } // namespace v8::internal 983 } } // namespace v8::internal
958 984
959 #endif // V8_UTILS_H_ 985 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « src/mips/lithium-mips.cc ('k') | src/utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698