implement correct prefix counting

This commit is contained in:
2025-06-05 03:42:30 +00:00
parent d3fe6efd47
commit 25e5a86a43

View File

@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 1,
"id": "58fc6db9", "id": "58fc6db9",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -13,7 +13,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 2,
"id": "e07be4b3", "id": "e07be4b3",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -27,7 +27,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 3,
"id": "1516ff91", "id": "1516ff91",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -41,7 +41,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 4,
"id": "55167c28", "id": "55167c28",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -53,17 +53,19 @@
"\tstep = 0\n", "\tstep = 0\n",
"\n", "\n",
"\tfor layer in layers:\n", "\tfor layer in layers:\n",
"\n", "\t\t\n",
"\t\t# assume that each range requires all of 2*k bits when performing prefix expansion\n",
"\t\tnum_ranges = len(layers[layer])\n", "\t\tnum_ranges = len(layers[layer])\n",
"\t\trange_expansion_bits = 2 * field_width[layer]\n", "\t\t# assume that each range requires all of 2*k prefixes when performing prefix expansion\n",
"\t\t# therefore there are 2*k * R for R ranges and width k\n",
"\t\tnum_prefixes = 2 * field_width[layer] * num_ranges\n",
"\t\tprefix_width = field_width[layer]\n",
"\n", "\n",
"\t\ttcam = {\n", "\t\ttcam = {\n",
"\t\t\t\"id\": f\"{layer}_range\",\n", "\t\t\t\"id\": f\"{layer}_range\",\n",
"\t\t\t\"step\": step,\n", "\t\t\t\"step\": step,\n",
"\t\t\t\"match\": \"ternary\",\n", "\t\t\t\"match\": \"ternary\",\n",
"\t\t\t\"entries\": num_ranges,\n", "\t\t\t\"entries\": num_prefixes,\n",
"\t\t\t\"key_size\": range_expansion_bits\n", "\t\t\t\"key_size\": prefix_width\n",
"\t\t}\n", "\t\t}\n",
"\n", "\n",
"\t\t# assume no pointer reuse for metadata storage\n", "\t\t# assume no pointer reuse for metadata storage\n",
@@ -91,7 +93,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 5,
"id": "48011528", "id": "48011528",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [