Mainly Tech projects on Python and Electronic Design Automation.

Saturday, March 18, 2006

What's wrong with Perl

It can be a refreshing tonic of a language when you move to perl
from something like basic, C or Java.
Perl can do what tens of Unix tools such as sed and awk can do from
the shell, but with more flexibility and higher order data structures
such as the perl 'hash' or 'associative array'.
You can sit and evolve a perl one-liner of X hundred characters
that will find and process millions of lines from thousands of files
from within hundreds of directories.
When you want to know how to do something else there is The Camel
, either the book or that human store of Perl Knowledge on the next
floor, a few cubicles over.
Before long, you have amassed a large personal perl knowledge
base, and can tackle most of your tasks, without having to consult
The Camel. You become more confident in perl and start to code for
others in your team, and write scripts in files rather than one
liners.

WAKE UP!

Languages have moved on.

Do you use perl references? Happy with them? Do you know that you
can get all that power without all the reference-gymnastics. Indeed,
you can get more power as you are freed from the mundane “how
do I create and use a hash of hashes”, to “O.K. The data
naturally starts as a hash of hashes so...”

Perl subroutines. Even AWK, one of the Unix stalwart languages
that perl was created to supplant has named arguments to its
functions. The better scripting languages can do a lot better,
allowing you to pass two lists into a function as easily as passing
in two integers. Or to return three hashes just as simply.

The perl slogan “There is more than one way to do it”
is often cited as one of perls strengths, and used by many
perl-mongers as their reason to stick with it. But how many of you
actually mean the extended form: “There is more than one way to
do it, and mine is the best”, or, “There is more than one
way to do it, but you will use mine!”, or more likely: “There
is more than one way to do it, and I don't know yours”, or
“There is more than one way to do it, and you will learn
mine!”, or “There is more than one way to do it, but I
don't know how to find any of them in Camels index”.

Perl still has goto! (and in its most evil of forms too, the
computed goto: where you have to interpret the program in your head
to work out where the goto might jump to from the listing because the
goto target is the result of an expression).

So much of perl documentation reads like 1001 recipes for using
1001 features, without any central theme to shape them.

Being an engineer, I am trained in finding patterns and
extrapolation. It is much easier for me to learn a small set of
powerful rules with a straightforward way of combining them. Perl,
unfortunately has a large number of 'gotchas' that bite when you try
to venture out from the recipes and examples given.

Conclusion

If you know perl, and have a need for programs greater than a few
tens of lines of code, then you should invest a week or two of your
time learning a different dynamic language. In that time, put aside
your perl knowledge and try to not just use the other languages
syntax, but learn how things are naturally done in that language.
Nothing may beat the 'perl -p -i -e' one-liner, but proper function
parameters and strict typing may be better for your longer scripts.

If you are thinking of learning Perl then think twice. Perls
'sweat-spot' is much diminished as new dynamic languages have emerged
with a less tacky support for new methodologies and standards such as
object oriented programming, program maintenance, functional
programming, XML, multi-language programming, and programming on
multiple frameworks such as dot-net and the Java Virtual Machine.

END.




Saturday, January 28, 2006

Generate your way through the Verification quagmire

I was thinking some more about an idea I had when commenting on someones verification problem here:
http://verificationguild.com/modules.php?name=Forums&file=viewtopic&p=3312&highlight=#3312
It is very hard to verify todays chip designs, but they are already quite regular.
My idea is to design IP that has its size more fully parameterized and generatable, so you would not design a 16 bit UART, you would design an n-bit UART with n able to take a range of values.
If the design of the UART has no 'corner cases' for increasing values of n, i.e. the internal architectural algorithm doesn't change for increasing n, then new ways to test the IP become available:
  • Formally test the IP generator performs its function over all n.
    It may be easier to formally prove the IP functionality for the IP generator over all n than to formally prove, for example, the functionality of a 16 bit version of the IP.
    Assertions would have to be written specifically for the genearator so that they too are parameterised by n.
    Questions: Are Assertion languages up to it? Are Formal checkers able to handle the complexity in the assertions?
  • More thoroughly verify the IP for a sequence of much smaller values of n and infer the quality of the IP generator for large values of n for which verification, especially formal and simulation based verification, is much harder, if not impossible.
Another example could be in designing and verifying some next-generation 32-by-32 channel switch that will take hundreds of millions of gates to implement. Design an m-by-m switch instead. Maybe you will get the 2,3,4,6,and 8 by 8 versions onto an FPGA and are able to do throughput tests, that then allow you to extrapolate the throughput of the 32-by-32 bit target version.

In time, Systems design and verification could be transformed as the requisite IP arrives fully parameterised, and with information on how performance scales with parameter sizes. System simulations for, say, a 32 bit CPU connected to a 64 bit bus and with a 16 and 32 bit peripheral could be done by the system simulation engine working out and configuring a simulation of a much smaller system maybe a four bit CPU with an 8 bit bus and 2 and 4 bit peripherals. The Sytem simulator could insert monitors, do the reduced simulation, then extrapolate the performance of the larger system. The smaller simulation should still be able to show faults that would be in the larger system as the system as a whole is just scaled.
One performance result that might yield to such extrapolation could be system power calculations based on toggle counts of individual IP blocks.

Is anyone doing this at the moment? I know of configurable CPU generators but they seem to be tailoring the instruction set to the software that is to be run.

- Paddy

Tuesday, March 01, 2005

Replacing a simple spreadsheet: Python needs what?

We were retracing the setup of a testbench for a simulation at work when my boss wanted to keep a record of a particular calculation we needed. It was really nothing too fancy - we just had to calculate how many device clock cycles elapsed in a JTAG idle statement from a good simulation , and make sure we had the same number when modifying the JTAG clock (which we could do independently of the device clock). This would ensure we idled for the same number of device clock cycles when we changed JTAG clock frequency ensuring the device had the same time to come out of reset.
Now my boss went for a simple spreadsheet solution. something like:
Original Values
(hidden cell function)
jtag_hi
640000

jtag_lo
640000

jtag_period
1280000
=b1+b2
jtag_idle
500




New Values

jtag_hi 1300

jtag_lo 100

jtag_period 1400
=b7+b8
jtag_idle 457000
=b3/b9*b4

I got thinking about the immediate use of the spreadsheet and thought why would I not do this in Python?

The idea is to show how a result is calculated ideally to be cut and pasted into a larger document or printed out.
In Ipython I would get the following log:
@pc[PC1]|2> jtag_lo=640000
@pc[PC1]|3> jtag_hi=640000
@pc[PC1]|4> jtag_period=jtag_lo+jtag_hi
@pc[PC1]|5> jtag_idle=500
@pc[PC1]|6> jtag_lo2=1300
@pc[PC1]|7> jtag_hi2=100
@pc[PC1]|8> jtag_period2=jtag_lo2+jtag_hi2
@pc[PC1]|9> jtag_idle2=jtag_idle*jtag_period/jtag_period2
@pc[PC1]|10> print jtag_idle2
457142
@pc[PC1]|11>

Notice how although the functions are shown, the intermediate answers are not, requiring the print at the end to display the final answer.
What would be ideal is if Ipython had a mode where it would show the value assigned to any name automatically, (when a simple = is typed interactively).
This mode should give the following type of output at the command line:
@pc[PC1]|2> jtag_lo=640000
= 640000
@pc[PC1]|3> jtag_hi=640000
= 640000
@pc[PC1]|4> jtag_period=jtag_lo+jtag_hi
= 1280000
@pc[PC1]|5> jtag_idle=500
= 500
@pc[PC1]|6> jtag_lo2=1300
= 1300
@pc[PC1]|7> jtag_hi2=100
= 100
@pc[PC1]|8> jtag_period2=jtag_lo2+jtag_hi2
= 1400
@pc[PC1]|9> jtag_idle2=jtag_idle*jtag_period/jtag_period2
= 457142

Finally, if Ipython allowed me to edit a line, e.g. line five to set jtag_idle to 50 , then replay lines 2 to 9 with the edited line 5 and show the new intermediate results, then I would prefer the Ipython solution to the spreadsheet one as I am very familiar with the procedural code and the resultant log, when printed or cut and pasted into a larger document would be both more informative than the spreadsheet (both the calculation and intermediate results would be shown at once); and more succinct (either plain text or simple HTML/RTF versus an embedded spreadsheet or HTML table that would loose the formulae).

Followers

Subscribe Now: google

Add to Google Reader or Homepage

Go deh too!

whos.amung.us

Blog Archive