Click here to Skip to main content
15,885,546 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch14-Mar-21 10:52
mvahoney the codewitch14-Mar-21 10:52 
GeneralRe: Things I find buried in the C++ reference Pin
Espen Harlinn14-Mar-21 12:42
professionalEspen Harlinn14-Mar-21 12:42 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch14-Mar-21 12:54
mvahoney the codewitch14-Mar-21 12:54 
GeneralRe: Things I find buried in the C++ reference Pin
Espen Harlinn15-Mar-21 11:29
professionalEspen Harlinn15-Mar-21 11:29 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch15-Mar-21 11:57
mvahoney the codewitch15-Mar-21 11:57 
GeneralRe: Things I find buried in the C++ reference Pin
Stuart Dootson15-Mar-21 1:09
professionalStuart Dootson15-Mar-21 1:09 
GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch15-Mar-21 2:22
mvahoney the codewitch15-Mar-21 2:22 
GeneralRe: Things I find buried in the C++ reference Pin
Stuart Dootson15-Mar-21 3:31
professionalStuart Dootson15-Mar-21 3:31 
honey the codewitch wrote:
Made extra difficult for the fact that in certain cases (like with 1 bit monochrome) I am not reading and writing on byte boundaries, but bit boundaries


Same here - I've got control registers like this:

Bit NumberLabelValue
31..13Not Used-
12Table Entry Lock0 = Unlocked
1 = Locked
11..9Not Used-
8Page Access0 = Enabled
1 = Disabled
7..6Data Bus Width01b = 16-bit
10b = 32-bit
5..0Wait States Setting000000b = 0 Wait States
000001b = 1 Wait State

111110b = 62 Wait States
111111b = 63 Wait States

I'm modelling each bit-field with a struct templatised on its bit locations, each register with a templatised list of bit-fields - something like this:
C++
using bf1 = bit_field_t<21, 10>;
using bf2 = bit_field_t<31, 24>;
using bf3 = bit_field_t<0, 0>;
using bf4 = bit_field_t<1, 1>;
using bf5 = bit_field_t<2, 2>;
using bf6 = bit_field_t<3, 3>;
using bf7 = bit_field_t<4, 8>;
using bf9 = bit_field_t<6, 6>;
using reg1_t = bit_field_register_t<bf1, bf2, bf3, bf4, bf5, bf6, bf7>;
using reg2_t = bit_field_register_t<bf1, bf2, bf3, bf4, bf5, bf6, bf9>;

(Why all the types? So the compiler can detect attempts to access incorrect bit-fields).

Each field of a bit-field register can be manipulated like so:
C++
int foo(reg1_t *r1) {
  r1->insert<bf1>(123);
  return r1->extract<bf7>();
}

and that code compiles to the following on AMD64 targets:
ASM
mov     eax, dword ptr [rdi]
mov     ecx, eax
and     ecx, -4193281
or      ecx, 125952
mov     dword ptr [rdi], ecx
shr     eax, 4
and     eax, 31
ret

This isn't intended for memory-mapped registers (as I said - it's an emulation of that), but could probably be used for that with a few mods.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Things I find buried in the C++ reference Pin
honey the codewitch15-Mar-21 3:52
mvahoney the codewitch15-Mar-21 3:52 
GeneralRe: Things I find buried in the C++ reference Pin
James Curran15-Mar-21 4:43
James Curran15-Mar-21 4:43 
GeneralOh no! Pin
Jörgen Andersson12-Mar-21 9:45
professionalJörgen Andersson12-Mar-21 9:45 
GeneralRe: Oh no! Pin
NotTodayYo12-Mar-21 10:09
NotTodayYo12-Mar-21 10:09 
GeneralRe: Oh no! Pin
RickZeeland12-Mar-21 21:04
mveRickZeeland12-Mar-21 21:04 
GeneralExploding Plastic Pin
honey the codewitch12-Mar-21 9:08
mvahoney the codewitch12-Mar-21 9:08 
GeneralRe: Exploding Plastic Pin
OriginalGriff12-Mar-21 11:17
mveOriginalGriff12-Mar-21 11:17 
GeneralThought of the Day Pin
OriginalGriff12-Mar-21 4:44
mveOriginalGriff12-Mar-21 4:44 
GeneralRe: Thought of the Day Pin
W Balboos, GHB12-Mar-21 5:22
W Balboos, GHB12-Mar-21 5:22 
GeneralThis was sent to me today ... Pin
CHill6012-Mar-21 3:29
mveCHill6012-Mar-21 3:29 
GeneralRe: This was sent to me today ... Pin
PIEBALDconsult12-Mar-21 3:32
mvePIEBALDconsult12-Mar-21 3:32 
GeneralRe: This was sent to me today ... Pin
CHill6012-Mar-21 3:33
mveCHill6012-Mar-21 3:33 
GeneralRe: This was sent to me today ... Pin
PIEBALDconsult12-Mar-21 3:42
mvePIEBALDconsult12-Mar-21 3:42 
GeneralSound of the Week Pin
Sander Rossel11-Mar-21 23:36
professionalSander Rossel11-Mar-21 23:36 
GeneralRe: Sound of the Week Pin
CHill6012-Mar-21 3:30
mveCHill6012-Mar-21 3:30 
GeneralRe: Sound of the Week Pin
David O'Neil12-Mar-21 8:10
professionalDavid O'Neil12-Mar-21 8:10 
GeneralRe: Sound of the Week Pin
Sander Rossel13-Mar-21 0:58
professionalSander Rossel13-Mar-21 0:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.