Skip to content

GCC+ARM Assembly: more than 30 operands in ‘asm’ #582

@mratsim

Description

@mratsim

See https://github.com/mratsim/constantine/actions/runs/17549567238/job/49838582594?pr=581

This is impacting Constantine integration in Nimbus-eth1, which is in particular targeting the growing SBC market (Single Board Computer):

  Executing task make_lib in /home/runner/work/constantine/constantine/constantine/constantine.nimble
Compiling static library:  lib/libconstantine.a
  compiler config:  --tlsEmulation=off  -d:danger  --panics:on -d:noSignalHandler  --mm:arc -d:useMalloc  --verbosity:0 --hints:off --warnings:off  --passC:-fno-semantic-interposition  --passC:-falign-functions=64  --passC:-fmerge-all-constants
/home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_mul_mont_arm64.nim.c: In function ‘mulMont_CIOS_sparebit_asm__OOZconstantineZnamedZconstantsZbls129537795sqrt_u2351’:
/home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_mul_mont_arm64.nim.c:388:1: error: more than 30 operands in ‘asm’
  388 | asm volatile(
      | ^~~
/home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_mul_mont_arm64.nim.c: In function ‘mulMont_CIOS_sparebit_asm__OOZconstantineZnamedZconstantsZbls129537795sqrt_u1159’:
/home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_mul_mont_arm64.nim.c:1080:1: error: more than 30 operands in ‘asm’
 1080 | asm volatile(
      | ^~~
/home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_mul_mont_arm64.nim.c: In function ‘sumprodMont_CIOS_spare2bits_asm__OOZconstantineZethereum95bls95signatures_u2214’:
/home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_mul_mont_arm64.nim.c:2073:1: error: more than 30 operands in ‘asm’
 2073 | asm volatile(
      | ^~~
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3 -pthread -fno-semantic-interposition -falign-functions=64 -fmerge-all-constants -O3 -fno-strict-aliasing -fno-ident -fno-math-errno   -I/home/runner/work/constantine/constantine/nim-linux-arm64-version-2-2-8ea8755cc0252eb52a3f1d68d1c91f8f5f7d449f/lib -I/home/runner/work/constantine/constantine/constantine/bindings -o /home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_mul_mont_arm64.nim.c.o /home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_mul_mont_arm64.nim.c' failed with exit code: 1


/home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_redc_mont_arm64.nim.c: In function ‘redcMont_asm__OOZconstantineZnamedZconstantsZbls129538195subgroups_u2115’:
/home/runner/work/constantine/constantine/constantine/nimcache/libconstantine_static/@pconstantine@smath@sarithmetic@sassembly@slimbs_asm_redc_mont_arm64.nim.c:53:1: error: more than 30 operands in ‘asm’
   53 | asm volatile(
      | ^~~
stack trace: (most recent call last)
/tmp/nimblecache-1194919871666104896/nimscriptapi_2151298592259230405.nim(219, 16)
/home/runner/work/constantine/constantine/constantine/constantine.nimble(310, 15) make_libTask
/home/runner/work/constantine/constantine/constantine/constantine.nimble(298, 5) genStaticLib
/home/runner/work/constantine/constantine/constantine/constantine.nimble(278, 5) compile
/home/runner/work/constantine/constantine/nim-linux-arm64-version-2-2-8ea8755cc0252eb52a3f1d68d1c91f8f5f7d449f/lib/system/nimscript.nim(264, 7) exec
/home/runner/work/constantine/constantine/nim-linux-arm64-version-2-2-8ea8755cc0252eb52a3f1d68d1c91f8f5f7d449f/lib/system/nimscript.nim(264, 7) Error: unhandled exception: FAILED: nim c  --tlsEmulation=off  -d:danger  --panics:on -d:noSignalHandler  --mm:arc -d:useMalloc  --verbosity:0 --hints:off --warnings:off  --passC:-fno-semantic-interposition  --passC:-falign-functions=64  --passC:-fmerge-all-constants --threads:on  --noMain --app:staticlib  --nimMainPrefix:ctt_init_  --out:libconstantine.a --outdir:lib  --nimcache:nimcache/libconstantine_static bindings/lib_constantine.nim [OSError]

The assembly does work with Clang on MacOS.

The code generator should be under the limit of 30 operands:

let
r = asmArray(r_PIR, N, PointerInReg, asmInput, memIndirect = memWrite)
b = asmArray(b_PIR, N, PointerInReg, asmInput, memIndirect = memRead)
M = asmArray(M_REG, N, ElemsInReg, asmInput)
tSym = ident"t"
t = asmArray(tSym, N, ElemsInReg, asmOutputEarlyClobber)
m0ninv = asmValue(m0ninv_REG, Reg, asmInput)
aSym = ident"A"
A = asmValue(aSym, Reg, asmOutputEarlyClobber)
biSym = ident"bi"
bi = asmValue(biSym, Reg, asmOutputEarlyClobber)
aaSym = ident"aa"
aa = asmArray(aaSym, N, ElemsInReg, asmInputOutput) # used as buffer for final substraction
mSym = ident"m"
m = asmValue(mSym, Reg, asmOutputEarlyClobber)
uSym = ident"u"
vSym = ident"v"
var # Break dependencies chain
u = asmValue(uSym, Reg, asmOutputEarlyClobber)
v = asmValue(vSym, Reg, asmOutputEarlyClobber)

  • r -> 1
  • b -> 1
  • M -> variable, maximum 6 for BLS12-381
  • t -> variable, maximum 6 for BLS12-381
  • m0ninv -> 1
  • A -> 1
  • bᵢ -> 1
  • aa -> variable, maximum 6 for BLS12-381, counts double as tagged input and output
  • m -> 1
  • u -> 1
  • v -> 1

For a total of 32 operands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions