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

Side by Side Diff: src/ia32/codegen-ia32.cc

Issue 597059: Added optimization for div/mod by constant power of 2. (Closed)
Patch Set: Moved div code, removed mod code, only div by 2. 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
« no previous file with comments | « no previous file | test/mjsunit/div-mod.js » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 1830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 ASSERT(op == Token::BIT_OR); 1841 ASSERT(op == Token::BIT_OR);
1842 if (int_value != 0) { 1842 if (int_value != 0) {
1843 __ or_(Operand(operand->reg()), Immediate(value)); 1843 __ or_(Operand(operand->reg()), Immediate(value));
1844 } 1844 }
1845 } 1845 }
1846 deferred->BindExit(); 1846 deferred->BindExit();
1847 answer = *operand; 1847 answer = *operand;
1848 break; 1848 break;
1849 } 1849 }
1850 1850
1851 case Token::DIV:
1852 if (!reversed && int_value == 2) {
1853 operand->ToRegister();
1854 frame_->Spill(operand->reg());
William Hesse 2010/05/10 14:10:43 If we know that we are in a to-int32 context, wher
1855
1856 DeferredInlineSmiOperation* deferred =
1857 new DeferredInlineSmiOperation(op,
1858 operand->reg(),
1859 operand->reg(),
1860 smi_value,
1861 overwrite_mode);
1862 // Check that lowest log2(value) bits of operand are zero, and test
1863 // smi tag at the same time.
1864 ASSERT_EQ(0, kSmiTag);
1865 ASSERT_EQ(1, kSmiTagSize);
1866 __ test(operand->reg(), Immediate(3));
1867 deferred->Branch(not_zero); // Branch if non-smi or odd smi.
1868 __ sar(operand->reg(), 1);
1869 deferred->BindExit();
1870 answer = *operand;
1871 } else {
1872 // Cannot fall through MOD to default case, so we duplicate the
1873 // default case here.
1874 Result constant_operand(value);
1875 if (reversed) {
1876 answer = LikelySmiBinaryOperation(op, &constant_operand, operand,
1877 overwrite_mode);
1878 } else {
1879 answer = LikelySmiBinaryOperation(op, operand, &constant_operand,
1880 overwrite_mode);
1881 }
1882 }
1883 break;
1851 // Generate inline code for mod of powers of 2 and negative powers of 2. 1884 // Generate inline code for mod of powers of 2 and negative powers of 2.
1852 case Token::MOD: 1885 case Token::MOD:
1853 if (!reversed && 1886 if (!reversed &&
1854 int_value != 0 && 1887 int_value != 0 &&
1855 (IsPowerOf2(int_value) || IsPowerOf2(-int_value))) { 1888 (IsPowerOf2(int_value) || IsPowerOf2(-int_value))) {
1856 operand->ToRegister(); 1889 operand->ToRegister();
1857 frame_->Spill(operand->reg()); 1890 frame_->Spill(operand->reg());
1858 DeferredCode* deferred = new DeferredInlineSmiOperation(op, 1891 DeferredCode* deferred = new DeferredInlineSmiOperation(op,
1859 operand->reg(), 1892 operand->reg(),
1860 operand->reg(), 1893 operand->reg(),
(...skipping 8255 matching lines...) Expand 10 before | Expand all | Expand 10 after
10116 10149
10117 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) 10150 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
10118 // tagged as a small integer. 10151 // tagged as a small integer.
10119 __ bind(&runtime); 10152 __ bind(&runtime);
10120 __ TailCallRuntime(ExternalReference(Runtime::kStringCompare), 2, 1); 10153 __ TailCallRuntime(ExternalReference(Runtime::kStringCompare), 2, 1);
10121 } 10154 }
10122 10155
10123 #undef __ 10156 #undef __
10124 10157
10125 } } // namespace v8::internal 10158 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/div-mod.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698