Skip to content

Conversation

@dneto0
Copy link
Collaborator

@dneto0 dneto0 commented Apr 25, 2025

Use compressed grammar tables for core instructions and operands

Use a new 'utils/ggt.py' script to generate the compressed tables.

  • The new tables are created at build time, and there is one static
    global table for each of the following:

    • a strings table
    • an instruction description table, sorted by opcode
      Each entry is a spvtools::InstructionDesc object.
    • an instruction name to opcode table, sorted by string name
      This includes aliases.
    • an operand description table, sorted by (operand type, operand value)
      Each entry is a spvtools::OperandDesc object.
    • an operand name table, sorted by (operand type, string name)
      This includes aliases.
    • a table of string aliases
    • a table of capabilities
    • a table of extensions
  • Entries in the tables use IndexRanges to refer to sequences of
    objects in one of the other tables.

    • A string encoded as an IndexRange into the global strings table.
    • A sequence of capabilities is encoded as an IndexRange into
      the capabilities table.
    • A sequence of extensions is encoded as an IndexRange into
      the extensions table.
    • A sequence of aliases is encoded as an IndexRange into
      the aliases table.
    • Each entry in the aliases table is an IndexRange into the
      global string table.
  • The InstructionDesc object has scalar values such as opcode,
    hasResult, hasValue, and uses IndexRanges to express the
    opcode name, aliases, operands, capabilities, operands, and
    extensions.

  • The OperandDesc object has scalar values such as enum value,
    and uses IndexRanges to express the operand name, aliases, operands,
    capabilities, operands, and extensions.

Remaining work:

  • Use compressed tables for extension enums and extended instruction
    sets.
  • At that point, the old utils/generate_grammar_tables.py will be
    obsolete and we can move ggt.py into it.

Bug: crbug.com/413723100

@dneto0 dneto0 force-pushed the smaller-table-squash branch 5 times, most recently from b916114 to 0948aff Compare April 27, 2025 21:09
@dneto0 dneto0 changed the title Smaller table squash Use compressed grammar tables for core instructions and operands Apr 27, 2025
@dneto0 dneto0 force-pushed the smaller-table-squash branch from 0948aff to 06db5e2 Compare April 28, 2025 17:28
@dneto0 dneto0 requested a review from alan-baker April 28, 2025 17:29
@dneto0 dneto0 marked this pull request as ready for review April 28, 2025 17:29
Use a new 'utils/ggt.py' script to generate the compressed tables.

- The new tables are created at build time, and there is one static
  global table for each of the following:
  - a strings table
  - an instruction description table, sorted by opcode
    Each entry is a spvtools::InstructionDesc object.
  - an instruction name to opcode table, sorted by string name
    This includes aliases.
  - an operand description table, sorted by (operand type, operand value)
    Each entry is a spvtools::OperandDesc object.
  - an operand name table, sorted by (operand type, string name)
    This includes aliases.
  - a table of string aliases
  - a table of capabilities
  - a table of extensions

- Entries in the tables use IndexRanges to refer to sequences of
  objects in one of the other tables.
   - A string encoded as an IndexRange into the global strings table.
   - A sequence of capabilities is encoded as an IndexRange into
     the capabilities table.
   - A sequence of extensions is encoded as an IndexRange into
     the extensions table.
   - A sequence of aliases is encoded as an IndexRange into
     the aliases table.
   - Each entry in the aliases table is an IndexRange into the
     global string table.

- The InstructionDesc object has scalar values such as opcode,
  hasResult, hasValue, and uses IndexRanges to express the
  opcode name, aliases, operands, capabilities, operands, and
  extensions.

- The OperandDesc object has scalar values such as enum value,
  and uses IndexRanges to express the operand name, aliases, operands,
  capabilities, operands, and extensions.

Remaining work:
- Use compressed tables for extension enums and extended instruction
  sets.
- At that point, the old utils/generate_grammar_tables.py will be
  obsolete and we can move ggt.py into it.

Bug: crbug.com/413723100
@dneto0 dneto0 force-pushed the smaller-table-squash branch from 06db5e2 to bd1b7a2 Compare April 28, 2025 18:18
Copy link
Contributor

@alan-baker alan-baker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very nice overall.

- fix typos
- to test for failure check SPV_SUCCESS != ...
- fix formatting

Co-authored-by: alan-baker <[email protected]>
@dneto0 dneto0 force-pushed the smaller-table-squash branch from c4c7ca0 to 71e3ec6 Compare April 30, 2025 20:53
@dneto0 dneto0 requested a review from alan-baker April 30, 2025 20:54
@dneto0 dneto0 enabled auto-merge (squash) April 30, 2025 21:16
@dneto0 dneto0 merged commit 62de1f7 into KhronosGroup:main Apr 30, 2025
22 of 23 checks passed
wooyoungqcom pushed a commit to CodeLinaro/SPIRV-Tools that referenced this pull request May 5, 2025
…onosGroup#6107)

* Use compressed grammar tables for core instructions and operands

Use a new 'utils/ggt.py' script to generate the compressed tables.

- The new tables are created at build time, and there is one static
  global table for each of the following:
  - a strings table
  - an instruction description table, sorted by opcode
    Each entry is a spvtools::InstructionDesc object.
  - an instruction name to opcode table, sorted by string name
    This includes aliases.
  - an operand description table, sorted by (operand type, operand value)
    Each entry is a spvtools::OperandDesc object.
  - an operand name table, sorted by (operand type, string name)
    This includes aliases.
  - a table of string aliases
  - a table of capabilities
  - a table of extensions

- Entries in the tables use IndexRanges to refer to sequences of
  objects in one of the other tables.
   - A string encoded as an IndexRange into the global strings table.
   - A sequence of capabilities is encoded as an IndexRange into
     the capabilities table.
   - A sequence of extensions is encoded as an IndexRange into
     the extensions table.
   - A sequence of aliases is encoded as an IndexRange into
     the aliases table.
   - Each entry in the aliases table is an IndexRange into the
     global string table.

- The InstructionDesc object has scalar values such as opcode,
  hasResult, hasValue, and uses IndexRanges to express the
  opcode name, aliases, operands, capabilities, operands, and
  extensions.

- The OperandDesc object has scalar values such as enum value,
  and uses IndexRanges to express the operand name, aliases, operands,
  capabilities, operands, and extensions.

Remaining work:
- Use compressed tables for extension enums and extended instruction
  sets.
- At that point, the old utils/generate_grammar_tables.py will be
  obsolete and we can move ggt.py into it.

Bug: crbug.com/413723100

* Fix Android.mk dependency on core_tables.inc

* Apply fixes from review

- fix typos
- to test for failure check SPV_SUCCESS != ...
- fix formatting

Co-authored-by: alan-baker <[email protected]>

---------

Co-authored-by: alan-baker <[email protected]>
@y-novikov y-novikov mentioned this pull request May 9, 2025
alan-baker pushed a commit that referenced this pull request May 9, 2025
Use sys.exit() instead.

Fixes: #6107
@dneto0 dneto0 deleted the smaller-table-squash branch September 25, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants