Skip to content

Inline fast path for InputStream::get - #2505

Closed
nikosavola wants to merge 2 commits into
KLayout:masterfrom
nikosavola:pr-stream-get-inline
Closed

nikosavola wants to merge 2 commits into
KLayout:masterfrom
nikosavola:pr-stream-get-inline

Conversation

@nikosavola

Copy link
Copy Markdown
Contributor
  • InputStream::get was defined in tlStream.cc, so byte-wise readers like the OASIS varint decoder paid a call into the tl library for every byte, two inside a CBLOCK
  • it is now defined in the class in tlStream.h. It serves bytes straight from the read buffer, and single bytes from the inflate ring buffer. Refills, the end of the inflated data and the last ring slot go to the old code, now called get_slow
  • the last ring slot is excluded because get rotates the ring there, so the read pointer does not wrap and a following unget (1) still works. The OASIS reader does that get/unget pair in mark_start_table
  • tlStream.h now needs the InflateFilter definition, so tlDeflate.h no longer includes tlStream.h and BitStream::get_byte moved to tlDeflate.cc
  • new test for byte-wise inflating reads with a get/unget pair per byte across the whole ring buffer
  • this is the first piece of the split of Inflate OASIS CBLOCKs in one go with zlib #2468
case before ms after ms speedup
OASIS read with CBLOCKs (vexriscv) 145.0 132.4 1.09x
GDS2 read (vexriscv) 135.9 127.8 1.06x
OASIS read (vexriscv) 71.5 69.9 1.02x

Xeon Gold 6248, gcc 13 -O2, before and after alternated for 6 rounds on one pinned core, every round agrees.

- get was out-of-line, so byte-wise readers such as the OASIS varint decoder and the GDS2 record reader paid a call per get, two inside a CBLOCK
- the inline get serves bytes from the raw buffer and single bytes from the inflate ring buffer, refills and the end of the inflated data stay in get_slow
- the last ring slot is left to get_slow too: get rotates the ring there so the read pointer does not wrap, otherwise a following unget(1) asserts
- tlStream.h now needs the InflateFilter definition, so tlDeflate.h no longer includes tlStream.h and BitStream::get_byte moved to tlDeflate.cc

| case | before ms | after ms | speedup |
|---|---:|---:|---:|
| oasis_read_vexriscv_compressed | 145.0 | 132.4 | 1.09x |
| gds2_read_vexriscv | 135.9 | 127.8 | 1.06x |
| oasis_read_vexriscv | 71.5 | 69.9 | 1.02x |

Xeon Gold 6248, g++ 13 -O2, before and after alternated for 6 rounds on one pinned core, every round agrees.
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.

1 participant