Shop OBEX P1 Docs P2 Docs Learn Events
Is "rev" provided through PropGCC? — Parallax Forums

Is "rev" provided through PropGCC?

DavidZemonDavidZemon Posts: 2,973
edited 2015-04-19 15:28 in Propeller 1
The Propeller has a couple pretty cool instructions with no equivalent in C. Specifically, I'm looking for the rev instruction. Is that provided through PropGCC? If not, could it be? I know I can use it via inline assembly, but that's quite verbose for a single instruction.

Comments

  • ersmithersmith Posts: 5,900
    edited 2015-04-18 17:07
    The Propeller has a couple pretty cool instructions with no equivalent in C. Specifically, I'm looking for the rev instruction. Is that provided through PropGCC? If not, could it be? I know I can use it via inline assembly, but that's quite verbose for a single instruction.
    x = __builtin_propeller_rev(y, n);
    

    Pretty much any Propeller instruction which doesn't have an "obvious" way to write it in C (the lock, wait, etc. instructions, for example) will have a __builtin_propeller_xxx function, where xxx is the PASM opcode (all lower case).

    The <propeller.h> include file has nice macro wrappers for many of these, but that's optional.

    Eric
  • AribaAriba Posts: 2,682
    edited 2015-04-18 17:09
    Have you tried this?
       __builtin_propeller_rev(myVar,0);
    
    I have never used this one, but I think all the Assembler instructions have an equivalent __builtin_ function.

    Andy

    Edit. Okay Eric was a bit faster - but only a bit..
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-04-18 17:36
    ersmith wrote: »
    x = __builtin_propeller_rev(y, n);
    

    Pretty much any Propeller instruction which doesn't have an "obvious" way to write it in C (the lock, wait, etc. instructions, for example) will have a __builtin_propeller_xxx function, where xxx is the PASM opcode (all lower case).

    The <propeller.h> include file has nice macro wrappers for many of these, but that's optional.

    Eric

    I thought I saw something like that but couldn't find it. Thanks!

    Andy, thanks to you too :P
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-04-19 08:13
    Is there a __builtin_propeller_andn? It seems to be missing and x &= ~(y) doesn't compile to andn.

    --Edit--
    Or maybe it does, but not when used with CMM?
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-04-19 08:24
    No, there is no andn builtin. Here's the complete list.
    propeller/propeller.c: * void __builtin_propeller_clkset(unsigned mode)
    propeller/propeller.c: * int __builtin_propeller_cogid(void)
    propeller/propeller.c: * int __builtin_propeller_coginit(unsigned mode)
    propeller/propeller.c: * void __builtin_propeller_cogstop(int id)
    propeller/propeller.c: * unsigned __builtin_propeller_rev(unsigned x, unsigned n)
    propeller/propeller.c: * unsigned __builtin_propeller_waitcnt(unsigned c, unsigned d)
    propeller/propeller.c: * void __builtin_propeller_waitpeq(unsigned state, unsigned mask)
    propeller/propeller.c: * void __builtin_propeller_waitpne(unsigned state, unsigned mask)
    propeller/propeller.c: * void __builtin_propeller_waitvid(unsigned colors, unsigned pixels)
    propeller/propeller.c: * int __builtin_propeller_locknew(void)
    propeller/propeller.c: * void __builtin_propeller_lockret(int x)
    propeller/propeller.c: * int __builtin_propeller_lockset(int x)
    propeller/propeller.c: * void __builtin_propeller_lockclr(int x)
    
  • ersmithersmith Posts: 5,900
    edited 2015-04-19 15:28
    Is there a __builtin_propeller_andn? It seems to be missing and x &= ~(y) doesn't compile to andn.

    I'm not sure about PropGCC 1.0, but later versions (like alpha v1_9_0) compile:
    unsigned test(unsigned x, unsigned y)
    {
        return x & ~y;
    }
    
    to
    	.text
    	.global	_test
    _test
    	andn	r0, r1
    	lret
    
    in both LMM and CMM mode.

    I have seen cases where andn is not used inside loops, though -- unfortunately the loop optimization code sometimes hoists the "~y" part out of the loop, and ends up using more registers as a result.
Sign In or Register to comment.