Welcome, Guest. Please login or register.

Author Topic: GCC asm() warning suppression options?  (Read 9523 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: GCC asm() warning suppression options?
« Reply #74 from previous page: July 03, 2009, 09:25:15 PM »
From what I gather looking at MS, they pretty much want to deprecate the C standard library in favour of their own "safe" versions of everything :)

I have to question the valididy of their safe "strcpy" alternative. All you have to do is give it a bad destination buffer size. How is that any safer?
int p; // A
 

Offline Trev

  • Zero
  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GCC asm() warning suppression options?
« Reply #75 on: July 03, 2009, 09:31:53 PM »
Everything post-C89 in the standard C library is considered Microsoft-specific. Their standards efforts are all centered on C++. Based on press, I gather they're doing a pretty good job, but I don't write much C++ code. There's always the "C++ as a better C" argument to fall back on....

EDIT: And no direct references to *snprintf in gas. So, need to do some debugging.

EDIT2: Well, it's actually operands of a specific length that pose a problem:

Code: [Select]
jsr a6@(-60  :W)   <-- 2 spaces no error
jsr a6@(-60   :W)  <-- 3 spaces ERROR 'js a6@(-60:W)'
jsr a6@(-60    :W) <-- 4 spaces no error

Building a Cygwin cross right now to see if there's a difference between the two runtime environments.

EDIT3: Same problem under Cygwin, so it's probably a bug in gas. Yay. I can work around it by using decimal values for library offsets in inlines, but blah, do I really want to modify those by hand? I guess I'll change fd2pragma and generate the headers again.

EDIT4: Or I could just pad the expressions in macros.h with enough spaces to prevent the error from occurring, which is what I've done.
« Last Edit: July 03, 2009, 10:40:29 PM by Trev »
 

Offline Trev

  • Zero
  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GCC asm() warning suppression options?
« Reply #76 on: July 04, 2009, 05:35:02 PM »
I'm struggling with read-only data placement at the moment. As the loader begins execution at the start of the first code hunk, all read-only data needs to be placed after code. GCC (supposedly) does this with a target macro, CONSTANT_POOL_BEFORE_FUNCTION. I've defined that macro as 0, which should tell the output routines to do what I want them to do; however, they're ignoring the value. At least, that's how it appears. Read-only data is still being generated before functions, so my hello.c test starts executing in the string "dos.library". Gotta love it. I could force all read-only data into a data hunk, but that shouldn't be necessary. :-/
 

Offline Trev

  • Zero
  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GCC asm() warning suppression options?
« Reply #77 on: July 04, 2009, 08:50:32 PM »
No answer on '#define CONSTANT_POOL_BEFORE_FUNCTION   0' yet, so I'm forcing everything into a data hunk with '#define READONLY_DATA_SECTION_ASM_OP   "\t.data"'. Obviously, that's not a viable long-term solution, but it keeps things moving. I'll have to ping the GCC gods on why CONSTANT_POOL_BEFORE_FUNCTION isn't working.
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: GCC asm() warning suppression options?
« Reply #78 on: July 04, 2009, 10:00:36 PM »
Quote from: Trev;514465
Read-only data is still being generated before functions, so my hello.c test starts executing in the string "dos.library".

Hmm. That's pretty bad. I don't know enough about the internals to be much help. Is CONSTANT_POOL_BEFORE_FUNCTION supposed to suppressed via #define CONSTANT_POOL_BEFORE_FUNCTION 0 or #undef CONSTANT_POOL_BEFORE_FUNCTION ?

Perhaps the switch depends on wether it is #defined at all, rather than what it is #defined as?
« Last Edit: July 04, 2009, 10:05:30 PM by Karlos »
int p; // A
 

Offline Trev

  • Zero
  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GCC asm() warning suppression options?
« Reply #79 on: July 05, 2009, 12:18:16 AM »
Quote from: Karlos;514484
Hmm. That's pretty bad. I don't know enough about the internals to be much help. Is CONSTANT_POOL_BEFORE_FUNCTION supposed to suppressed via #define CONSTANT_POOL_BEFORE_FUNCTION 0 or #undef CONSTANT_POOL_BEFORE_FUNCTION ?

Perhaps the switch depends on wether it is #defined at all, rather than what it is #defined as?

Defining to 0 should be the way to go. If undefined, the compiler defines it as 1. It's only checked in two locations (before and after writing a compiled function to assembly source), but it's an old option, only used by one mainline target. It's possible the option has been inadvertently deprecated by the current maintainers.
 

Offline Trev

  • Zero
  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GCC asm() warning suppression options?
« Reply #80 on: July 05, 2009, 10:22:01 PM »
Moving right along. I'm using the Geek Gadgets patches as a reference, but I'm not merging them. ixemul and libnix will be gone (to be replaced by newlib), as will simple (but annoying) things like legacy built-in definitions (MCH_AMIGA, AMIGA, et all to be replaced with __amigaos__) and attribute shortcuts (e.g. no __chip for __attribute__((__chip__))). Workarounds for missing definitions can be added to the build process for existing software or bundled into compatibility frameworks like the SDI headers.

Features like stack extension and position-independent / base-relative code will be worked into the standard GCC framework.

I'd also like to differentiate between hardware ISRs and AmigaOS ISRs, i.e. rte v. rts with cc set (?). I'm not sure if the Geek Gadgets port does that.
 

Offline Tension

Re: GCC asm() warning suppression options?
« Reply #81 on: July 06, 2009, 12:21:01 AM »
Indeed

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: GCC asm() warning suppression options?
« Reply #82 on: July 06, 2009, 05:13:45 PM »
Quote from: Trev;514575
Moving right along. I'm using the Geek Gadgets patches as a reference, but I'm not merging them. ixemul and libnix will be gone (to be replaced by newlib), as will simple (but annoying) things like legacy built-in definitions (MCH_AMIGA, AMIGA, et all to be replaced with __amigaos__) and attribute shortcuts (e.g. no __chip for __attribute__((__chip__))). Workarounds for missing definitions can be added to the build process for existing software or bundled into compatibility frameworks like the SDI headers.


Surely __chip is supportable via a #define __chip __attribute__((__chip__)) type affair?
int p; // A
 

Offline Trev

  • Zero
  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GCC asm() warning suppression options?
« Reply #83 on: July 06, 2009, 05:54:41 PM »
Yes, and the Geek Gadgets sources define that in the compiler itself to provide source-level compatibility with other compilers. I don't see any reason to do that in the compiler when it can be done just as easily in a Makefile or header.

Also,    CONSTANT_POOL_BEFORE_FUNCTION didn't do what I thought it did. I'm on the GCC list, hopefully getting pointed in the right direction.

EDIT: And rather humorously, I hit a race condition when making gcc with 'make -j 5 all-gcc' on my Core i7. Builds were much, much faster, but I can't have the process hanging (well, spinning forever, in this case) on me. GCC builds quickly, though. newlib is going to be a pain.
« Last Edit: July 06, 2009, 06:06:31 PM by Trev »
 

Offline Trev

  • Zero
  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GCC asm() warning suppression options?
« Reply #84 on: July 06, 2009, 09:14:01 PM »
8, 16, and 32 bit rotates in gcc 4.4.0:

Code: [Select]

static inline unsigned char _rotl8(unsigned char val, unsigned char shift)
{
    shift &= 7;
    val = (val>>(8 - shift)) | (val << shift);
    return val;
}

static inline unsigned char _rotr8(unsigned char val, unsigned char shift)
{
    shift &= 7;
    val = (val<<(8 - shift)) | (val >> shift);
    return val;
}

static inline unsigned short _rotl16(unsigned short val, unsigned char shift)
{
    shift &= 15;
    val = (val>>(16 - shift)) | (val << shift);
    return val;
}

static inline unsigned short _rotr16(unsigned short val, unsigned char shift)
{
    shift &= 15;
    val = (val<<(16 - shift)) | (val >> shift);
    return val;
}

static inline unsigned long _rotl32(unsigned long val, unsigned char shift)
{
    shift &= 31;
    val = (val>>(32 - shift)) | (val << shift);
    return val;
}

static inline unsigned long _rotr32(unsigned long val, unsigned char shift)
{
    shift &= 31;
    val = (val<<(32 - shift)) | (val >> shift);
    return val;
}


Code: [Select]

volatile unsigned char w = 1;
   c:   1f7c 0001 0027  moveb #1,%sp@(39)

volatile unsigned char a = _rotl8(w, 1);
  12:   102f 0027       moveb %sp@(39),%d0
  16:   0280 0000 00ff  andil #255,%d0
  1c:   2200            movel %d0,%d1
  1e:   d281            addl %d1,%d1
  20:   ee80            asrl #7,%d0
  22:   8001            orb %d1,%d0
  24:   1f40 0026       moveb %d0,%sp@(38)

volatile unsigned char b = _rotr8(w, 1);
  28:   102f 0027       moveb %sp@(39),%d0
  2c:   0280 0000 00ff  andil #255,%d0
  32:   2200            movel %d0,%d1
  34:   e281            asrl #1,%d1
  36:   ef88            lsll #7,%d0
  38:   8001            orb %d1,%d0
  3a:   1f40 0025       moveb %d0,%sp@(37)

volatile unsigned short x = 1;
  3e:   3f7c 0001 0022  movew #1,%sp@(34)

volatile unsigned short c = _rotl16(x, 1);
  44:   302f 0022       movew %sp@(34),%d0
  48:   0280 0000 ffff  andil #65535,%d0
  4e:   2200            movel %d0,%d1
  50:   d281            addl %d1,%d1
  52:   740f            moveq #15,%d2
  54:   e4a0            asrl %d2,%d0
  56:   8041            orw %d1,%d0
  58:   3f40 0020       movew %d0,%sp@(32)

volatile unsigned short d = _rotr16(x, 1);
  5c:   302f 0022       movew %sp@(34),%d0
  60:   0280 0000 ffff  andil #65535,%d0
  66:   2200            movel %d0,%d1
  68:   e281            asrl #1,%d1
  6a:   e5a8            lsll %d2,%d0
  6c:   8041            orw %d1,%d0
  6e:   3f40 001e       movew %d0,%sp@(30)

volatile unsigned long y = 1;
  72:   7001            moveq #1,%d0
  74:   2f40 001a       movel %d0,%sp@(26)

volatile unsigned long e = _rotl32(y, 1);
  78:   202f 001a       movel %sp@(26),%d0
  7c:   e398            roll #1,%d0
  7e:   2f40 0016       movel %d0,%sp@(22)

volatile unsigned long f = _rotr32(y, 1);
  82:   202f 001a       movel %sp@(26),%d0
  86:   e298            rorl #1,%d0
  88:   2f40 0012       movel %d0,%sp@(18)

volatile unsigned z = 1;
  8c:   7401            moveq #1,%d2
  8e:   2f42 000e       movel %d2,%sp@(14)

volatile unsigned g = _rotl(z, 1);
  92:   202f 000e       movel %sp@(14),%d0
  96:   e398            roll #1,%d0
  98:   2f40 000a       movel %d0,%sp@(10)

volatile unsigned h = _rotr(z, 1);
  9c:   202f 000e       movel %sp@(14),%d0
  a0:   e298            rorl #1,%d0
  a2:   2f40 0006       movel %d0,%sp@(6)


In the nonvolatile world (and in the compile-time templates), these examples are all reduced to integer constants.
« Last Edit: July 06, 2009, 09:22:44 PM by Trev »
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: GCC asm() warning suppression options?
« Reply #85 on: July 07, 2009, 03:19:46 PM »
Careful, that's almost on-topic :D
int p; // A
 

Offline Trev

  • Zero
  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GCC asm() warning suppression options?
« Reply #86 on: July 07, 2009, 06:52:54 PM »
Quote from: Karlos;514817
Careful, that's almost on-topic :D


You're right. Seen any good movies lately?

(And there really should be a simple way to get rid of the warning. It really does imply that something is syntactically wrong with the inline assembly.)
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: GCC asm() warning suppression options?
« Reply #87 on: August 11, 2009, 07:21:15 PM »
Today I stumbled across a very nice gcc specific builtin:

__builtin_constant_p(x)

This evaluates to 1 if x is known to be a compile time constant. A quick test confirmed that it works on stuff as old 2.95.x. This is great, because it obviates the need for the template versions for constant-sized rotates. For example:
Code: [Select]
 inline uint32 rotLeft32(uint32 bits, uint32 val)
  {
    if (__builtin_constant_p(bits)) {
      // from template version
      if (bits&31) {
        // only rotate when modulus 32 > 0
        if ((bits&31) < 9) {
          asm(&quot;rol.l %1, %0&quot; : &quot;=d&quot;(val) : &quot;I&quot;(bits&31), &quot;0&quot;(val) : &quot;cc&quot;);
        }
        else if ((bits&31)==16) {
          asm(&quot;swap %0&quot; : &quot;=d&quot;(val) : &quot;0&quot;(val) : &quot;cc&quot;);
        }
        else if ((bits&31)>23) {
          // use opposite rotate for N > 23
          asm(&quot;ror.l %1, %0&quot; : &quot;=d&quot;(val) : &quot;I&quot;(32-(bits&31)), &quot;0&quot;(val) : &quot;cc&quot;);
        }
        else {
          // use register rotate for all intermediate sizes
          asm(&quot;rol.l %1, %0&quot; : &quot;=d&quot;(val) : &quot;d&quot;(bits&31), &quot;0&quot;(val) : &quot;cc&quot;);
        }
      }
    }
    else {
      asm(&quot;rol.l %1, %0&quot; : &quot;=d&quot;(val) : &quot;d&quot;(bits), &quot;0&quot;(val) : &quot;cc&quot;);
    }
    return val;
  }

This single inline emits code as efficiently as the template version in all cases where bits evaluates to a constant value at compile time. One thing to note is that __builtin_constant(x) only really works at optimisation levels -O1 and higher.

@Trev

Any progress with the gcc 4 m68k amigaos build?
« Last Edit: August 11, 2009, 08:14:18 PM by Karlos »
int p; // A