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

Side by Side Diff: test/cctest/test-utils.cc

Issue 13932006: Replace OS::MemCopy with OS::MemMove (just as fast but more flexible). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 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 | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (i <= length) { 91 if (i <= length) {
92 CHECK_EQ(i - 1, StrLength(buffer.start())); 92 CHECK_EQ(i - 1, StrLength(buffer.start()));
93 } else { 93 } else {
94 CHECK_EQ(length, StrLength(buffer.start())); 94 CHECK_EQ(length, StrLength(buffer.start()));
95 } 95 }
96 buffer.Dispose(); 96 buffer.Dispose();
97 } 97 }
98 } 98 }
99 99
100 100
101 void TestMemCopy(Vector<byte> src, 101 static const int kAreaSize = 512;
102 Vector<byte> dst, 102
103 int source_alignment, 103
104 int destination_alignment, 104 void TestMemMove(byte* area1,
105 int length_alignment) { 105 byte* area2,
106 memset(dst.start(), 0xFF, dst.length()); 106 byte* area3,
107 byte* to = dst.start() + 32 + destination_alignment; 107 int src_offset,
108 byte* from = src.start() + source_alignment; 108 int dest_offset,
109 int length = OS::kMinComplexMemCopy + length_alignment; 109 int length) {
110 OS::MemCopy(to, from, static_cast<size_t>(length)); 110 for (int i = 0; i < kAreaSize; i++) {
111 printf("[%d,%d,%d]\n", 111 area1[i] = i & 0xFF;
112 source_alignment, destination_alignment, length_alignment); 112 area2[i] = i & 0xFF;
113 for (int i = 0; i < length; i++) { 113 area3[i] = i & 0xFF;
114 CHECK_EQ(from[i], to[i]);
115 } 114 }
116 CHECK_EQ(0xFF, to[-1]); 115 OS::MemMove(area1 + dest_offset, area1 + src_offset, length);
117 CHECK_EQ(0xFF, to[length]); 116 MoveBytes(area2 + dest_offset, area2 + src_offset, length);
117 memmove(area3 + dest_offset, area3 + src_offset, length);
118 if (memcmp(area1, area3, kAreaSize) != 0) {
119 printf("OS::MemMove(): src_offset: %d, dest_offset: %d, length: %d\n",
120 src_offset, dest_offset, length);
121 for (int i = 0; i < kAreaSize; i++) {
122 if (area1[i] == area3[i]) continue;
123 printf("diff at offset %d (%p): is %d, should be %d\n",
124 i, reinterpret_cast<void*>(area1 + i), area1[i], area3[i]);
125 }
126 CHECK(false);
127 }
128 if (memcmp(area2, area3, kAreaSize) != 0) {
129 printf("MoveBytes(): src_offset: %d, dest_offset: %d, length: %d\n",
130 src_offset, dest_offset, length);
131 for (int i = 0; i < kAreaSize; i++) {
132 if (area2[i] == area3[i]) continue;
133 printf("diff at offset %d (%p): is %d, should be %d\n",
134 i, reinterpret_cast<void*>(area2 + i), area2[i], area3[i]);
135 }
136 CHECK(false);
137 }
118 } 138 }
119 139
120 140
121 141 TEST(MemMove) {
122 TEST(MemCopy) {
123 v8::V8::Initialize(); 142 v8::V8::Initialize();
124 OS::SetUp(); 143 OS::SetUp();
125 const int N = OS::kMinComplexMemCopy + 128; 144 byte* area1 = new byte[kAreaSize];
126 Vector<byte> buffer1 = Vector<byte>::New(N); 145 byte* area2 = new byte[kAreaSize];
127 Vector<byte> buffer2 = Vector<byte>::New(N); 146 byte* area3 = new byte[kAreaSize];
128 147
129 for (int i = 0; i < N; i++) { 148 static const int kMinOffset = 32;
130 buffer1[i] = static_cast<byte>(i & 0x7F); 149 static const int kMaxOffset = 64;
131 } 150 static const int kMaxLength = 128;
151 STATIC_ASSERT(kMaxOffset + kMaxLength < kAreaSize);
132 152
133 // Same alignment. 153 for (int src_offset = kMinOffset; src_offset <= kMaxOffset; src_offset++) {
134 for (int i = 0; i < 32; i++) { 154 for (int dst_offset = kMinOffset; dst_offset <= kMaxOffset; dst_offset++) {
135 TestMemCopy(buffer1, buffer2, i, i, i * 2); 155 for (int length = 0; length <= kMaxLength; length++) {
136 } 156 TestMemMove(area1, area2, area3, src_offset, dst_offset, length);
137 157 }
138 // Different alignment.
139 for (int i = 0; i < 32; i++) {
140 for (int j = 1; j < 32; j++) {
141 TestMemCopy(buffer1, buffer2, i, (i + j) & 0x1F , 0);
142 } 158 }
143 } 159 }
144 160 delete[] area1;
145 // Different lengths 161 delete[] area2;
146 for (int i = 0; i < 32; i++) { 162 delete[] area3;
147 TestMemCopy(buffer1, buffer2, 3, 7, i);
148 }
149
150 buffer2.Dispose();
151 buffer1.Dispose();
152 } 163 }
153 164
154 165
155 TEST(Collector) { 166 TEST(Collector) {
156 Collector<int> collector(8); 167 Collector<int> collector(8);
157 const int kLoops = 5; 168 const int kLoops = 5;
158 const int kSequentialSize = 1000; 169 const int kSequentialSize = 1000;
159 const int kBlockSize = 7; 170 const int kBlockSize = 7;
160 for (int loop = 0; loop < kLoops; loop++) { 171 for (int loop = 0; loop < kLoops; loop++) {
161 Vector<int> block = collector.AddBlock(7, 0xbadcafe); 172 Vector<int> block = collector.AddBlock(7, 0xbadcafe);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 TEST(SequenceCollectorRegression) { 227 TEST(SequenceCollectorRegression) {
217 SequenceCollector<char> collector(16); 228 SequenceCollector<char> collector(16);
218 collector.StartSequence(); 229 collector.StartSequence();
219 collector.Add('0'); 230 collector.Add('0');
220 collector.AddBlock( 231 collector.AddBlock(
221 i::Vector<const char>("12345678901234567890123456789012", 32)); 232 i::Vector<const char>("12345678901234567890123456789012", 32));
222 i::Vector<char> seq = collector.EndSequence(); 233 i::Vector<char> seq = collector.EndSequence();
223 CHECK_EQ(0, strncmp("0123456789012345678901234567890123", 234 CHECK_EQ(0, strncmp("0123456789012345678901234567890123",
224 seq.start(), seq.length())); 235 seq.start(), seq.length()));
225 } 236 }
OLDNEW
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698