Blame SOURCES/kvm-include-Add-a-lookup-table-of-sizes.patch

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