From 9cf39b7a259a165c845c74d70670bf5eaf79e565 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 17 Aug 2023 14:40:39 +0100 Subject: [PATCH] Prefetch next tile in tile loop iteration --- src/landscape.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/landscape.cpp b/src/landscape.cpp index 65384b6fe0..871067e8cf 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -43,6 +43,8 @@ #include "table/strings.h" #include "table/sprites.h" +#include INCLUDE_FOR_PREFETCH_NTA + #include "safeguards.h" extern const TileTypeProcs @@ -866,10 +868,13 @@ void RunTileLoop(bool apply_day_length) } while (count--) { + /* Get the next tile in sequence using a Galois LFSR. */ + TileIndex next = (tile >> 1) ^ (-(int32)(tile & 1) & feedback); + if (count > 0) PREFETCH_NTA(&_m[next]); + _tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile); - /* Get the next tile in sequence using a Galois LFSR. */ - tile = (tile >> 1) ^ (-(int32)(tile & 1) & feedback); + tile = next; } _cur_tileloop_tile = tile; @@ -887,13 +892,16 @@ void RunAuxiliaryTileLoop() TileIndex tile = _aux_tileloop_tile; while (count--) { + /* Get the next tile in sequence using a Galois LFSR. */ + TileIndex next = (tile >> 1) ^ (-(int32)(tile & 1) & feedback); + if (count > 0) PREFETCH_NTA(&_m[next]); + if (IsFloodingTypeTile(tile) && !IsNonFloodingWaterTile(tile)) { FloodingBehaviour fb = GetFloodingBehaviour(tile); if (fb != FLOOD_NONE) TileLoopWaterFlooding(fb, tile); } - /* Get the next tile in sequence using a Galois LFSR. */ - tile = (tile >> 1) ^ (-(int32)(tile & 1) & feedback); + tile = next; } _aux_tileloop_tile = tile;