Skip to content

Commit

Permalink
optimize LEA
Browse files Browse the repository at this point in the history
- go inlining
- optimized AMD64 using github.com/minio/c2goasm
- support arm64 NEON using github.com/gorse-io/goat
  - tested in Mac Mini M1
  • Loading branch information
RyuaNerin committed Jan 1, 2024
1 parent fc755d3 commit 72588bf
Show file tree
Hide file tree
Showing 32 changed files with 7,220 additions and 5,300 deletions.
39 changes: 36 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,windows,linux,go
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,windows,linux,go
# Created by https://www.toptal.com/developers/gitignore/api/go,linux,windows,visualstudiocode,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=go,linux,windows,visualstudiocode,macos

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
Expand Down Expand Up @@ -39,6 +39,39 @@ go.work
# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
Expand Down Expand Up @@ -84,4 +117,4 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,windows,linux,go
# End of https://www.toptal.com/developers/gitignore/api/go,linux,windows,visualstudiocode,macos
1 change: 1 addition & 0 deletions lea/READMD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# [Source Code](https://seed.kisa.or.kr/kisa/Board/20/detailView.do)
2 changes: 2 additions & 0 deletions lea/amd64_c2goasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.s
*.o
28 changes: 28 additions & 0 deletions lea/amd64_c2goasm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
EXECUTABLES=clang c2goasm asm2plan9s asmfmt as yasm
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH")))

C2GOASM=c2goasm

CC=clang
CFLAGS=-O3 -fno-asynchronous-unwind-tables -fno-exceptions -fno-rtti -mno-red-zone -mstackrealign -mllvm -inline-threshold=1000
CFLAGS_ARCH=-arch x86_64 -masm=intel

CFLAGS_SSE2=-msse -msse2
CFLAGS_SSSE3=${CFLAGS_SSE2} -mssse3
CFLAGS_AVX2=${CFLAGS_SSSE3} -mavx -mavx2


all: sse2 avx2 init

sse2:
${CC} ${CFLAGS} ${CFLAGS_ARCH} ${CFLAGS_SSE2} -S src/lea_sse2.c -o src/lea_sse2.s
${C2GOASM} -a -f src/lea_sse2.s lea_amd64_sse2.s

avx2:
${CC} ${CFLAGS} ${CFLAGS_ARCH} ${CFLAGS_AVX2} -S src/lea_avx2.c -o src/lea_avx2.s
${C2GOASM} -a -f src/lea_avx2.s lea_amd64_avx2.s

init:
${CC} ${CFLAGS} ${CFLAGS_ARCH} ${CFLAGS_SSE2} -S src/lea_init.c -o src/lea_init.s
${C2GOASM} -a -f src/lea_init.s lea_init.s
11 changes: 11 additions & 0 deletions lea/amd64_c2goasm/lea_amd64_avx2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build amd64 && gc && !purego

package lea

import "unsafe"

//go:noescape
func __lea_encrypt_8block(ct, pt, rk unsafe.Pointer, round uint64)

Check failure on line 8 in lea/amd64_c2goasm/lea_amd64_avx2.go

View workflow job for this annotation

GitHub Actions / build

missing function body

Check failure on line 8 in lea/amd64_c2goasm/lea_amd64_avx2.go

View workflow job for this annotation

GitHub Actions / build

missing function body

//go:noescape
func __lea_decrypt_8block(pt, ct, rk unsafe.Pointer, round uint64)

Check failure on line 11 in lea/amd64_c2goasm/lea_amd64_avx2.go

View workflow job for this annotation

GitHub Actions / build

missing function body

Check failure on line 11 in lea/amd64_c2goasm/lea_amd64_avx2.go

View workflow job for this annotation

GitHub Actions / build

missing function body
11 changes: 11 additions & 0 deletions lea/amd64_c2goasm/lea_amd64_sse2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build amd64 && gc && !purego

package lea

import "unsafe"

//go:noescape
func __lea_encrypt_4block(ct, pt, rk unsafe.Pointer, round uint64)

Check failure on line 8 in lea/amd64_c2goasm/lea_amd64_sse2.go

View workflow job for this annotation

GitHub Actions / build

missing function body

Check failure on line 8 in lea/amd64_c2goasm/lea_amd64_sse2.go

View workflow job for this annotation

GitHub Actions / build

missing function body

//go:noescape
func __lea_decrypt_4block(pt, ct, rk unsafe.Pointer, round uint64)

Check failure on line 11 in lea/amd64_c2goasm/lea_amd64_sse2.go

View workflow job for this annotation

GitHub Actions / build

missing function body

Check failure on line 11 in lea/amd64_c2goasm/lea_amd64_sse2.go

View workflow job for this annotation

GitHub Actions / build

missing function body
Loading

0 comments on commit 72588bf

Please sign in to comment.