qemu/include/qemu/units.h
<<
>>
Prefs
   1/*
   2 * IEC binary prefixes definitions
   3 *
   4 * Copyright (C) 2015 Nikunj A Dadhania, IBM Corporation
   5 * Copyright (C) 2018 Philippe Mathieu-Daudé <f4bug@amsat.org>
   6 *
   7 * SPDX-License-Identifier: GPL-2.0-or-later
   8 */
   9
  10#ifndef QEMU_UNITS_H
  11#define QEMU_UNITS_H
  12
  13#define KiB     (INT64_C(1) << 10)
  14#define MiB     (INT64_C(1) << 20)
  15#define GiB     (INT64_C(1) << 30)
  16#define TiB     (INT64_C(1) << 40)
  17#define PiB     (INT64_C(1) << 50)
  18#define EiB     (INT64_C(1) << 60)
  19
  20/*
  21 * The following lookup table is intended to be used when a literal string of
  22 * the number of bytes is required (for example if it needs to be stringified).
  23 * It can also be used for generic shortcuts of power-of-two sizes.
  24 * This table is generated using the AWK script below:
  25 *
  26 *  BEGIN {
  27 *      suffix="KMGTPE";
  28 *      for(i=10; i<64; i++) {
  29 *          val=2**i;
  30 *          s=substr(suffix, int(i/10), 1);
  31 *          n=2**(i%10);
  32 *          pad=21-int(log(n)/log(10));
  33 *          printf("#define S_%d%siB %*d\n", n, s, pad, val);
  34 *      }
  35 *  }
  36 */
  37
  38#define S_1KiB                  1024
  39#define S_2KiB                  2048
  40#define S_4KiB                  4096
  41#define S_8KiB                  8192
  42#define S_16KiB                16384
  43#define S_32KiB                32768
  44#define S_64KiB                65536
  45#define S_128KiB              131072
  46#define S_256KiB              262144
  47#define S_512KiB              524288
  48#define S_1MiB               1048576
  49#define S_2MiB               2097152
  50#define S_4MiB               4194304
  51#define S_8MiB               8388608
  52#define S_16MiB             16777216
  53#define S_32MiB             33554432
  54#define S_64MiB             67108864
  55#define S_128MiB           134217728
  56#define S_256MiB           268435456
  57#define S_512MiB           536870912
  58#define S_1GiB            1073741824
  59#define S_2GiB            2147483648
  60#define S_4GiB            4294967296
  61#define S_8GiB            8589934592
  62#define S_16GiB          17179869184
  63#define S_32GiB          34359738368
  64#define S_64GiB          68719476736
  65#define S_128GiB        137438953472
  66#define S_256GiB        274877906944
  67#define S_512GiB        549755813888
  68#define S_1TiB         1099511627776
  69#define S_2TiB         2199023255552
  70#define S_4TiB         4398046511104
  71#define S_8TiB         8796093022208
  72#define S_16TiB       17592186044416
  73#define S_32TiB       35184372088832
  74#define S_64TiB       70368744177664
  75#define S_128TiB     140737488355328
  76#define S_256TiB     281474976710656
  77#define S_512TiB     562949953421312
  78#define S_1PiB      1125899906842624
  79#define S_2PiB      2251799813685248
  80#define S_4PiB      4503599627370496
  81#define S_8PiB      9007199254740992
  82#define S_16PiB    18014398509481984
  83#define S_32PiB    36028797018963968
  84#define S_64PiB    72057594037927936
  85#define S_128PiB  144115188075855872
  86#define S_256PiB  288230376151711744
  87#define S_512PiB  576460752303423488
  88#define S_1EiB   1152921504606846976
  89#define S_2EiB   2305843009213693952
  90#define S_4EiB   4611686018427387904
  91#define S_8EiB   9223372036854775808
  92
  93#endif
  94