Files
mercury/runtime/mercury.c
Peter Wang 573e6f2f00 Support unboxed float fields in high-level C grades.
Branches: main

Support unboxed float fields in high-level C grades.

When the representation of `float' is no wider than a machine word, d.u.
functor arguments of type `float' (or equivalent) will be stored directly
within cells constructed for that functor, instead of a pointer to the box
containing the value.  This was already so for low-level C grades.

compiler/mlds.m:
	Add an option to mlds_type, equivalent to
	`mlds_array_type(mlds_generic_type)' except that some elements are
	known to be floats.

	Update some comments.

compiler/ml_global_data.m:
	Remember the `--unboxed-float' option in `ml_global_data'.

	Special case generic arrays in `ml_gen_static_scalar_const_addr' and
	`ml_gen_static_scalar_const_value'.  Float literals cannot be used to
	initialize an element of a generic array in C.  If any appear, replace
	the generic array type by an instance of
	`mlds_mostly_generic_array_type' with float fields in the positions
	which have float initializers.

compiler/ml_code_util.m:
	Make `ml_must_box_field_type' and `ml_gen_box_const_rval' depend on the
	`--unboxed-float' option.

	Delete some now-misleading comments.

	Delete an unused predicate.

compiler/mlds_to_c.m:
	Update code that writes out scalar static data to handle
	`mlds_mostly_generic_array_type'.

	In one case, for `--high-level-data' only, output float constants by
	their integer representation, so that they may be cast to pointer
	types.

compiler/ml_unify_gen.m:
	Rename some predicates for clarity.

compiler/ml_accurate_gc.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Conform to changes.

library/float.m:
	Add hidden functions to return the integer representation of the bit
	layout of floating point values.

library/exception.m:
	Delete mention of MR_AVOID_MACROS.

runtime/mercury.c:
runtime/mercury.h:
	Make MR_box_float/MR_unbox_float act like "casts" when MR_BOXED_FLOAT
	is undefined, and only define them in high-level grades.  I think they
	should be replaced by MR_float_to_word/MR_word_to_float (which have
	less confusing names when there is no boxing) but that would require
	some header file reshuffling which I don't want to undertake yet.

	Delete references to MR_AVOID_MACROS.  Apparently it existed to support
	the defunct gcc back-end but I cannot see it ever being defined.

runtime/mercury_conf_param.h:
	MR_HIGHLEVEL_CODE no longer implies MR_BOXED_FLOAT.

	Delete mention of MR_AVOID_MACROS.

runtime/mercury_float.h:
	Fix a comment.

tests/hard_coded/Mmakefile:
tests/hard_coded/float_ground_term.exp:
tests/hard_coded/float_ground_term.m:
	Add a test case.
2011-08-22 07:56:10 +00:00

108 lines
2.5 KiB
C

/*
** vim: ts=4 sw=4 expandtab
*/
/*
** Copyright (C) 1999-2003, 2006, 2011 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
/*
** mercury.c - This file defines the builtin functions, constants, etc. that
** are used when generating high-level C code.
** (For the low-level C code, see mercury_imp.h.)
*/
#ifndef MR_HIGHLEVEL_CODE
#include "mercury_imp.h"
#endif
#include "mercury.h"
#include "mercury_type_info.h" /* for MR_TYPECTOR_REP* */
#include "mercury_type_desc.h" /* for MR_TypeCtorDesc */
#include "mercury_misc.h" /* for MR_fatal_error() */
#include "mercury_heap.h" /* for MR_create[1-3]() prototypes */
#include "mercury_builtin_types.h"
#ifdef MR_HIGHLEVEL_CODE
/*---------------------------------------------------------------------------*/
/*
** Variable definitions
*/
#ifdef MR_NATIVE_GC
void *mercury__private_builtin__stack_chain;
#endif
MR_Word mercury__private_builtin__dummy_var;
/*---------------------------------------------------------------------------*/
/*
** Provide definitions for functions declared `extern inline'.
** Note that this code duplicates the code in mercury.h/mercury_heap.h.
*/
MR_OUTLINE_DEFN(
MR_Word
MR_create1_func(MR_Word w1)
,
{
MR_Word *p = (MR_Word *) MR_new_object(MR_Word, 1 * sizeof(MR_Word),
NULL, "create1");
p[0] = w1;
return (MR_Word) p;
}
)
MR_OUTLINE_DEFN(
MR_Word
MR_create2_func(MR_Word w1, MR_Word w2)
,
{
MR_Word *p = (MR_Word *) MR_new_object(MR_Word, 2 * sizeof(MR_Word),
NULL, "create2");
p[0] = w1;
p[1] = w2;
return (MR_Word) p;
}
)
MR_OUTLINE_DEFN(
MR_Word
MR_create3_func(MR_Word w1, MR_Word w2, MR_Word w3)
,
{
MR_Word *p = (MR_Word *) MR_new_object(MR_Word, 3 * sizeof(MR_Word),
NULL, "create3");
p[0] = w1;
p[1] = w2;
p[2] = w3;
return (MR_Word) p;
}
)
#if defined(MR_BOXED_FLOAT) && !defined(MR_GNUC)
MR_OUTLINE_DEFN(
MR_Box
MR_box_float(MR_Float f)
,
{
MR_Float *ptr;
MR_make_hp_float_aligned();
ptr = (MR_Float *) MR_new_object_atomic(MR_Float, sizeof(MR_Float),
MR_ALLOC_SITE_FLOAT, NULL);
*ptr = f;
return (MR_Box) ptr;
}
)
#endif /* MR_BOXED_FLOAT && !MR_GNUC */
#endif /* ! MR_HIGHLEVEL_CODE */
/*---------------------------------------------------------------------------*/