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

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

Issue 14643004: Provide BitField64 utility class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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/utils.h ('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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 TEST(ExponentNumberStr) { 242 TEST(ExponentNumberStr) {
243 UnicodeCache uc; 243 UnicodeCache uc;
244 CHECK_EQ(1e1, StringToDouble(&uc, "1e1", NO_FLAGS)); 244 CHECK_EQ(1e1, StringToDouble(&uc, "1e1", NO_FLAGS));
245 CHECK_EQ(1e1, StringToDouble(&uc, "1e+1", NO_FLAGS)); 245 CHECK_EQ(1e1, StringToDouble(&uc, "1e+1", NO_FLAGS));
246 CHECK_EQ(1e-1, StringToDouble(&uc, "1e-1", NO_FLAGS)); 246 CHECK_EQ(1e-1, StringToDouble(&uc, "1e-1", NO_FLAGS));
247 CHECK_EQ(1e100, StringToDouble(&uc, "1e+100", NO_FLAGS)); 247 CHECK_EQ(1e100, StringToDouble(&uc, "1e+100", NO_FLAGS));
248 CHECK_EQ(1e-100, StringToDouble(&uc, "1e-100", NO_FLAGS)); 248 CHECK_EQ(1e-100, StringToDouble(&uc, "1e-100", NO_FLAGS));
249 CHECK_EQ(1e-106, StringToDouble(&uc, ".000001e-100", NO_FLAGS)); 249 CHECK_EQ(1e-106, StringToDouble(&uc, ".000001e-100", NO_FLAGS));
250 } 250 }
251 251
252 class OneBit1: public BitField<uint32_t, 0, 1> {};
253 class OneBit2: public BitField<uint32_t, 7, 1> {};
254 class EightBit1: public BitField<uint32_t, 0, 8> {};
255 class EightBit2: public BitField<uint32_t, 13, 8> {};
256 252
257 TEST(BitField) { 253 TEST(BitField) {
258 uint32_t x; 254 uint32_t x;
259 255
260 // One bit bit field can hold values 0 and 1. 256 // One bit bit field can hold values 0 and 1.
257 class OneBit1: public BitField<uint32_t, 0, 1> {};
258 class OneBit2: public BitField<uint32_t, 7, 1> {};
261 CHECK(!OneBit1::is_valid(static_cast<uint32_t>(-1))); 259 CHECK(!OneBit1::is_valid(static_cast<uint32_t>(-1)));
262 CHECK(!OneBit2::is_valid(static_cast<uint32_t>(-1))); 260 CHECK(!OneBit2::is_valid(static_cast<uint32_t>(-1)));
263 for (int i = 0; i < 2; i++) { 261 for (int i = 0; i < 2; i++) {
264 CHECK(OneBit1::is_valid(i)); 262 CHECK(OneBit1::is_valid(i));
265 x = OneBit1::encode(i); 263 x = OneBit1::encode(i);
266 CHECK_EQ(i, OneBit1::decode(x)); 264 CHECK_EQ(i, OneBit1::decode(x));
267 265
268 CHECK(OneBit2::is_valid(i)); 266 CHECK(OneBit2::is_valid(i));
269 x = OneBit2::encode(i); 267 x = OneBit2::encode(i);
270 CHECK_EQ(i, OneBit2::decode(x)); 268 CHECK_EQ(i, OneBit2::decode(x));
271 } 269 }
272 CHECK(!OneBit1::is_valid(2)); 270 CHECK(!OneBit1::is_valid(2));
273 CHECK(!OneBit2::is_valid(2)); 271 CHECK(!OneBit2::is_valid(2));
274 272
275 // Eight bit bit field can hold values from 0 tp 255. 273 // Eight bit bit field can hold values from 0 tp 255.
274 class EightBit1: public BitField<uint32_t, 0, 8> {};
275 class EightBit2: public BitField<uint32_t, 13, 8> {};
276 CHECK(!EightBit1::is_valid(static_cast<uint32_t>(-1))); 276 CHECK(!EightBit1::is_valid(static_cast<uint32_t>(-1)));
277 CHECK(!EightBit2::is_valid(static_cast<uint32_t>(-1))); 277 CHECK(!EightBit2::is_valid(static_cast<uint32_t>(-1)));
278 for (int i = 0; i < 256; i++) { 278 for (int i = 0; i < 256; i++) {
279 CHECK(EightBit1::is_valid(i)); 279 CHECK(EightBit1::is_valid(i));
280 x = EightBit1::encode(i); 280 x = EightBit1::encode(i);
281 CHECK_EQ(i, EightBit1::decode(x)); 281 CHECK_EQ(i, EightBit1::decode(x));
282 CHECK(EightBit2::is_valid(i)); 282 CHECK(EightBit2::is_valid(i));
283 x = EightBit2::encode(i); 283 x = EightBit2::encode(i);
284 CHECK_EQ(i, EightBit2::decode(x)); 284 CHECK_EQ(i, EightBit2::decode(x));
285 } 285 }
286 CHECK(!EightBit1::is_valid(256)); 286 CHECK(!EightBit1::is_valid(256));
287 CHECK(!EightBit2::is_valid(256)); 287 CHECK(!EightBit2::is_valid(256));
288 } 288 }
289
290
291 TEST(BitField64) {
292 uint64_t x;
293
294 // Test most significant bits.
295 class UpperBits: public BitField64<int, 61, 3> {};
296 x = V8_2PART_UINT64_C(0xE0000000, 00000000);
297 CHECK(x == UpperBits::encode(7));
298 CHECK_EQ(7, UpperBits::decode(x));
299
300 // Test the 32/64-bit boundary bits.
301 class MiddleBits: public BitField64<int, 31, 2> {};
302 x = V8_2PART_UINT64_C(0x00000001, 80000000);
303 CHECK(x == MiddleBits::encode(3));
304 CHECK_EQ(3, MiddleBits::decode(x));
305 }
OLDNEW
« no previous file with comments | « src/utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698