sv_binutils: generate register categories mapping
authorDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Sun, 10 Apr 2022 19:52:00 +0000 (19:52 +0000)
committerDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Sun, 10 Apr 2022 19:52:08 +0000 (19:52 +0000)
src/openpower/sv/sv_binutils.py

index e11c9f4738f7f590f3b6b0eabd94316dd09e75c7..8b3dbf6c062ce83b8ee083e9ef97d910e22ba272 100644 (file)
@@ -334,6 +334,18 @@ class Codegen(_enum.Enum):
             yield f"#define SVP64_NAME_MAX {max(map(lambda entry: len(entry.name), entries))}"
             yield ""
 
+            yield "enum svp64_reg_category {"
+            yield "    SVP64_REG_CATEGORY_UNKNOWN,"
+            yield "    SVP64_REG_CATEGORY_GPR,"
+            yield "    SVP64_REG_CATEGORY_FPR,"
+            yield "    SVP64_REG_CATEGORY_CR_3BIT,"
+            yield "    SVP64_REG_CATEGORY_CR_5BIT,"
+            yield "};"
+            yield ""
+
+            yield "enum svp64_reg_category"
+            yield "svp64_reg_category(unsigned char type);"
+
             yield "#ifdef __cplusplus"
             yield "}"
             yield "#endif"
@@ -359,6 +371,45 @@ class Codegen(_enum.Enum):
             yield "    sizeof (svp64_entries) / sizeof (svp64_entries[0]);"
             yield ""
 
+            yield "#ifndef BC"
+            yield "#define BC CRB"
+            yield "#endif"
+            yield ""
+            yield "enum svp64_reg_category"
+            yield "svp64_reg_category(unsigned char type)"
+            yield "{"
+            yield "    size_t i;"
+            yield "    static struct {"
+            yield "        unsigned char type;"
+            yield "        unsigned char category;"
+            yield "    } const table[] = {"
+            yield "        {BF  , SVP64_REG_CATEGORY_CR_3BIT},"
+            yield "        {BFA , SVP64_REG_CATEGORY_CR_3BIT},"
+            yield "        {BA  , SVP64_REG_CATEGORY_CR_5BIT},"
+            yield "        {BB  , SVP64_REG_CATEGORY_CR_5BIT},"
+            yield "        {BC  , SVP64_REG_CATEGORY_CR_5BIT},"
+            yield "        {BI  , SVP64_REG_CATEGORY_CR_5BIT},"
+            yield "        {BT  , SVP64_REG_CATEGORY_CR_5BIT},"
+            yield "        {RA  , SVP64_REG_CATEGORY_GPR},"
+            yield "        {RB  , SVP64_REG_CATEGORY_GPR},"
+            yield "        {RC  , SVP64_REG_CATEGORY_GPR},"
+            yield "        {RS  , SVP64_REG_CATEGORY_GPR},"
+            yield "        {RT  , SVP64_REG_CATEGORY_GPR},"
+            yield "        {FRA , SVP64_REG_CATEGORY_FPR},"
+            yield "        {FRB , SVP64_REG_CATEGORY_FPR},"
+            yield "        {FRC , SVP64_REG_CATEGORY_FPR},"
+            yield "        {FRS , SVP64_REG_CATEGORY_FPR},"
+            yield "        {FRT , SVP64_REG_CATEGORY_FPR},"
+            yield "    };"
+            yield ""
+            yield "    for (i = 0; i < sizeof (table) / sizeof (table[0]); ++i) {"
+            yield "        if (table[i].type == type)"
+            yield "            return (enum svp64_reg_category)table[i].category;"
+            yield "    }"
+            yield ""
+            yield "    return SVP64_REG_CATEGORY_UNKNOWN;"
+            yield "}"
+
         return {
             Codegen.PPC_SVP64_H: ppc_svp64_h,
             Codegen.PPC_SVP64_OPC_C: ppc_svp64_opc_c,