OLD | NEW |
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 252 |
| 253 class OneBit1: public BitField<uint32_t, 0, 1> {}; |
| 254 class OneBit2: public BitField<uint32_t, 7, 1> {}; |
| 255 class EightBit1: public BitField<uint32_t, 0, 8> {}; |
| 256 class EightBit2: public BitField<uint32_t, 13, 8> {}; |
| 257 |
253 TEST(BitField) { | 258 TEST(BitField) { |
254 uint32_t x; | 259 uint32_t x; |
255 | 260 |
256 // One bit bit field can hold values 0 and 1. | 261 // 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> {}; | |
259 CHECK(!OneBit1::is_valid(static_cast<uint32_t>(-1))); | 262 CHECK(!OneBit1::is_valid(static_cast<uint32_t>(-1))); |
260 CHECK(!OneBit2::is_valid(static_cast<uint32_t>(-1))); | 263 CHECK(!OneBit2::is_valid(static_cast<uint32_t>(-1))); |
261 for (int i = 0; i < 2; i++) { | 264 for (int i = 0; i < 2; i++) { |
262 CHECK(OneBit1::is_valid(i)); | 265 CHECK(OneBit1::is_valid(i)); |
263 x = OneBit1::encode(i); | 266 x = OneBit1::encode(i); |
264 CHECK_EQ(i, OneBit1::decode(x)); | 267 CHECK_EQ(i, OneBit1::decode(x)); |
265 | 268 |
266 CHECK(OneBit2::is_valid(i)); | 269 CHECK(OneBit2::is_valid(i)); |
267 x = OneBit2::encode(i); | 270 x = OneBit2::encode(i); |
268 CHECK_EQ(i, OneBit2::decode(x)); | 271 CHECK_EQ(i, OneBit2::decode(x)); |
269 } | 272 } |
270 CHECK(!OneBit1::is_valid(2)); | 273 CHECK(!OneBit1::is_valid(2)); |
271 CHECK(!OneBit2::is_valid(2)); | 274 CHECK(!OneBit2::is_valid(2)); |
272 | 275 |
273 // Eight bit bit field can hold values from 0 tp 255. | 276 // 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))); | 277 CHECK(!EightBit1::is_valid(static_cast<uint32_t>(-1))); |
277 CHECK(!EightBit2::is_valid(static_cast<uint32_t>(-1))); | 278 CHECK(!EightBit2::is_valid(static_cast<uint32_t>(-1))); |
278 for (int i = 0; i < 256; i++) { | 279 for (int i = 0; i < 256; i++) { |
279 CHECK(EightBit1::is_valid(i)); | 280 CHECK(EightBit1::is_valid(i)); |
280 x = EightBit1::encode(i); | 281 x = EightBit1::encode(i); |
281 CHECK_EQ(i, EightBit1::decode(x)); | 282 CHECK_EQ(i, EightBit1::decode(x)); |
282 CHECK(EightBit2::is_valid(i)); | 283 CHECK(EightBit2::is_valid(i)); |
283 x = EightBit2::encode(i); | 284 x = EightBit2::encode(i); |
284 CHECK_EQ(i, EightBit2::decode(x)); | 285 CHECK_EQ(i, EightBit2::decode(x)); |
285 } | 286 } |
286 CHECK(!EightBit1::is_valid(256)); | 287 CHECK(!EightBit1::is_valid(256)); |
287 CHECK(!EightBit2::is_valid(256)); | 288 CHECK(!EightBit2::is_valid(256)); |
288 } | 289 } |
289 | 290 |
290 | 291 |
| 292 class UpperBits: public BitField64<int, 61, 3> {}; |
| 293 class MiddleBits: public BitField64<int, 31, 2> {}; |
| 294 |
291 TEST(BitField64) { | 295 TEST(BitField64) { |
292 uint64_t x; | 296 uint64_t x; |
293 | 297 |
294 // Test most significant bits. | 298 // Test most significant bits. |
295 class UpperBits: public BitField64<int, 61, 3> {}; | |
296 x = V8_2PART_UINT64_C(0xE0000000, 00000000); | 299 x = V8_2PART_UINT64_C(0xE0000000, 00000000); |
297 CHECK(x == UpperBits::encode(7)); | 300 CHECK(x == UpperBits::encode(7)); |
298 CHECK_EQ(7, UpperBits::decode(x)); | 301 CHECK_EQ(7, UpperBits::decode(x)); |
299 | 302 |
300 // Test the 32/64-bit boundary bits. | 303 // Test the 32/64-bit boundary bits. |
301 class MiddleBits: public BitField64<int, 31, 2> {}; | |
302 x = V8_2PART_UINT64_C(0x00000001, 80000000); | 304 x = V8_2PART_UINT64_C(0x00000001, 80000000); |
303 CHECK(x == MiddleBits::encode(3)); | 305 CHECK(x == MiddleBits::encode(3)); |
304 CHECK_EQ(3, MiddleBits::decode(x)); | 306 CHECK_EQ(3, MiddleBits::decode(x)); |
305 } | 307 } |
OLD | NEW |