mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-27 23:34:52 +00:00
Branches: main Store double-precision `float' constructor arguments in unboxed form, in high-level C grades on 32-bit platforms, i.e. `float' (and equivalent) arguments may occupy two machine words. As the C code generated by the MLDS back-end makes use of MR_Float variables and parameters, float (un)boxing may be reduced substantially in many programs. compiler/prog_data.m: Add `double_word' as a new option for constructor argument widths, only used for float arguments as yet. compiler/make_hlds_passes.m: Set constructor arguments to have `double_word' width if required, and possible. compiler/type_util.m: Add helper predicate. compiler/builtin_ops.m: compiler/c_util.m: compiler/llds.m: Add two new binary operators used by the MLDS back-end. compiler/arg_pack.m: Handle `double_word' arguments. compiler/ml_code_util.m: Deciding whether or not a float constructor argument requires boxing now depends on the width of the field. compiler/ml_global_data.m: When a float constant appears as an initialiser of a generic array element, it is now always unboxed, irrespective of --unboxed-float. compiler/ml_type_gen.m: Take double-word arguments into account when generating structure fields. compiler/ml_unify_gen.m: Handle double-word float constructor arguments in (de)constructions. In some cases we break a float argument into its two words, so generating two assignments statements or two separate rvals. Take double-word arguments into account when calculating field offsets. compiler/mlds_to_c.m: The new binary operators require no changes here. As a special case, write `MR_float_from_dword_ptr(&X)' instead of `MR_float_from_dword(X, Y)' when X, Y are consecutive words within a field. The definition of `MR_float_from_dword_ptr' is more straightforward, and gcc produces better code than if we use the more general `MR_float_from_dword'. compiler/rtti_out.m: For double-word arguments, generate MR_DuArgLocn structures with MR_arg_bits set to -1. compiler/rtti_to_mlds.m: Handle double-word arguments in field offset calculation. compiler/unify_gen.m: Partially handle double_word arguments in LLDS back-end. compiler/handle_options.m: Set --unboxed-float when targetting Java, C# and Erlang. compiler/structure_reuse.direct.choose_reuse.m: Rename a predicate. compiler/bytecode.m: compiler/equiv_type.m: compiler/equiv_type_hlds.m: compiler/llds_to_x86_64.m: compiler/mlds_to_gcc.m: compiler/mlds_to_il.m: compiler/opt_debug.m: Conform to changes. library/construct.m: library/store.m: Handle double-word constructor arguments. runtime/mercury_conf.h.in: Clarify what `MR_BOXED_FLOAT' now means. runtime/mercury_float.h: Add helper macros for converting between doubles and word/dwords. runtime/mercury_deconstruct.c: runtime/mercury_deconstruct.h: Add a macro `MR_arg_value' and a helper function to extract a constructor argument value. This replaces `MR_unpack_arg'. runtime/mercury_type_info.h: Remove `MR_unpack_arg'. Document that MR_DuArgLocn.MR_arg_bits may be -1. runtime/mercury_deconstruct_macros.h: runtime/mercury_deep_copy_body.h: runtime/mercury_ml_arg_body.h: runtime/mercury_table_type_body.h: runtime/mercury_tabling.c: runtime/mercury_type_info.c: Handle double-word constructor arguments. tests/hard_coded/Mercury.options: tests/hard_coded/Mmakefile: tests/hard_coded/lco_double.exp: tests/hard_coded/lco_double.m: tests/hard_coded/pack_args_float.exp: tests/hard_coded/pack_args_float.m: Add test cases. trace/mercury_trace_vars.c: Conform to changes.
78 lines
2.3 KiB
Mathematica
78 lines
2.3 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
|
|
:- module pack_args_float.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- type animal
|
|
---> ant % 0
|
|
; bat % 1
|
|
; cat % 2
|
|
; dog % 3
|
|
; eel % 4
|
|
; fox % 5
|
|
; gnu % 6
|
|
; hog % 7
|
|
; ibis % 8
|
|
; jay % 9
|
|
; kea % 10
|
|
; lark % 11
|
|
; moa % 12
|
|
; newt % 13
|
|
; owl % 14
|
|
; pug. % 15
|
|
|
|
:- type struct
|
|
---> struct(
|
|
animal, animal, % word 0 | word 0
|
|
float, % word 1 | word 1+2
|
|
float, % word 2 | word 3+4
|
|
animal, animal, animal, animal % word 3 | word 5
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
Static = struct(ant, bat, 1.1, 2.2, cat, dog, eel, fox),
|
|
write_struct(Static, !IO),
|
|
io.nl(!IO),
|
|
|
|
Dynamic = struct(ani(pug), ani(owl), 101.101, 202.202,
|
|
ani(newt), ani(moa), lark, jay),
|
|
write_struct(Dynamic, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- func ani(animal) = animal.
|
|
:- pragma no_inline(ani/1).
|
|
|
|
ani(X) = X.
|
|
|
|
:- pred write_struct(struct::in, io::di, io::uo) is det.
|
|
:- pragma no_inline(write_struct/3).
|
|
|
|
write_struct(struct(A, B, X, Y, C, D, E, F), !IO) :-
|
|
write_animal(A, !IO), write_string(", ", !IO),
|
|
write_animal(B, !IO), write_string(", ", !IO),
|
|
write_float(X, !IO), write_string(", ", !IO),
|
|
write_float(Y, !IO), write_string(", ", !IO),
|
|
write_animal(C, !IO), write_string(", ", !IO),
|
|
write_animal(D, !IO), write_string(", ", !IO),
|
|
write_animal(E, !IO), write_string(", ", !IO),
|
|
write_animal(F, !IO).
|
|
|
|
:- pred write_animal(animal::in, io::di, io::uo) is det.
|
|
|
|
write_animal(Animal, !IO) :-
|
|
write(Animal, !IO).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sts=4 sw=4 et
|