Skip to content

Commit 05a0266

Browse files
authored
Merge pull request #149 from mmcloughlin/asm-module
Move avo assembly generator to separate `asm` module
2 parents 6f02425 + 2a026ef commit 05a0266

File tree

13 files changed

+71
-48
lines changed

13 files changed

+71
-48
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ build-nocgo:
3232
cross-build: build-arm build-arm64 build-nocgo
3333

3434
generate:
35-
go run sha1cdblock_amd64_asm.go -out sha1cdblock_amd64.s
36-
sed -i 's;&\samd64;&\n// +build !noasm,gc,amd64;g' sha1cdblock_amd64.s
37-
38-
cd ubc && go run ubc_amd64_asm.go -out ubc_amd64.s
39-
sed -i 's;&\samd64;&\n// +build !noasm,gc,amd64;g' ubc/ubc_amd64.s
35+
go generate -x ./...
4036

4137
verify: generate
4238
git diff --exit-code

sha1cdblock_amd64_asm.go renamed to asm/asm.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
//go:build ignore
2-
// +build ignore
3-
41
package main
52

63
import (
74
. "github.com/mmcloughlin/avo/build"
85
"github.com/mmcloughlin/avo/buildtags"
96
. "github.com/mmcloughlin/avo/operand"
107
. "github.com/mmcloughlin/avo/reg"
11-
shared "github.com/pjbgf/sha1cd/internal"
128
)
139

14-
//go:generate go run sha1cdblock_amd64_asm.go -out sha1cdblock_amd64.s
10+
const (
11+
// Constants for the SHA-1 hash function.
12+
RoundConst0 = 0x5A827999
13+
RoundConst1 = 0x6ED9EBA1
14+
RoundConst2 = 0x8F1BBCDC
15+
RoundConst3 = 0xCA62C1D6
16+
17+
// SHA1 processes the input data in chunks. Each chunk contains 64 bytes.
18+
Chunk = 64
19+
)
1520

1621
func main() {
1722
Constraint(buildtags.Not("noasm").ToConstraint())
@@ -61,7 +66,7 @@ func main() {
6166
}
6267

6368
// Store message values on the stack.
64-
w := AllocLocal(shared.Chunk)
69+
w := AllocLocal(Chunk)
6570
W := func(r int) Mem { return w.Offset((r % 16) * 4) }
6671

6772
Comment("len(p) >= chunk")
@@ -161,39 +166,39 @@ func main() {
161166
Commentf("ROUND1(%d)", index)
162167
LOAD(index)
163168
FUNC1(a, b, c, d, e)
164-
MIX(a, b, c, d, e, shared.K0)
169+
MIX(a, b, c, d, e, RoundConst0)
165170
LOADM1(index)
166171
}
167172

168173
ROUND1x := func(a, b, c, d, e GPVirtual, index int) {
169174
Commentf("ROUND1x(%d)", index)
170175
SHUFFLE(index)
171176
FUNC1(a, b, c, d, e)
172-
MIX(a, b, c, d, e, shared.K0)
177+
MIX(a, b, c, d, e, RoundConst0)
173178
LOADM1(index)
174179
}
175180

176181
ROUND2 := func(a, b, c, d, e GPVirtual, index int) {
177182
Commentf("ROUND2(%d)", index)
178183
SHUFFLE(index)
179184
FUNC2(a, b, c, d, e)
180-
MIX(a, b, c, d, e, shared.K1)
185+
MIX(a, b, c, d, e, RoundConst1)
181186
LOADM1(index)
182187
}
183188

184189
ROUND3 := func(a, b, c, d, e GPVirtual, index int) {
185190
Commentf("ROUND3(%d)", index)
186191
SHUFFLE(index)
187192
FUNC3(a, b, c, d, e)
188-
MIX(a, b, c, d, e, shared.K2)
193+
MIX(a, b, c, d, e, RoundConst2)
189194
LOADM1(index)
190195
}
191196

192197
ROUND4 := func(a, b, c, d, e GPVirtual, index int) {
193198
Commentf("ROUND4(%d)", index)
194199
SHUFFLE(index)
195200
FUNC4(a, b, c, d, e)
196-
MIX(a, b, c, d, e, shared.K3)
201+
MIX(a, b, c, d, e, RoundConst3)
197202
LOADM1(index)
198203
}
199204

@@ -297,7 +302,7 @@ func main() {
297302
ADDL(r, hash[i])
298303
}
299304

300-
ADDQ(I8(shared.Chunk), p_base)
305+
ADDQ(I8(Chunk), p_base)
301306
CMPQ(p_base, di64)
302307
JB(LabelRef("loop"))
303308

asm/go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module github.com/pjbgf/sha1cd/asm
2+
3+
go 1.21
4+
5+
require (
6+
github.com/mmcloughlin/avo v0.6.0
7+
github.com/pjbgf/sha1cd v0.0.0-local
8+
)
9+
10+
require (
11+
golang.org/x/mod v0.14.0 // indirect
12+
golang.org/x/tools v0.16.1 // indirect
13+
)
14+
15+
replace github.com/pjbgf/sha1cd => ..

asm/go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/mmcloughlin/avo v0.6.0 h1:QH6FU8SKoTLaVs80GA8TJuLNkUYl4VokHKlPhVDg4YY=
2+
github.com/mmcloughlin/avo v0.6.0/go.mod h1:8CoAGaCSYXtCPR+8y18Y9aB/kxb8JSS6FRI7mSkvD+8=
3+
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
4+
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
5+
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
6+
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
7+
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
8+
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=

go.mod

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
module github.com/pjbgf/sha1cd
22

33
go 1.21
4-
5-
require github.com/mmcloughlin/avo v0.6.0
6-
7-
require (
8-
golang.org/x/mod v0.17.0 // indirect
9-
golang.org/x/sync v0.7.0 // indirect
10-
golang.org/x/tools v0.20.0 // indirect
11-
)

go.sum

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +0,0 @@
1-
github.com/mmcloughlin/avo v0.6.0 h1:QH6FU8SKoTLaVs80GA8TJuLNkUYl4VokHKlPhVDg4YY=
2-
github.com/mmcloughlin/avo v0.6.0/go.mod h1:8CoAGaCSYXtCPR+8y18Y9aB/kxb8JSS6FRI7mSkvD+8=
3-
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
4-
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
5-
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
6-
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
7-
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
8-
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
9-
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
10-
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
11-
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
12-
golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
13-
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=

sha1cd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import (
1717
"errors"
1818
"hash"
1919

20-
_ "github.com/mmcloughlin/avo/build"
2120
shared "github.com/pjbgf/sha1cd/internal"
2221
)
2322

23+
//go:generate go run -C asm . -out ../sha1cdblock_amd64.s -pkg $GOPACKAGE
24+
2425
func init() {
2526
crypto.RegisterHash(crypto.SHA1, New)
2627
}

sha1cdblock_amd64.s

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// Code generated by command: go run sha1cdblock_amd64_asm.go -out sha1cdblock_amd64.s. DO NOT EDIT.
1+
// Code generated by command: go run asm.go -out ../sha1cdblock_amd64.s -pkg sha1cd. DO NOT EDIT.
22

33
//go:build !noasm && gc && amd64
4-
// +build !noasm,gc,amd64
54

65
#include "textflag.h"
76

ubc/ubc_amd64_asm.go renamed to ubc/asm/asm.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build ignore
2-
// +build ignore
3-
41
package main
52

63
import (
@@ -10,8 +7,6 @@ import (
107
"github.com/pjbgf/sha1cd/ubc"
118
)
129

13-
//go:generate go run ubc_amd64_asm.go -out ubc_amd64.s
14-
1510
const (
1611
DvTypeOffset = 0
1712
DvKOffset = 4

ubc/asm/go.mod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module github.com/pjbgf/sha1cd/ubc/asm
2+
3+
go 1.21
4+
5+
require (
6+
github.com/mmcloughlin/avo v0.6.0
7+
github.com/pjbgf/sha1cd v0.0.0-local
8+
)
9+
10+
require (
11+
golang.org/x/mod v0.17.0 // indirect
12+
golang.org/x/sync v0.7.0 // indirect
13+
golang.org/x/tools v0.20.0 // indirect
14+
)
15+
16+
replace github.com/pjbgf/sha1cd => ../..

0 commit comments

Comments
 (0)