This commit is contained in:
Nicolas 2025-10-07 23:23:14 +02:00
parent 997e797689
commit 6810c9dd0a
7 changed files with 58 additions and 48 deletions

View File

@ -19,8 +19,7 @@ jobs:
gcc-12-aarch64-linux-gnu \
gcc-12-arm-linux-gnueabihf \
gcc-12-mips-linux-gnu \
gcc-12-riscv64-linux-gnu \
mingw-w64
gcc-12-riscv64-linux-gnu
- name: Build object files
run: bash src/copapy/obj/crosscompile.sh

View File

@ -7,7 +7,21 @@ on:
branches: [main]
jobs:
build_stencils:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build object files
run: bash src/copapy/obj/crosscompile.sh
- uses: actions/upload-artifact@v4
with:
name: stencil-object-files
path: src/copapy/obj/*.o
build-ubuntu:
needs: [build_stencils]
runs-on: ubuntu-latest
strategy:
@ -18,15 +32,16 @@ jobs:
- name: Check out code
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: stencil-object-files
path: src/copapy/obj
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build ops obj files
run: |
bash src/copapy/obj/nativecompile.sh
- name: Install Python dependencies
run: python -m pip install -e .[dev]
@ -44,12 +59,6 @@ jobs:
#- name: Lint code with flake8
# run: flake8
- uses: actions/upload-artifact@v4
if: strategy.job-index == 0
with:
name: stencil-object-files-linux
path: src/copapy/obj/*.o
- uses: actions/upload-artifact@v4
if: strategy.job-index == 0
with:
@ -57,6 +66,7 @@ jobs:
path: bin/*
build-windows:
needs: [build_stencils]
runs-on: windows-latest
strategy:
@ -67,6 +77,11 @@ jobs:
- name: Check out code
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: stencil-object-files
path: src/copapy/obj
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
@ -100,12 +115,6 @@ jobs:
#- name: Lint code with flake8
# run: flake8
- uses: actions/upload-artifact@v4
if: strategy.job-index == 0
with:
name: stencil-object-files-win
path: src/copapy/obj/*.o
- uses: actions/upload-artifact@v4
if: strategy.job-index == 0
with:

View File

@ -1,9 +1,9 @@
#!/bin/bash
set -e
set -v
python src/copapy/generate_stencils.py
SRC=src/copapy/stencils.c
DEST=src/copapy/obj
python src/copapy/generate_stencils.py $SRC
mkdir -p $DEST
gcc -c $SRC -O0 -o $DEST/stencils_x86_64_O0.o
gcc -c $SRC -O1 -o $DEST/stencils_x86_64_O1.o

View File

@ -1,27 +1,29 @@
from typing import Generator
import argparse
op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/',
'gt': '>', 'eq': '==', 'mod': '%'}
func_prefix = '' # __attribute__((ms_abi))
def get_function_start() -> str:
return """
int function_start(){
return f"""
{func_prefix}int function_start(){{
result_int(0); // dummy call instruction before marker gets striped
asm volatile (".long 0xE2401F0F");
return 1;
}
}}
"""
def get_function_end() -> str:
return """
int function_end(){
return f"""
{func_prefix}int function_end(){{
result_int(0);
asm volatile (".long 0xE1401F0F");
return 1;
}
}}
"""
@ -109,6 +111,14 @@ def permutate(*lists: list[str]) -> Generator[list[str], None, None]:
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("path", type=str, help="Output file path")
parser.add_argument("--abi", type=str, default="", help="Optionaler String (Standard: '')")
args = parser.parse_args()
if args.abi:
func_prefix = f"__attribute__(({args.abi}_abi)) "
types = ['int', 'float']
ops = ['add', 'sub', 'mul', 'div', 'gt', 'eq']
@ -146,5 +156,5 @@ if __name__ == "__main__":
code += get_function_start() + get_function_end()
with open('src/copapy/stencils.c', 'w') as f:
with open(args.path, 'w') as f:
f.write(code)

View File

@ -12,20 +12,21 @@
set -e
set -v
python src/copapy/generate_stencils.py
SRC=src/copapy/stencils.c
DEST=src/copapy/obj
OPT=O3
mkdir -p $DEST
x86_64-w64-mingw32-gcc --version
# Windows x86_64 (ARM64)
python src/copapy/generate_stencils.py --abi ms $SRC
gcc-12 -$OPT -c $SRC -o $DEST/stencils_AMD64_$OPT.o
# Native x86_64
python src/copapy/generate_stencils.py $SRC
gcc-12 -$OPT -c $SRC -o $DEST/stencils_x86_64_$OPT.o
# Windows x86_64 (ARM64)
mingw-w64 -$OPT -c $SRC -o $DEST/stencils_AMD64_$OPT.o
# ARM64
aarch64-linux-gnu-gcc-12 -$OPT -c $SRC -o $DEST/stencils_aarch64_$OPT.o

View File

@ -5,10 +5,17 @@ set -v
SRC=src/copapy/stencils.c
DEST=src/copapy/obj
python src/copapy/generate_stencils.py
python src/copapy/generate_stencils.py $SRC
mkdir -p $DEST
gcc-12 -c $SRC -O0 -o $DEST/stencils_x86_64_O0.o
gcc-12 -c $SRC -O1 -o $DEST/stencils_x86_64_O1.o
gcc-12 -c $SRC -O2 -o $DEST/stencils_x86_64_O2.o
gcc-12 -c $SRC -O3 -o $DEST/stencils_x86_64_O3.o
python src/copapy/generate_stencils.py --abi ms $SRC
gcc-12 -c $SRC -O0 -o $DEST/stencils_AMD64_O0.o
gcc-12 -c $SRC -O1 -o $DEST/stencils_AMD64_O1.o
gcc-12 -c $SRC -O2 -o $DEST/stencils_AMD64_O2.o
gcc-12 -c $SRC -O3 -o $DEST/stencils_AMD64_O3.o

View File

@ -1,16 +0,0 @@
#!/bin/bash
set -e
set -v
SRC=src/copapy/stencils.c
DEST=src/copapy/obj
python src/copapy/generate_stencils.py
mkdir -p $DEST
x86_64-w64-mingw32-gcc -c $SRC -O0 -o $DEST/stencils_AMD64_O0.o
x86_64-w64-mingw32-gcc -c $SRC -O1 -o $DEST/stencils_AMD64_O1.o
x86_64-w64-mingw32-gcc -c $SRC -O2 -o $DEST/stencils_AMD64_O2.o
x86_64-w64-mingw32-gcc -c $SRC -O3 -o $DEST/stencils_AMD64_O3.o
x86_64-w64-mingw32-gcc --version