kvasir-io / Kvasir

C++ Metaprogramming library enabling better static checking and register abstraction in embedded software
Apache License 2.0
409 stars 40 forks source link

Writing all bits of a register doesn't result in a blind write #119

Open LegalizeAdulthood opened 6 years ago

LegalizeAdulthood commented 6 years ago

Having gotten my basic GBA prototype working, I attempted to reproduce the first tonc demo and compared the assembly dump of my .o to the one produced by that first code example. Their code results in a blind write to the DISPCNT register, but my Kvasir code results in a read-modify-write to the register. At first I thought this was because I wasn't writing all fields of the register, but even when I did that, I got a read-modify-write implementation.

I thought kvasir would optimize writing to all bits in the register as a blind write?

Perhaps I am not defining my DISPCNT register correctly (see GBA.hpp), or I am doing something wrong in using my register definitions?

My first assumption is user error on my part :)

Is there a shortcut for saying "clear all bits/fields in the register except those explicitly given a value"?

odinthenerd commented 6 years ago

internally kvasir should be oring all the bitmasks of modified fields with the "has default value" bitmask and if that ends up as 0xFFFFFFFF then it should turn it into a blind write. I'll have a look and get back to you.

odinthenerd commented 6 years ago

it might be that I hard coded it to look for 0xFFFFFFFF rather than the actual width of the register, I see this is a 16 bit register

LegalizeAdulthood commented 6 years ago

Hrm. I see that the mask helper function I was using is generating 32-bit masks. I will adjust my field definitions and see if that gets me to a blind write.