Go Down

Topic: Another optimization question - can I speed up this 32 bit multiply? (Read 2 times) previous topic - next topic


Plus it's another reason not to use defines

What do you mean by that anyway?  I shouldn't be using defines?  How else can I use inline assembly?

Nick Gammon

What do you mean? Without using defines? Defines are just a text pre-preprocessing thing. An example from optiboot.c:

Code: [Select]

  __asm__ __volatile__ (
    "   com %[ch]\n" // ones complement, carry set
    "   sec\n"
    "1: brcc 2f\n"
    "   cbi %[uartPort],%[uartBit]\n"
    "   rjmp 3f\n"
    "2: sbi %[uartPort],%[uartBit]\n"
    "   nop\n"
    "3: rcall uartDelay\n"
    "   rcall uartDelay\n"
    "   lsr %[ch]\n"
    "   dec %[bitcnt]\n"
    "   brne 1b\n"
      [bitcnt] "d" (10),
      [ch] "r" (ch),
      [uartPort] "I" (_SFR_IO_ADDR(UART_PORT)),
      [uartBit] "I" (UART_TX_BIT)

No define there. No backslashes (apart from the \n inside the assembler string).

Nick Gammon

Coding Badly


Does that mean the \t isn't needed?  Some seem to use it some don't.  The code I'm using had them already.

As for defines, I know what they do, but what I'm saying is without them I'd have to drop that assembly in everywhere I want to use it.  I can't use it like a function, but without the overhead of a function call.  Unless I can use an inline function and the compiler knows not to do all kinds of crazy stuff with the function parameters.

Go Up