Skip to content

Commit

Permalink
cmd/compile: WIP implement codegen of count-{leading,trailing}-ones o…
Browse files Browse the repository at this point in the history
…n loong64

tests TODO

Updates golang#59120

Change-Id: Icde85d717999600954244c1105b7c55759d3469f
  • Loading branch information
xen0n committed Mar 27, 2023
1 parent 717265b commit ff64d75
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/cmd/compile/internal/loong64/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
ssa.OpLOONG64CTZV,
ssa.OpLOONG64CLZW,
ssa.OpLOONG64CLZV,
ssa.OpLOONG64CTOW,
ssa.OpLOONG64CTOV,
ssa.OpLOONG64CLOW,
ssa.OpLOONG64CLOV,
ssa.OpLOONG64REVB2H,
ssa.OpLOONG64REVB2W,
ssa.OpLOONG64REVBV,
Expand Down
9 changes: 8 additions & 1 deletion src/cmd/compile/internal/ssa/_gen/LOONG64.rules
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@
// unary ops
(Neg(64|32|16|8) ...) => (NEGV ...)
(Neg(32|64)F ...) => (NEG(F|D) ...)
(Ctz(32|64) ...) => (CTZ(W|V) ...)
(Ctz32 (Com32 x)) => (CTOW x)
(Ctz64 (Com64 x)) => (CTOV x)
(Ctz(32|64) x) => (CTZ(W|V) x)
(Ctz(8|16|32|64)NonZero ...) => (Ctz(8|16|32|64) ...)
(BitLen64 <t> (Com64 x)) => (NEGV <t> (SUBVconst <t> [64] (CLOV <t> x)))
(BitLen32 <t> (Com32 x)) => (NEGV <t> (SUBVconst <t> [32] (CLOW <t> x)))
(BitLen64 <t> x) => (NEGV <t> (SUBVconst <t> [64] (CLZV <t> x)))
(BitLen32 <t> x) => (NEGV <t> (SUBVconst <t> [32] (CLZW <t> x)))
(Bswap(16|32|64) ...) => (REVB(2H|2W|V) ...)
Expand Down Expand Up @@ -619,6 +623,9 @@
(OR x x) => x
(XOR x x) => (MOVVconst [0])

// recognize and fold counting of leading/trailing ones
(C(TZW|TZV|LZW|LZV) (NOR (MOVVconst [0]) x)) => (C(TOW|TOV|LOW|LOV) x)

// remove redundant *const ops
(ADDVconst [0] x) => x
(SUBVconst [0] x) => x
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func init() {
{name: "CTZV", argLength: 1, reg: gp11, asm: "CTZV"}, // Count trailing (low order) zeroes (returns 0-64)
{name: "CLZW", argLength: 1, reg: gp11, asm: "CLZW"}, // Count leading (high order) zeroes (returns 0-32)
{name: "CLZV", argLength: 1, reg: gp11, asm: "CLZV"}, // Count leading (high order) zeroes (returns 0-64)
{name: "CTOW", argLength: 1, reg: gp11, asm: "CTOW"}, // Count trailing (low order) ones (returns 0-32)
{name: "CTOV", argLength: 1, reg: gp11, asm: "CTOV"}, // Count trailing (low order) ones (returns 0-64)
{name: "CLOW", argLength: 1, reg: gp11, asm: "CLOW"}, // Count leading (high order) ones (returns 0-32)
{name: "CLOV", argLength: 1, reg: gp11, asm: "CLOV"}, // Count leading (high order) ones (returns 0-64)
{name: "REVB2H", argLength: 1, reg: gp11, asm: "REVB2H"}, // Swap bytes: 0x11223344 -> 0x22114433 (sign extends to 64 bits)
{name: "REVB2W", argLength: 1, reg: gp11, asm: "REVB2W"}, // Swap bytes: 0x1122334455667788 -> 0x4433221188776655
{name: "REVBV", argLength: 1, reg: gp11, asm: "REVBV"}, // Swap bytes: 0x1122334455667788 -> 0x8877665544332211
Expand Down
56 changes: 56 additions & 0 deletions src/cmd/compile/internal/ssa/opGen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

190 changes: 186 additions & 4 deletions src/cmd/compile/internal/ssa/rewriteLOONG64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff64d75

Please sign in to comment.