Skip to content

Commit 687aa45

Browse files
authored
Add cwager_x64ff_mt multithreaded amd64 assembly solution (#1056)
1 parent e89c7ae commit 687aa45

7 files changed

Lines changed: 667 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cwager_x64ff_mt
2+
cwager_x64ff_mt.o
3+
core
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine:3.13
2+
3+
RUN apk add --no-cache build-base nasm
4+
5+
WORKDIR /opt/app
6+
7+
COPY *.sh *.asm README.md ./
8+
9+
RUN ./build.sh
10+
11+
ENTRYPOINT ["./run.sh"]

PrimeAssembly/solution_4/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# cwager_x64ff_mt
2+
3+
![Algorithm](https://img.shields.io/badge/Algorithm-base-green)
4+
![Faithfulness](https://img.shields.io/badge/Faithful-yes-green)
5+
![Parallelism](https://img.shields.io/badge/Parallel-yes-green)
6+
![Bit count](https://img.shields.io/badge/Bits-1-green)
7+
8+
`cwager_x64ff_mt` is a multithreaded x86-64 NASM implementation of the base Sieve of Eratosthenes.
9+
10+
The main source file is `cwager_x64ff_mt.asm`.
11+
12+
Each worker thread repeatedly:
13+
14+
- allocates a fresh sieve buffer dynamically at runtime
15+
- initializes that buffer from scratch
16+
- runs a faithful base-algorithm sieve over odd candidates only
17+
- discards the sieve unless it is the final completed pass for that worker
18+
19+
The implementation keeps the benchmark state in a dynamically allocated benchmark structure and gives each worker its own dynamically allocated worker state structure.
20+
21+
Each worker state structure contains the runtime sieve metadata and the sieve buffer pointer:
22+
23+
- sieve size
24+
- derived bit count
25+
- derived word count
26+
- pass count
27+
- sieve buffer pointer
28+
29+
This is intended to be the assembly equivalent of the "class containing the full state of the sieve" required by the current drag-race faithfulness rules. The sieve size and corresponding buffer are established dynamically at runtime for each worker, and each timed pass recreates a fresh sieve buffer from scratch before running the base algorithm.
30+
31+
## Run instructions
32+
33+
### NASM/GCC
34+
35+
From this directory:
36+
37+
```bash
38+
./build.sh
39+
./run.sh
40+
```
41+
42+
This produces the executable `cwager_x64ff_mt` from `cwager_x64ff_mt.asm`.
43+
44+
### Docker
45+
46+
```bash
47+
docker build -t cwager-x64ff-mt .
48+
docker run --rm cwager-x64ff-mt
49+
```
50+
51+
## Output
52+
53+
Example output from this machine:
54+
55+
```text
56+
cwager_x64ff_mt;128068;5.001;16;algorithm=base,faithful=yes,bits=1
57+
cwager_x64ff_mt;128397;5.000;16;algorithm=base,faithful=yes,bits=1
58+
```
59+
60+
## Notes
61+
62+
This implementation targets amd64/x86-64 Linux, links against pthreads, and reports using the label `cwager_x64ff_mt`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

PrimeAssembly/solution_4/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
nasm -felf64 cwager_x64ff_mt.asm -o cwager_x64ff_mt.o
4+
gcc -no-pie -pthread cwager_x64ff_mt.o -o cwager_x64ff_mt

0 commit comments

Comments
 (0)