[m-dev.] diff: work around gcc global register problem

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 15 14:26:02 AEDT 2000


Estimated hours taken: 1

library/string.m:
	Work around a GNU C problem in grade asm_fast.gc.tr.debug,
	where gcc failed to compile the recently-added `set_char' procedures,
	aborting with the following message:

		string.c: In function `string_module70':
		string.c:46208: fixed or forbidden register 3 (bx) was
			spilled for class GENERAL_REGS.
		This may be due to a compiler bug or to impossible asm
		statements or clauses.

	The work-around was to move the code which actually sets the
	character into a separate C function.

Workspace: /home/pgrad/fjh/ws/hg
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.136
diff -u -d -r1.136 string.m
--- library/string.m	2000/11/13 08:06:16	1.136
+++ library/string.m	2000/11/15 03:19:06
@@ -1525,6 +1525,23 @@
 
 /*-----------------------------------------------------------------------*/
 
+:- pragma c_header_code("
+#ifdef USE_GCC_GLOBAL_REGISTERS
+	/*
+	** GNU C version egcs-1.1.2 on x86 crashes with `fixed or forbidden
+	** register spilled' in grade asm_fast.gc.tr.debug
+	** if we write this inline.
+	*/
+	static void MR_set_char(String str, MR_Integer ind, MR_Char ch)
+	{
+		str[ind] = ch;
+	}
+#else
+	#define MR_set_char(str, ind, ch) \\
+		((str)[ind] = (ch))
+#endif
+").
+
 /*
 :- pred string__set_char(char, int, string, string).
 :- mode string__set_char(in, in, in, out) is semidet.
@@ -1538,7 +1555,7 @@
 		SUCCESS_INDICATOR = TRUE;
 		MR_allocate_aligned_string_msg(Str, len, MR_PROC_LABEL);
 		strcpy(Str, Str0);
-		Str[Index] = Ch;
+		MR_set_char(Str, Index, Ch);
 	}
 ").
 
@@ -1553,7 +1570,7 @@
 	} else {
 		SUCCESS_INDICATOR = TRUE;
 		Str = Str0;
-		Str[Index] = Ch;
+		MR_set_char(Str, Index, Ch);
 	}
 ").
 
@@ -1568,7 +1585,7 @@
 	size_t len = strlen(Str0);
 	MR_allocate_aligned_string_msg(Str, len, MR_PROC_LABEL);
 	strcpy(Str, Str0);
-	Str[Index] = Ch;
+	MR_set_char(Str, Index, Ch);
 ").
 
 /*
@@ -1578,7 +1595,7 @@
 :- pragma c_code(string__unsafe_set_char(Ch::in, Index::in, Str0::di, Str::uo),
 		[will_not_call_mercury, thread_safe], "
 	Str = Str0;
-	Str[Index] = Ch;
+	MR_set_char(Str, Index, Ch);
 ").
 
 /*-----------------------------------------------------------------------*/

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list