Log in

No account? Create an account
Bad tools will make you hate life. - Adventures in Engineering — LiveJournal
The wanderings of a modern ronin.

Ben Cantrick
  Date: 2006-04-05 07:49
  Subject:   Bad tools will make you hate life.
  Mood:Stab! STAB! Stabbity-stab!!!
After 15 hours of hitting my head on things that should have taken 10 minutes, I have learned something today:

  • With good tools, you can make some pretty neat stuff in a reasonable amount of time. For instance, ~600 lines of main control code in a week that has yet to break in several fairly nasty integration tests.

  • With bad tools, you'll be hating your life and spending 15 hours doing something that should take you ten minutes.

I'm talking about compilers here, but the general lesson is a good one to remember.

I'd like to give the "pathetic and broken" award to the C2C compiler, which could not properly emit code to make this C statement work:

uchar8 = (uint16 >> 8) & 0xFF;

The really amusing irony here is that the uint16 is stored internally as a high byte and a low byte. All you need to do is take the high byte already stored in memory and copy it to the memory address of uchar8. Two instructions, max.

Nor could it manage this:

if(int16 < 0) { ... }

I shit you not - I had to hand-check the sign bit of my integer variable to see if it was negative, because the compiler couldn't emit code that would successfully do it! Three instructions for my version (mask with 0x8000, subtract 0x8000 from result, jump if result = zero). The C2C generated between 15 and 20 instructions to do the same thing, which kinda adds up when you only have 2k of instruction ROM to work with. And, let me repeat myself, the code it made still didn't work. Thought it did consistantly crash and freeze the PIC 16xxx I was working on. No small feat, as they're fairly goof-proof chips. After hacking it on my own, I got the interrupt handler working at 250 repetitions per second, rock solid. (Actually, theoretically it could do 800-900 second, but I didn't test it that fast.)

I'm smart enough to know that I probably wouldn't write a good compiler for the PIC. That makes me smarter than the people who wrote C2C. Apparently the BoostC compiler from the same site is going to supercede C2C. The sooner the better, if you ask me. Pay money for that thing? I'd rather stab myself in the crotch - repeatedly - with an angry, 800 lb blue marlin.

Post A Comment | 6 Comments | | Link

Mike Agney
  User: magney
  Date: 2006-04-05 09:28 (UTC)
  Subject:   (no subject)
If this is typical of compilers for embedded systems, that would explain a lot about the horrendous mobile web browsers I've had to support.
Reply | Thread | Link

Ben Cantrick
  User: mackys
  Date: 2006-04-05 21:58 (UTC)
  Subject:   (no subject)
I've got nothing but love for Microchip's PIC18 compiler, which I used to do the control board. Great compiler, rock solid code generation. It costs you $300, but when you're paid hourly and under a deadline... that starts to look like small potatoes.
Reply | Parent | Thread | Link

  User: nickhalfasleep
  Date: 2006-04-05 14:52 (UTC)
  Subject:   (no subject)

You should've written it in embedded java.

Reply | Thread | Link

Ben Cantrick
  User: mackys
  Date: 2006-04-05 21:56 (UTC)
  Subject:   That would be pretty cool.
If someone manages to squeeze a JVM into 2k of code and 228 bytes of RAM, let me know!
Reply | Parent | Thread | Link

Ben Cantrick
  User: mackys
  Date: 2006-04-05 21:55 (UTC)
  Subject:   Corrections, or why posting at 1:30 am is asking for trouble.
The original second statement was posted as:

if(uint16 < 0)

This is, of course, impossible. Unsinged integers cannot be negative, by definition. The code in fact did use a signed integer, I just messed up the post here. It's corrected in the post now.

Secondly, checking for the top bit to be set in a 16 bit quantity is even easier than I thought. Bitwise AND with 0x8000 and jump if non-zero. Two instructions. If your ALU is only 8 bits wide, then bitwise AND the top byte with 0x80, and jnz.
Reply | Thread | Link

Alex Belits: mona
  User: abelits
  Date: 2006-04-06 04:23 (UTC)
  Subject:   (no subject)
Just horrible...
Reply | Thread | Link

May 2015