[Cryptech Tech] Keeping magic numbers in sync between Verilog and C

Rob Austein sra at hactrn.net
Thu Oct 1 19:05:36 UTC 2015


At Thu, 01 Oct 2015 11:35:22 +0200, Joachim Strömbergson wrote:
> 
> Having constants/params in separate definition files is the right way to
> go about it. But if we move all magic localparams we will have to start
> prefixing parameters (AES_FOO). It will also be cumbersome to maintain a
> single file. So we want to collect the common defines - typically addresses.

Addresses, flag numbers, error codes (if any), that sort of thing.
API constants.  Anything not needed for the API should remain
internal.

> Each core could then have its own module specific header and include the
> common cryptech.vh with appropriate include guard. In this way, the
> updates to the common file is minimized. Prefixing will be needed anyway
> if we are collecting definitions in some way into a common c header.
> 
> Rob, do you see it as a hard problem to grep out and consume multiple
> header files - i.e. is a single common file crucial?

Taking this in reverse order, no, a single common file is not crucial,
Python's os.walk() is my friend.

As far as prefixing goes, you might consider prefixing the public API
symbols anyway, just so that it's obvious when the core and C are
using the same symbol.  Yeah, it's a bit more typing, Zest la vie.
Again, this only applies to public symbols.

> It is usually quite easy to do in Python as long as its just a question
> of parameters with symbolic names modulo one or a few levels of
> indirection. I've written such scripts several times and can probably
> dig one up.

I have code that thinks it can read Verilog integer constant syntax
and write out equivalent C constants, and parsing a line like:

  localparam foo = <verilog_integer_constant>; // optional comment

is not hard.  If you have code handy that does significantly more than
that, sure send it along.

Let's try to avoid doing anything complicated enough to require
http://www.dabeaz.com/ply/ :)


More information about the Tech mailing list