Skip to content

Commit 62e50ab

Browse files
ldemaillyCopilot
andauthored
Loop optimization: auto align elf64 loop targets (#72)
* Adding a better version of the C opt loop * Add missing file * Using test optimization and compilation for clang gcc * Adding NOP to try loop aligned * Update elf64.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Auto align jump targets * Fix the govulncheck ci error * Fix the for linter too (mix of C and go in sample/) * Auto align so we don't need the manually aligned one * Clean up a bit the code (#73) * simplify minloop * lint * Use constants for nop and rex* and refactor code a bit --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5d73efc commit 62e50ab

File tree

12 files changed

+293
-176
lines changed

12 files changed

+293
-176
lines changed

.github/workflows/gochecks.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
if: matrix.os == 'ubuntu-latest'
2828
run: |
2929
go install golang.org/x/vuln/cmd/govulncheck@latest
30-
govulncheck ./...
30+
CGO_ENABLED=0 govulncheck ./...
3131
- name: Download linter config
3232
if: matrix.os == 'ubuntu-latest'
3333
run: curl -fsS -o .golangci.yml https://raw.githubusercontent.com/fortio/workflows/main/golangci.yml
@@ -36,6 +36,8 @@ jobs:
3636
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # pin@v8
3737
with:
3838
version: v2.8.0
39+
env:
40+
CGO_ENABLED: 0
3941
- name: Run tests
4042
run: |
4143
go version

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ a.out.dSYM
5151
tiny_vm
5252

5353
grol_cvm_debug
54+
*.s

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ nativecloop: Makefile cvm/loop.c
126126
time $(AOUT) # comment needed to avoid CreateProcess(NULL, time ./a.out, ...) failed.
127127
$(CC) -O3 -Wall -Wextra -pedantic -Werror -DNOVOLATILE cvm/loop.c
128128
time $(AOUT) # comment for windows
129+
$(CC) -O3 -Wall -Wextra -pedantic -Werror -Wno-language-extension-token native/sample/minloop.c
130+
time $(AOUT) # comment for windows
129131

130132
elf64: vm
131133
$(MAKE) -C native test-loop-native

asm/asm.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ func compile(elf64 bool, reader *bufio.Reader, writer *bufio.Writer) int {
318318
args := fields[1:]
319319
narg := len(args)
320320
switch instr {
321-
case "return":
321+
case "nop", "return":
322322
if narg != 0 {
323-
return log.FErrf("Expecting 0 arguments for return, got %d (%v)", narg, args)
323+
return log.FErrf("Expecting 0 arguments for %s, got %d (%v)", instr, narg, args)
324324
}
325325
case "var", "param", "sys", "syss": // one or more arguments
326326
if narg == 0 {
@@ -420,6 +420,9 @@ func compile(elf64 bool, reader *bufio.Reader, writer *bufio.Writer) int {
420420
}
421421
log.Debugf("Param -> Defined parameters: %v", resolver.vars)
422422
continue
423+
case "nop":
424+
data = false
425+
op = op.SetOpcode(cpu.Nop)
423426
case "return":
424427
data = false
425428
op = op.SetOpcode(cpu.Ret)

0 commit comments

Comments
 (0)