Skip to content

Commit c4b7210

Browse files
authored
Amd64 handwritten 1-bit and 8-bit faithful base implementations (PlummersSoftwareLLC#593)
1 parent 988276e commit c4b7210

File tree

6 files changed

+397
-13
lines changed

6 files changed

+397
-13
lines changed

PrimeAmd64/solution_1/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ FROM alpine:3.14
22
WORKDIR /opt/app
33
COPY . .
44
RUN ./make.sh
5-
ENTRYPOINT [ "./run8.sh" ]
5+
ENTRYPOINT [ "./run.sh" ]

PrimeAmd64/solution_1/README.md

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,51 @@
1-
# amd64 solution by @dacvs (https://dacvs.neocities.org/)
1+
# amd64 solution by dacvs (https://dacvs.neocities.org/)
22

33
![Algorithm](https://img.shields.io/badge/Algorithm-base-green)
44
![Faithfulness](https://img.shields.io/badge/Faithful-yes-green)
55
![Parallelism](https://img.shields.io/badge/Parallel-no-green)
6+
![Bit count](https://img.shields.io/badge/Bits-1-green)
67
![Bit count](https://img.shields.io/badge/Bits-8-yellowgreen)
78

8-
This is an 8-bit faithful implementation of the base prime number sieve algorithm from Dave Plummer's Software Drag Race.
9+
This is a faithful implementation of the base prime number sieve algorithm from Dave Plummer's Software Drag Race.
910
This submission is written in machine language (amd64) in the style of my video series "Handmade Linux x86 executables."
1011
(https://www.youtube.com/playlist?list=PLZCIHSjpQ12woLj0sjsnqDH8yVuXwTy3p).
1112

12-
When I open the source file dacvs8.dmp in vi (really vim) on my Ubuntu system, the text editor provides "syntax highlighting" by graying out the comments. This requires no special configuration.
13+
When I open a source file (dacvs1.dmp or dacvs8.dmp) in vi (really vim) on my Ubuntu system, the text editor provides "syntax highlighting" by graying out the comments. This requires no special configuration.
1314

1415
## Run instructions
1516

1617
To make the binary, run `make.sh` (on a Linux system).
17-
To execute the binary (after it is made) for primes up to 1 million, run `run8.sh`.
18+
To execute the binaries (after they are made) for primes up to 1 million, run `run.sh`.
1819

19-
## Output of run8.sh
20+
## Output of run.sh
2021
```
21-
dsmith8;6383;5.000102;1;algorithm=base,faithful=yes,bits=8
22+
dacvs1;5581;5.000286;1;algorithm=base,faithful=yes,bits=1
23+
dacvs8;7021;5.000677;1;algorithm=base,faithful=yes,bits=8
24+
```
25+
26+
## Output of run1p.sh
27+
```
28+
P 2
29+
P 3
30+
P 5
31+
P 7
32+
P 11
33+
P 13
34+
P 17
35+
P 19
36+
P 23
37+
P 29
38+
...
39+
P 999953
40+
P 999959
41+
P 999961
42+
P 999979
43+
P 999983
44+
= 78498
45+
I 5315
46+
T 5000700682
47+
1062.9
48+
dacvs1;5315;5.000701;1;algorithm=base,faithful=yes,bits=1
2249
```
2350

2451
## Output of run8p.sh
@@ -62,14 +89,16 @@ A new object is created each time through the loop. However, I arranged a memory
6289
Yes, although not every request for memory triggers a system call, as described above.
6390

6491
### The size of the memory buffer must correspond to the size of the sieve.
65-
Yes, the buffer has 8 bits for each sieve number 1, 3, 5, 7, 9, ..., (M-1)/2.
92+
Yes, in the 8-bit program, the buffer has 8 bits for each sieve number 1, 3, 5, 7, 9, ..., (M-1)/2.
93+
94+
The 1-bit program has 1 bit for each sieve number 1, 3, 5, 7, 9, ..., (M-1)/2, but the number of sieve bits is rounded up to the next multiple of 64, as sieve bits are accessed as members of 64-bit integers.
6695

6796
## This submission conforms to the rules:
6897
### Solution uses sieve of Eratosthenes.
6998
Yes.
7099

71100
### Benchmarked code returns a list of primes.
72-
Script run8.sh puts out a single line of statistics in the preferred style. Script run8p.sh puts out a list of primes to stderr and a single line of statistics to stdout.
101+
Script run.sh puts out one line of statistics in the preferred style for each program, 1-bit and 8-bit. Scripts run1p.sh and run8p.sh each put out a list of primes to stderr and a single line of statistics to stdout.
73102

74103
### Solution runs for at least 5 seconds, then stops as quickly as possible after that.
75104
The algorithm completes its current pass before checking the clock, then stops if at least 5 seconds have passed. The program gets the time (down to the nanosecond) from Linux system call clock_gettime.

0 commit comments

Comments
 (0)