1.1 --- a/memory/memory_utils.cc Sun Apr 11 19:34:07 2021 +0200
1.2 +++ b/memory/memory_utils.cc Mon Apr 12 00:12:51 2021 +0200
1.3 @@ -4,14 +4,14 @@
1.4
1.5 /* Return page 'n' for the configured page size. */
1.6
1.7 -offset_t page(unsigned int n)
1.8 +length_t page(unsigned int n)
1.9 {
1.10 return PAGE_SIZE * n;
1.11 }
1.12
1.13 /* Return the order of 'size', where 2 ** order yields the size. */
1.14
1.15 -unsigned int page_order(offset_t size)
1.16 +unsigned int page_order(length_t size)
1.17 {
1.18 /* Count zeros from the left, stopping at the first set bit, using the width
1.19 of the size value (in bits, starting with the width in bytes) to
1.20 @@ -22,16 +22,21 @@
1.21
1.22 /* Return 'value' rounded up to the nearest 'increment'. */
1.23
1.24 -offset_t round(offset_t value, offset_t increment)
1.25 +length_t round(length_t value, length_t increment)
1.26 {
1.27 return trunc(value + increment - 1, increment);
1.28 }
1.29
1.30 +offset_t round_offset(offset_t value, length_t increment)
1.31 +{
1.32 + return trunc_offset(value + increment - 1, increment);
1.33 +}
1.34 +
1.35 /* Return 'value' rounded up to the nearest multiple of 'increment'. */
1.36
1.37 -offset_t round_multiple(offset_t value, offset_t increment)
1.38 +length_t round_multiple(length_t value, length_t increment)
1.39 {
1.40 - offset_t last = increment;
1.41 + length_t last = increment;
1.42
1.43 while (1)
1.44 {
1.45 @@ -45,7 +50,12 @@
1.46
1.47 /* Return 'value' rounded down (or truncated) to the nearest 'increment'. */
1.48
1.49 -offset_t trunc(offset_t value, offset_t increment)
1.50 +length_t trunc(length_t value, length_t increment)
1.51 +{
1.52 + return (value / increment) * increment;
1.53 +}
1.54 +
1.55 +offset_t trunc_offset(offset_t value, length_t increment)
1.56 {
1.57 return (value / increment) * increment;
1.58 }
1.59 @@ -53,9 +63,9 @@
1.60 /* Return 'value' rounded down (or truncated) to the nearest multiple of
1.61 'increment'. */
1.62
1.63 -offset_t trunc_multiple(offset_t value, offset_t increment)
1.64 +length_t trunc_multiple(length_t value, length_t increment)
1.65 {
1.66 - offset_t last = increment;
1.67 + length_t last = increment;
1.68
1.69 while (1)
1.70 {
1.71 @@ -70,15 +80,15 @@
1.72 /* Find the maximum size aligned region within the region from 'start' to (but
1.73 not including) 'end', with the given initial 'increment'. */
1.74
1.75 -offset_t max_multiple(offset_t start, offset_t end, offset_t increment)
1.76 +length_t max_multiple(length_t start, length_t end, length_t increment)
1.77 {
1.78 /* The largest possible aligned region is derived from the region size. */
1.79
1.80 - offset_t size = trunc_multiple(end - start, increment);
1.81 + length_t size = trunc_multiple(end - start, increment);
1.82
1.83 /* Apply the alignment to the start. */
1.84
1.85 - offset_t aligned = round(start, size);
1.86 + length_t aligned = round(start, size);
1.87
1.88 /* If the region is aligned, return the size. */
1.89
1.90 @@ -88,7 +98,7 @@
1.91 /* If the region is not aligned to the current size, recalculate the aligned
1.92 size. */
1.93
1.94 - offset_t aligned_size;
1.95 + length_t aligned_size;
1.96
1.97 do
1.98 {