Skip to contentSkip to conversation

math-emu/setcc: avoid gcc extension

PATCH In review Randy Dunlap 4 participants 10 messages Jan 7, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 math-emu/setcc: avoid gcc extension

From: Randy Dunlap <[email protected]>

setcc() in math-emu is written as a gcc extension statement expression macro that returns a value. However, it's not used that way and it's not needed like that, so just make it a do-while non-extension macro so that we don't use an extension when it's not needed.

All 4 .c files that use setcc() produce the same code after this patch.

---
 arch/i386/math-emu/status_w.h        |    5 +++--
---
 arch/i386/math-emu/status_w.h |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/i386/math-emu/status_w.h +3 -2
@@ -48,9 +48,10 @@
 
 #define status_word() \
   ((partial_status & ~SW_Top & 0xffff) | ((top << SW_Top_Shift) & SW_Top))
-#define setcc(cc) ({ \
+#define setcc(cc) do { \
   partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
-  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
+  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); } \
+	while (0)
 
 #ifdef PECULIAR_486
    /* Default, this conveys no information, but an 80486 does it. */

---

#1 lore raw
Quoted 4 lines

setcc() in math-emu is written as a gcc extension statement expression macro that returns a value. However, it's not used that way and it's not needed like that, so just make it a do-while non-extension macro so that we don't use an extension when it's not needed.

Looks fine, except

arch/i386/math-emu/status_w.h line 54

Quoted 6 lines
arch/i386/math-emu/status_w.h +3 -2
-#define setcc(cc) ({ \
+#define setcc(cc) do { \
   partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
-  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
+  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); } \
+	while (0)

closing brace on the "while" line, please.

Segher

#2 lore raw
Quoted 1 line · On Sun, 7 Jan 2007 14:27:32 +0100 Segher Boessenkool wrote:

closing brace on the "while" line, please.

---
From: Randy Dunlap <[email protected]>

setcc() in math-emu is written as a gcc extension statement expression macro that returns a value. However, it's not used that way and it's not needed like that, so just make it a do-while non-extension macro so that we don't use an extension when it's not needed.

---
 arch/i386/math-emu/status_w.h        |    5 +++--
---
 arch/i386/math-emu/status_w.h |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/i386/math-emu/status_w.h +3 -2
@@ -48,9 +48,10 @@
 
 #define status_word() \
   ((partial_status & ~SW_Top & 0xffff) | ((top << SW_Top_Shift) & SW_Top))
-#define setcc(cc) ({ \
+#define setcc(cc) do { \
   partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
-  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
+  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); \
+	} while (0)
 
 #ifdef PECULIAR_486
    /* Default, this conveys no information, but an 80486 does it. */
#3 lore raw

arch/i386/math-emu/status_w.h line 54

Quoted 6 lines
arch/i386/math-emu/status_w.h +3 -2
-#define setcc(cc) ({ \
+#define setcc(cc) do { \
   partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
-  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
+  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); \
+	} while (0)

There's an extra tab in that last line. Could you also please fix the indenting (use a tab, not spaces) -- I know it was there originally, but since there are only a few lines in that file like that... :-)

[You must be tired of me by now, heh]

Thanks,

Segher

#4 lore raw
Quoted 4 lines · On Sun, 7 Jan 2007 20:12:42 +0100 Segher Boessenkool wrote:

There's an extra tab in that last line. Could you also please fix the indenting (use a tab, not spaces) -- I know it was there originally, but since there are only a few lines in that file like that... :-)

how's this one?
---
From: Randy Dunlap <[email protected]>

setcc() in math-emu is written as a gcc extension statement expression macro that returns a value. However, it's not used that way and it's not needed like that, so just make it a do-while non-extension macro so that we don't use an extension when it's not needed.

---
 arch/i386/math-emu/status_w.h        |    5 +++--
---
 arch/i386/math-emu/status_w.h |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/i386/math-emu/status_w.h +4 -3
@@ -48,9 +48,10 @@
 
 #define status_word() \
   ((partial_status & ~SW_Top & 0xffff) | ((top << SW_Top_Shift) & SW_Top))
-#define setcc(cc) ({ \
-  partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
-  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
+#define setcc(cc) do { \
+	partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
+	partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); \
+} while (0)
 
 #ifdef PECULIAR_486
    /* Default, this conveys no information, but an 80486 does it. */
#5 lore raw
Quoted 11 lines · Randy Dunlap
Quoted 4 lines · On Sun, 7 Jan 2007 20:12:42 +0100 Segher Boessenkool wrote:

There's an extra tab in that last line. Could you also please fix the indenting (use a tab, not spaces) -- I know it was there originally, but since there are only a few lines in that file like that... :-)

how's this one?
---
From: Randy Dunlap <[email protected]>

Quoted 5 lines

setcc() in math-emu is written as a gcc extension statement expression macro that returns a value. However, it's not used that way and it's not needed like that, so just make it a do-while non-extension macro so that we don't use an extension when it's not needed.

is that the proposed coding style for macros? if it returns a value, use "({ })"? if not, use the "do ... while" notation?

rday

#6 lore raw
In reply to Randy Dunlap
Quoted 6 lines
Quoted 4 lines

There's an extra tab in that last line. Could you also please fix the indenting (use a tab, not spaces) -- I know it was there originally, but since there are only a few lines in that file like that... :-)

how's this one?

I meant fix all the wrongly indented lines in that file (there are only a few, and all around where you're patching anyway).

Care for one extra time? :-)

Segher

#7 lore raw
Quoted 11 lines · On Sun, 7 Jan 2007 20:29:21 +0100 Segher Boessenkool wrote:
Quoted 6 lines
Quoted 4 lines

There's an extra tab in that last line. Could you also please fix the indenting (use a tab, not spaces) -- I know it was there originally, but since there are only a few lines in that file like that... :-)

how's this one?

I meant fix all the wrongly indented lines in that file (there are only a few, and all around where you're patching anyway).

Care for one extra time? :-)

Not really. That should be a different patch IMO.

---
~Randy

#8 lore raw
In reply to Randy Dunlap
Quoted 27 lines · Randy Dunlap
Quoted 4 lines · On Sun, 7 Jan 2007 20:12:42 +0100 Segher Boessenkool wrote:

There's an extra tab in that last line. Could you also please fix the indenting (use a tab, not spaces) -- I know it was there originally, but since there are only a few lines in that file like that... :-)

how's this one?
---
From: Randy Dunlap <[email protected]>

setcc() in math-emu is written as a gcc extension statement expression macro that returns a value. However, it's not used that way and it's not needed like that, so just make it a do-while non-extension macro so that we don't use an extension when it's not needed.

---
 arch/i386/math-emu/status_w.h        |    5 +++--
---
 arch/i386/math-emu/status_w.h |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

arch/i386/math-emu/status_w.h line 54

Quoted 10 lines
arch/i386/math-emu/status_w.h +4 -3
@@ -48,9 +48,10 @@
 
 #define status_word() \
   ((partial_status & ~SW_Top & 0xffff) | ((top << SW_Top_Shift) & SW_Top))
-#define setcc(cc) ({ \
-  partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
-  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
+#define setcc(cc) do { \
+	partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
+	partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); \
+} while (0)

Is there any reason you this shouldn't be an inline function?

#9 lore raw
Quoted 29 lines · On Sun, 7 Jan 2007 19:58:45 +0000 Christoph Hellwig wrote:
Quoted 28 lines · Randy Dunlap
Quoted 4 lines · On Sun, 7 Jan 2007 20:12:42 +0100 Segher Boessenkool wrote:

There's an extra tab in that last line. Could you also please fix the indenting (use a tab, not spaces) -- I know it was there originally, but since there are only a few lines in that file like that... :-)

how's this one?
---
From: Randy Dunlap <[email protected]>

setcc() in math-emu is written as a gcc extension statement expression macro that returns a value. However, it's not used that way and it's not needed like that, so just make it a do-while non-extension macro so that we don't use an extension when it's not needed.

---
 arch/i386/math-emu/status_w.h        |    5 +++--
---
 arch/i386/math-emu/status_w.h |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/i386/math-emu/status_w.h +0 -0
@@ -48,9 +48,10 @@
 
Quoted 11 lines

arch/i386/math-emu/status_w.h line 54

Quoted 9 lines
arch/i386/math-emu/status_w.h +4 -3
 #define status_word() \
   ((partial_status & ~SW_Top & 0xffff) | ((top << SW_Top_Shift) & SW_Top))
-#define setcc(cc) ({ \
-  partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
-  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
+#define setcc(cc) do { \
+	partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
+	partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); \
+} while (0)

Is there any reason you this shouldn't be an inline function?

That would be OK in theory, so I just tried it.

I don't get the same object files produced with an inline function (for arch/i386/math-emu/fpu_etc.o), so I don't feel that it's quite as safe without digging deeping into the .o file and its changes.

The 3 other .o files that use setcc() were the same when using the inline patch version.

---
From: Randy Dunlap <[email protected]>

setcc() in math-emu is written as a gcc extension statement expression macro that returns a value. However, it's not used that way and it's not needed like that, so just make it a do-while non-extension macro so that we don't use an extension when it's not needed.

---
 arch/i386/math-emu/status_w.h        |    5 +++--
---
 arch/i386/math-emu/status_w.h |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/i386/math-emu/status_w.h +5 -3
@@ -48,9 +48,11 @@
 
 #define status_word() \
   ((partial_status & ~SW_Top & 0xffff) | ((top << SW_Top_Shift) & SW_Top))
-#define setcc(cc) ({ \
-  partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3); \
-  partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3); })
+static inline void setcc(int cc)
+{
+	partial_status &= ~(SW_C0|SW_C1|SW_C2|SW_C3);
+	partial_status |= (cc) & (SW_C0|SW_C1|SW_C2|SW_C3);
+}
 
 #ifdef PECULIAR_486
    /* Default, this conveys no information, but an 80486 does it. */