Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #29 from previous page: June 30, 2009, 11:34:56 PM »
Quote from: Trev;514038
Actually, that sounds like a quite valid use. Within the design of the operating system even. (Well, sort of. But manipulating stack frames is kind of at the core of exception handling, isn't it?)

Well, yes, but not quite like this. Normally C++ exceptions operate entirely in userland and unwind the stack of the process they were fired in (well, if you omit threadsafe.lib in old gcc, watch the fun when that assertion fails).

Here, we are actually in the supervisor state, altering the saved stack frame of the thread that performed the illegal op and altering the return address such that when the trap is complete, it returns to a completely different location. Right into our code that throws the exception.

The old thread about that is on here somewhere. Amazingly it really does work very well and I built it into my codebase. I'm currently figuring out how to accomplish the same thing inside a signal handler under posix, but it always seems as if the exception occurred inside main() rather than where it really happened.

-edit-

http://www.amiga.org/forums/showthread.php?t=25181 here
« Last Edit: June 30, 2009, 11:40:13 PM by Karlos »
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #30 on: July 01, 2009, 07:41:32 AM »
Quote from: Trev;514045
Were you ever able to simulate a null pointer exception, short of wrapping all pointers in a class and overloading the indirection operator?


No. Well, I didn't try too hard as I was never able to get mmu.library working on my system. Every time I'd install it, it would drop to bits.
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #31 on: July 01, 2009, 07:51:18 AM »
Quote from: Trev;514073
I suspect your template will be faster, but only because the optimizer isn't doing rol's:

Well, that and the fact it doesn't require an additional register to hold the shift value for many of the sizes. Saving a register gives the optimizer more breathing space in 'real' code.

Quote
I don't know anything about how the optimizer works, really, so I don't know why it's always opting for one solution over another.

It could be that the RTL model only supports rotation in one direction? Just a guess.
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #32 on: July 01, 2009, 07:54:13 AM »
Well, the day has just started here and I have to head off for work in 2 minutes :)
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #33 on: July 01, 2009, 07:55:17 AM »
Quote from: Trev;514078
And I suspect that GCC will reduce to constant values anything that isn't defined as or determined to be volatile.


Not so sure it can do that inside an asm() though.
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #34 on: July 01, 2009, 09:47:24 PM »
I don't use asm volatile in my templates as there's no reason to presuppose the code has to be emitted in every case. If the compiler can see the code is redundant it should be allowed to remove it.

Strange, though, I didn't get the anticipated rotate instructions generated by gcc 2.95.3. I wonder why?

-edit-

How is it with rotation of 8/16-bit types?

2.95.3's behaviour is slightly moot at this point as I'm hoping to use a later version anyway. Still a bit confused by your findings above though. Perhaps this could be down to stormgcc's backend? I was under the impression they hadn't messed about with the m68k compiler part at all.
« Last Edit: July 01, 2009, 10:03:20 PM by Karlos »
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #35 on: July 03, 2009, 08:55:13 PM »
Quote from: Trev;514158
And what I was really interested in is why gcc 4.4.0 doesn't optimize correctly--in fact, worse than gcc 2.95.3 (which still isn't optimal). A shiney new gcc 4.4.0 m68k-*-amigaos* with fixed optimization (for this parituclar issue, anyway) and a native newlib implementation would be, well, shiney.

Indeed it would :)

Kind of scary that what started out as what I hoped was a simple "is there an -Wno-complain-about-asm" option turned into this :laughing:

-edit-

Do I take it my crazy Machine::rot8/16/32() are still fair game, then?
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #36 on: July 03, 2009, 09:07:57 PM »
The reason I didn't go for "signed direction" with the rotate operations was that you don't get that behaviour with <> either, by default.

I should point out that the template versions only exist to optimise "constant" rotates. There are normal inline methods where the number of bits to rotate is a variable.
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #37 on: July 03, 2009, 09:14:51 PM »
I should probably rename this thread "Trev builds gcc 4.4 for m68k target" ;)
int p; // A
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #38 on: 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 KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #39 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 KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #40 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 KarlosTopic starter

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

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: GCC asm() warning suppression options?
« Reply #42 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