Page 1 of 1

Programming using registers with C

Posted: Tue Jun 18, 2019 2:16 pm
by hamdim
Hello,

I am trying to adapt a C project about Elliptic Curve Diffie-Helmen key exchange,
which uses registers, and when I tried to compile it, it says "there's no such registers name"

My Q is what are the registers I can use in Raspberry Pi 3 B (BCM2835) to temporarily store processed data instead of variables stored in RAM,
! not the register used to configure the GPIO

Thank you in advance !

Re: Programming using registers with C

Posted: Tue Jun 18, 2019 3:41 pm
by jahboater
hamdim wrote:
Tue Jun 18, 2019 2:16 pm
Hello,

I am trying to adapt a C project about Elliptic Curve Diffie-Helmen key exchange,
which uses registers, and when I tried to compile it, it says "there's no such registers name"

My Q is what are the registers I can use in Raspberry Pi 3 B (BCM2835) to temporarily store processed data instead of variables stored in RAM,
! not the register used to configure the GPIO

Thank you in advance !
Do you mean CPU registers?

These are R0 ... R15, of which R0 to R12 are useful (32 bits wide).
There are also 16 SIMD (NEON) registers (128 bits wide)

In 64 bit mode you get twice the number of registers. 31 integer and 32 SIMD. Register 31 is the zero register.
X0 ... X30 (64 bits) and W0 ... W30 (32 bits), XZR and WZR .

If you are programming in a language like C or C++ then the compiler will allocate and use the CPU registers very efficiently.
You can use the "register" keyword to force it to use a particular register, but its usually a bad idea.

Can you post a bit of the code that's in error?

Re: Programming using registers with C

Posted: Tue Jun 18, 2019 3:51 pm
by PeterO
Show us the code you are trying to compile ! We aren't mind readers !

PeterO

Re: Programming using registers with C

Posted: Wed Jun 19, 2019 3:04 pm
by hamdim
Thank you very much for your quick response !
here's the error message
fp25519_x64.c:340:4: error: unknown register name ‘%rdx’ in ‘asm’
);
^
fp25519_x64.c:340:4: error: unknown register name ‘%rcx’ in ‘asm’
fp25519_x64.c:340:4: error: unknown register name ‘%rax’ in ‘asm’


and this is the github link for the project i'm trying to impliment in raspberry pi
https://github.com/armfazh/rfc7748_precomputed

Re: Programming using registers with C

Posted: Wed Jun 19, 2019 3:07 pm
by rpdom
Well, you're obviously trying to compile code that was written to run on Intel type X86_64 system (PC) and not a Pi. It won't work.

Re: Programming using registers with C

Posted: Wed Jun 19, 2019 3:13 pm
by RaTTuS
to quote ....
"Prime field arithmetic is optimized for the 4th and 6th generation of Intel Core processors (Haswell and Skylake micro-architectures)."

Re: Programming using registers with C

Posted: Wed Jun 19, 2019 3:24 pm
by jahboater
RaTTuS wrote:
Wed Jun 19, 2019 3:13 pm
to quote ....
"Prime field arithmetic is optimized for the 4th and 6th generation of Intel Core processors (Haswell and Skylake micro-architectures)."
Its using BMI2 - a recent bit manipulation instruction set.
Probably quite hard to translate that into RISC, even aarch64 (the Pi in 64-bit mode).
That file is one enormous inline asm statement!

Re: Programming using registers with C

Posted: Wed Jun 19, 2019 6:02 pm
by hamdim
Thank you you very much for your responses,
I will try to understand the logic to the same functionality in raspberry
after all, I am trying to impliment Internet Key Exchange v2 on the raspberryPI
:D