Skip to content

Utility to safely manipulate registers with zero overhead

License

Notifications You must be signed in to change notification settings

marcobergamin/register

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Register

A simple utility to safely manipulate registers with zero overhead.\

Why

I wanted to make a super simple utility with these features:

  • Just a single reinterpret_cast<> for N registers, useful in case of future safety certifications
  • Operations don't touch the stack. Zero stack used!
  • Any bitmask calculated at compile time
  • Errors like setting the bit 17 of a 16 bit registers caught at compile time
  • The address of a given register is part of its type, no extra memory required to store any pointer.
  • Last but not least: no macros

Example

In this section, a few examples with the generated assembly.
Compiler used: ARM gcc 11.2.1 (none), flags -std=c++14 -O3

#include <mabe/register.hpp>

// Lets define a couple of registers
namespace my_regs {
using reg32 = RegU32<0x1000>;
using reg8 = RegU8<0x1004>;
}

Setting all bits (32 bit reg)

my_regs::reg32::set_all();

ARM assembly:

mov r3, #4096 ; 0x1000
mvn r2, #0
str r2, [r3]

Setting bits 2,3,31 (32 bit reg)

my_regs::reg32::set_bits<2, 3, 31>();

ARM assembly:

mov r2, #4096            ; 0x1000
ldr r3, [r2]
orr r3, r3, # 2147483636 ; 0x8000000c
str r3, [r2]

Clearing bit 1 (8 bit reg)

my_regs::reg8::clear_bit<1>();

ARM assembly:

mov	r2, #4096	; 0x1000
ldrb	r3, [r2, #4]
and	r3, r3, #253	; 0xfd
strb	r3, [r2, #4]

!!! Note !!!

This project is still work in progress. Any feedback is appreciated.

About

Utility to safely manipulate registers with zero overhead

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published