summaryrefslogtreecommitdiff
path: root/lib/igt_draw.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-12-07 09:41:25 +0000
committerArkadiusz Hiler <arkadiusz.hiler@intel.com>2017-12-19 15:20:09 +0200
commit8b6b95f31785014ccfdeb19de9bd093245176348 (patch)
tree2049fd7d64a33aaf413ca5bb27956794004734cb /lib/igt_draw.c
parentfda6c109954db928c249befefa4734f430dc948f (diff)
lib/draw: Use more typical form for computing swizzle addresses
Actually use the XOR operation rather than open coding it with three bitwise operators (including XOR itself). Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Diffstat (limited to 'lib/igt_draw.c')
-rw-r--r--lib/igt_draw.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/lib/igt_draw.c b/lib/igt_draw.c
index 76ffb6c2..8f823829 100644
--- a/lib/igt_draw.c
+++ b/lib/igt_draw.c
@@ -97,29 +97,28 @@ const char *igt_draw_get_method_name(enum igt_draw_method method)
}
}
-#define BIT(num, bit) ((num >> bit) & 1)
-
-static int swizzle_addr(int addr, int swizzle)
+static unsigned long swizzle_bit(unsigned int bit, unsigned long offset)
{
- int bit6;
+ return (offset & (1ul << bit)) >> (bit - 6);
+}
+static int swizzle_addr(unsigned long addr, int swizzle)
+{
switch (swizzle) {
case I915_BIT_6_SWIZZLE_NONE:
- bit6 = BIT(addr, 6);
- break;
+ return addr;
case I915_BIT_6_SWIZZLE_9:
- bit6 = BIT(addr, 6) ^ BIT(addr, 9);
- break;
+ return addr ^ swizzle_bit(9, addr);
case I915_BIT_6_SWIZZLE_9_10:
- bit6 = BIT(addr, 6) ^ BIT(addr, 9) ^ BIT(addr, 10);
- break;
+ return addr ^ swizzle_bit(9, addr) ^ swizzle_bit(10, addr);
case I915_BIT_6_SWIZZLE_9_11:
- bit6 = BIT(addr, 6) ^ BIT(addr, 9) ^ BIT(addr, 11);
- break;
+ return addr ^ swizzle_bit(9, addr) ^ swizzle_bit(11, addr);
case I915_BIT_6_SWIZZLE_9_10_11:
- bit6 = BIT(addr, 6) ^ BIT(addr, 9) ^ BIT(addr, 10) ^
- BIT(addr, 11);
- break;
+ return (addr ^
+ swizzle_bit(9, addr) ^
+ swizzle_bit(10, addr) ^
+ swizzle_bit(11, addr));
+
case I915_BIT_6_SWIZZLE_UNKNOWN:
case I915_BIT_6_SWIZZLE_9_17:
case I915_BIT_6_SWIZZLE_9_10_17:
@@ -127,12 +126,8 @@ static int swizzle_addr(int addr, int swizzle)
/* If we hit this case, we need to implement support for the
* appropriate swizzling method. */
igt_require(false);
- break;
+ return addr;
}
-
- addr &= ~(1 << 6);
- addr |= (bit6 << 6);
- return addr;
}
static int tile(int x, int y, uint32_t x_tile_size, uint32_t y_tile_size,