~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/mach0data.ic

  • Committer: Brian Aker
  • Date: 2010-10-20 20:26:18 UTC
  • mfrom: (1859.2.13 refactor)
  • Revision ID: brian@tangent.org-20101020202618-9222n39lm329urv5
Merge for Brian 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
36
36
        ulint   n)      /*!< in: ulint integer to be stored, >= 0, < 256 */
37
37
{
38
38
        ut_ad(b);
39
 
        ut_ad((n | 0xFFUL) <= 0xFFUL);
 
39
        ut_ad(n <= 0xFFUL);
40
40
 
41
41
        b[0] = (byte)n;
42
42
}
65
65
        ulint   n)      /*!< in: ulint integer to be stored */
66
66
{
67
67
        ut_ad(b);
68
 
        ut_ad((n | 0xFFFFUL) <= 0xFFFFUL);
 
68
        ut_ad(n <= 0xFFFFUL);
69
69
 
70
70
        b[0] = (byte)(n >> 8);
71
71
        b[1] = (byte)(n);
81
81
/*=============*/
82
82
        const byte*     b)      /*!< in: pointer to 2 bytes */
83
83
{
84
 
        return(((ulint)(b[0]) << 8) | (ulint)(b[1]));
 
84
        ut_ad(b);
 
85
        return( ((ulint)(b[0]) << 8)
 
86
                + (ulint)(b[1])
 
87
                );
85
88
}
86
89
 
87
90
/********************************************************//**
126
129
        ulint   n)      /*!< in: ulint integer to be stored */
127
130
{
128
131
        ut_ad(b);
129
 
        ut_ad((n | 0xFFFFFFUL) <= 0xFFFFFFUL);
 
132
        ut_ad(n <= 0xFFFFFFUL);
130
133
 
131
134
        b[0] = (byte)(n >> 16);
132
135
        b[1] = (byte)(n >> 8);
145
148
{
146
149
        ut_ad(b);
147
150
        return( ((ulint)(b[0]) << 16)
148
 
                | ((ulint)(b[1]) << 8)
149
 
                | (ulint)(b[2])
 
151
                + ((ulint)(b[1]) << 8)
 
152
                + (ulint)(b[2])
150
153
                );
151
154
}
152
155
 
180
183
{
181
184
        ut_ad(b);
182
185
        return( ((ulint)(b[0]) << 24)
183
 
                | ((ulint)(b[1]) << 16)
184
 
                | ((ulint)(b[2]) << 8)
185
 
                | (ulint)(b[3])
 
186
                + ((ulint)(b[1]) << 16)
 
187
                + ((ulint)(b[2]) << 8)
 
188
                + (ulint)(b[3])
186
189
                );
187
190
}
188
191
 
280
283
void
281
284
mach_write_to_8(
282
285
/*============*/
 
286
        byte*   b,      /*!< in: pointer to 8 bytes where to store */
 
287
        dulint  n)      /*!< in: dulint integer to be stored */
 
288
{
 
289
        ut_ad(b);
 
290
 
 
291
        mach_write_to_4(b, ut_dulint_get_high(n));
 
292
        mach_write_to_4(b + 4, ut_dulint_get_low(n));
 
293
}
 
294
 
 
295
/*******************************************************//**
 
296
The following function is used to store data in 8 consecutive
 
297
bytes. We store the most significant byte to the lowest address. */
 
298
UNIV_INLINE
 
299
void
 
300
mach_write_ull(
 
301
/*===========*/
283
302
        byte*           b,      /*!< in: pointer to 8 bytes where to store */
284
303
        ib_uint64_t     n)      /*!< in: 64-bit integer to be stored */
285
304
{
292
311
/********************************************************//**
293
312
The following function is used to fetch data from 8 consecutive
294
313
bytes. The most significant byte is at the lowest address.
 
314
@return dulint integer */
 
315
UNIV_INLINE
 
316
dulint
 
317
mach_read_from_8(
 
318
/*=============*/
 
319
        const byte*     b)      /*!< in: pointer to 8 bytes */
 
320
{
 
321
        ulint   high;
 
322
        ulint   low;
 
323
 
 
324
        ut_ad(b);
 
325
 
 
326
        high = mach_read_from_4(b);
 
327
        low = mach_read_from_4(b + 4);
 
328
 
 
329
        return(ut_dulint_create(high, low));
 
330
}
 
331
 
 
332
/********************************************************//**
 
333
The following function is used to fetch data from 8 consecutive
 
334
bytes. The most significant byte is at the lowest address.
295
335
@return 64-bit integer */
296
336
UNIV_INLINE
297
337
ib_uint64_t
298
 
mach_read_from_8(
299
 
/*=============*/
 
338
mach_read_ull(
 
339
/*==========*/
300
340
        const byte*     b)      /*!< in: pointer to 8 bytes */
301
341
{
302
342
        ib_uint64_t     ull;
314
354
void
315
355
mach_write_to_7(
316
356
/*============*/
317
 
        byte*           b,      /*!< in: pointer to 7 bytes where to store */
318
 
        ib_uint64_t     n)      /*!< in: 56-bit integer */
 
357
        byte*   b,      /*!< in: pointer to 7 bytes where to store */
 
358
        dulint  n)      /*!< in: dulint integer to be stored */
319
359
{
320
360
        ut_ad(b);
321
361
 
322
 
        mach_write_to_3(b, (ulint) (n >> 32));
323
 
        mach_write_to_4(b + 3, (ulint) n);
 
362
        mach_write_to_3(b, ut_dulint_get_high(n));
 
363
        mach_write_to_4(b + 3, ut_dulint_get_low(n));
324
364
}
325
365
 
326
366
/********************************************************//**
327
367
The following function is used to fetch data from 7 consecutive
328
368
bytes. The most significant byte is at the lowest address.
329
 
@return 56-bit integer */
 
369
@return dulint integer */
330
370
UNIV_INLINE
331
 
ib_uint64_t
 
371
dulint
332
372
mach_read_from_7(
333
373
/*=============*/
334
374
        const byte*     b)      /*!< in: pointer to 7 bytes */
335
375
{
 
376
        ulint   high;
 
377
        ulint   low;
 
378
 
336
379
        ut_ad(b);
337
380
 
338
 
        return(ut_ull_create(mach_read_from_3(b), mach_read_from_4(b + 3)));
 
381
        high = mach_read_from_3(b);
 
382
        low = mach_read_from_4(b + 3);
 
383
 
 
384
        return(ut_dulint_create(high, low));
339
385
}
340
386
 
341
387
/*******************************************************//**
345
391
void
346
392
mach_write_to_6(
347
393
/*============*/
348
 
        byte*           b,      /*!< in: pointer to 6 bytes where to store */
349
 
        ib_uint64_t     n)      /*!< in: 48-bit integer */
 
394
        byte*   b,      /*!< in: pointer to 6 bytes where to store */
 
395
        dulint  n)      /*!< in: dulint integer to be stored */
350
396
{
351
397
        ut_ad(b);
352
398
 
353
 
        mach_write_to_2(b, (ulint) (n >> 32));
354
 
        mach_write_to_4(b + 2, (ulint) n);
 
399
        mach_write_to_2(b, ut_dulint_get_high(n));
 
400
        mach_write_to_4(b + 2, ut_dulint_get_low(n));
355
401
}
356
402
 
357
403
/********************************************************//**
358
404
The following function is used to fetch data from 6 consecutive
359
405
bytes. The most significant byte is at the lowest address.
360
 
@return 48-bit integer */
 
406
@return dulint integer */
361
407
UNIV_INLINE
362
 
ib_uint64_t
 
408
dulint
363
409
mach_read_from_6(
364
410
/*=============*/
365
411
        const byte*     b)      /*!< in: pointer to 6 bytes */
366
412
{
 
413
        ulint   high;
 
414
        ulint   low;
 
415
 
367
416
        ut_ad(b);
368
417
 
369
 
        return(ut_ull_create(mach_read_from_2(b), mach_read_from_4(b + 2)));
 
418
        high = mach_read_from_2(b);
 
419
        low = mach_read_from_4(b + 2);
 
420
 
 
421
        return(ut_dulint_create(high, low));
370
422
}
371
423
 
372
424
/*********************************************************//**
373
 
Writes a 64-bit integer in a compressed form (5..9 bytes).
 
425
Writes a dulint in a compressed form (5..9 bytes).
374
426
@return size in bytes */
375
427
UNIV_INLINE
376
428
ulint
377
 
mach_ull_write_compressed(
378
 
/*======================*/
379
 
        byte*           b,      /*!< in: pointer to memory where to store */
380
 
        ib_uint64_t     n)      /*!< in: 64-bit integer to be stored */
 
429
mach_dulint_write_compressed(
 
430
/*=========================*/
 
431
        byte*   b,      /*!< in: pointer to memory where to store */
 
432
        dulint  n)      /*!< in: dulint integer to be stored */
381
433
{
382
434
        ulint   size;
383
435
 
384
436
        ut_ad(b);
385
437
 
386
 
        size = mach_write_compressed(b, (ulint) (n >> 32));
387
 
        mach_write_to_4(b + size, (ulint) n);
 
438
        size = mach_write_compressed(b, ut_dulint_get_high(n));
 
439
        mach_write_to_4(b + size, ut_dulint_get_low(n));
388
440
 
389
441
        return(size + 4);
390
442
}
391
443
 
392
444
/*********************************************************//**
393
 
Returns the size of a 64-bit integer when written in the compressed form.
 
445
Returns the size of a dulint when written in the compressed form.
394
446
@return compressed size in bytes */
395
447
UNIV_INLINE
396
448
ulint
397
 
mach_ull_get_compressed_size(
398
 
/*=========================*/
399
 
        ib_uint64_t     n)      /*!< in: 64-bit integer to be stored */
 
449
mach_dulint_get_compressed_size(
 
450
/*============================*/
 
451
        dulint   n)     /*!< in: dulint integer to be stored */
400
452
{
401
 
        return(4 + mach_get_compressed_size((ulint) (n >> 32)));
 
453
        return(4 + mach_get_compressed_size(ut_dulint_get_high(n)));
402
454
}
403
455
 
404
456
/*********************************************************//**
405
 
Reads a 64-bit integer in a compressed form.
406
 
@return the value read */
 
457
Reads a dulint in a compressed form.
 
458
@return read dulint */
407
459
UNIV_INLINE
408
 
ib_uint64_t
409
 
mach_ull_read_compressed(
410
 
/*=====================*/
 
460
dulint
 
461
mach_dulint_read_compressed(
 
462
/*========================*/
411
463
        const byte*     b)      /*!< in: pointer to memory from where to read */
412
464
{
413
 
        ib_uint64_t     n;
414
 
        ulint           size;
 
465
        ulint   high;
 
466
        ulint   low;
 
467
        ulint   size;
415
468
 
416
469
        ut_ad(b);
417
470
 
418
 
        n = (ib_uint64_t) mach_read_compressed(b);
419
 
 
420
 
        size = mach_get_compressed_size((ulint) n);
421
 
 
422
 
        n <<= 32;
423
 
        n |= (ib_uint64_t) mach_read_from_4(b + size);
424
 
 
425
 
        return(n);
 
471
        high = mach_read_compressed(b);
 
472
 
 
473
        size = mach_get_compressed_size(high);
 
474
 
 
475
        low = mach_read_from_4(b + size);
 
476
 
 
477
        return(ut_dulint_create(high, low));
426
478
}
427
479
 
428
480
/*********************************************************//**
429
 
Writes a 64-bit integer in a compressed form (1..11 bytes).
 
481
Writes a dulint in a compressed form (1..11 bytes).
430
482
@return size in bytes */
431
483
UNIV_INLINE
432
484
ulint
433
 
mach_ull_write_much_compressed(
434
 
/*===========================*/
435
 
        byte*           b,      /*!< in: pointer to memory where to store */
436
 
        ib_uint64_t     n)      /*!< in: 64-bit integer to be stored */
 
485
mach_dulint_write_much_compressed(
 
486
/*==============================*/
 
487
        byte*   b,      /*!< in: pointer to memory where to store */
 
488
        dulint  n)      /*!< in: dulint integer to be stored */
437
489
{
438
490
        ulint   size;
439
491
 
440
492
        ut_ad(b);
441
493
 
442
 
        if (!(n >> 32)) {
443
 
                return(mach_write_compressed(b, (ulint) n));
 
494
        if (ut_dulint_get_high(n) == 0) {
 
495
                return(mach_write_compressed(b, ut_dulint_get_low(n)));
444
496
        }
445
497
 
446
498
        *b = (byte)0xFF;
447
 
        size = 1 + mach_write_compressed(b + 1, (ulint) (n >> 32));
 
499
        size = 1 + mach_write_compressed(b + 1, ut_dulint_get_high(n));
448
500
 
449
 
        size += mach_write_compressed(b + size, (ulint) n & 0xFFFFFFFF);
 
501
        size += mach_write_compressed(b + size, ut_dulint_get_low(n));
450
502
 
451
503
        return(size);
452
504
}
453
505
 
454
506
/*********************************************************//**
455
 
Returns the size of a 64-bit integer when written in the compressed form.
 
507
Returns the size of a dulint when written in the compressed form.
456
508
@return compressed size in bytes */
457
509
UNIV_INLINE
458
510
ulint
459
 
mach_ull_get_much_compressed_size(
460
 
/*==============================*/
461
 
        ib_uint64_t     n)      /*!< in: 64-bit integer to be stored */
 
511
mach_dulint_get_much_compressed_size(
 
512
/*=================================*/
 
513
        dulint   n)     /*!< in: dulint integer to be stored */
462
514
{
463
 
        if (!(n >> 32)) {
464
 
                return(mach_get_compressed_size((ulint) n));
 
515
        if (0 == ut_dulint_get_high(n)) {
 
516
                return(mach_get_compressed_size(ut_dulint_get_low(n)));
465
517
        }
466
518
 
467
 
        return(1 + mach_get_compressed_size((ulint) (n >> 32))
468
 
               + mach_get_compressed_size((ulint) n & ULINT32_MASK));
 
519
        return(1 + mach_get_compressed_size(ut_dulint_get_high(n))
 
520
               + mach_get_compressed_size(ut_dulint_get_low(n)));
469
521
}
470
522
 
471
523
/*********************************************************//**
472
 
Reads a 64-bit integer in a compressed form.
473
 
@return the value read */
 
524
Reads a dulint in a compressed form.
 
525
@return read dulint */
474
526
UNIV_INLINE
475
 
ib_uint64_t
476
 
mach_ull_read_much_compressed(
477
 
/*==========================*/
 
527
dulint
 
528
mach_dulint_read_much_compressed(
 
529
/*=============================*/
478
530
        const byte*     b)      /*!< in: pointer to memory from where to read */
479
531
{
480
 
        ib_uint64_t     n;
481
 
        ulint           size;
 
532
        ulint   high;
 
533
        ulint   low;
 
534
        ulint   size;
482
535
 
483
536
        ut_ad(b);
484
537
 
485
538
        if (*b != (byte)0xFF) {
486
 
                n = 0;
 
539
                high = 0;
487
540
                size = 0;
488
541
        } else {
489
 
                n = (ib_uint64_t) mach_read_compressed(b + 1);
490
 
 
491
 
                size = 1 + mach_get_compressed_size((ulint) n);
492
 
                n <<= 32;
493
 
        }
494
 
 
495
 
        n |= mach_read_compressed(b + size);
496
 
 
497
 
        return(n);
498
 
}
499
 
 
500
 
/*********************************************************//**
501
 
Reads a 64-bit integer in a compressed form
502
 
if the log record fully contains it.
503
 
@return pointer to end of the stored field, NULL if not complete */
504
 
UNIV_INLINE
505
 
byte*
506
 
mach_ull_parse_compressed(
507
 
/*======================*/
508
 
        byte*           ptr,    /* in: pointer to buffer from where to read */
509
 
        byte*           end_ptr,/* in: pointer to end of the buffer */
510
 
        ib_uint64_t*    val)    /* out: read value */
511
 
{
512
 
        ulint           size;
513
 
 
514
 
        ut_ad(ptr);
515
 
        ut_ad(end_ptr);
516
 
        ut_ad(val);
517
 
 
518
 
        if (end_ptr < ptr + 5) {
519
 
 
520
 
                return(NULL);
521
 
        }
522
 
 
523
 
        *val = mach_read_compressed(ptr);
524
 
 
525
 
        size = mach_get_compressed_size((ulint) *val);
526
 
 
527
 
        ptr += size;
528
 
 
529
 
        if (end_ptr < ptr + 4) {
530
 
 
531
 
                return(NULL);
532
 
        }
533
 
 
534
 
        *val <<= 32;
535
 
        *val |= mach_read_from_4(ptr);
536
 
 
537
 
        return(ptr + 4);
 
542
                high = mach_read_compressed(b + 1);
 
543
 
 
544
                size = 1 + mach_get_compressed_size(high);
 
545
        }
 
546
 
 
547
        low = mach_read_compressed(b + size);
 
548
 
 
549
        return(ut_dulint_create(high, low));
538
550
}
539
551
#ifndef UNIV_HOTBACKUP
540
552
/*********************************************************//**
709
721
/*===========================*/
710
722
        const byte*     buf)            /*!< in: from where to read */
711
723
{
712
 
        return((ulint)(buf[0]) | ((ulint)(buf[1]) << 8));
 
724
        return((ulint)(*buf) + ((ulint)(*(buf + 1))) * 256);
713
725
}
714
726
 
715
727
/*********************************************************//**