thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ae23c9
From ac9ce8475684e9ed0670a7ac798e57ca2c971e54 Mon Sep 17 00:00:00 2001
ae23c9
From: Kevin Wolf <kwolf@redhat.com>
ae23c9
Date: Thu, 6 Dec 2018 17:12:31 +0000
ae23c9
Subject: [PATCH 06/15] include: Add a lookup table of sizes
ae23c9
ae23c9
RH-Author: Kevin Wolf <kwolf@redhat.com>
ae23c9
Message-id: <20181206171240.5674-7-kwolf@redhat.com>
ae23c9
Patchwork-id: 83294
ae23c9
O-Subject: [RHEL-8.0 qemu-kvm PATCH 06/15] include: Add a lookup table of sizes
ae23c9
Bugzilla: 1656507
ae23c9
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
ae23c9
From: Leonid Bloch <lbloch@janustech.com>
ae23c9
ae23c9
Adding a lookup table for the powers of two, with the appropriate size
ae23c9
prefixes. This is needed when a size has to be stringified, in which
ae23c9
case something like '(1 * KiB)' would become a literal '(1 * (1L << 10))'
ae23c9
string. Powers of two are used very often for sizes, so such a table
ae23c9
will also make it easier and more intuitive to write them.
ae23c9
ae23c9
This table is generatred using the following AWK script:
ae23c9
ae23c9
BEGIN {
ae23c9
	suffix="KMGTPE";
ae23c9
	for(i=10; i<64; i++) {
ae23c9
		val=2**i;
ae23c9
		s=substr(suffix, int(i/10), 1);
ae23c9
		n=2**(i%10);
ae23c9
		pad=21-int(log(n)/log(10));
ae23c9
		printf("#define S_%d%siB %*d\n", n, s, pad, val);
ae23c9
	}
ae23c9
}
ae23c9
ae23c9
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
ae23c9
Reviewed-by: Alberto Garcia <berto@igalia.com>
ae23c9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
(cherry picked from commit 540b8492618ebbe98e7462bd7d31361b8cb10a05)
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 include/qemu/units.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
ae23c9
 1 file changed, 55 insertions(+)
ae23c9
ae23c9
diff --git a/include/qemu/units.h b/include/qemu/units.h
ae23c9
index 692db3f..68a7758 100644
ae23c9
--- a/include/qemu/units.h
ae23c9
+++ b/include/qemu/units.h
ae23c9
@@ -17,4 +17,59 @@
ae23c9
 #define PiB     (INT64_C(1) << 50)
ae23c9
 #define EiB     (INT64_C(1) << 60)
ae23c9
 
ae23c9
+#define S_1KiB                  1024
ae23c9
+#define S_2KiB                  2048
ae23c9
+#define S_4KiB                  4096
ae23c9
+#define S_8KiB                  8192
ae23c9
+#define S_16KiB                16384
ae23c9
+#define S_32KiB                32768
ae23c9
+#define S_64KiB                65536
ae23c9
+#define S_128KiB              131072
ae23c9
+#define S_256KiB              262144
ae23c9
+#define S_512KiB              524288
ae23c9
+#define S_1MiB               1048576
ae23c9
+#define S_2MiB               2097152
ae23c9
+#define S_4MiB               4194304
ae23c9
+#define S_8MiB               8388608
ae23c9
+#define S_16MiB             16777216
ae23c9
+#define S_32MiB             33554432
ae23c9
+#define S_64MiB             67108864
ae23c9
+#define S_128MiB           134217728
ae23c9
+#define S_256MiB           268435456
ae23c9
+#define S_512MiB           536870912
ae23c9
+#define S_1GiB            1073741824
ae23c9
+#define S_2GiB            2147483648
ae23c9
+#define S_4GiB            4294967296
ae23c9
+#define S_8GiB            8589934592
ae23c9
+#define S_16GiB          17179869184
ae23c9
+#define S_32GiB          34359738368
ae23c9
+#define S_64GiB          68719476736
ae23c9
+#define S_128GiB        137438953472
ae23c9
+#define S_256GiB        274877906944
ae23c9
+#define S_512GiB        549755813888
ae23c9
+#define S_1TiB         1099511627776
ae23c9
+#define S_2TiB         2199023255552
ae23c9
+#define S_4TiB         4398046511104
ae23c9
+#define S_8TiB         8796093022208
ae23c9
+#define S_16TiB       17592186044416
ae23c9
+#define S_32TiB       35184372088832
ae23c9
+#define S_64TiB       70368744177664
ae23c9
+#define S_128TiB     140737488355328
ae23c9
+#define S_256TiB     281474976710656
ae23c9
+#define S_512TiB     562949953421312
ae23c9
+#define S_1PiB      1125899906842624
ae23c9
+#define S_2PiB      2251799813685248
ae23c9
+#define S_4PiB      4503599627370496
ae23c9
+#define S_8PiB      9007199254740992
ae23c9
+#define S_16PiB    18014398509481984
ae23c9
+#define S_32PiB    36028797018963968
ae23c9
+#define S_64PiB    72057594037927936
ae23c9
+#define S_128PiB  144115188075855872
ae23c9
+#define S_256PiB  288230376151711744
ae23c9
+#define S_512PiB  576460752303423488
ae23c9
+#define S_1EiB   1152921504606846976
ae23c9
+#define S_2EiB   2305843009213693952
ae23c9
+#define S_4EiB   4611686018427387904
ae23c9
+#define S_8EiB   9223372036854775808
ae23c9
+
ae23c9
 #endif
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9