The following gist contains two Assembly files, one x86-64 in AT&T syntax and the other, an Aarch64 Assemly code. It also has a C file expressing how the two subroutiens may be used, as the subroutines in both files are callable in C. Keep in mind that both .S
files are annotated with comments on the very top of the file.
These subroutines were mainly authored for the sake of education. My cousin passed away yesterday and I'm upset so I wanted to keep busy. Please do not use these two subroutines in any serious manner unless you have scrutinized them well and you are sure they will endow you with the necessary functionality.
Note that both these files contain GNU Assembler macros, and as we will see, they are meant to be compiled using GCC or Clang along with a C program declaring them as external symbols.
qandum.x64.s
-> A subroutine calledqandum
that is basically a PRNG using TSC system register. You must pass it rotate and shift look up tables as seed. These values may not succeed the value of 63.bytestew.a64.s
-> A subroutine calledbytestew
that takes an unsigned character string and its length, and returns a hash in the form of an unsigned double word.vonjerriman.c
-> C interface for the two subroutines, including example with stdout print.
This subroutine uses x86-64's TSC register to seed, but also uses the look-up tables given by the users to do a barell hash of the seed. RDTSC will load the upper and lower parts of the system register into EAX and EDX. But qandum
combines them into a single 64-bit integer, and then proceeds to do the barrel hash using Rotate Right, Shift-Right-and-Add and Rotate Left instructions. At the end the number is sufficiently randomized. You may modulo this with the size of your array to select a random index, and so on. This subroutine only uses integer and accumulator opertions. No multi-cycle operations are used.
This subroutine will take the given string of unsigned bytes, read them one-by-one, and use Aarch64's bit manipulation instructions, Bit-Field Insert and Bit-Field Extract to shuffle every two bits of the byte around. And it will then combine it with the final digest. The digest is 64-bits, and it by itself goes through the same Insert-and-Extract pipeline at every loop. One thing to keep in mind, Aarch64's bit manipulators, according to ARM Cortex optimization guide, are indeed multi-cycle. So threfore this function will not be super-performant.
To compile the x86-64 code, just run gcc -D __qandum__ vonjerriman.c qandum.x64.s
. But if you wish to X-Compile the Aarch64 code on a usual PC, you will need aarch64-linux-gnu-gcc
. After you have acquired the executable, or have built it form sourc,e just run aarch64-linux-gnu-gcc -D __bytestew__ vonjerriman.c bytestew.s
. Then run the executable with qemu-aarch64 -L /usr/aarch64-linux-gnu ./a.out
.
Please visit my Github profile to view my other projects. I have many projects brewing at the same time, paid and unpaid, and due to the aforementioned bereavenet I may have to code to keep my mind busy as the death is not the only issue, my aunt's gone crazy and threatened to shank my uncle, thus making my mom very upset. You can expect form me morre projects. Whilst you are here, please visit my project PoxHash and another simple Assembly gist DJB2 Hash. This one is an early Assembly project of mine and I have progressed much since then. It's good for contrast. These two subroutines themselves are very simple.
Thanks, and take care.