Skip to content

Commit 33a8b40

Browse files
committed
First round of examples!
1 parent 9bd81d2 commit 33a8b40

File tree

81 files changed

+1196
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1196
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore all .csv files
2+
*.csv
3+
4+
# Ignore specific directory
5+
./_Inline
6+
7+
# Ignore specific file
8+
addArrayofIntegers_C.pl

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
11
# perlAssembly
2+
3+
This is probably one of the things that should never be allowed to exist, but why not use Perl and its capabilities to inline foreign code, to FAFO with assembly without a build system? Everything in a single file! In the process one may find ways to use Perl to enhance NASM and vice versa. But for now, I make no such claims : I am just using the perlAssembly git repo to illustrate how one can use Perl to drive (and learn to code!) assembly programs from a single file.
4+
5+
## x86-64 examples
6+
7+
### addIntegers.pl
8+
Simple integer addition in Perl
9+
10+
### addArrayofIntegers.pl
11+
Explore multiple equivalent ways to add *large* arrays in Perl:
12+
* ASM\_blank : test the speed of calling ASM from Perl (no computations are done)
13+
* ASM\_doubles : pass the array as a packed string of doubles and do scalar double floating addition in assembly
14+
* ASM\_doubles\_AVX: pass the array as a packed string of doubles and do packed floating point addition in assembly
15+
* ForLoop : standard for loop in Perl
16+
* ListUtil: sum function from list utilities
17+
* PDL : uses summation in PDL
18+
19+
Varieties w\_alloc : allocate memory for each iteration to test the speed of pack, those marked
20+
as wo\_alloc, use a pre-computed data structure to pass the array to the underlying code.
21+
The first benchmark gives the true cost of offloading summation to of a Perl array to a given
22+
function when the source data are in Perl. The second, just benchmarks the calculation speed.
23+
For the example considered here, it makes ZERO senso to offload the calculation as ListUtil is
24+
already within 15% of the assembly solution. If however, one was managing the array, not as a
25+
Perl array, but as an area in memory through a Perl object, then one COULD consider offloading.
26+
27+
#### Results
28+
mean median stddev
29+
ASM\_blank 2.3e-06 2.0e-06 1.1e-06
30+
ASM\_doubles\_AVX\_w\_alloc 3.6e-03 3.5e-03 4.2e-04
31+
ASM\_doubles\_AVX\_wo\_alloc 3.0e-04 2.9e-04 2.7e-05
32+
ASM\_doubles\_w\_alloc 4.3e-03 4.1e-03 4.5e-04
33+
ASM\_doubles\_wo\_alloc 8.9e-04 8.7e-04 3.0e-05
34+
ASM\_w\_alloc 4.3e-03 4.2e-03 4.5e-04
35+
ASM\_wo\_alloc 9.2e-04 9.1e-04 4.1e-05
36+
ForLoop 1.9e-02 1.9e-02 2.6e-04
37+
ListUtil 4.5e-03 4.5e-03 1.4e-04
38+
PDL\_w\_alloc 2.1e-02 2.1e-02 6.7e-04
39+
PDL\_wo\_alloc 9.2e-04 9.0e-04 3.9e-05
40+
41+
### Disclaimer
42+
The code here is NOT meant to be portable. I code in Linux and in x86-64, so if you are looking into Window's ABI or ARM, you will be disappointed. But as my knowledge of ARM assembly grows, I intend to rewrite some examples in Arm assembly!
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version : 0.86
2+
languages : %
3+
AS : ASM
4+
ASM : ASM
5+
C : C
6+
C++ : CPP
7+
CPP : CPP
8+
CXX : CPP
9+
Cplusplus : CPP
10+
Foo : Foo
11+
GASP : ASM
12+
NASM : ASM
13+
PDLPP : Pdlpp
14+
Pdlpp : Pdlpp
15+
as : ASM
16+
asm : ASM
17+
c++ : CPP
18+
cplusplus : CPP
19+
cpp : CPP
20+
cxx : CPP
21+
foo : Foo
22+
gasp : ASM
23+
nasm : ASM
24+
pdlpp : Pdlpp
25+
types : %
26+
ASM : compiled
27+
C : compiled
28+
CPP : compiled
29+
Foo : interpreted
30+
Pdlpp : compiled
31+
modules : %
32+
ASM : Inline::ASM
33+
C : Inline::C
34+
CPP : Inline::CPP
35+
Foo : Inline::Foo
36+
Pdlpp : Inline::Pdlpp
37+
suffixes : %
38+
ASM : so
39+
C : so
40+
CPP : so
41+
Foo : foo
42+
Pdlpp : so
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
md5 : 0e807e0d0019302e8463d90c1263be38
2+
name : addArrayofIntegers_pl_0e80
3+
version : ""
4+
language : ASM
5+
language_id : ASM
6+
installed : 0
7+
date_compiled : Mon Jun 17 21:07:29 2024
8+
inline_version : 0.86
9+
ILSM : %
10+
module : Inline::ASM
11+
suffix : so
12+
type : compiled
13+
Config : %
14+
apiversion : ?
15+
archname : x86_64-linux
16+
cc : cc
17+
ccflags : -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
18+
ld : cc
19+
osname : linux
20+
osvers : 5.19.0-38-generic
21+
so : so
22+
version : 5.38.0
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
md5 : 170c9874a28ebeb75479e4559340ebb7
2+
name : addArrayofIntegers_pl_170c
3+
version : ""
4+
language : ASM
5+
language_id : ASM
6+
installed : 0
7+
date_compiled : Mon Jun 17 18:42:56 2024
8+
inline_version : 0.86
9+
ILSM : %
10+
module : Inline::ASM
11+
suffix : so
12+
type : compiled
13+
Config : %
14+
apiversion : ?
15+
archname : x86_64-linux
16+
cc : cc
17+
ccflags : -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
18+
ld : cc
19+
osname : linux
20+
osvers : 5.19.0-38-generic
21+
so : so
22+
version : 5.38.0
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
md5 : 17d480c17d771567a50e3aa433dd0dba
2+
name : addArrayofIntegers_pl_17d4
3+
version : ""
4+
language : ASM
5+
language_id : ASM
6+
installed : 0
7+
date_compiled : Mon Jun 17 19:30:17 2024
8+
inline_version : 0.86
9+
ILSM : %
10+
module : Inline::ASM
11+
suffix : so
12+
type : compiled
13+
Config : %
14+
apiversion : ?
15+
archname : x86_64-linux
16+
cc : cc
17+
ccflags : -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
18+
ld : cc
19+
osname : linux
20+
osvers : 5.19.0-38-generic
21+
so : so
22+
version : 5.38.0
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
md5 : 27699279c9b6a585f3dec726636eb04b
2+
name : addArrayofIntegers_pl_2769
3+
version : ""
4+
language : ASM
5+
language_id : ASM
6+
installed : 0
7+
date_compiled : Mon Jun 17 19:06:01 2024
8+
inline_version : 0.86
9+
ILSM : %
10+
module : Inline::ASM
11+
suffix : so
12+
type : compiled
13+
Config : %
14+
apiversion : ?
15+
archname : x86_64-linux
16+
cc : cc
17+
ccflags : -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
18+
ld : cc
19+
osname : linux
20+
osvers : 5.19.0-38-generic
21+
so : so
22+
version : 5.38.0

0 commit comments

Comments
 (0)