From 85c7608274bf728839be45f91b11ed31e8371671 Mon Sep 17 00:00:00 2001 From: Leonid Lobachev Date: Mon, 23 Sep 2019 14:05:18 -0700 Subject: [PATCH] staging: gasket: page_table: simplify gasket_components_to_dev_address Refactor gasket_components_to_dev_address to be faster and easier to understand. The old implementation was unnecessarily complex and masked the page_index for simple addresses but not extended ones. It makes the most sense for this function to perform no such masking. Change-Id: If5f68cb6f1bf3000a5d5b77aab89cb8e391c3cf4 Signed-off-by: Nick Ewalt Signed-off-by: Todd Poynor --- gasket_page_table.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/gasket_page_table.c b/gasket_page_table.c index 1c35c0a..4e84864 100644 --- a/gasket_page_table.c +++ b/gasket_page_table.c @@ -725,26 +725,9 @@ static ulong gasket_components_to_dev_address(struct gasket_page_table *pg_tbl, int is_simple, uint page_index, uint offset) { - ulong lvl0_index, lvl1_index; + ulong dev_addr = (page_index << GASKET_SIMPLE_PAGE_SHIFT) | offset; - if (is_simple) { - /* Return simple addresses directly. */ - lvl0_index = page_index & (pg_tbl->config.total_entries - 1); - return (lvl0_index << GASKET_SIMPLE_PAGE_SHIFT) | offset; - } - - /* - * This could be compressed into fewer statements, but - * A) the compiler should optimize it - * B) this is not slow - * C) this is an uncommon operation - * D) this is actually readable this way. - */ - lvl0_index = page_index / GASKET_PAGES_PER_SUBTABLE; - lvl1_index = page_index & (GASKET_PAGES_PER_SUBTABLE - 1); - return (pg_tbl)->extended_flag | - (lvl0_index << GASKET_EXTENDED_LVL0_SHIFT) | - (lvl1_index << GASKET_EXTENDED_LVL1_SHIFT) | offset; + return is_simple ? dev_addr : (pg_tbl->extended_flag | dev_addr); } /*