Skip to content

Commit

Permalink
Keep off counter in a register
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMula committed Apr 28, 2022
1 parent 9a5c03b commit 1b8091b
Show file tree
Hide file tree
Showing 2 changed files with 524 additions and 546 deletions.
70 changes: 32 additions & 38 deletions huff0/_generate/gen.go
Expand Up @@ -69,16 +69,10 @@ func (d decompress4x) generateProcedure(name string) {
Pragma("noescape")

out := reg.RAX // Fixed since we need 8H
offsetComp, err := ReturnIndex(0).Resolve()
if err != nil {
panic(err)
}
offP := offsetComp.Addr
{
off := GP8()
XORB(off, off) // off = 0
MOVB(off, offP)
}

off := GP64()
XORQ(off, off)

exhausted := reg.RBX // Fixed since we need 8H
XORQ(exhausted.As64(), exhausted.As64()) // exhausted = false

Expand All @@ -97,27 +91,32 @@ func (d decompress4x) generateProcedure(name string) {
Label("main_loop")

br0 := Dereference(Param("pbr0"))
d.decodeTwoValues(0, br0, peekBits, table, buffer, out, exhausted, offP)
d.decodeTwoValues(0, br0, peekBits, table, buffer, off, out, exhausted)
br1 := Dereference(Param("pbr1"))
d.decodeTwoValues(1, br1, peekBits, table, buffer, out, exhausted, offP)
d.decodeTwoValues(1, br1, peekBits, table, buffer, off, out, exhausted)
br2 := Dereference(Param("pbr2"))
d.decodeTwoValues(2, br2, peekBits, table, buffer, out, exhausted, offP)
d.decodeTwoValues(2, br2, peekBits, table, buffer, off, out, exhausted)
br3 := Dereference(Param("pbr3"))
d.decodeTwoValues(3, br3, peekBits, table, buffer, out, exhausted, offP)
d.decodeTwoValues(3, br3, peekBits, table, buffer, off, out, exhausted)

ADDB(U8(2), offP) // off += 2
ADDB(U8(2), off.As8()) // off += 2

TESTB(exhausted.As8H(), exhausted.As8H()) // any br[i].ofs < 4?
JNZ(LabelRef("done"))

CMPB(offP, U8(0))
CMPB(off.As8(), U8(0))
JNZ(LabelRef("main_loop"))

Label("done")
offsetComp, err := ReturnIndex(0).Resolve()
if err != nil {
panic(err)
}
MOVB(off.As8(), offsetComp.Addr)
RET()
}

func (d decompress4x) decodeTwoValues(id int, br gotypes.Component, peekBits, table, buffer reg.GPVirtual, out, exhausted reg.GPPhysical, offP Mem) {
func (d decompress4x) decodeTwoValues(id int, br gotypes.Component, peekBits, table, buffer, off reg.GPVirtual, out, exhausted reg.GPPhysical) {
Commentf("br%d.fillFast()", id)
brOffset := GP64()
brBitsRead := GP64()
Expand Down Expand Up @@ -211,8 +210,6 @@ func (d decompress4x) decodeTwoValues(id int, br gotypes.Component, peekBits, ta
Comment("these two writes get coalesced")
Comment("buf[stream][off] = uint8(v0.entry >> 8)")
Comment("buf[stream][off+1] = uint8(v1.entry >> 8)")
off := GP64()
MOVBQZX(offP, off)
MOVW(out.As16(), Mem{Base: buffer, Index: off, Scale: 1, Disp: id * buffoff})

Comment("update the bitrader reader structure")
Expand All @@ -232,16 +229,10 @@ func (d decompress4x8bit) generateProcedure(name string) {
Pragma("noescape")

out := reg.RAX // Fixed since we need 8H
offsetComp, err := ReturnIndex(0).Resolve()
if err != nil {
panic(err)
}
offP := offsetComp.Addr
{
off := GP8()
XORB(off, off) // off = 0
MOVB(off, offP)
}

off := GP64()
XORQ(off, off)

exhausted := reg.RBX // Fixed since we need 8H
XORQ(exhausted.As64(), exhausted.As64()) // exhausted = false

Expand All @@ -260,27 +251,32 @@ func (d decompress4x8bit) generateProcedure(name string) {
Label("main_loop")

br0 := Dereference(Param("pbr0"))
d.decodeFourValues(0, br0, peekBits, table, buffer, out, exhausted, offP)
d.decodeFourValues(0, br0, peekBits, table, buffer, off, out, exhausted)
br1 := Dereference(Param("pbr1"))
d.decodeFourValues(1, br1, peekBits, table, buffer, out, exhausted, offP)
d.decodeFourValues(1, br1, peekBits, table, buffer, off, out, exhausted)
br2 := Dereference(Param("pbr2"))
d.decodeFourValues(2, br2, peekBits, table, buffer, out, exhausted, offP)
d.decodeFourValues(2, br2, peekBits, table, buffer, off, out, exhausted)
br3 := Dereference(Param("pbr3"))
d.decodeFourValues(3, br3, peekBits, table, buffer, out, exhausted, offP)
d.decodeFourValues(3, br3, peekBits, table, buffer, off, out, exhausted)

ADDB(U8(4), offP) // off += 4
ADDB(U8(4), off.As8()) // off += 4

TESTB(exhausted.As8H(), exhausted.As8H()) // any br[i].ofs < 4?
JNZ(LabelRef("done"))

CMPB(offP, U8(0))
CMPB(off.As8(), U8(0))
JNZ(LabelRef("main_loop"))

Label("done")
offsetComp, err := ReturnIndex(0).Resolve()
if err != nil {
panic(err)
}
MOVB(off.As8(), offsetComp.Addr)
RET()
}

func (d decompress4x8bit) decodeFourValues(id int, br gotypes.Component, peekBits, table, buffer reg.GPVirtual, out, exhausted reg.GPPhysical, offP Mem) {
func (d decompress4x8bit) decodeFourValues(id int, br gotypes.Component, peekBits, table, buffer, off reg.GPVirtual, out, exhausted reg.GPPhysical) {
Commentf("br%d.fillFast()", id)
brOffset := GP64()
brBitsRead := GP64()
Expand Down Expand Up @@ -361,8 +357,6 @@ func (d decompress4x8bit) decodeFourValues(id int, br gotypes.Component, peekBit
Comment("buf[stream][off+1] = uint8(v1.entry >> 8)")
Comment("buf[stream][off+2] = uint8(v2.entry >> 8)")
Comment("buf[stream][off+3] = uint8(v3.entry >> 8)")
off := GP64()
MOVBQZX(offP, off)
MOVL(out.As32(), Mem{Base: buffer, Index: off, Scale: 1, Disp: id * buffoff})

Comment("update the bitrader reader structure")
Expand Down

0 comments on commit 1b8091b

Please sign in to comment.