SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "code",
  5.    "execution_count": null,
  6.    "metadata": {
  7.     "ExecuteTime": {
  8.      "end_time": "2019-03-17T20:28:08.969898Z",
  9.      "start_time": "2019-03-17T20:28:08.963947Z"
  10.     }
  11.    },
  12.    "outputs": [],
  13.    "source": [
  14.     "def setidx(i):\n",
  15.     "    ''' in: int\n",
  16.     "    out: 5bit set index (str)'''\n",
  17.     "    b = '{0:016b}'.format(i)\n",
  18.     "    return(b[-10:-5])\n",
  19.     "def tag(i):\n",
  20.     "    ''' in: int\n",
  21.     "    out: 6bit tag '''\n",
  22.     "    b = '{0:016b}'.format(i)\n",
  23.     "    return(b[-16:-10])"
  24.    ]
  25.   },
  26.   {
  27.    "cell_type": "code",
  28.    "execution_count": null,
  29.    "metadata": {
  30.     "ExecuteTime": {
  31.      "end_time": "2019-03-17T20:28:09.336349Z",
  32.      "start_time": "2019-03-17T20:28:09.331364Z"
  33.     }
  34.    },
  35.    "outputs": [],
  36.    "source": [
  37.     "def runs(arr):\n",
  38.     "    hit_count = 0\n",
  39.     "    for i in range(0, 512, 4):\n",
  40.     "        st = [] # set index list\n",
  41.     "        d2 = {} # hist of set idxs per start idx\n",
  42.     "        for item in arr:\n",
  43.     "            val = setidx(item + i)\n",
  44.     "            st.append(val)\n",
  45.     "            try:\n",
  46.     "                d2[val] += 1\n",
  47.     "            except:\n",
  48.     "                d2[val] = 1\n",
  49.     "        if min(d2.values()) == 1: # for some starting address, we get hits\n",
  50.     "            hit_count += 1\n",
  51.     "    print(hit_count / (512 / 4)) # ratio of starting addrs w/ hit"
  52.    ]
  53.   },
  54.   {
  55.    "cell_type": "code",
  56.    "execution_count": null,
  57.    "metadata": {
  58.     "ExecuteTime": {
  59.      "end_time": "2019-03-17T20:28:09.756222Z",
  60.      "start_time": "2019-03-17T20:28:09.749208Z"
  61.     }
  62.    },
  63.    "outputs": [],
  64.    "source": [
  65.     "runs([i * 256 * 4 for i in range(4)]) # stride = 256"
  66.    ]
  67.   },
  68.   {
  69.    "cell_type": "code",
  70.    "execution_count": null,
  71.    "metadata": {
  72.     "ExecuteTime": {
  73.      "end_time": "2019-03-17T20:28:10.608852Z",
  74.      "start_time": "2019-03-17T20:28:10.604830Z"
  75.     }
  76.    },
  77.    "outputs": [],
  78.    "source": [
  79.     "runs([i * 255 * 4 for i in range(5)]) # stride = 255"
  80.    ]
  81.   }
  82.  ],
  83.  "metadata": {
  84.   "kernelspec": {
  85.    "display_name": "Python 3",
  86.    "language": "python",
  87.    "name": "python3"
  88.   },
  89.   "language_info": {
  90.    "codemirror_mode": {
  91.     "name": "ipython",
  92.     "version": 3
  93.    },
  94.    "file_extension": ".py",
  95.    "mimetype": "text/x-python",
  96.    "name": "python",
  97.    "nbconvert_exporter": "python",
  98.    "pygments_lexer": "ipython3",
  99.    "version": "3.6.7"
  100.   }
  101.  },
  102.  "nbformat": 4,
  103.  "nbformat_minor": 2
  104. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top