summaryrefslogtreecommitdiff
path: root/vere/ext/gmp/gen/README.md
blob: ebc0bcad09b76ccdd73a72c3974856e1d75d9e25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Generated architecture specific `.c`, `.s`, and `.h` files

To generate these, first run the `./configure` script under the unpacked GMP dependency directory with the following options:

macOS:
```terminal
./configure --with-pic --disable-shared
```

linux-x86_64:
```terminal
./configure --with-pic --disable-shared --host=x86_64-linux-musl
```

linux-aarch64:
```terminal
./configure --with-pic --disable-shared --host=aarch64-linux-musl
```

windows (from wsl):
```terminal
CC_FOR_BUILD=gcc ./configure --host=x86_64-w64-mingw32 --disable-shared
```

Next, navigate under `mpn/` and run the following to generate the assembly files:

```bash
for file in $(find . -maxdepth 1 -print | grep "\.asm$"); do
    filename_no_path="${file#"./"}";
    filename="${filename_no_path%.*}";
    echo "m4 -DHAVE_CONFIG_H -D__GMP_WITHIN_GMP -DOPERATION_${filename} -DPIC $file > ${filename}.s";
    m4 -DHAVE_CONFIG_H -D__GMP_WITHIN_GMP -DOPERATION_${filename} -DPIC $file > ${filename}.s;
done
```

Next, copy the generated `mpn/*.s` files under the appropriate path, e.g.,
`aarch64-macos/mpn/.`

Now, under the GMP root dir run `make` and copy these files as well:

- `config.h`
- `mp_bases.h`
- `fac_table.h`
- `fib_table.h`
- `trialdivtab.h`
- `sieve_table.h`
- `mpn/fib_table.c`
- `mpn/jacobitab.h`
- `mpn/mp_bases.c`
- `mpn/perfsqr.h`

e.g.
```bash
cp {config.h, mp_bases.h,fac_table.h,fib_table.h,trialdivtab.h,sieve_table.h} aarch64-macos/.
cp {mpn/fib_table.c,mpn/jacobitab.h,mpn/mp_bases.c,mpn/perfsqr.h} aarch64-macos/mpn/.
```

## Some additional snippets

### Write the generated assembly file paths into a file `ssources`

```bash
for file in $(find ./mpn -maxdepth 1 -print | grep "\.s" | sort); do
    echo $(realpath $file) >> ssources;
done
```

### Write the relevant C source file paths into a file `csources`

```bash
for file in $(find ./mpn -maxdepth 1 -print | grep "\.c" | sort); do
    echo $(realpath $file) >> csources;
done
```