root/src/dps8/ucache.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ucInvalidate
  2. ucacheStats

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 70f11728-171b-11ee-ac22-80ee73e9b8e7
   5  *
   6  * ---------------------------------------------------------------------------
   7  *
   8  * Copyright (c) 2022 Charles Anthony
   9  * Copyright (c) 2022-2025 The DPS8M Development Team
  10  *
  11  * This software is made available under the terms of the ICU License.
  12  * See the LICENSE.md file at the top-level directory of this distribution.
  13  *
  14  * ---------------------------------------------------------------------------
  15  */
  16 
  17 #include <string.h>
  18 
  19 #include "dps8.h"
  20 #include "dps8_cpu.h"
  21 
  22 void ucInvalidate (cpu_state_t * cpup) {
     /* [previous][next][first][last][top][bottom][index][help] */
  23   (void)memset (cpu.uCache.caches, 0, sizeof (cpu.uCache.caches));
  24 }
  25 
  26 void ucCacheSave \
  27          (cpu_state_t * cpup, uint ucNum, word15 segno, word18 offset, word14 bound,
  28           word1 p, word24 address, word3 r1, bool paged) {
  29   if (segno >= UC_CACHE_SZ) {
  30     return;
  31   }
  32   // With the associative memories modelled (enable_wam) and the SDWAM or
  33   // (for a paged segment) the PTWAM off, the hardware fetches the SDW/PTW
  34   // on every access, so a store to it takes effect at once; the micro-
  35   // cache must not hide that (PA885 10B). Not cached then: CAMS/CAMP,
  36   // which turn them off, and a CPU reset or configuration change clear
  37   // the micro-cache, so ucCacheCheck needn't test this on every hit.
  38   if (cpu.tweaks.enable_wam && (! cpu.cu.SD_ON || (paged && ! cpu.cu.PT_ON)))
  39     return;
  40   ucache_t * ep;
  41   ep          = & cpu.uCache.caches[ucNum][segno];
  42   ep->valid   = true;
  43   ep->segno   = segno;
  44   ep->offset  = offset;
  45   ep->bound   = bound;
  46   ep->address = address;
  47   ep->r1      = r1;
  48   ep->p       = p;
  49   ep->paged   = paged;
  50 #if defined(HDBG)
  51   hdbgNote ("ucache", "save %u %05o:%06o %05o %o %08o %o %o",
  52             ucNum, segno, offset, bound, p, address, r1, paged);
  53 #endif
  54 }
  55 
  56 // (inline: a hint, so that it stays inlined into both copies of the
  57 // append cycles; see FULL_MODEL_ON)
  58 inline bool ucCacheCheck \
  59          (cpu_state_t * cpup, uint ucNum, word15 segno, word18 offset, word14 * bound,
  60           word1 * p, word24 * address, word3 * r1, bool * paged) {
  61   if (segno >= UC_CACHE_SZ) {
  62 #if defined(UCACHE_STATS)
  63     cpu.uCache.segnoSkips ++;
  64 #endif
  65     return false;
  66   }
  67   ucache_t * ep;
  68   ep = & cpu.uCache.caches[ucNum][segno];
  69   // Is cache entry valid?
  70   if (! ep->valid) {
  71 #if defined(HDBG)
  72     hdbgNote ("ucache", "check not valid");
  73 #endif
  74     goto miss;
  75   }
  76 
  77 
  78 
  79 
  80 
  81 
  82 
  83 
  84 
  85   // Same page?
  86   if (ep->paged && ((ep->offset & PG18MASK) != (offset & PG18MASK))) {
  87 #if defined(HDBG)
  88     hdbgNote ("ucache", "pgno %o != %o\r\n", (ep->offset & PG18MASK), (offset & PG18MASK));
  89 #endif
  90     goto miss;
  91   }
  92   // In bounds?
  93   if (((offset >> 4) & 037777) > ep->bound) {
  94     //sim_printf ("bound %o != %o\r\n", ((offset >> 4) & 037777), ep->bound);
  95 #if defined(HDBG)
  96     hdbgNote ("ucache", "bound %o != %o\r\n", ((offset >> 4) & 037777), ep->bound);
  97 #endif
  98     goto miss;
  99   }
 100 #if defined(HDBG)
 101   hdbgNote ("ucache", "hit %u %05o:%06o %05o %o %08o %o %o",
 102             ucNum, segno, offset, ep->bound, ep->p, ep->address, ep->r1, ep->paged);
 103 #endif
 104   * bound = ep->bound;
 105 
 106 
 107 
 108 
 109 
 110 
 111 
 112 
 113 
 114 
 115 
 116 
 117 
 118 
 119   * address = ep->address;
 120 
 121   * r1      = ep->r1;
 122   * p       = ep->p;
 123   * paged   = ep->paged;
 124 #if defined(UCACHE_STATS)
 125   cpu.uCache.hits[ucNum] ++;
 126 #endif
 127   return true;
 128 miss:;
 129 #if defined(UCACHE_STATS)
 130   cpu.uCache.misses[ucNum] ++;
 131 #endif
 132   return false;
 133 }
 134 
 135 #if defined(UCACHE_STATS)
 136 void ucacheStats (int cpuNo) {
     /* [previous][next][first][last][top][bottom][index][help] */
 137   (void)fflush(stdout);
 138   (void)fflush(stderr);
 139   sim_msg ("\r\n|   CPU %c Micro-cache Statistics  |", 'A' + cpuNo);
 140   sim_msg ("\r\n+---------------------------------+\r\n");
 141 # define pct(a, b) ((b) ? (a) * 100.0 / ((a) + (b)) : 0)
 142 # define args(a, b, c) a, b, c, pct (a, (b + c))
 143 # define stats(n) args ( (long long unsigned)cpus[cpuNo].uCache.hits  [n], \
 144                          (long long unsigned)cpus[cpuNo].uCache.misses[n], \
 145                          (long long unsigned)cpus[cpuNo].uCache.skips [n] )
 146   (void)fflush(stdout);
 147   (void)fflush(stderr);
 148 # if defined(WIN_STDIO)
 149   sim_msg ("\r|  Instruction Fetch:             |\r\n|    Hits        %15llu  |"
 150            "\r\n|    Misses      %15llu  |\r\n|    Skipped     %15llu  |"
 151            "\r\n|    Effectiveness   %10.2f%%  |\r\n",
 152            stats (UC_INSTRUCTION_FETCH));
 153   (void)fflush(stdout);
 154   (void)fflush(stderr);
 155   sim_msg ("\r+---------------------------------+\r\n");
 156   sim_msg ("\r|  Operand Read:                  |\r\n|    Hits        %15llu  |"
 157            "\r\n|    Misses      %15llu  |\r\n|    Skipped     %15llu  |"
 158            "\r\n|    Effectiveness   %10.2f%%  |\r\n",
 159            stats (UC_OPERAND_READ));
 160   (void)fflush(stdout);
 161   (void)fflush(stderr);
 162 #  if defined(IDWF_CACHE)
 163   sim_msg ("\r+---------------------------------+\r\n");
 164   sim_msg ("\r|  Indirect Word Fetch:           |\r\n|    Hits        %15llu  |"
 165            "\r\n|    Misses      %15llu  |\r\n|    Skipped     %15llu  |"
 166            "\r\n|    Effectiveness   %10.2f%%  |\r\n",
 167            stats (UC_INDIRECT_WORD_FETCH));
 168   (void)fflush(stdout);
 169   (void)fflush(stderr);
 170 #  endif
 171   sim_msg ("\r+---------------------------------+\r\n");
 172   sim_msg ("\r|  Cache Bypasses:                |\r\n");
 173   sim_msg ("\r|    RALR        %15llu  |\r\n",
 174            (long long unsigned)cpus[cpuNo].uCache.ralrSkips);
 175   sim_msg ("\r|    CALL6       %15llu  |\r\n",
 176            (long long unsigned)cpus[cpuNo].uCache.call6Skips);
 177   sim_msg ("\r|    Segno       %15llu  |\r\n",
 178            (long long unsigned)cpus[cpuNo].uCache.segnoSkips);
 179   (void)fflush(stdout);
 180   (void)fflush(stderr);
 181 # else
 182   sim_msg ("\r|  Instruction Fetch:             |\r\n|    Hits        %'15llu  |"
 183            "\r\n|    Misses      %'15llu  |\r\n|    Skipped     %'15llu  |"
 184            "\r\n|    Effectiveness   %'10.2f%%  |\r\n",
 185            stats (UC_INSTRUCTION_FETCH));
 186   (void)fflush(stdout);
 187   (void)fflush(stderr);
 188   sim_msg ("\r+---------------------------------+\r\n");
 189   sim_msg ("\r|  Operand Read:                  |\r\n|    Hits        %'15llu  |"
 190            "\r\n|    Misses      %'15llu  |\r\n|    Skipped     %'15llu  |"
 191            "\r\n|    Effectiveness   %'10.2f%%  |\r\n",
 192            stats (UC_OPERAND_READ));
 193   (void)fflush(stdout);
 194   (void)fflush(stderr);
 195 #  if defined(IDWF_CACHE)
 196   sim_msg ("\r+---------------------------------+\r\n");
 197   sim_msg ("\r|  Indirect Word Fetch:           |\r\n|    Hits        %'15llu  |"
 198            "\r\n|    Misses      %'15llu  |\r\n|    Skipped     %'15llu  |"
 199            "\r\n|    Effectiveness   %'10.2f%%  |\r\n",
 200            stats (UC_INDIRECT_WORD_FETCH));
 201   (void)fflush(stdout);
 202   (void)fflush(stderr);
 203 #  endif
 204   sim_msg ("\r+---------------------------------+\r\n");
 205   sim_msg ("\r|  Cache Bypasses:                |\r\n");
 206   sim_msg ("\r|    RALR        %'15llu  |\r\n",
 207            (long long unsigned)cpus[cpuNo].uCache.ralrSkips);
 208   sim_msg ("\r|    CALL6       %'15llu  |\r\n",
 209            (long long unsigned)cpus[cpuNo].uCache.call6Skips);
 210   sim_msg ("\r|    Segno       %'15llu  |\r\n",
 211            (long long unsigned)cpus[cpuNo].uCache.segnoSkips);
 212   (void)fflush(stdout);
 213   (void)fflush(stderr);
 214 # endif
 215   sim_msg ("\r+---------------------------------+\r\n");
 216   (void)fflush(stdout);
 217   (void)fflush(stderr);
 218 # undef pct
 219 # undef args
 220 # undef stats
 221 }
 222 #endif

/* [previous][next][first][last][top][bottom][index][help] */