[m-rev.] for review: single precision floats

Peter Wang wangp at students.csse.unimelb.edu.au
Mon Feb 5 14:42:22 AEDT 2007


Estimated hours taken: 4
Branches: main

Make it easy for the user to select single-precision floats instead of the
default double-precision floats.  This can be done by using the `.spf' grade
component, or the option `--single-prec-float'.

NEWS:
	Mention the changes.

compiler/options.m:
	Add the `--single-prec-float' option (also `--single-precision-float').

	Comment out the documentation for `--unboxed-float'.  It shouldn't be
	necessary for users to use it directly any more.

compiler/handle_options.m:
	Handle the `.spf' grade component.

	Make `--single-prec-float' imply `--unboxed-float'.

compiler/compile_target_code.m:
	Pass `-DMR_USE_SINGLE_PREC_FLOAT' to the C compiler when
	single-precision floats are enabled.

doc/reference_manual.texi:
doc/user_guide.texi:
	Document `.spf' and `--single-prec-float'.

runtime/mercury_conf_param.h:
	Document `MR_USE_SINGLE_PREC_FLOAT' differently now that it is
	documented in the mmc help and manual.

runtime/mercury_float.h:
	Undefine `MR_BOXED_FLOAT' if `MR_USE_SINGLE_PREC_FLOAT' is defined.

runtime/mercury_grade.h:
	Update the macros that define the MR_GRADE macro to include "_spf"
	if `MR_USE_SINGLE_PREC_FLOAT' is defined.

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
	Update these scripts to support the `.spf' grade component and
	`--single-prec-float' command-line option.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.441
diff -u -r1.441 NEWS
--- NEWS	2 Feb 2007 05:39:26 -0000	1.441
+++ NEWS	5 Feb 2007 01:06:39 -0000
@@ -78,6 +78,9 @@
 * The compiler now issues a warning when an inst declaration is not
   consistent with any of the types in scope.
 
+* We have made it easier to use single-precision floats, which do not need
+  to be boxed on 32-bit machines.
+
 Changes to the Mercury deep profiler:
 
 * The deep profiler now supports measuring a proxy for time: a counter that
@@ -154,6 +157,10 @@
   This makes it easier to diagnose mode errors caused by insts that are not
   consistent with the type they are intended to be consistent with.
 
+* Single-precision floats can now be selected for the C backends by using the
+  `.spf' grade component, or passing the `--single-prec-float' option to the
+  compiler.
+
 Changes to the Mercury standard library:
 
 * The predicates io.seek_binary/5 and io.binary_stream_offset/4 have been
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.103
diff -u -r1.103 compile_target_code.m
--- compiler/compile_target_code.m	8 Jan 2007 03:03:08 -0000	1.103
+++ compiler/compile_target_code.m	5 Feb 2007 00:50:38 -0000
@@ -671,6 +671,14 @@
         MinimalModelDebug = no,
         MinimalModelOpt = MinimalModelBaseOpt
     ),
+    globals.io_lookup_bool_option(single_prec_float, SinglePrecFloat, !IO),
+    (
+        SinglePrecFloat = yes,
+        SinglePrecFloatOpt = "-DMR_USE_SINGLE_PREC_FLOAT "
+    ;
+        SinglePrecFloat = no,
+        SinglePrecFloatOpt = ""
+    ),
     globals.io_lookup_bool_option(type_layout, TypeLayoutOption, !IO),
     (
         TypeLayoutOption = no,
@@ -757,6 +765,7 @@
         UseTrailOpt, 
         ReserveTagOpt, 
         MinimalModelOpt, 
+        SinglePrecFloatOpt,
         TypeLayoutOpt,
         InlineAllocOpt, " ", 
         AnsiOpt, " ", 
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.294
diff -u -r1.294 handle_options.m
--- compiler/handle_options.m	29 Jan 2007 04:31:42 -0000	1.294
+++ compiler/handle_options.m	5 Feb 2007 00:51:14 -0000
@@ -1010,6 +1010,10 @@
             true
         ),
 
+        % We assume that single-precision floats do not need to be boxed.
+        option_implies(single_prec_float, unboxed_float, bool(yes),
+            !Globals),
+
         option_implies(highlevel_code, mutable_always_boxed, bool(no),
             !Globals),
 
@@ -2089,6 +2093,9 @@
     ;       comp_trail          % whether or not to use trailing
     ;       comp_tag            % whether or not to reserve a tag
     ;       comp_minimal_model  % whether we set up for minimal model tabling
+    ;       comp_single_prec_float
+                                % whether or not to use single precision
+                                % floating point values
     ;       comp_pic            % Do we need to reserve a register for
                                 % PIC (position independent code)?
     ;       comp_lowlevel       % what to do to target code
@@ -2397,6 +2404,10 @@
     use_minimal_model_own_stacks - bool(yes),
     minimal_model_debug - bool(yes)], no, yes).
 
+grade_component_table("spf", comp_single_prec_float, 
+    [single_prec_float - bool(yes),
+    unboxed_float - bool(yes)], no, yes).
+
     % Pic reg components.
 grade_component_table("picreg", comp_pic, [pic_reg - bool(yes)], no, yes).
 
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.546
diff -u -r1.546 options.m
--- compiler/options.m	19 Jan 2007 07:04:25 -0000	1.546
+++ compiler/options.m	5 Feb 2007 02:27:37 -0000
@@ -298,6 +298,7 @@
     ;       use_minimal_model_stack_copy
     ;       use_minimal_model_own_stacks
     ;       minimal_model_debug
+    ;       single_prec_float
     ;       type_layout
     ;       maybe_thread_safe_opt
     ;       extend_stacks_when_needed
@@ -1063,6 +1064,7 @@
     use_minimal_model_stack_copy        -   bool(no),
     use_minimal_model_own_stacks        -   bool(no),
     minimal_model_debug                 -   bool(no),
+    single_prec_float                   -   bool(no),
     type_layout                         -   bool(yes),
 
     % Data representation compilation model options
@@ -1816,6 +1818,8 @@
 long_option("use-minimal-model-stack_copy", use_minimal_model_stack_copy).
 long_option("use-minimal-model-own-stacks", use_minimal_model_own_stacks).
 long_option("minimal-model-debug",  minimal_model_debug).
+long_option("single-prec-float",    single_prec_float).
+long_option("single-precision-float",   single_prec_float).
 long_option("pic",                  pic).
 long_option("pic-reg",              pic_reg).
 long_option("tags",                 tags).
@@ -3473,7 +3477,7 @@
 % it has been superceded by the il grade.
         "\tor one of those with one or more of the grade modifiers",
         "\t`.gc', `.mps', `.prof', `.memprof', `.profdeep', `.tr',",
-        "\t`rt', `.debug', `.par' and/or `.pic_reg' appended.",
+        "\t`.rt', `.spf', `.debug', `.par' and/or `.pic_reg' appended.",
         "\tDepending on your particular installation, only a subset",
         "\tof these possible grades will have been installed.",
         "\tAttempting to use a grade which has not been installed",
@@ -3627,6 +3631,10 @@
         "\t`thread_safe' attribute.  `no' means that the foreign",
         "\tprocedure is treated as though it has a `not_thread_safe'",
         "\tattribute.  The default is no.",
+        "--single-prec-float\t\t(grade modifier: `.spf')",
+        "\tUse single precision floats so that, on 32-bit machines,",
+        "\tfloating point values don't need to be boxed.  Double",
+        "\tprecision floats are used by default.",
         "--extend-stacks-when-needed",
         "\tSpecify that code that increments a stack pointer must",
         "\textend the stack when this is needed.",
@@ -3781,7 +3789,7 @@
         "\tcode. This tag is intended to be used to give an explicit",
         "\trepresentation to free variables.",
         "\tThis is necessary for a seamless Herbrand constraint solver -",
-        "\tfor use with HAL.",
+        "\tfor use with HAL."
 
         % The --conf-low-tag-bits option is reserved for use
         % by the `mmc' script; it is deliberately not documented.
@@ -3792,14 +3800,15 @@
         % The --bytes-per-word option is intended for use
         % by the `mmc' script; it is deliberately not documented.
 
-        "--unboxed-float",
-        "(This option is not for general use.)",
-        "\tDon't box floating point numbers.",
-        "\tThis assumes that a Mercury float will fit in a word.",
-        "\tThe C code needs to be compiled with `-UBOXED_FLOAT'.",
-        "\tIt may also need to be compiled with",
-        "\t`-DUSE_SINGLE_PREC_FLOAT', if double precision",
-        "\tfloats don't fit into a word."
+        % This is a developer only option.
+%       "--unboxed-float",
+%       "(This option is not for general use.)",
+%       "\tDon't box floating point numbers.",
+%       "\tThis assumes that a Mercury float will fit in a word.",
+%       "\tThe C code needs to be compiled with `-UBOXED_FLOAT'.",
+%       "\tIt may also need to be compiled with",
+%       "\t`-DUSE_SINGLE_PREC_FLOAT', if double precision",
+%       "\tfloats don't fit into a word."
 
         % This is a developer only option.
 %       "--no-unboxed-enums",
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.379
diff -u -r1.379 reference_manual.texi
--- doc/reference_manual.texi	15 Jan 2007 02:23:58 -0000	1.379
+++ doc/reference_manual.texi	5 Feb 2007 00:52:45 -0000
@@ -6543,7 +6543,7 @@
 In the current implementation, @samp{MR_Integer} is a typedef for an
 integral type whose size is the same size as a pointer; @samp{MR_Float} is
 a typedef for @samp{double} (unless the program and the Mercury library
-was compiled with @samp{-DUSE_SINGLE_PREC_FLOAT}, in which case it is
+was compiled with @samp{--single-prec-float}, in which case it is
 a typedef for @samp{float}); @samp{MR_Char} is a typedef for @samp{char};
 and @samp{MR_String} is a typedef for @samp{MR_Char *}.
 
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.509
diff -u -r1.509 user_guide.texi
--- doc/user_guide.texi	19 Jan 2007 07:05:04 -0000	1.509
+++ doc/user_guide.texi	5 Feb 2007 00:58:55 -0000
@@ -6835,6 +6835,7 @@
 @cindex .mps (grade modifier)
 @cindex .agc (grade modifier)
 @cindex .rt (grade modifier)
+ at cindex .spf (grade modifier)
 @cindex .debug (grade modifier)
 @cindex .decldebug (grade modifier)
 @cindex .par (grade modifier)
@@ -6845,6 +6846,7 @@
 @cindex gc (grade modifier)
 @cindex agc (grade modifier)
 @cindex rt (grade modifier)
+ at cindex spf (grade modifier)
 @cindex debug (grade modifier)
 @cindex decldebug (grade modifier)
 @cindex par (grade modifier)
@@ -6869,6 +6871,9 @@
 @item Whether or not to reserve a tag in the data representation of the generated code:
 @samp{rt} (the default is no reserved tag)
 
+ at item Whether to use single-precision representation of floating point values:
+ at samp{spf} (the default is to use double-precision floats)
+
 @item What debugging features to enable:
 @samp{debug} and @samp{decldebug} (the default is no debugging features).
 
@@ -6987,6 +6992,9 @@
 @item @samp{.rt}
 @code{--reserve-tag}.
 
+ at item @samp{.spf}
+ at code{--single-prec-float}
+
 @item @samp{.debug}
 @code{--debug}.
 
@@ -7265,6 +7273,15 @@
 procedure is treated as though it has a @samp{not_thread_safe}
 attribute.  The default is @samp{no}.
 
+ at sp 1
+ at item @code{--single-prec-float} (grades: any grade containing @samp{.spf})
+ at findex --single-prec-float
+ at cindex Data representation
+Use single precision floats so that, on 32-bit machines
+floating point values don't need to be boxed.  Double
+precision floats are used by default.
+This option is not yet supported for the IL or Java back-ends.
+
 @end table
 
 @node Developer compilation model options
Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.93
diff -u -r1.93 mercury_conf_param.h
--- runtime/mercury_conf_param.h	3 Jan 2007 05:17:15 -0000	1.93
+++ runtime/mercury_conf_param.h	5 Feb 2007 00:48:27 -0000
@@ -56,6 +56,7 @@
 ** MR_USE_MINIMAL_MODEL_STACK_COPY
 ** MR_USE_MINIMAL_MODEL_OWN_STACKS
 ** MR_MINIMAL_MODEL_DEBUG
+** MR_USE_SINGLE_PREC_FLOAT
 ** MR_EXTEND_STACKS_WHEN_NEEDED
 ** MR_STACK_SEGMENTS
 ** MR_INLINE_ALLOC
@@ -77,6 +78,7 @@
 **		--reserve-tag
 **		--use-minimal-model
 **		--minimal-model-debug
+**		--single-prec-float
 **		--extend-stacks-when-needed
 **		--stack-segments
 **		--inline-alloc
@@ -89,10 +91,6 @@
 **	The generated object code must be position independent.
 **	See runtime/mercury_goto.h.
 **
-** MR_USE_SINGLE_PREC_FLOAT:
-**	Use C's `float' rather than C's `double' for the
-**	Mercury floating point type (`MR_Float').
-**
 ** MR_USE_REGPARM:
 **	For the MLDS back-end (i.e. MR_HIGHLEVEL_CODE),
 **	on x86, use a different (more efficient) calling convention.
Index: runtime/mercury_float.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_float.h,v
retrieving revision 1.18
diff -u -r1.18 mercury_float.h
--- runtime/mercury_float.h	29 Nov 2002 16:13:01 -0000	1.18
+++ runtime/mercury_float.h	5 Feb 2007 00:48:27 -0000
@@ -17,6 +17,8 @@
   typedef float MR_Float;
   #define MR_FLT_MIN_PRECISION	7
   #define MR_FLT_FMT		"%f"
+  /* We assume that sizeof(float) <= sizeof(MR_Word). */
+  #undef MR_BOXED_FLOAT
 #else
   typedef double MR_Float;
   #define MR_FLT_MIN_PRECISION	15
Index: runtime/mercury_grade.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_grade.h,v
retrieving revision 1.69
diff -u -r1.69 mercury_grade.h
--- runtime/mercury_grade.h	17 Nov 2006 05:23:26 -0000	1.69
+++ runtime/mercury_grade.h	5 Feb 2007 01:12:15 -0000
@@ -321,8 +321,10 @@
 ** Parts 10-11 (i.e. tag bits, and (un)boxed float) are documented as
 ** "not for general use", and can't be set via the `--grade' option;
 ** we therefore can't make them part of the grade option string.
+** Single-precision floats, do form part of the grade option string
+** and implies unboxed floats.
 **
-** Likewise part 12 (i.e. MR_NEW_MERCURYFILE_STRUCT) can't be set
+** Part 12 (i.e. MR_NEW_MERCURYFILE_STRUCT) can't be set
 ** by the `--grade' option; it is intended to be set by the configure script
 ** at configuration time. So we don't include it in the grade option string.
 */
@@ -338,7 +340,12 @@
 #endif
 #define MR_GRADE_OPT_PART_10	MR_GRADE_OPT_PART_9
 
-#ifdef MR_BOXED_FLOAT
+#if defined(MR_USE_SINGLE_PREC_FLOAT)
+  #if defined(MR_BOXED_FLOAT)
+    #error "single-precision floats implies unboxed floats"
+  #endif
+  #define MR_GRADE_PART_11	MR_PASTE2(MR_GRADE_PART_10, _spf)
+#elif defined(MR_BOXED_FLOAT)
   #define MR_GRADE_PART_11	MR_GRADE_PART_10
 #else				/* "ubf" stands for "unboxed float" */
   #define MR_GRADE_PART_11	MR_PASTE2(MR_GRADE_PART_10, _ubf)
Index: scripts/canonical_grade.sh-subr
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/canonical_grade.sh-subr,v
retrieving revision 1.16
diff -u -r1.16 canonical_grade.sh-subr
--- scripts/canonical_grade.sh-subr	1 Nov 2006 02:31:17 -0000	1.16
+++ scripts/canonical_grade.sh-subr	5 Feb 2007 00:48:27 -0000
@@ -134,6 +134,11 @@
 	*)	;;
 esac
 
+case $single_prec_float in
+	true)		GRADE="$GRADE.spf" ;;
+	false)		;;
+esac
+
 # We ignore the value of $picreg in computing the name of the grade
 # that we will use as a directory name in the Mercury linker.
 # case $picreg in
Index: scripts/init_grade_options.sh-subr
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/init_grade_options.sh-subr,v
retrieving revision 1.27
diff -u -r1.27 init_grade_options.sh-subr
--- scripts/init_grade_options.sh-subr	1 Nov 2006 02:31:17 -0000	1.27
+++ scripts/init_grade_options.sh-subr	5 Feb 2007 00:50:01 -0000
@@ -43,6 +43,7 @@
 	--use-minimal-model-stack-copy
 	--use-minimal-model-own-stacks
 	--minimal-model-debug
+	--single-prec-float
 	--pic-reg
 	--no-stack-trace
 	--debug
@@ -78,6 +79,7 @@
 use_minimal_model_stack_copy=false
 use_minimal_model_own_stacks=false
 minimal_model_debug=false
+single_prec_float=false
 pic_reg=false
 debug=false
 decl_debug=false
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.118
diff -u -r1.118 mgnuc.in
--- scripts/mgnuc.in	1 Nov 2006 02:31:18 -0000	1.118
+++ scripts/mgnuc.in	5 Feb 2007 00:50:05 -0000
@@ -374,6 +374,11 @@
     *)              MINIMAL_MODEL_OPTS="" ;;
 esac
 
+case $single_prec_float in
+    true)           SINGLE_PREC_FLOAT_OPTS="-DMR_USE_SINGLE_PREC_FLOAT" ;;
+    false)          SINGLE_PREC_FLOAT_OPTS="" ;;
+esac
+
 case $pic_reg in
     true)           PICREG_OPTS="-DMR_PIC_REG" ;;
     false)          PICREG_OPTS="" ;;
@@ -601,6 +606,7 @@
     $RECORD_TERM_SIZE_OPTS\
     $RESERVE_TAG_OPTS\
     $MINIMAL_MODEL_OPTS\
+    $SINGLE_PREC_FLOAT_OPTS\
     $SPLIT_OPTS\
     $THREAD_OPTS\
     $PICREG_OPTS\
Index: scripts/parse_grade_options.sh-subr
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/parse_grade_options.sh-subr,v
retrieving revision 1.33
diff -u -r1.33 parse_grade_options.sh-subr
--- scripts/parse_grade_options.sh-subr	1 Nov 2006 02:31:18 -0000	1.33
+++ scripts/parse_grade_options.sh-subr	5 Feb 2007 00:49:58 -0000
@@ -165,6 +165,11 @@
     --no-minimal-model-debug)
         minimal_model_debug=false ;;
 
+    --single-prec-float)
+        single_prec_float=true ;;
+    --no-single-prec-float)
+        single_prec_float=false ;;
+
     --pic-reg)
         pic_reg=true ;;
     --no-pic-reg)
@@ -225,6 +230,7 @@
         use_minimal_model_stack_copy=false
         use_minimal_model_own_stacks=false
         minimal_model_debug=false
+        single_prec_float=false
         pic_reg=false
         debug=false
         decl_debug=false
@@ -455,6 +461,10 @@
                     minimal_model_debug=true
                     ;;
 
+                spf)
+                    single_prec_float=true
+                    ;;
+
                 picreg)
                     pic_reg=true
                     ;;
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list