hamdim
Posts: 3
Joined: Tue Jun 18, 2019 2:09 pm

Programming using registers with C

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 !

jahboater
Posts: 4607
Joined: Wed Feb 04, 2015 6:38 pm

Re: Programming using registers with C

Tue Jun 18, 2019 3:41 pm

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?
Last edited by jahboater on Tue Jun 18, 2019 3:54 pm, edited 1 time in total.

User avatar
PeterO
Posts: 4942
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming using registers with C

Tue Jun 18, 2019 3:51 pm

Show us the code you are trying to compile ! We aren't mind readers !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

hamdim
Posts: 3
Joined: Tue Jun 18, 2019 2:09 pm

Re: Programming using registers with C

Wed Jun 19, 2019 3:04 pm

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

User avatar
rpdom
Posts: 15021
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Programming using registers with C

Wed Jun 19, 2019 3:07 pm

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.

User avatar
RaTTuS
Posts: 10415
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Programming using registers with C

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)."
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

jahboater
Posts: 4607
Joined: Wed Feb 04, 2015 6:38 pm

Re: Programming using registers with C

Wed Jun 19, 2019 3:24 pm

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!

hamdim
Posts: 3
Joined: Tue Jun 18, 2019 2:09 pm

Re: Programming using registers with C

Wed Jun 19, 2019 6:02 pm

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

Return to “Advanced users”