summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2021-06-29 07:24:03 +0100
committerFreeArtMan <dos21h@gmail.com>2021-06-29 07:24:03 +0100
commit98c141acc95bf183b4231c270aded680f7105b9f (patch)
tree2b5603294d22f413a76bf9ff8501e1ca698ed9b0
parent0bd60d9a349c9c267517da052173e86e580baa7c (diff)
downloadmd-content-98c141acc95bf183b4231c270aded680f7105b9f.tar.gz
md-content-98c141acc95bf183b4231c270aded680f7105b9f.zip
arm64 some fixes and publish on main page
-rw-r--r--md/writeup/arm64_assembly_crc32.md19
1 files changed, 14 insertions, 5 deletions
diff --git a/md/writeup/arm64_assembly_crc32.md b/md/writeup/arm64_assembly_crc32.md
index c284349..48ffd21 100644
--- a/md/writeup/arm64_assembly_crc32.md
+++ b/md/writeup/arm64_assembly_crc32.md
@@ -12,6 +12,9 @@ that functionality for macos and linux.
## Verify architecture
+Before running any of this code, check that archirecture is correct in case of Apple M1 its easiest to do.
+With Raspberry Pi 4 need to run it with 64bit linux.
+
### Raspberry Pi 4
Run command
@@ -19,13 +22,13 @@ Run command
uname -a
Linux raspberrypi 5.4.42-v8+ #1319 SMP PREEMPT Wed May 20 14:18:56 BST 2020 aarch64 GNU/Linux
```
-There is substring "aarch64" that indicates that os bitnes is 64bit
+There is substring "aarch64" that indicates that os supports 64 bits
To check if CPU supports crc32 instructions run
```
cat /proc/cpuinfo | grep crc
```
-check for "crc32" substring
+search for "crc32" substring
### Apple M1
@@ -45,16 +48,18 @@ in output string should be "arm64"
## ARM64 crc32 instructions
Wiki have table with all different kind of implementation of crc32 https://en.wikipedia.org/wiki/Cyclic_redundancy_check
-arm64 crc32 implementation reffered in wiki table as __CRC-32__. There is support also for __CRC-32C__.
+arm64 crc32 implementation reffered in wiki table as __CRC-32__. There is support also for __CRC-32C__ variant.
There is 4 types of crc32 instruction for 1,2,4,8 byte of data that are marked with
postfix b,h,w,x.
Wraped up examples of instructions:
```c
+//crc32
#define CRC32X(crc, value) __asm__("crc32x %w[c], %w[c], %x[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32W(crc, value) __asm__("crc32w %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32H(crc, value) __asm__("crc32h %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32B(crc, value) __asm__("crc32b %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
+//crc32c
#define CRC32CX(crc, value) __asm__("crc32cx %w[c], %w[c], %x[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32CW(crc, value) __asm__("crc32cw %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
#define CRC32CH(crc, value) __asm__("crc32ch %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value))
@@ -101,6 +106,10 @@ initial values is __crc=0x0__ and final result not need to be preprocessed.
## Source code
+
+Here is complete source code of software and hardware crc32, that runs over some array of data and compares
+results of 2 software implementations and hardware.
+
```c
#include <stdlib.h>
#include <stdio.h>
@@ -218,13 +227,13 @@ int main() {
## Compile
### Raspbery Pi 4
-
+Need to set extra *-march* option to enable architecture variant that supports crc.
```
gcc asm_crc32.c -o asm_crc32 -march=armv8.1-a
```
### Apple M1
-
+Works without extra options
```
gcc asm_crc32.c -o asm_crc32
```