diff options
255 files changed, 6925 insertions, 3576 deletions
diff --git a/ChangeLog.MELT b/ChangeLog.MELT index 5d2b0800b3e..38994354f73 100644 --- a/ChangeLog.MELT +++ b/ChangeLog.MELT @@ -1,4 +1,7 @@ +2009-09-18 Basile Starynkevitch <basile@starynkevitch.net> + MELT branch merged with trunk rev 151837 + 2009-09-16 Basile Starynkevitch <basile@starynkevitch.net> MELT branch merged with trunk rev 151762 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8d6ae7df4d1..cc4e9dc3e85 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,156 @@ +2009-09-18 Jakub Jelinek <jakub@redhat.com> + + * stmt.c (expand_asm_operands): Set REG_ATTRS on the temporary from + output decl. + +2009-09-17 Michael Haubenwallner <michael.haubenwallner@salomon.at> + + PR target/40913 + * config/pa/t-hpux-shlib: Set soname in libgcc_s.sl. + +2009-09-17 Jakub Jelinek <jakub@redhat.com> + + * c-decl.c (finish_struct): Adjust DECL_SOURCE_LOCATION of + TYPE_STUB_DECL. + +2009-09-17 Alexandre Oliva <aoliva@redhat.com> + + * dwarf2out.c (loc_descriptor): Emit DW_OP_stack_value and + DW_OP_implicit_value even without dwarf_version 4. + +2009-09-17 Jan Hubicka <jh@suse.cz> + + * dwarf2out.c: Include tree-pass.h and gimple.h. + (loc_list_plus_const): New function. + (loc_descriptor_from_tree_1): Rename to ... + (loc_descriptor_from_tree): ... remove original. + (loc_list_from_tree): New function. + (add_AT_location_description): Accept location list. + (tls_mem_loc_descriptor): Update call of loc_descriptor_from_tree. + (concatn_mem_loc_descriptor): Remove. + (mem_loc_descriptor): Handle CONCAT/CONCATN and VAR_LOCATION by + returning NULL. + (secname_for_decl): Move up. + (hidden_reference_p): New function; break out from ... + (loc_by_refernece): ... here; move up. + (dw_loc_list): New function. + (single_element_loc_list): New function. + (single_element_loc_list_p): New function. + (add_loc_descr_to_each): New function. + (add_loc_list): New function. + (loc_descr_from_tree): Make wraper of loc_list_from_tree. + (loc_list_from_tree): Reroganized from loc_descr_from_tree; + add diagnostics why expansion failed. + (add_location_or_const_value_attribute): Support location lists. + (add_bound_info): Likewise. + (descr_info_loc): Update call of loc_descriptor_from_tree. + (gen_variable_die): Work on location lists. + * final.c (pass_final): Add dump file. + * Makefile.in (dwarf2out.o): Add new dependencies. + +2009-09-17 Janis Johnson <janis187@us.ibm.com> + + PR c/41049 + * real.c decimal_from_integer, decimal_integer_string): New. + (real_from_integer): Use them as special case for decimal float. + * config/dfp-bit.c (_si_to_sd, _usi_to_sd): Use default rounding. + (_di_to_sd, _di_to_dd, _di_to_td, _udi_to_sd, _udi_to_dd, _udi_to_td): + Do not append zero after the decimal point in string to convert. + +2009-09-17 Alexander Monakov <amonakov@ispras.ru> + + * graphite-sese-to-poly.c (pdr_add_data_dimensions): Add bounds only + for ARRAY_REFs. Use array_ref_{low,up}_bound to determine bounds. + +2009-09-17 Martin Jambor <mjambor@suse.cz> + + * common.opt (fipa-sra): New switch. + * opts.c (decode_options): Turn flag_ipa_sra on for opt2. + * timevar.def (TV_IPA_SRA): New timevar. + * params.def (ipa-sra-ptr-growth-factor): New parameter. + * doc/invoke.texi: Document -fipa-sra and ipa-sra-ptr-growth-factor. + * tree-sra.c: Include cgraph.c. + (enum sra_mode): Added SRA_MODE_EARLY_IPA. + (struct access): Added fields stmt, grp_maybe_modified, grp_scalar_ptr + and grp_not_necessarilly_dereferenced. + (func_param_count): New variable. + (encountered_apply_args): New variable. + (bb_dereferences): New variable. + (final_bbs): New variable. + (no_accesses_representant): New variable. + (no_accesses_p): New function. + (dump_access): Dump the new fields. + (sra_initialize): Set encountered_apply_args to false. + (get_ssa_base_param): New function. + (mark_parm_dereference): New function. + (create_access): Caring for INIDRECT_REFs and different handling of + varialble length accesses in early IPA SRA. Store the stmt - a new + parameter - to the new access. + (build_access_from_expr_1): New parameter stmt, passed to + create_access. Handle INDIRECT_REFs. + (build_access_from_expr): Pass the current statement to + build_access_from_expr_1. + (disqualify_ops_if_throwing_stmt): Trigger only in intraprocedural + passes. + (build_accesses_from_assign): Pass the current statement to + build_access_from_expr_1. Do not create assign links in IPA-SRA. + (scan_function): Call handle_ssa_defs on phi nodes. Set bits in + final_bbs when necessary. Check for calls to __builtin_apply_args. + Fixup EH info if anythng was changed. + (is_unused_scalar_param): New function. + (ptr_parm_has_direct_uses): New function. + (find_param_candidates): New function. + (mark_maybe_modified): New function. + (analyze_modified_params): New function. + (propagate_dereference_distances): New function. + (dump_dereferences_table): New function. + (analyze_caller_dereference_legality): New function. + (unmodified_by_ref_scalar_representative): New function. + (splice_param_accesses): New function. + (decide_one_param_reduction): New function. + (enum ipa_splicing_result): New type. + (splice_all_param_accesses): New function. + (get_param_index): New function. + (turn_representatives_into_adjustments): New function. + (analyze_all_param_acesses): New function. + (get_replaced_param_substitute): New function. + (get_adjustment_for_base): New function. + (replace_removed_params_ssa_names): New function. + (sra_ipa_reset_debug_stmts): New function. + (sra_ipa_modify_expr): New function. + (sra_ipa_modify_assign): New function. + (convert_callers): New function. + (modify_function): New function. + (ipa_sra_preliminary_function_checks): New function. + (ipa_early_sra): New function. + (ipa_early_sra_gate): New function. + (pass_early_ipa_sra): New variable. + * Makefile.in (tree-sra.o): Add cgraph.h to dependencies. + +2009-09-17 Michael Matz <matz@suse.de> + + PR middle-end/41347 + * tree.c (build_type_attribute_qual_variant): Export. + * tree.h (build_type_attribute_qual_variant): Declare. + * tree-inline.c (remap_type_1): Use it to build variants with + the original qualifiers and attributes. + +2009-09-17 Andreas Krebbel <Andreas.Krebbel@de.ibm.com> + + * cfglayout.c (fixup_reorder_chain): Accept conditional jumps + without a fallthrough edge. + +2009-09-16 DJ Delorie <dj@redhat.com> + + * config/m32c/m32c.c (m32c_emit_epilogue): Check for R8C or M16C + chip and ignore the "fast_interrupt" attribute if so. + +2009-09-16 Richard Henderson <rth@redhat.com> + + PR middle-end/41360 + * cfgbuild.c (find_bb_boundaries): Really re-instate 2009-09-02 + barrier fix. + 2009-09-16 Richard Henderson <rth@redhat.com> PR target/41246 diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP index f0ee07fcea2..94aba7c048f 100644 --- a/gcc/DATESTAMP +++ b/gcc/DATESTAMP @@ -1 +1 @@ -20090916 +20090918 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 7ab783f1dcd..6db8a54ba24 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2776,7 +2776,7 @@ dwarf2out.o : dwarf2out.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ output.h $(DIAGNOSTIC_H) $(REAL_H) hard-reg-set.h $(REGS_H) $(EXPR_H) \ libfuncs.h $(TOPLEV_H) dwarf2out.h reload.h $(GGC_H) $(EXCEPT_H) dwarf2asm.h \ $(TM_P_H) langhooks.h $(HASHTAB_H) gt-dwarf2out.h $(TARGET_H) $(CGRAPH_H) \ - $(MD5_H) $(INPUT_H) $(FUNCTION_H) $(VARRAY_H) + $(MD5_H) $(INPUT_H) $(FUNCTION_H) $(VARRAY_H) $(GIMPLE_H) $(TREE_PASS_H) dwarf2asm.o : dwarf2asm.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(FLAGS_H) $(RTL_H) $(TREE_H) output.h dwarf2asm.h $(TM_P_H) $(GGC_H) \ gt-dwarf2asm.h $(DWARF2_H) $(SPLAY_TREE_H) $(TARGET_H) @@ -2936,8 +2936,9 @@ tree-ssa-ccp.o : tree-ssa-ccp.c $(TREE_FLOW_H) $(CONFIG_H) \ $(TREE_DUMP_H) $(BASIC_BLOCK_H) $(TREE_PASS_H) langhooks.h \ tree-ssa-propagate.h value-prof.h $(FLAGS_H) $(TARGET_H) $(TOPLEV_H) tree-sra.o : tree-sra.c $(CONFIG_H) $(SYSTEM_H) coretypes.h alloc-pool.h \ - $(TM_H) $(TREE_H) $(GIMPLE_H) $(TREE_FLOW_H) $(IPA_PROP_H) $(DIAGNOSTIC_H) \ - statistics.h $(TREE_DUMP_H) $(TIMEVAR_H) $(PARAMS_H) $(TARGET_H) $(FLAGS_H) + $(TM_H) $(TREE_H) $(GIMPLE_H) $(CGRAPH_H) $(TREE_FLOW_H) $(IPA_PROP_H) \ + $(DIAGNOSTIC_H) statistics.h $(TREE_DUMP_H) $(TIMEVAR_H) $(PARAMS_H) \ + $(TARGET_H) $(FLAGS_H) tree-switch-conversion.o : tree-switch-conversion.c $(CONFIG_H) $(SYSTEM_H) \ $(TREE_H) $(TM_P_H) $(TREE_FLOW_H) $(DIAGNOSTIC_H) $(TREE_INLINE_H) \ $(TIMEVAR_H) $(TM_H) coretypes.h $(TREE_DUMP_H) $(GIMPLE_H) \ diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index dae5c00e6a3..1e4d3db4f95 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,71 @@ +2009-09-17 Bob Duff <duff@adacore.com> + + * g-socket.ads: Document the fact that Close_Selector has no effect on + a closed selector. + * g-socket.adb: Raise an exception when a Selector that should be open + is closed. + (Check_Selector): Declare RSig as a constant rather than a renames, + less confusing. + +2009-09-17 Robert Dewar <dewar@adacore.com> + + * exp_ch9.adb, exp_ch5.adb, exp_ch4.adb, prj-conf.adb, prj-env.ads, + prj-ext.adb, prj-ext.ads, prj-pars.adb, prj-part.adb, prj-proc.adb, + prj-tree.ads: Minor reformatting + +2009-09-17 Emmanuel Briot <briot@adacore.com> + + * prj-conf.adb, prj-env.adb, prj-env.ads (Create_Temp_File): Moved to + spec. + (Do_Autoconf): If the object directory does not exists, create auto.cgpr + in a temporary directory instead + +2009-09-17 Bob Duff <duff@adacore.com> + + * a-dynpri.adb (Set_Priority): Don't do anything if the task is already + terminated. + (Get_Priority): Correct message for "terminated" case -- it said "null". + +2009-09-17 Robert Dewar <dewar@adacore.com> + + * exp_ch6.adb: Minor reformatting + +2009-09-17 Emmanuel Briot <briot@adacore.com> + + * gnatcmd.adb, make.adb, prj-part.adb, prj-ext.adb, prj-ext.ads, + switch-m.adb, switch-m.ads, clean.adb, prj-tree.ads + (Project_Node_Tree_Data.Project_Path): New field. + + * prj-conf.adb (Do_Autoconf): Remove "creating auto.cgpr" message + +2009-09-17 Emmanuel Briot <briot@adacore.com> + + * prj-ext.adb, prj-ext.ads, makeutl.adb (Is_External_Assignment): + Remove duplicate code. + (Prj.Ext): Fix memory leak + (Check): Now allow the syntax "-Xfoo=" to set an empty value to the + variable. This was previously allowed in the code in + Is_External_Assignment, and some tests rely on it + +2009-09-17 Bob Duff <duff@adacore.com> + + * gnat_rm.texi, s-oscons-tmplt.c: Minor typo + +2009-09-17 Emmanuel Briot <briot@adacore.com> + + * gnatcmd.adb, prj-proc.adb, make.adb, prj-ext.adb, prj-ext.ads, + makeutl.adb, makeutl.ads, clean.adb, prj-pars.adb, prj-pars.ads, + prj-conf.adb, prj-conf.ads, prj-tree.adb, prj-tree.ads, prj-proc.ads, + prj-nmsc.ads (Add, Value_Of, Reset): new parameter Tree. + Scenario variables are now specific to each project tree loaded in + memory. + Code clean ups. + +2009-09-17 Javier Miranda <miranda@adacore.com> + + * exp_disp.adb (Make_DT): Remove wrong line of code that was + undocumented and probably added by mistake. + 2009-09-16 Eric Botcazou <ebotcazou@adacore.com> * gcc-interface/trans.c (Attribute_to_gnu) <Attr_Size>: Strip diff --git a/gcc/ada/a-dynpri.adb b/gcc/ada/a-dynpri.adb index 33122176f0a..9116a573948 100644 --- a/gcc/ada/a-dynpri.adb +++ b/gcc/ada/a-dynpri.adb @@ -67,7 +67,7 @@ package body Ada.Dynamic_Priorities is end if; if Task_Identification.Is_Terminated (T) then - raise Tasking_Error with Error_Message & "null task"; + raise Tasking_Error with Error_Message & "terminated task"; end if; return Target.Common.Base_Priority; @@ -93,8 +93,12 @@ package body Ada.Dynamic_Priorities is raise Program_Error with Error_Message & "null task"; end if; + -- Setting the priority of an already-terminated task doesn't do + -- anything (see RM-D.5.1(7)). Note that Get_Priority is different in + -- this regard. + if Task_Identification.Is_Terminated (T) then - raise Tasking_Error with Error_Message & "terminated task"; + return; end if; SSL.Abort_Defer.all; diff --git a/gcc/ada/clean.adb b/gcc/ada/clean.adb index 790b8423529..b7bfd059869 100644 --- a/gcc/ada/clean.adb +++ b/gcc/ada/clean.adb @@ -35,6 +35,7 @@ with Prj; use Prj; with Prj.Env; with Prj.Ext; with Prj.Pars; +with Prj.Tree; use Prj.Tree; with Prj.Util; use Prj.Util; with Snames; with Switch; use Switch; @@ -90,7 +91,7 @@ package body Clean is Project_File_Name : String_Access := null; - Project_Tree : constant Prj.Project_Tree_Ref := new Prj.Project_Tree_Data; + Project_Node_Tree : Project_Node_Tree_Ref; Main_Project : Prj.Project_Id := Prj.No_Project; @@ -1402,6 +1403,7 @@ package body Clean is Prj.Pars.Parse (Project => Main_Project, In_Tree => Project_Tree, + In_Node_Tree => Project_Node_Tree, Project_File_Name => Project_File_Name.all, Flags => Gnatmake_Flags, Packages_To_Check => Packages_To_Check_By_Gnatmake); @@ -1556,6 +1558,10 @@ package body Clean is Csets.Initialize; Namet.Initialize; Snames.Initialize; + + Project_Node_Tree := new Project_Node_Tree_Data; + Prj.Tree.Initialize (Project_Node_Tree); + Prj.Initialize (Project_Tree); -- Check if the platform is VMS and, if it is, change some variables @@ -1685,7 +1691,7 @@ package body Clean is elsif Arg (3) = 'P' then Prj.Ext.Add_Search_Project_Directory - (Arg (4 .. Arg'Last)); + (Project_Node_Tree, Arg (4 .. Arg'Last)); else Bad_Argument; @@ -1873,7 +1879,8 @@ package body Clean is if OK then Prj.Ext.Add - (External_Name => + (Project_Node_Tree, + External_Name => Ext_Asgn (Start .. Equal_Pos - 1), Value => Ext_Asgn (Equal_Pos + 1 .. Stop)); diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 49d23162eb0..6a65e10a167 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -4120,12 +4120,12 @@ package body Exp_Ch4 is Then_Statements => New_List ( Make_Assignment_Statement (Sloc (Thenx), - Name => New_Occurrence_Of (Cnn, Sloc (Thenx)), + Name => New_Occurrence_Of (Cnn, Sloc (Thenx)), Expression => Relocate_Node (Thenx))), Else_Statements => New_List ( Make_Assignment_Statement (Sloc (Elsex), - Name => New_Occurrence_Of (Cnn, Sloc (Elsex)), + Name => New_Occurrence_Of (Cnn, Sloc (Elsex)), Expression => Relocate_Node (Elsex)))); Set_Assignment_OK (Name (First (Then_Statements (New_If)))); @@ -4134,16 +4134,15 @@ package body Exp_Ch4 is New_N := New_Occurrence_Of (Cnn, Loc); else - -- No expansion needed, gigi handles it like a C conditional -- expression. return; end if; - -- Move the SLOC of the parent If statement to the newly created one - -- and change it to the SLOC of the expression which, after - -- expansion, will correspond to what is being evaluated. + -- Move the SLOC of the parent If statement to the newly created one and + -- change it to the SLOC of the expression which, after expansion, will + -- correspond to what is being evaluated. if Present (Parent (N)) and then Nkind (Parent (N)) = N_If_Statement @@ -4152,6 +4151,9 @@ package body Exp_Ch4 is Set_Sloc (Parent (N), Loc); end if; + -- Make sure Then_Actions and Else_Actions are appropriately moved + -- to the new if statement. + if Present (Then_Actions (N)) then Insert_List_Before (First (Then_Statements (New_If)), Then_Actions (N)); diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index 39700bda9e0..021afbf5282 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -3142,8 +3142,8 @@ package body Exp_Ch5 is -- Second, we deal with the obvious rewriting for the cases where the -- condition of the IF is known at compile time to be True or False. - -- Third, we remove elsif parts which have non-empty Condition_Actions - -- and rewrite as independent if statements. For example: + -- Third, we remove elsif parts which have non-empty Condition_Actions and + -- rewrite as independent if statements. For example: -- if x then xs -- elsif y then ys diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 238aad61043..4a31187d9d1 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -171,9 +171,9 @@ package body Exp_Ch6 is -- -- A := TypeA (Temp); -- - -- after the call. Here TypeA is the actual type of variable A. - -- For out parameters, the initial declaration has no expression. - -- If A is not an entity name, we generate instead: + -- after the call. Here TypeA is the actual type of variable A. For out + -- parameters, the initial declaration has no expression. If A is not an + -- entity name, we generate instead: -- -- Var : TypeA renames A; -- Temp : T := Var; -- omitting expression for out parameter. @@ -183,8 +183,8 @@ package body Exp_Ch6 is -- For other in-out parameters, we emit the required constraint checks -- before and/or after the call. -- - -- For all parameter modes, actuals that denote components and slices - -- of packed arrays are expanded into suitable temporaries. + -- For all parameter modes, actuals that denote components and slices of + -- packed arrays are expanded into suitable temporaries. -- -- For non-scalar objects that are possibly unaligned, add call by copy -- code (copy in for IN and IN OUT, copy out for OUT and IN OUT). @@ -419,8 +419,8 @@ package body Exp_Ch6 is -- Create the actual which is a pointer to the appropriate finalization -- list. Acc_Type is present if and only if this call is the - -- initialization of an allocator. Use the Current_Scope or the Acc_Type - -- as appropriate. + -- initialization of an allocator. Use the Current_Scope or the + -- Acc_Type as appropriate. if Present (Acc_Type) and then (Ekind (Acc_Type) = E_Anonymous_Access_Type diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb index 526a2dd552c..db22726bb64 100644 --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -835,8 +835,8 @@ package body Exp_Ch9 is end loop; -- If we are in a package body, the activation chain variable is - -- declared in the body, but the Activation_Chain_Entity is attached to - -- the spec. + -- declared in the body, but the Activation_Chain_Entity is attached + -- to the spec. if Nkind (P) = N_Package_Body then Decls := Declarations (P); diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb index 34aacef8c25..00fd9f22e70 100644 --- a/gcc/ada/exp_disp.adb +++ b/gcc/ada/exp_disp.adb @@ -5140,9 +5140,8 @@ package body Exp_Disp is exit when Parent_Typ = Current_Typ; - if Is_CPP_Class (Parent_Typ) - or else Is_Interface (Typ) - then + if Is_CPP_Class (Parent_Typ) then + -- The tags defined in the C++ side will be inherited when -- the object is constructed (Exp_Ch3.Build_Init_Procedure) diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb index d32ebfc37a8..8afde3beec3 100644 --- a/gcc/ada/g-socket.adb +++ b/gcc/ada/g-socket.adb @@ -282,6 +282,12 @@ package body GNAT.Sockets is Res : C.int; begin + if Selector.R_Sig_Socket = No_Socket + or else Selector.W_Sig_Socket = No_Socket + then + raise Program_Error with "closed selector"; + end if; + -- Send one byte to unblock select system call Res := Signalling_Fds.Write (C.int (Selector.W_Sig_Socket)); @@ -330,6 +336,14 @@ package body GNAT.Sockets is Status : out Selector_Status) is begin + if Selector /= null + and then (Selector.R_Sig_Socket = No_Socket + or else + Selector.W_Sig_Socket = No_Socket) + then + raise Program_Error with "closed selector"; + end if; + -- Wait for socket to become available for reading Wait_On_Socket @@ -473,11 +487,17 @@ package body GNAT.Sockets is is Res : C.int; Last : C.int; - RSig : Socket_Type renames Selector.R_Sig_Socket; + RSig : constant Socket_Type := Selector.R_Sig_Socket; TVal : aliased Timeval; TPtr : Timeval_Access; begin + if Selector.R_Sig_Socket = No_Socket + or else Selector.W_Sig_Socket = No_Socket + then + raise Program_Error with "closed selector"; + end if; + Status := Completed; -- No timeout or Forever is indicated by a null timeval pointer @@ -563,6 +583,12 @@ package body GNAT.Sockets is procedure Close_Selector (Selector : in out Selector_Type) is begin + if Selector.R_Sig_Socket = No_Socket + or else Selector.W_Sig_Socket = No_Socket + then + return; + end if; + -- Close the signalling file descriptors used internally for the -- implementation of Abort_Selector. @@ -636,6 +662,13 @@ package body GNAT.Sockets is -- Used to set Socket to non-blocking I/O begin + if Selector /= null and then + (Selector.R_Sig_Socket = No_Socket + or else Selector.W_Sig_Socket = No_Socket) + then + raise Program_Error with "closed selector"; + end if; + -- Set the socket to non-blocking I/O Req := (Name => Non_Blocking_IO, Enabled => True); @@ -727,6 +760,12 @@ package body GNAT.Sockets is Res : C.int; begin + if Selector.R_Sig_Socket /= No_Socket + or else Selector.W_Sig_Socket /= No_Socket + then + raise Program_Error with "selector already open"; + end if; + -- We open two signalling file descriptors. One of them is used to send -- data to the other, which is included in a C_Select socket set. The -- communication is used to force a call to C_Select to complete, and diff --git a/gcc/ada/g-socket.ads b/gcc/ada/g-socket.ads index a6445e044ad..39a917a5480 100644 --- a/gcc/ada/g-socket.ads +++ b/gcc/ada/g-socket.ads @@ -1072,7 +1072,8 @@ package GNAT.Sockets is -- Close Selector and all internal descriptors associated; deallocate any -- associated resources. This subprogram may be called only when there is -- no other task still using Selector (i.e. still executing Check_Selector - -- or Abort_Selector on this Selector). + -- or Abort_Selector on this Selector). Has no effect if Selector is + -- already closed. procedure Check_Selector (Selector : in out Selector_Type; diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi index 1f26563397b..e25400d09fc 100644 --- a/gcc/ada/gnat_rm.texi +++ b/gcc/ada/gnat_rm.texi @@ -7733,11 +7733,11 @@ Followed. In addition to the implementation dependent pragmas and attributes, and the implementation advice, there are a number of other Ada features that are potentially implementation dependent. These are mentioned -throughout the Ada Reference Manual, and are summarized in annex M@. +throughout the Ada Reference Manual, and are summarized in Annex M@. A requirement for conforming Ada compilers is that they provide documentation describing how the implementation deals with each of these -issues. In this chapter, you will find each point in annex M listed +issues. In this chapter, you will find each point in Annex M listed followed by a description in italic font of how GNAT @c SGI info: @ignore diff --git a/gcc/ada/gnatcmd.adb b/gcc/ada/gnatcmd.adb index 42d08dcd48f..563b92d150e 100644 --- a/gcc/ada/gnatcmd.adb +++ b/gcc/ada/gnatcmd.adb @@ -26,7 +26,7 @@ with GNAT.Directory_Operations; use GNAT.Directory_Operations; with Csets; -with Makeutl; +with Makeutl; use Makeutl; with MLib.Tgt; use MLib.Tgt; with MLib.Utl; with MLib.Fil; @@ -38,6 +38,7 @@ with Prj; use Prj; with Prj.Env; with Prj.Ext; use Prj.Ext; with Prj.Pars; +with Prj.Tree; use Prj.Tree; with Prj.Util; use Prj.Util; with Sinput.P; with Snames; use Snames; @@ -57,7 +58,7 @@ with GNAT.OS_Lib; use GNAT.OS_Lib; with VMS_Conv; use VMS_Conv; procedure GNATCmd is - Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data; + Project_Node_Tree : Project_Node_Tree_Ref; Project_File : String_Access; Project : Prj.Project_Id; Current_Verbosity : Prj.Verbosity := Prj.Default; @@ -1268,6 +1269,9 @@ begin Snames.Initialize; + Project_Node_Tree := new Project_Node_Tree_Data; + Prj.Tree.Initialize (Project_Node_Tree); + Prj.Initialize (Project_Tree); Last_Switches.Init; @@ -1600,7 +1604,7 @@ begin and then Argv (Argv'First + 1 .. Argv'First + 2) = "aP" then Add_Search_Project_Directory - (Argv (Argv'First + 3 .. Argv'Last)); + (Project_Node_Tree, Argv (Argv'First + 3 .. Argv'Last)); Remove_Switch (Arg_Num); @@ -1694,7 +1698,8 @@ begin begin if Equal_Pos >= Argv'First + 3 and then Equal_Pos /= Argv'Last then - Add (External_Name => + Add (Project_Node_Tree, + External_Name => Argv (Argv'First + 2 .. Equal_Pos - 1), Value => Argv (Equal_Pos + 1 .. Argv'Last)); else @@ -1753,6 +1758,7 @@ begin Prj.Pars.Parse (Project => Project, In_Tree => Project_Tree, + In_Node_Tree => Project_Node_Tree, Project_File_Name => Project_File.all, Flags => Gnatmake_Flags, Packages_To_Check => Packages_To_Check); @@ -2114,7 +2120,7 @@ begin -- arguments. for J in 1 .. Last_Switches.Last loop - Test_If_Relative_Path + GNATCmd.Test_If_Relative_Path (Last_Switches.Table (J), Current_Work_Dir); end loop; @@ -2124,7 +2130,7 @@ begin Project_Dir : constant String := Name_Buffer (1 .. Name_Len); begin for J in 1 .. First_Switches.Last loop - Test_If_Relative_Path + GNATCmd.Test_If_Relative_Path (First_Switches.Table (J), Project_Dir); end loop; end; diff --git a/gcc/ada/make.adb b/gcc/ada/make.adb index b19aa22da71..dacf290c273 100644 --- a/gcc/ada/make.adb +++ b/gcc/ada/make.adb @@ -49,10 +49,16 @@ with Prj; use Prj; with Prj.Com; with Prj.Env; with Prj.Pars; +with Prj.Tree; use Prj.Tree; with Prj.Util; with SFN_Scan; with Sinput.P; with Snames; use Snames; + +pragma Warnings (Off); +with System.HTable; +pragma Warnings (On); + with Switch; use Switch; with Switch.M; use Switch.M; with Targparm; use Targparm; @@ -68,8 +74,6 @@ with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables; with GNAT.Case_Util; use GNAT.Case_Util; with GNAT.OS_Lib; use GNAT.OS_Lib; -with System.HTable; - package body Make is use ASCII; @@ -640,7 +644,7 @@ package body Make is -- directory of the ultimate extending project. If it is not, we ignore -- the fact that this ALI file is read-only. - procedure Process_Multilib; + procedure Process_Multilib (Project_Node_Tree : Project_Node_Tree_Ref); -- Add appropriate --RTS argument to handle multilib ---------------------------------------------------- @@ -710,7 +714,8 @@ package body Make is File_Name : String; Index : Int; Program : Make_Program_Type; - Unknown_Switches_To_The_Compiler : Boolean := True); + Unknown_Switches_To_The_Compiler : Boolean := True; + Project_Node_Tree : Project_Node_Tree_Ref); procedure Add_Switch (S : String_Access; Program : Make_Program_Type; @@ -998,7 +1003,7 @@ package body Make is -- during a compilation are also transitively included in the W section -- of the originally compiled file. - procedure Initialize; + procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref); -- Performs default and package initialization. Therefore, -- Compile_Sources can be called by an external unit. @@ -1010,8 +1015,13 @@ package body Make is -- Args must have a lower bound of 1. Success indicates if the link -- succeeded or not. - procedure Scan_Make_Arg (Argv : String; And_Save : Boolean); - -- Scan make arguments. Argv is a single argument to be processed + procedure Scan_Make_Arg + (Project_Node_Tree : Project_Node_Tree_Ref; + Argv : String; + And_Save : Boolean); + -- Scan make arguments. Argv is a single argument to be processed. + -- Project_Node_Tree will be used to initialize external references. It + -- must have been initialized. ------------------- -- Add_Arguments -- @@ -1233,7 +1243,8 @@ package body Make is File_Name : String; Index : Int; Program : Make_Program_Type; - Unknown_Switches_To_The_Compiler : Boolean := True) + Unknown_Switches_To_The_Compiler : Boolean := True; + Project_Node_Tree : Project_Node_Tree_Ref) is Switches : Variable_Value; Switch_List : String_List_Id; @@ -1274,7 +1285,8 @@ package body Make is Write_Line (Argv); end if; - Scan_Make_Arg (Argv, And_Save => False); + Scan_Make_Arg + (Project_Node_Tree, Argv, And_Save => False); if not Gnatmake_Switch_Found and then not Switch_May_Be_Passed_To_The_Compiler @@ -4019,6 +4031,8 @@ package body Make is Mapping_Path : Path_Name_Type := No_Path; -- The path name of the mapping file + Project_Node_Tree : Project_Node_Tree_Ref; + Discard : Boolean; pragma Warnings (Off, Discard); @@ -4366,7 +4380,7 @@ package body Make is Obsoleted.Reset; - Make.Initialize; + Make.Initialize (Project_Node_Tree); Bind_Shared := No_Shared_Switch'Access; Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access; @@ -4845,7 +4859,8 @@ package body Make is end if; Add_Switches - (File_Name => Main_Unit_File_Name, + (Project_Node_Tree => Project_Node_Tree, + File_Name => Main_Unit_File_Name, Index => Main_Index, The_Package => Builder_Package, Program => None, @@ -4900,7 +4915,8 @@ package body Make is end if; Add_Switches - (File_Name => " ", + (Project_Node_Tree => Project_Node_Tree, + File_Name => " ", Index => 0, The_Package => Builder_Package, Program => None, @@ -4916,7 +4932,8 @@ package body Make is end if; Add_Switches - (File_Name => " ", + (Project_Node_Tree => Project_Node_Tree, + File_Name => " ", Index => 0, The_Package => Builder_Package, Program => None); @@ -5007,10 +5024,11 @@ package body Make is end if; Add_Switches - (File_Name => Main_Unit_File_Name, - Index => Main_Index, - The_Package => Binder_Package, - Program => Binder); + (Project_Node_Tree => Project_Node_Tree, + File_Name => Main_Unit_File_Name, + Index => Main_Index, + The_Package => Binder_Package, + Program => Binder); end if; -- Add linker switches from the project file for the first main @@ -5023,10 +5041,11 @@ package body Make is end if; Add_Switches - (File_Name => Main_Unit_File_Name, - Index => Main_Index, - The_Package => Linker_Package, - Program => Linker); + (Project_Node_Tree => Project_Node_Tree, + File_Name => Main_Unit_File_Name, + Index => Main_Index, + The_Package => Linker_Package, + Program => Linker); end if; end; end if; @@ -6310,10 +6329,11 @@ package body Make is end if; Add_Switches - (File_Name => Main_Unit_File_Name, - Index => Main_Index, - The_Package => Binder_Package, - Program => Binder); + (Project_Node_Tree => Project_Node_Tree, + File_Name => Main_Unit_File_Name, + Index => Main_Index, + The_Package => Binder_Package, + Program => Binder); end if; -- Add linker switches from the project file for this main, @@ -6327,10 +6347,11 @@ package body Make is end if; Add_Switches - (File_Name => Main_Unit_File_Name, - Index => Main_Index, - The_Package => Linker_Package, - Program => Linker); + (Project_Node_Tree => Project_Node_Tree, + File_Name => Main_Unit_File_Name, + Index => Main_Index, + The_Package => Linker_Package, + Program => Linker); end if; -- As we are using a project file, for relative paths we add @@ -6521,7 +6542,7 @@ package body Make is -- Initialize -- ---------------- - procedure Initialize is + procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref) is procedure Check_Version_And_Help is new Check_Version_And_Help_G (Makeusg); @@ -6529,6 +6550,13 @@ package body Make is -- Start of processing for Initialize begin + -- Prepare the project's tree, since this is used to hold external + -- references, project path and other attributes that can be impacted by + -- the command line switches + + Project_Node_Tree := new Project_Node_Tree_Data; + Prj.Tree.Initialize (Project_Node_Tree); + -- Override default initialization of Check_Object_Consistency since -- this is normally False for GNATBIND, but is True for GNATMAKE since -- we do not need to check source consistency again once GNATMAKE has @@ -6611,11 +6639,12 @@ package body Make is -- do not include --version or --help. Scan_Args : for Next_Arg in 1 .. Argument_Count loop - Scan_Make_Arg (Argument (Next_Arg), And_Save => True); + Scan_Make_Arg + (Project_Node_Tree, Argument (Next_Arg), And_Save => True); end loop Scan_Args; if N_M_Switch > 0 and RTS_Specified = null then - Process_Multilib; + Process_Multilib (Project_Node_Tree); end if; if Commands_To_Stdout then @@ -6700,7 +6729,8 @@ package body Make is In_Tree => Project_Tree, Project_File_Name => Project_File_Name.all, Packages_To_Check => Packages_To_Check_By_Gnatmake, - Flags => Gnatmake_Flags); + Flags => Gnatmake_Flags, + In_Node_Tree => Project_Node_Tree); -- The parsing of project files may have changed the current output @@ -7281,7 +7311,9 @@ package body Make is -- Process_Multilib -- ---------------------- - procedure Process_Multilib is + procedure Process_Multilib + (Project_Node_Tree : Project_Node_Tree_Ref) + is Output_FD : File_Descriptor; Output_Name : String_Access; Arg_Index : Natural := 0; @@ -7382,8 +7414,9 @@ package body Make is -- Otherwise add -margs --RTS=output - Scan_Make_Arg ("-margs", And_Save => True); - Scan_Make_Arg ("--RTS=" & Line (1 .. N_Read), And_Save => True); + Scan_Make_Arg (Project_Node_Tree, "-margs", And_Save => True); + Scan_Make_Arg + (Project_Node_Tree, "--RTS=" & Line (1 .. N_Read), And_Save => True); end Process_Multilib; ----------------------------- @@ -7485,7 +7518,11 @@ package body Make is -- Scan_Make_Arg -- ------------------- - procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is + procedure Scan_Make_Arg + (Project_Node_Tree : Project_Node_Tree_Ref; + Argv : String; + And_Save : Boolean) + is Success : Boolean; begin @@ -7750,7 +7787,7 @@ package body Make is Add_Switch (Argv, Linker, And_Save => And_Save); else - Scan_Make_Switches (Argv, Success); + Scan_Make_Switches (Project_Node_Tree, Argv, Success); end if; -- If we have seen a regular switch process it @@ -7889,7 +7926,7 @@ package body Make is "project file"); else - Scan_Make_Switches (Argv, Success); + Scan_Make_Switches (Project_Node_Tree, Argv, Success); end if; -- -d @@ -7906,13 +7943,13 @@ package body Make is Make_Failed ("-i cannot be used in conjunction with a " & "project file"); else - Scan_Make_Switches (Argv, Success); + Scan_Make_Switches (Project_Node_Tree, Argv, Success); end if; -- -j (need to save the result) elsif Argv (2) = 'j' then - Scan_Make_Switches (Argv, Success); + Scan_Make_Switches (Project_Node_Tree, Argv, Success); if And_Save then Saved_Maximum_Processes := Maximum_Processes; @@ -8001,7 +8038,7 @@ package body Make is -- -Xext=val (External assignment) elsif Argv (2) = 'X' - and then Is_External_Assignment (Argv) + and then Is_External_Assignment (Project_Node_Tree, Argv) then -- Is_External_Assignment has side effects -- when it returns True; @@ -8052,7 +8089,8 @@ package body Make is -- is passed to the compiler. else - Scan_Make_Switches (Argv, Gnatmake_Switch_Found); + Scan_Make_Switches + (Project_Node_Tree, Argv, Gnatmake_Switch_Found); if not Gnatmake_Switch_Found then Add_Switch (Argv, Compiler, And_Save => And_Save); diff --git a/gcc/ada/makeutl.adb b/gcc/ada/makeutl.adb index c0d9de4d764..a570737d711 100644 --- a/gcc/ada/makeutl.adb +++ b/gcc/ada/makeutl.adb @@ -447,10 +447,12 @@ package body Makeutl is -- Is_External_Assignment -- ---------------------------- - function Is_External_Assignment (Argv : String) return Boolean is + function Is_External_Assignment + (Tree : Prj.Tree.Project_Node_Tree_Ref; + Argv : String) return Boolean + is Start : Positive := 3; Finish : Natural := Argv'Last; - Equal_Pos : Natural; pragma Assert (Argv'First = 1); pragma Assert (Argv (1 .. 2) = "-X"); @@ -468,20 +470,9 @@ package body Makeutl is end if; end if; - Equal_Pos := Start; - - while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop - Equal_Pos := Equal_Pos + 1; - end loop; - - if Equal_Pos = Start or else Equal_Pos > Finish then - return False; - else - Prj.Ext.Add - (External_Name => Argv (Start .. Equal_Pos - 1), - Value => Argv (Equal_Pos + 1 .. Finish)); - return True; - end if; + return Prj.Ext.Check + (Tree => Tree, + Declaration => Argv (Start .. Finish)); end Is_External_Assignment; --------------- diff --git a/gcc/ada/makeutl.ads b/gcc/ada/makeutl.ads index 1dff5a16aa1..95114f07c9a 100644 --- a/gcc/ada/makeutl.ads +++ b/gcc/ada/makeutl.ads @@ -28,6 +28,7 @@ with Namet; use Namet; with Opt; with Osint; with Prj; use Prj; +with Prj.Tree; with Types; use Types; with GNAT.OS_Lib; use GNAT.OS_Lib; @@ -83,7 +84,9 @@ package Makeutl is -- source files are still associated with the same units). Return True -- if everything is still valid - function Is_External_Assignment (Argv : String) return Boolean; + function Is_External_Assignment + (Tree : Prj.Tree.Project_Node_Tree_Ref; + Argv : String) return Boolean; -- Verify that an external assignment switch is syntactically correct -- -- Correct forms are: diff --git a/gcc/ada/prj-conf.adb b/gcc/ada/prj-conf.adb index 879178de122..bcf434b15e1 100644 --- a/gcc/ada/prj-conf.adb +++ b/gcc/ada/prj-conf.adb @@ -29,6 +29,7 @@ with Makeutl; use Makeutl; with MLib.Tgt; with Opt; use Opt; with Output; use Output; +with Prj.Env; with Prj.Err; with Prj.Part; with Prj.PP; @@ -697,6 +698,8 @@ package body Prj.Conf is Args : Argument_List (1 .. 5); Arg_Last : Positive; + Obj_Dir_Exists : Boolean := True; + begin -- Check if the object directory exists. If Setup_Projects is True -- (-p) and directory does not exist, attempt to create it. @@ -731,6 +734,7 @@ package body Prj.Conf is Prj.Err.Error_Msg (Flags, "?object directory " & Obj_Dir & " does not exist"); + Obj_Dir_Exists := False; when Silent => null; end case; @@ -744,8 +748,35 @@ package body Prj.Conf is -- If no config file was specified, set the auto.cgpr one if Config_File_Name = "" then - Args (3) := new String' - (Obj_Dir & Directory_Separator & Auto_Cgpr); + if Obj_Dir_Exists then + Args (3) := + new String'(Obj_Dir & Directory_Separator & Auto_Cgpr); + + else + declare + Path_FD : File_Descriptor; + Path_Name : Path_Name_Type; + + begin + Prj.Env.Create_Temp_File + (In_Tree => Project_Tree, + Path_FD => Path_FD, + Path_Name => Path_Name, + File_Use => "configuration file"); + + if Path_FD /= Invalid_FD then + Args (3) := new String'(Get_Name_String (Path_Name)); + GNAT.OS_Lib.Close (Path_FD); + + else + -- We'll have an error message later on + + Args (3) := + new String' + (Obj_Dir & Directory_Separator & Auto_Cgpr); + end if; + end; + end if; else Args (3) := new String'(Config_File_Name); end if; @@ -783,9 +814,16 @@ package body Prj.Conf is Write_Eol; elsif not Quiet_Output then - Write_Str ("creating "); - Write_Str (Simple_Name (Args (3).all)); - Write_Eol; + -- Display no message if we are creating auto.cgpr, unless in + -- verbose mode + + if Config_File_Name /= "" + or else Verbose_Mode + then + Write_Str ("creating "); + Write_Str (Simple_Name (Args (3).all)); + Write_Eol; + end if; end if; Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Switches.all, @@ -1000,7 +1038,6 @@ package body Prj.Conf is begin -- Parse the user project tree - Prj.Tree.Initialize (Project_Node_Tree); Prj.Initialize (Project_Tree); Main_Project := No_Project; diff --git a/gcc/ada/prj-conf.ads b/gcc/ada/prj-conf.ads index f228ae3fde3..82b8dc34726 100644 --- a/gcc/ada/prj-conf.ads +++ b/gcc/ada/prj-conf.ads @@ -59,6 +59,10 @@ package Prj.Conf is -- Find the main configuration project and parse the project tree rooted at -- this configuration project. -- + -- Project_Node_Tree must have been initialized first (and possibly the + -- value for external references and project path should also have been + -- set). + -- -- If the processing fails, Main_Project is set to No_Project. If the error -- happend while parsing the project itself (ie creating the tree), -- User_Project_Node is also set to Empty_Node. diff --git a/gcc/ada/prj-env.adb b/gcc/ada/prj-env.adb index 0ffacdbdc5b..c5182abea09 100644 --- a/gcc/ada/prj-env.adb +++ b/gcc/ada/prj-env.adb @@ -97,14 +97,6 @@ package body Prj.Env is -- Return a project that is either Project or an extended ancestor of -- Project that itself is not extended. - procedure Create_Temp_File - (In_Tree : Project_Tree_Ref; - Path_FD : out File_Descriptor; - Path_Name : out Path_Name_Type; - File_Use : String); - -- Create a temporary file, and fail with an error if it could not be - -- created. - ---------------------- -- Ada_Include_Path -- ---------------------- diff --git a/gcc/ada/prj-env.ads b/gcc/ada/prj-env.ads index ffcea0756b6..27259c29b98 100644 --- a/gcc/ada/prj-env.ads +++ b/gcc/ada/prj-env.ads @@ -39,6 +39,13 @@ package Prj.Env is -- of package Fmap), so that Osint.Find_File will find the correct path -- corresponding to a source. + procedure Create_Temp_File + (In_Tree : Project_Tree_Ref; + Path_FD : out File_Descriptor; + Path_Name : out Path_Name_Type; + File_Use : String); + -- Create temporary file, and fail with an error if it could not be created + procedure Create_Mapping_File (Project : Project_Id; Language : Name_Id; diff --git a/gcc/ada/prj-ext.adb b/gcc/ada/prj-ext.adb index 8098a3a23b1..9c9707c1cfa 100644 --- a/gcc/ada/prj-ext.adb +++ b/gcc/ada/prj-ext.adb @@ -23,63 +23,33 @@ -- -- ------------------------------------------------------------------------------ +with System.OS_Lib; use System.OS_Lib; with Hostparm; -with Makeutl; use Makeutl; -with Osint; use Osint; +with Makeutl; use Makeutl; +with Osint; use Osint; +with Prj.Tree; use Prj.Tree; with Sdefault; -with Table; - -with GNAT.HTable; package body Prj.Ext is - Ada_Project_Path : constant String := "ADA_PROJECT_PATH"; - -- Name of alternate env. variable that contain path name(s) of directories - -- where project files may reside. GPR_PROJECT_PATH has precedence over - -- ADA_PROJECT_PATH. - - Gpr_Prj_Path : constant String_Access := Getenv (Gpr_Project_Path); - Ada_Prj_Path : constant String_Access := Getenv (Ada_Project_Path); - -- The path name(s) of directories where project files may reside. - -- May be empty. - No_Project_Default_Dir : constant String := "-"; + -- Indicator in the project path to indicate that the default search + -- directories should not be added to the path - Current_Project_Path : String_Access; - -- The project path. Initialized by procedure Initialize_Project_Path - -- below. + Uninitialized_Prefix : constant String := '#' & Path_Separator; + -- Prefix to indicate that the project path has not been initilized yet. + -- Must be two characters long - procedure Initialize_Project_Path; + procedure Initialize_Project_Path (Tree : Prj.Tree.Project_Node_Tree_Ref); -- Initialize Current_Project_Path - package Htable is new GNAT.HTable.Simple_HTable - (Header_Num => Header_Num, - Element => Name_Id, - No_Element => No_Name, - Key => Name_Id, - Hash => Hash, - Equal => "="); - -- External references are stored in this hash table, either by procedure - -- Add (directly or through a call to function Check) or by function - -- Value_Of when an environment variable is found non empty. Value_Of - -- first for external reference in this table, before checking the - -- environment. Htable is emptied (reset) by procedure Reset. - - package Search_Directories is new Table.Table - (Table_Component_Type => Name_Id, - Table_Index_Type => Natural, - Table_Low_Bound => 1, - Table_Initial => 4, - Table_Increment => 100, - Table_Name => "Prj.Ext.Search_Directories"); - -- The table for the directories specified with -aP switches - --------- -- Add -- --------- procedure Add - (External_Name : String; + (Tree : Prj.Tree.Project_Node_Tree_Ref; + External_Name : String; Value : String) is The_Key : Name_Id; @@ -92,34 +62,45 @@ package body Prj.Ext is Name_Buffer (1 .. Name_Len) := External_Name; Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len)); The_Key := Name_Find; - Htable.Set (The_Key, The_Value); + Name_To_Name_HTable.Set (Tree.External_References, The_Key, The_Value); end Add; - ----------- ---------------------------------- -- Add_Search_Project_Directory -- ---------------------------------- - procedure Add_Search_Project_Directory (Path : String) is + procedure Add_Search_Project_Directory + (Tree : Prj.Tree.Project_Node_Tree_Ref; + Path : String) + is + Tmp : String_Access; begin - Name_Len := 0; - Add_Str_To_Name_Buffer (Path); - Search_Directories.Append (Name_Find); + if Tree.Project_Path = null then + Tree.Project_Path := new String'(Uninitialized_Prefix & Path); + else + Tmp := Tree.Project_Path; + Tree.Project_Path := new String'(Tmp.all & Path_Separator & Path); + Free (Tmp); + end if; end Add_Search_Project_Directory; + ----------- -- Check -- ----------- - function Check (Declaration : String) return Boolean is + function Check + (Tree : Prj.Tree.Project_Node_Tree_Ref; + Declaration : String) return Boolean + is begin for Equal_Pos in Declaration'Range loop if Declaration (Equal_Pos) = '=' then exit when Equal_Pos = Declaration'First; - exit when Equal_Pos = Declaration'Last; Add - (External_Name => + (Tree => Tree, + External_Name => Declaration (Declaration'First .. Equal_Pos - 1), - Value => + Value => Declaration (Equal_Pos + 1 .. Declaration'Last)); return True; end if; @@ -132,42 +113,57 @@ package body Prj.Ext is -- Initialize_Project_Path -- ----------------------------- - procedure Initialize_Project_Path is + procedure Initialize_Project_Path (Tree : Prj.Tree.Project_Node_Tree_Ref) is Add_Default_Dir : Boolean := True; First : Positive; Last : Positive; New_Len : Positive; New_Last : Positive; - begin - -- The current directory is always first + Ada_Project_Path : constant String := "ADA_PROJECT_PATH"; + Gpr_Project_Path : constant String := "GPR_PROJECT_PATH"; + -- Name of alternate env. variable that contain path name(s) of + -- directories where project files may reside. GPR_PROJECT_PATH has + -- precedence over ADA_PROJECT_PATH. - Name_Len := 1; - Name_Buffer (Name_Len) := '.'; + Gpr_Prj_Path : String_Access := Getenv (Gpr_Project_Path); + Ada_Prj_Path : String_Access := Getenv (Ada_Project_Path); + -- The path name(s) of directories where project files may reside. + -- May be empty. - -- If there are directories in the Search_Directories table, add them + begin + -- The current directory is always first in the search path. Since the + -- Project_Path currently starts with '#:' as a sign that it isn't + -- initialized, we simply replace '#' with '.' + + if Tree.Project_Path = null then + Tree.Project_Path := new String'('.' & Path_Separator); + else + Tree.Project_Path (Tree.Project_Path'First) := '.'; + end if; - for J in 1 .. Search_Directories.Last loop - Name_Len := Name_Len + 1; - Name_Buffer (Name_Len) := Path_Separator; - Add_Str_To_Name_Buffer - (Get_Name_String (Search_Directories.Table (J))); - end loop; + -- Then the reset of the project path (if any) currently contains the + -- directories added through Add_Search_Project_Directory - -- If environment variable is defined and not empty, add its content + -- If environment variables are defined and not empty, add their content if Gpr_Prj_Path.all /= "" then - Name_Len := Name_Len + 1; - Name_Buffer (Name_Len) := Path_Separator; - Add_Str_To_Name_Buffer (Gpr_Prj_Path.all); + Add_Search_Project_Directory (Tree, Gpr_Prj_Path.all); end if; + Free (Gpr_Prj_Path); + if Ada_Prj_Path.all /= "" then - Name_Len := Name_Len + 1; - Name_Buffer (Name_Len) := Path_Separator; - Add_Str_To_Name_Buffer (Ada_Prj_Path.all); + Add_Search_Project_Directory (Tree, Ada_Prj_Path.all); end if; + Free (Ada_Prj_Path); + + -- Copy to Name_Buffer, since we will need to manipulate the path + + Name_Len := Tree.Project_Path'Length; + Name_Buffer (1 .. Name_Len) := Tree.Project_Path.all; + -- Scan the directory path to see if "-" is one of the directories. -- Remove each occurrence of "-" and set Add_Default_Dir to False. -- Also resolve relative paths and symbolic links. @@ -239,6 +235,8 @@ package body Prj.Ext is First := Last + 1; end loop; + Free (Tree.Project_Path); + -- Set the initial value of Current_Project_Path if Add_Default_Dir then @@ -260,7 +258,7 @@ package body Prj.Ext is end if; else - Current_Project_Path := + Tree.Project_Path := new String'(Name_Buffer (1 .. Name_Len) & Path_Separator & Prefix.all & ".." & Directory_Separator & @@ -272,8 +270,8 @@ package body Prj.Ext is end; end if; - if Current_Project_Path = null then - Current_Project_Path := new String'(Name_Buffer (1 .. Name_Len)); + if Tree.Project_Path = null then + Tree.Project_Path := new String'(Name_Buffer (1 .. Name_Len)); end if; end Initialize_Project_Path; @@ -281,32 +279,36 @@ package body Prj.Ext is -- Project_Path -- ------------------ - function Project_Path return String is + function Project_Path (Tree : Project_Node_Tree_Ref) return String is begin - if Current_Project_Path = null then - Initialize_Project_Path; + if Tree.Project_Path = null + or else Tree.Project_Path (Tree.Project_Path'First) = '#' + then + Initialize_Project_Path (Tree); end if; - return Current_Project_Path.all; + return Tree.Project_Path.all; end Project_Path; ----------- -- Reset -- ----------- - procedure Reset is + procedure Reset (Tree : Prj.Tree.Project_Node_Tree_Ref) is begin - Htable.Reset; + Name_To_Name_HTable.Reset (Tree.External_References); end Reset; ---------------------- -- Set_Project_Path -- ---------------------- - procedure Set_Project_Path (New_Path : String) is + procedure Set_Project_Path + (Tree : Project_Node_Tree_Ref; + New_Path : String) is begin - Free (Current_Project_Path); - Current_Project_Path := new String'(New_Path); + Free (Tree.Project_Path); + Tree.Project_Path := new String'(New_Path); end Set_Project_Path; -------------- @@ -314,7 +316,8 @@ package body Prj.Ext is -------------- function Value_Of - (External_Name : Name_Id; + (Tree : Prj.Tree.Project_Node_Tree_Ref; + External_Name : Name_Id; With_Default : Name_Id := No_Name) return Name_Id is @@ -325,7 +328,8 @@ package body Prj.Ext is Canonical_Case_File_Name (Name); Name_Len := Name'Length; Name_Buffer (1 .. Name_Len) := Name; - The_Value := Htable.Get (Name_Find); + The_Value := + Name_To_Name_HTable.Get (Tree.External_References, Name_Find); if The_Value /= No_Name then return The_Value; @@ -341,7 +345,8 @@ package body Prj.Ext is Name_Len := Env_Value'Length; Name_Buffer (1 .. Name_Len) := Env_Value.all; The_Value := Name_Find; - Htable.Set (External_Name, The_Value); + Name_To_Name_HTable.Set + (Tree.External_References, External_Name, The_Value); Free (Env_Value); return The_Value; diff --git a/gcc/ada/prj-ext.ads b/gcc/ada/prj-ext.ads index 931c3c5d07f..c171f5940f1 100644 --- a/gcc/ada/prj-ext.ads +++ b/gcc/ada/prj-ext.ads @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2000-2007, Free Software Foundation, Inc. -- +-- Copyright (C) 2000-2009, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -26,44 +26,70 @@ -- Subprograms to set, get and cache external references, to be used as -- External functions in project files. +with Prj.Tree; + package Prj.Ext is - Gpr_Project_Path : constant String := "GPR_PROJECT_PATH"; - -- Name of primary env. variable that contain path name(s) of directories - -- where project files may reside. + ------------------ + -- Project Path -- + ------------------ - procedure Add_Search_Project_Directory (Path : String); + procedure Add_Search_Project_Directory + (Tree : Prj.Tree.Project_Node_Tree_Ref; + Path : String); -- Add a directory to the project path. Directories added with this -- procedure are added in order after the current directory and before -- the path given by the environment variable GPR_PROJECT_PATH. A value -- of "-" will remove the default project directory from the project path. + -- + -- Calls to this subprogram must be performed before the first call to + -- Project_Path below, or PATH will be added at the end of the search + -- path. - function Project_Path return String; + function Project_Path (Tree : Prj.Tree.Project_Node_Tree_Ref) return String; -- Return the current value of the project path, either the value set -- during elaboration of the package or, if procedure Set_Project_Path has -- been called, the value set by the last call to Set_Project_Path. - procedure Set_Project_Path (New_Path : String); + procedure Set_Project_Path + (Tree : Prj.Tree.Project_Node_Tree_Ref; + New_Path : String); -- Give a new value to the project path. The new value New_Path should -- always start with the current directory (".") and the path separators -- should be the correct ones for the platform. + ------------------------- + -- External References -- + ------------------------- + + -- External references influence the way a project tree is processed (in + -- particular they provide the values for the typed string variables that + -- are then used in case constructions). + + -- External references are project-tree specific, so that when multiple + -- trees are loaded in parallel we can have different scenarios (or even + -- load the same tree twice and see different views of it). + procedure Add - (External_Name : String; + (Tree : Prj.Tree.Project_Node_Tree_Ref; + External_Name : String; Value : String); -- Add an external reference (or modify an existing one) function Value_Of - (External_Name : Name_Id; + (Tree : Prj.Tree.Project_Node_Tree_Ref; + External_Name : Name_Id; With_Default : Name_Id := No_Name) return Name_Id; -- Get the value of an external reference, and cache it for future uses - function Check (Declaration : String) return Boolean; + function Check + (Tree : Prj.Tree.Project_Node_Tree_Ref; + Declaration : String) return Boolean; -- Check that an external declaration <external>=<value> is correct. -- If it is correct, the external reference is Added. - procedure Reset; + procedure Reset (Tree : Prj.Tree.Project_Node_Tree_Ref); -- Clear the internal data structure that stores the external references -- and free any allocated memory. diff --git a/gcc/ada/prj-nmsc.ads b/gcc/ada/prj-nmsc.ads index eec6289e503..c69084f99ff 100644 --- a/gcc/ada/prj-nmsc.ads +++ b/gcc/ada/prj-nmsc.ads @@ -33,11 +33,10 @@ private package Prj.Nmsc is Flags : Processing_Flags); -- Perform consistency and semantic checks on all the projects in the tree. -- This procedure interprets the various case statements in the project - -- based on the current environment variables (the "scenario"). After - -- checking the validity of the naming scheme, it searches for all the - -- source files of the project. The result of this procedure is a filled-in - -- data structure for Project_Id which contains all the information about - -- the project. This information is only valid while the scenario variables - -- are preserved. + -- based on the current external references. After checking the validity of + -- the naming scheme, it searches for all the source files of the project. + -- The result of this procedure is a filled-in data structure for + -- Project_Id which contains all the information about the project. This + -- information is only valid while the external references are preserved. end Prj.Nmsc; diff --git a/gcc/ada/prj-pars.adb b/gcc/ada/prj-pars.adb index bacbf8d7f87..7ab7ea047c6 100644 --- a/gcc/ada/prj-pars.adb +++ b/gcc/ada/prj-pars.adb @@ -45,18 +45,22 @@ package body Prj.Pars is Project_File_Name : String; Packages_To_Check : String_List_Access := All_Packages; Flags : Processing_Flags; - Reset_Tree : Boolean := True) + Reset_Tree : Boolean := True; + In_Node_Tree : Prj.Tree.Project_Node_Tree_Ref := null) is - Project_Node : Project_Node_Id := Empty_Node; - The_Project : Project_Id := No_Project; - Success : Boolean := True; - Current_Dir : constant String := Get_Current_Dir; - Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref; + Project_Node : Project_Node_Id := Empty_Node; + The_Project : Project_Id := No_Project; + Success : Boolean := True; + Current_Dir : constant String := Get_Current_Dir; + Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref := In_Node_Tree; Automatically_Generated : Boolean; Config_File_Path : String_Access; + begin - Project_Node_Tree := new Project_Node_Tree_Data; - Prj.Tree.Initialize (Project_Node_Tree); + if Project_Node_Tree = null then + Project_Node_Tree := new Project_Node_Tree_Data; + Prj.Tree.Initialize (Project_Node_Tree); + end if; -- Parse the main project file into a tree diff --git a/gcc/ada/prj-pars.ads b/gcc/ada/prj-pars.ads index 01caff93c19..4e7d4808d4a 100644 --- a/gcc/ada/prj-pars.ads +++ b/gcc/ada/prj-pars.ads @@ -25,6 +25,8 @@ -- General wrapper for the parsing of project files +with Prj.Tree; + package Prj.Pars is procedure Set_Verbosity (To : Verbosity); @@ -36,20 +38,21 @@ package Prj.Pars is Project_File_Name : String; Packages_To_Check : String_List_Access := All_Packages; Flags : Processing_Flags; - Reset_Tree : Boolean := True); + Reset_Tree : Boolean := True; + In_Node_Tree : Prj.Tree.Project_Node_Tree_Ref := null); -- Parse and process a project files and all its imported project files, in -- the project tree In_Tree. -- All the project files are parsed (through Prj.Tree) to create a tree in -- memory. That tree is then processed (through Prj.Proc) to create a - -- expanded representation of the tree based on the current scenario - -- variables. This function is only a convenient wrapper over other + -- expanded representation of the tree based on the current external + -- references. This function is only a convenient wrapper over other -- services provided in the Prj.* package hierarchy. -- -- If parsing is successful, Project is the project ID of the root project -- file; otherwise, Project_Id is set to No_Project. Project_Node_Tree is -- set to the tree (unprocessed) representation of the project file. This -- tree is permanently correct, whereas Project will need to be recomputed - -- if the scenario variables change. + -- if the external references change. -- -- Packages_To_Check indicates the packages where any unknown attribute -- produces an error. For other packages, an unknown attribute produces a @@ -57,5 +60,9 @@ package Prj.Pars is -- -- When Reset_Tree is True, all the project data are removed from the -- project table before processing. + -- + -- In_Node_Tree (if given) must have been Initialized. The main reason to + -- pass an existing tree, is to pass the external references that will then + -- be used to process the tree. end Prj.Pars; diff --git a/gcc/ada/prj-part.adb b/gcc/ada/prj-part.adb index fc0438ba4f0..1ed78ab227b 100644 --- a/gcc/ada/prj-part.adb +++ b/gcc/ada/prj-part.adb @@ -212,7 +212,8 @@ package body Prj.Part is -- file (.cgpr) since some specific checks apply. function Project_Path_Name_Of - (Project_File_Name : String; + (In_Tree : Project_Node_Tree_Ref; + Project_File_Name : String; Directory : String) return String; -- Returns the path name of a project file. Returns an empty string -- if project file cannot be found. @@ -455,13 +456,14 @@ package body Prj.Part is if Current_Verbosity >= Medium then Write_Str ("GPR_PROJECT_PATH="""); - Write_Str (Project_Path); + Write_Str (Project_Path (In_Tree)); Write_Line (""""); end if; declare Path_Name : constant String := - Project_Path_Name_Of (Real_Project_File_Name.all, + Project_Path_Name_Of (In_Tree, + Real_Project_File_Name.all, Directory => Current_Directory); begin @@ -478,7 +480,7 @@ package body Prj.Part is ("project file """ & Project_File_Name & """ not found in " - & Project_Path); + & Project_Path (In_Tree)); Project := Empty_Node; return; end if; @@ -755,7 +757,8 @@ package body Prj.Part is Imported_Path_Name : constant String := Project_Path_Name_Of - (Original_Path, + (In_Tree, + Original_Path, Project_Directory_Path); Resolved_Path : constant String := @@ -1338,8 +1341,10 @@ package body Prj.Part is -- Read the original casing of the project name declare - Loc : Source_Ptr := Location_Of (Project, In_Tree); + Loc : Source_Ptr; + begin + Loc := Location_Of (Project, In_Tree); for J in 1 .. Name_Len loop Name_Buffer (J) := Sinput.Source (Loc); Loc := Loc + 1; @@ -1432,7 +1437,8 @@ package body Prj.Part is Extended_Project_Path_Name : constant String := Project_Path_Name_Of - (Original_Path_Name, + (In_Tree, + Original_Path_Name, Get_Name_String (Project_Directory)); @@ -1909,7 +1915,8 @@ package body Prj.Part is -------------------------- function Project_Path_Name_Of - (Project_File_Name : String; + (In_Tree : Project_Node_Tree_Ref; + Project_File_Name : String; Directory : String) return String is @@ -1922,7 +1929,7 @@ package body Prj.Part is ------------------- function Try_Path_Name (Path : String) return String_Access is - Prj_Path : constant String := Project_Path; + Prj_Path : constant String := Project_Path (In_Tree); First : Natural; Last : Natural; Result : String_Access := null; diff --git a/gcc/ada/prj-proc.adb b/gcc/ada/prj-proc.adb index 9893cf6129b..0cd20c8f19d 100644 --- a/gcc/ada/prj-proc.adb +++ b/gcc/ada/prj-proc.adb @@ -1041,7 +1041,8 @@ package body Prj.Proc is end if; end if; - Value := Prj.Ext.Value_Of (Name, Default); + Value := + Prj.Ext.Value_Of (From_Project_Node_Tree, Name, Default); if Value = No_Name then if not Quiet_Output then @@ -2255,9 +2256,8 @@ package body Prj.Proc is Check (In_Tree, Project, Flags); end if; - -- If main project is an extending all project, set the object - -- directory of all virtual extending projects to the object - -- directory of the main project. + -- If main project is an extending all project, set object directory of + -- all virtual extending projects to object directory of main project. if Project /= No_Project and then @@ -2424,12 +2424,13 @@ package body Prj.Proc is declare Imported : Project_List; Declaration_Node : Project_Node_Id := Empty_Node; - Name : constant Name_Id := - Name_Of - (From_Project_Node, From_Project_Node_Tree); - Name_Node : constant Tree_Private_Part.Project_Name_And_Node := - Tree_Private_Part.Projects_Htable.Get - (From_Project_Node_Tree.Projects_HT, Name); + + Name : constant Name_Id := + Name_Of (From_Project_Node, From_Project_Node_Tree); + + Name_Node : constant Tree_Private_Part.Project_Name_And_Node := + Tree_Private_Part.Projects_Htable.Get + (From_Project_Node_Tree.Projects_HT, Name); begin Project := Processed_Projects.Get (Name); diff --git a/gcc/ada/prj-proc.ads b/gcc/ada/prj-proc.ads index 40b5bf35d19..4257c9004f8 100644 --- a/gcc/ada/prj-proc.ads +++ b/gcc/ada/prj-proc.ads @@ -40,7 +40,7 @@ package Prj.Proc is Flags : Prj.Processing_Flags; Reset_Tree : Boolean := True); -- Process a project tree (ie the direct resulting of parsing a .gpr file) - -- based on the current scenario variables. + -- based on the current external references. -- -- The result of this phase_1 is a partial project tree (Project) where -- only a few fields have been initialized (in particular the list of diff --git a/gcc/ada/prj-tree.adb b/gcc/ada/prj-tree.adb index 08e4977c056..4823a988d6c 100644 --- a/gcc/ada/prj-tree.adb +++ b/gcc/ada/prj-tree.adb @@ -983,6 +983,10 @@ package body Prj.Tree is begin Project_Node_Table.Init (Tree.Project_Nodes); Projects_Htable.Reset (Tree.Projects_HT); + + -- Do not reset the external references, in case we are reloading a + -- project, since we want to preserve the current environment + -- Name_To_Name_HTable.Reset (Tree.External_References); end Initialize; ---------- diff --git a/gcc/ada/prj-tree.ads b/gcc/ada/prj-tree.ads index e587d3705aa..53f2eefc8b8 100644 --- a/gcc/ada/prj-tree.ads +++ b/gcc/ada/prj-tree.ads @@ -1000,9 +1000,8 @@ package Prj.Tree is package Tree_Private_Part is - -- This is conceptually in the private part - - -- However, for efficiency, some packages are accessing it directly + -- This is conceptually in the private part. However, for efficiency, + -- some packages are accessing it directly. type Project_Node_Record is record @@ -1371,11 +1370,36 @@ package Prj.Tree is end Tree_Private_Part; + package Name_To_Name_HTable is new GNAT.Dynamic_HTables.Simple_HTable + (Header_Num => Header_Num, + Element => Name_Id, + No_Element => No_Name, + Key => Name_Id, + Hash => Hash, + Equal => "="); + -- Comment required describing what this table is used for ??? + type Project_Node_Tree_Data is record Project_Nodes : Tree_Private_Part.Project_Node_Table.Instance; Projects_HT : Tree_Private_Part.Projects_Htable.Instance; + + External_References : Name_To_Name_HTable.Instance; + -- External references are stored in this hash table (and manipulated + -- through subprogrames in prj-ext.ads). External references are + -- project-tree specific so that one can load the same tree twice but + -- have two views of it, for instance. + + Project_Path : String_Access; + -- The project path, manipulated through subprograms in prj-ext.ads. + -- As a special case, if the first character is '#:" or this variable is + -- unset, this means that the PATH has not been fully initialized yet + -- (although subprograms prj-ext.ads will properly take care of that). + -- + -- The project path is tree specific, since we might want to load + -- simultaneously multiple projects, each with its own search path, in + -- particular when using different compilers with different default + -- search directories. end record; - -- The data for a project node tree procedure Free (Proj : in out Project_Node_Tree_Ref); -- Free memory used by Prj diff --git a/gcc/ada/s-oscons-tmplt.c b/gcc/ada/s-oscons-tmplt.c index bce8648209b..c1075d68126 100644 --- a/gcc/ada/s-oscons-tmplt.c +++ b/gcc/ada/s-oscons-tmplt.c @@ -58,7 +58,7 @@ pragma Style_Checks ("M32766"); ** s-oscons-tmpl.s. ** ** The default one assumes that the template can be compiled by the newly- - ** build cross compiler. It uses markup produced in the (pseudo-)assembly + ** built cross compiler. It uses markup produced in the (pseudo-)assembly ** listing: ** ** xgcc -DTARGET=\"$target\" -C -E s-oscons-tmplt.c > s-oscons-tmplt.i diff --git a/gcc/ada/switch-m.adb b/gcc/ada/switch-m.adb index 8456ea32b58..316b77e702b 100644 --- a/gcc/ada/switch-m.adb +++ b/gcc/ada/switch-m.adb @@ -532,8 +532,9 @@ package body Switch.M is ------------------------ procedure Scan_Make_Switches - (Switch_Chars : String; - Success : out Boolean) + (Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref; + Switch_Chars : String; + Success : out Boolean) is Ptr : Integer := Switch_Chars'First; Max : constant Integer := Switch_Chars'Last; @@ -590,7 +591,8 @@ package body Switch.M is and then Switch_Chars (Ptr .. Ptr + 1) = "aP" then Add_Search_Project_Directory - (Switch_Chars (Ptr + 2 .. Switch_Chars'Last)); + (Project_Node_Tree, + Switch_Chars (Ptr + 2 .. Switch_Chars'Last)); elsif C = 'v' and then Switch_Chars'Length = 3 then Ptr := Ptr + 1; diff --git a/gcc/ada/switch-m.ads b/gcc/ada/switch-m.ads index 9a6124b4640..a7301761f93 100644 --- a/gcc/ada/switch-m.ads +++ b/gcc/ada/switch-m.ads @@ -30,17 +30,21 @@ -- the otherwise undocumented debug switches that are also recognized. with System.OS_Lib; use System.OS_Lib; +with Prj.Tree; package Switch.M is procedure Scan_Make_Switches - (Switch_Chars : String; - Success : out Boolean); + (Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref; + Switch_Chars : String; + Success : out Boolean); -- Scan a gnatmake switch and act accordingly. For switches that are -- recognized, Success is set to True. A switch that is not recognized and -- consists of one small letter causes a fatal error exit and control does -- not return. For all other not recognized switches, Success is set to -- False, so that the switch may be passed to the compiler. + -- Project_Node_Tree is used to store tree-specific parameters like the + -- project path procedure Normalize_Compiler_Switches (Switch_Chars : String; diff --git a/gcc/c-decl.c b/gcc/c-decl.c index ed8863dddd9..c44e35cff46 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -6859,6 +6859,11 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, } C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0; + /* Update type location to the one of the definition, instead of e.g. + a forward declaration. */ + if (TYPE_STUB_DECL (t)) + DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc; + /* Finish debugging output for this type. */ rest_of_type_compilation (t, toplevel); diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c index 5744108b5d4..b063f898507 100644 --- a/gcc/cfgbuild.c +++ b/gcc/cfgbuild.c @@ -485,9 +485,9 @@ find_bb_boundaries (basic_block bb) if (!flow_transfer_insn) flow_transfer_insn = prev_nonnote_insn_bb (insn); } - else if (control_flow_insn_p (insn)) - flow_transfer_insn = insn; + if (control_flow_insn_p (insn)) + flow_transfer_insn = insn; if (insn == end) break; insn = NEXT_INSN (insn); diff --git a/gcc/cfglayout.c b/gcc/cfglayout.c index bc8ed8b7f32..d6d1b3ab697 100644 --- a/gcc/cfglayout.c +++ b/gcc/cfglayout.c @@ -787,6 +787,17 @@ fixup_reorder_chain (void) { if (any_condjump_p (bb_end_insn)) { + /* This might happen if the conditional jump has side + effects and could therefore not be optimized away. + Make the basic block to end with a barrier in order + to prevent rtl_verify_flow_info from complaining. */ + if (!e_fall) + { + gcc_assert (!onlyjump_p (bb_end_insn)); + bb->il.rtl->footer = emit_barrier_after (bb_end_insn); + continue; + } + /* If the old fallthru is still next, nothing to do. */ if (bb->aux == e_fall->dest || e_fall->dest == EXIT_BLOCK_PTR) diff --git a/gcc/common.opt b/gcc/common.opt index e3322a720ae..d15996662bd 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -557,6 +557,10 @@ feliminate-dwarf2-dups Common Report Var(flag_eliminate_dwarf2_dups) Perform DWARF2 duplicate elimination +fipa-sra +Common Report Var(flag_ipa_sra) Init(0) Optimization +Perform interprocedural reduction of aggregates + feliminate-unused-debug-symbols Common Report Var(flag_debug_only_used_symbols) Perform unused type elimination in debug info diff --git a/gcc/config/dfp-bit.c b/gcc/config/dfp-bit.c index d315d5b56f0..19f2fdae67d 100644 --- a/gcc/config/dfp-bit.c +++ b/gcc/config/dfp-bit.c @@ -568,7 +568,6 @@ INT_TO_DFP (INT_TYPE i) decContext context; decContextDefault (&context, DEC_INIT_DECIMAL128); - context.round = DEC_ROUND_DOWN; f64 = *DEC_FLOAT_FROM_INT (&f64, i); u32.f = *decSingleFromWider (&u32.f, &f64, &context); if (DFP_EXCEPTIONS_ENABLED && context.status != 0) @@ -593,7 +592,7 @@ INT_TO_DFP (INT_TYPE i) DFP_INIT_ROUNDMODE (context.round); /* Use a C library function to get a floating point string. */ - sprintf (buf, INT_FMT ".0", CAST_FOR_FMT(i)); + sprintf (buf, INT_FMT ".", CAST_FOR_FMT(i)); /* Convert from the floating point string to a decimal* type. */ FROM_STRING (&s, buf, &context); IEEE_TO_HOST (s, &f); diff --git a/gcc/config/m32c/m32c.c b/gcc/config/m32c/m32c.c index ae4c8973dea..1bf3d1bcb2f 100644 --- a/gcc/config/m32c/m32c.c +++ b/gcc/config/m32c/m32c.c @@ -4052,8 +4052,26 @@ m32c_emit_epilogue (void) if (!bank_switch_p (cfun->decl) && cfun->machine->intr_pushm) emit_insn (gen_popm (GEN_INT (cfun->machine->intr_pushm))); + /* The FREIT (Fast REturn from InTerrupt) instruction should be + generated only for M32C/M32CM targets (generate the REIT + instruction otherwise). */ if (fast_interrupt_p (cfun->decl)) - emit_jump_insn (gen_epilogue_freit ()); + { + /* Check if fast_attribute is set for M32C or M32CM. */ + if (TARGET_A24) + { + emit_jump_insn (gen_epilogue_freit ()); + } + /* If fast_interrupt attribute is set for an R8C or M16C + target ignore this attribute and generated REIT + instruction. */ + else + { + warning (OPT_Wattributes, + "%<fast_interrupt%> attribute directive ignored"); + emit_jump_insn (gen_epilogue_reit_16 ()); + } + } else if (TARGET_A16) emit_jump_insn (gen_epilogue_reit_16 ()); else diff --git a/gcc/config/pa/t-hpux-shlib b/gcc/config/pa/t-hpux-shlib index 66556d4cbd1..d5a5b6c8609 100644 --- a/gcc/config/pa/t-hpux-shlib +++ b/gcc/config/pa/t-hpux-shlib @@ -26,6 +26,7 @@ SHLIB_DIR = @multilib_dir@ SHLIB_SLIBDIR_QUAL = @shlib_slibdir_qual@ SHLIB_LINK = $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -shared -nodefaultlibs \ + -Wl,+h -Wl,$(SHLIB_SONAME) \ -o $(SHLIB_DIR)/$(SHLIB_NAME).tmp @multilib_flags@ $(SHLIB_OBJS) && \ rm -f $(SHLIB_DIR)/$(SHLIB_SONAME) && \ if [ -f $(SHLIB_DIR)/$(SHLIB_NAME) ]; then \ diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 93b90b5c0ee..8bf0dde4226 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-09-17 Andrew Pinski <pinskia@gcc.gnu.org> + + PR c++/39365 + * g++.dg/expr/bool3.C: New test. + * g++.dg/expr/bool4.C: New test. + 2009-09-14 Richard Henderson <rth@redhat.com> Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index cdc6a10a825..aff002dc666 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1287,7 +1287,7 @@ type_promotes_to (tree type) /* bool always promotes to int (not unsigned), even if it's the same size. */ - if (type == boolean_type_node) + if (TREE_CODE (type) == BOOLEAN_TYPE) type = integer_type_node; /* Normally convert enums to int, but convert wide enums to something diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 53165b38dc3..059511396c5 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4556,7 +4556,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, return error_mark_node; /* Forbid using -- on `bool'. */ - if (same_type_p (declared_type, boolean_type_node)) + if (TREE_CODE (declared_type) == BOOLEAN_TYPE) { if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR) { @@ -6787,7 +6787,7 @@ convert_for_assignment (tree type, tree rhs, /* If -Wparentheses, warn about a = b = c when a has type bool and b does not. */ if (warn_parentheses - && type == boolean_type_node + && TREE_CODE (type) == BOOLEAN_TYPE && TREE_CODE (rhs) == MODIFY_EXPR && !TREE_NO_WARNING (rhs) && TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index bad291122e7..f812d6159ff 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -335,7 +335,7 @@ Objective-C and Objective-C++ Dialects}. -fcse-follow-jumps -fcse-skip-blocks -fcx-fortran-rules -fcx-limited-range @gol -fdata-sections -fdce -fdce @gol -fdelayed-branch -fdelete-null-pointer-checks -fdse -fdse @gol --fearly-inlining -fexpensive-optimizations -ffast-math @gol +-fearly-inlining -fipa-sra -fexpensive-optimizations -ffast-math @gol -ffinite-math-only -ffloat-store -fexcess-precision=@var{style} @gol -fforward-propagate -ffunction-sections @gol -fgcse -fgcse-after-reload -fgcse-las -fgcse-lm @gol @@ -5664,6 +5664,7 @@ also turns on the following optimization flags: -fgcse -fgcse-lm @gol -finline-small-functions @gol -findirect-inlining @gol +-fipa-sra @gol -foptimize-sibling-calls @gol -fpeephole2 @gol -fregmove @gol @@ -5824,6 +5825,14 @@ having large chains of nested wrapper functions. Enabled by default. +@item -fipa-sra +@opindex fipa-sra +Perform interprocedural scalar replacement of aggregates, removal of +unused parameters and replacement of parameters passed by reference +by parameters passed by value. + +Enabled at levels @option{-O2}, @option{-O3} and @option{-Os}. + @item -finline-limit=@var{n} @opindex finline-limit By default, GCC limits the size of functions that can be inlined. This flag @@ -8132,6 +8141,12 @@ the parameter is reserved exclusively for debug insns created by @option{-fvar-tracking-assignments}, but debug insns may get (non-overlapping) uids above it if the reserved range is exhausted. +@item ipa-sra-ptr-growth-factor +IPA-SRA will replace a pointer to an aggregate with one or more new +parameters only when their cumulative size is less or equal to +@option{ipa-sra-ptr-growth-factor} times the size of the original +pointer parameter. + @end table @end table diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 14836d539e8..d2d2fefd153 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -89,6 +89,8 @@ along with GCC; see the file COPYING3. If not see #include "hashtab.h" #include "cgraph.h" #include "input.h" +#include "gimple.h" +#include "tree-pass.h" #ifdef DWARF2_DEBUGGING_INFO static void dwarf2out_source_line (unsigned int, const char *, int, bool); @@ -4655,6 +4657,16 @@ loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset) } } +/* Add a constant OFFSET to a location list. */ + +static void +loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset) +{ + dw_loc_list_ref d; + for (d = list_head; d != NULL; d = d->dw_loc_next) + loc_descr_plus_const (&d->expr, offset); +} + /* Return the size of a location descriptor. */ static unsigned long @@ -5938,8 +5950,8 @@ static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx, enum var_init_status); static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode, enum var_init_status); -static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int); -static dw_loc_descr_ref loc_descriptor_from_tree (tree); +static dw_loc_list_ref loc_list_from_tree (tree, int); +static dw_loc_descr_ref loc_descriptor_from_tree (tree, int); static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int); static tree field_type (const_tree); static unsigned int simple_type_align_in_bits (const_tree); @@ -5947,7 +5959,7 @@ static unsigned int simple_decl_align_in_bits (const_tree); static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree); static HOST_WIDE_INT field_byte_offset (const_tree); static void add_AT_location_description (dw_die_ref, enum dwarf_attribute, - dw_loc_descr_ref); + dw_loc_list_ref); static void add_data_member_location_attribute (dw_die_ref, tree); static void add_const_value_attribute (dw_die_ref, rtx); static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *); @@ -10958,36 +10970,6 @@ is_based_loc (const_rtx rtl) && CONST_INT_P (XEXP (rtl, 1))))); } -/* Return a descriptor that describes the concatenation of N locations - used to form the address of a memory location. */ - -static dw_loc_descr_ref -concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode, - enum var_init_status initialized) -{ - unsigned int i; - dw_loc_descr_ref cc_loc_result = NULL; - unsigned int n = XVECLEN (concatn, 0); - - for (i = 0; i < n; ++i) - { - dw_loc_descr_ref ref; - rtx x = XVECEXP (concatn, 0, i); - - ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED); - if (ref == NULL) - return NULL; - - add_loc_descr (&cc_loc_result, ref); - add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x))); - } - - if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED) - add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0)); - - return cc_loc_result; -} - /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0) failed. */ @@ -11006,7 +10988,7 @@ tls_mem_loc_descriptor (rtx mem) || !DECL_THREAD_LOCAL_P (base)) return NULL; - loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2); + loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 2); if (loc_result == NULL) return NULL; @@ -11016,6 +10998,26 @@ tls_mem_loc_descriptor (rtx mem) return loc_result; } +/* Output debug info about reason why we failed to expand expression as dwarf + expression. */ + +static void +expansion_failed (tree expr, rtx rtl, char const *reason) +{ + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Failed to expand as dwarf: "); + if (expr) + print_generic_expr (dump_file, expr, dump_flags); + if (rtl) + { + fprintf (dump_file, "\n"); + print_rtl (dump_file, rtl); + } + fprintf (dump_file, "\nReason: %s\n", reason); + } +} + /* The following routine converts the RTL for a variable or parameter (resident in memory) into an equivalent Dwarf representation of a mechanism for getting the address of that same variable onto the top of a @@ -11163,7 +11165,11 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode, FIXME: might try to use DW_OP_const_value here, though DW_OP_piece complicates it. */ if (!marked) - return 0; + { + expansion_failed (NULL_TREE, rtl, + "Constant was removed from constant pool.\n"); + return 0; + } } if (GET_CODE (rtl) == SYMBOL_REF @@ -11193,6 +11199,14 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode, VEC_safe_push (rtx, gc, used_rtx_array, rtl); break; + case CONCAT: + case CONCATN: + case VAR_LOCATION: + expansion_failed (NULL_TREE, rtl, + "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor"); + gcc_unreachable (); + return 0; + case PRE_MODIFY: /* Extract the PLUS expression nested inside and fall into PLUS code below. */ @@ -11322,11 +11336,6 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode, mem_loc_result = int_loc_descriptor (INTVAL (rtl)); break; - case CONCATN: - mem_loc_result = concatn_mem_loc_descriptor (rtl, mode, - VAR_INIT_STATUS_INITIALIZED); - break; - case EQ: op = DW_OP_eq; goto do_scompare; @@ -11768,7 +11777,7 @@ loc_descriptor (rtx rtl, enum machine_mode mode, break; case CONST_INT: - if (mode != VOIDmode && mode != BLKmode && dwarf_version >= 4) + if (mode != VOIDmode && mode != BLKmode) { HOST_WIDE_INT i = INTVAL (rtl); int litsize; @@ -11822,7 +11831,7 @@ loc_descriptor (rtx rtl, enum machine_mode mode, break; case CONST_DOUBLE: - if (mode != VOIDmode && dwarf_version >= 4) + if (mode != VOIDmode) { /* Note that a CONST_DOUBLE rtx could represent either an integer or a floating-point constant. A CONST_DOUBLE is used whenever @@ -11853,7 +11862,7 @@ loc_descriptor (rtx rtl, enum machine_mode mode, break; case CONST_VECTOR: - if (mode != VOIDmode && dwarf_version >= 4) + if (mode != VOIDmode) { unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl)); unsigned int length = CONST_VECTOR_NUNITS (rtl); @@ -11941,8 +11950,7 @@ loc_descriptor (rtx rtl, enum machine_mode mode, && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE) break; case LABEL_REF: - if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE - && dwarf_version >= 4) + if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE) { loc_result = new_loc_descr (DW_OP_implicit_value, DWARF2_ADDR_SIZE, 0); @@ -11954,8 +11962,7 @@ loc_descriptor (rtx rtl, enum machine_mode mode, default: if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode - && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE - && dwarf_version >= 4) + && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE) { /* Value expression. */ loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized); @@ -11972,16 +11979,310 @@ loc_descriptor (rtx rtl, enum machine_mode mode, return loc_result; } -/* Similar, but generate the descriptor from trees instead of rtl. This comes - up particularly with variable length arrays. WANT_ADDRESS is 2 if this is - a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a - top-level invocation, and we require the address of LOC; is 0 if we require - the value of LOC. */ +/* We need to figure out what section we should use as the base for the + address ranges where a given location is valid. + 1. If this particular DECL has a section associated with it, use that. + 2. If this function has a section associated with it, use that. + 3. Otherwise, use the text section. + XXX: If you split a variable across multiple sections, we won't notice. */ + +static const char * +secname_for_decl (const_tree decl) +{ + const char *secname; + + if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl)) + { + tree sectree = DECL_SECTION_NAME (decl); + secname = TREE_STRING_POINTER (sectree); + } + else if (current_function_decl && DECL_SECTION_NAME (current_function_decl)) + { + tree sectree = DECL_SECTION_NAME (current_function_decl); + secname = TREE_STRING_POINTER (sectree); + } + else if (cfun && in_cold_section_p) + secname = crtl->subsections.cold_section_label; + else + secname = text_section_label; + + return secname; +} + +/* Return true when DECL_BY_REFERENCE is defined and set for DECL. */ + +static bool +decl_by_reference_p (tree decl) +{ + return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL + || TREE_CODE (decl) == VAR_DECL) + && DECL_BY_REFERENCE (decl)); +} + + +/* Dereference a location expression LOC if DECL is passed by invisible + reference. */ static dw_loc_descr_ref -loc_descriptor_from_tree_1 (tree loc, int want_address) +loc_by_reference (dw_loc_descr_ref loc, tree decl) +{ + HOST_WIDE_INT size; + enum dwarf_location_atom op; + + if (loc == NULL) + return NULL; + + if (!decl_by_reference_p (decl)) + return loc; + + /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead + change it into corresponding DW_OP_breg{0...31,x} 0. Then the + location expression is considered to be address of a memory location, + rather than the register itself. */ + if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31) + || loc->dw_loc_opc == DW_OP_regx) + && (loc->dw_loc_next == NULL + || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit + && loc->dw_loc_next->dw_loc_next == NULL))) + { + if (loc->dw_loc_opc == DW_OP_regx) + { + loc->dw_loc_opc = DW_OP_bregx; + loc->dw_loc_oprnd2.v.val_int = 0; + } + else + { + loc->dw_loc_opc + = (enum dwarf_location_atom) + (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0)); + loc->dw_loc_oprnd1.v.val_int = 0; + } + return loc; + } + + size = int_size_in_bytes (TREE_TYPE (decl)); + if (size > DWARF2_ADDR_SIZE || size == -1) + return 0; + else if (size == DWARF2_ADDR_SIZE) + op = DW_OP_deref; + else + op = DW_OP_deref_size; + add_loc_descr (&loc, new_loc_descr (op, size, 0)); + return loc; +} + +/* Return dwarf representation of location list representing for + LOC_LIST of DECL. */ + +static dw_loc_list_ref +dw_loc_list (var_loc_list * loc_list, tree decl, bool toplevel) +{ + const char *endname, *secname; + dw_loc_list_ref list; + rtx varloc; + enum var_init_status initialized; + struct var_loc_node *node; + dw_loc_descr_ref descr; + char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; + + bool by_reference = decl_by_reference_p (decl); + + /* Now that we know what section we are using for a base, + actually construct the list of locations. + The first location information is what is passed to the + function that creates the location list, and the remaining + locations just get added on to that list. + Note that we only know the start address for a location + (IE location changes), so to build the range, we use + the range [current location start, next location start]. + This means we have to special case the last node, and generate + a range of [last location start, end of function label]. */ + + node = loc_list->first; + varloc = NOTE_VAR_LOCATION (node->var_loc_note); + secname = secname_for_decl (decl); + + if (NOTE_VAR_LOCATION_LOC (node->var_loc_note)) + initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note); + else + initialized = VAR_INIT_STATUS_INITIALIZED; + + if (!toplevel || by_reference) + { + gcc_assert (GET_CODE (varloc) == VAR_LOCATION); + /* Single part. */ + if (GET_CODE (XEXP (varloc, 1)) != PARALLEL) + descr = loc_by_reference (mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0), + TYPE_MODE (TREE_TYPE (decl)), + initialized), + decl); + else + descr = NULL; + } + else + descr = loc_descriptor (varloc, DECL_MODE (decl), initialized); + + if (!current_function_decl) + endname = text_end_label; + else + { + ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, + current_function_funcdef_no); + endname = ggc_strdup (label_id); + } + list = new_loc_list (descr, node->label, node->next ? node->next->label : endname, secname, 1); + node = node->next; + + if (!node) + return NULL; + + for (; node->next; node = node->next) + if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX) + { + /* The variable has a location between NODE->LABEL and + NODE->NEXT->LABEL. */ + enum var_init_status initialized = + NOTE_VAR_LOCATION_STATUS (node->var_loc_note); + varloc = NOTE_VAR_LOCATION (node->var_loc_note); + if (!toplevel || by_reference) + { + gcc_assert (GET_CODE (varloc) == VAR_LOCATION); + /* Single part. */ + if (GET_CODE (XEXP (varloc, 1)) != PARALLEL) + descr = mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0), + TYPE_MODE (TREE_TYPE (decl)), initialized); + else + descr = NULL; + descr = loc_by_reference (descr, decl); + } + else + descr = loc_descriptor (varloc, DECL_MODE (decl), initialized); + add_loc_descr_to_loc_list (&list, descr, + node->label, node->next->label, secname); + } + + /* If the variable has a location at the last label + it keeps its location until the end of function. */ + if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX) + { + enum var_init_status initialized = + NOTE_VAR_LOCATION_STATUS (node->var_loc_note); + + varloc = NOTE_VAR_LOCATION (node->var_loc_note); + if (!toplevel || by_reference) + { + gcc_assert (GET_CODE (varloc) == VAR_LOCATION); + /* Single part. */ + if (GET_CODE (XEXP (varloc, 1)) != PARALLEL) + descr = mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0), + TYPE_MODE (TREE_TYPE (decl)), initialized); + else + descr = NULL; + descr = loc_by_reference (descr, decl); + } + else + descr = loc_descriptor (varloc, DECL_MODE (decl), initialized); + add_loc_descr_to_loc_list (&list, descr, node->label, endname, secname); + } + return list; +} + +/* Return single element location list containing loc descr REF. */ + +static dw_loc_list_ref +single_element_loc_list (dw_loc_descr_ref ref) +{ + return new_loc_list (ref, NULL, NULL, NULL, 0); +} + +/* Return if the loc_list has only single element and thus can be represented + as location description. */ + +static bool +single_element_loc_list_p (dw_loc_list_ref list) { - dw_loc_descr_ref ret, ret1; + return (!list->dw_loc_next && !list->begin && !list->end); +} + +/* To each location in list LIST add loc descr REF. */ + +static void +add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref) +{ + dw_loc_descr_ref copy; + add_loc_descr (&list->expr, ref); + list = list->dw_loc_next; + while (list) + { + copy = GGC_CNEW (dw_loc_descr_node); + memcpy (copy, ref, sizeof (dw_loc_descr_node)); + add_loc_descr (&list->expr, copy); + while (copy->dw_loc_next) + { + dw_loc_descr_ref new_copy = GGC_CNEW (dw_loc_descr_node); + memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node)); + copy->dw_loc_next = new_copy; + copy = new_copy; + } + list = list->dw_loc_next; + } +} + +/* Given two lists RET and LIST + produce location list that is result of adding expression in LIST + to expression in RET on each possition in program. + Might be destructive on both RET and LIST. + + TODO: We handle only simple cases of RET or LIST having at most one + element. General case would inolve sorting the lists in program order + and merging them that will need some additional work. + Adding that will improve quality of debug info especially for SRA-ed + structures. */ + +static void +add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list) +{ + if (!list) + return; + if (!*ret) + { + *ret = list; + return; + } + if (!list->dw_loc_next) + { + add_loc_descr_to_each (*ret, list->expr); + return; + } + if (!(*ret)->dw_loc_next) + { + add_loc_descr_to_each (list, (*ret)->expr); + *ret = list; + return; + } + expansion_failed (NULL_TREE, NULL_RTX, + "Don't know how to merge two non-trivial" + " location lists.\n"); + *ret = NULL; + return; +} + +/* Generate Dwarf location list representing LOC. + If WANT_ADDRESS is false, expression computing LOC will be computed + If WANT_ADDRESS is 1, expression computing address of LOC will be returned + if WANT_ADDRESS is 2, expression computing address useable in location + will be returned (i.e. DW_OP_reg can be used + to refer to register values) + TODO: Dwarf4 adds types to the stack machine that ought to be used here + DW_OP_stack_value will help in cases where we fail to find address of the + expression. + */ + +static dw_loc_list_ref +loc_list_from_tree (tree loc, int want_address) +{ + dw_loc_descr_ref ret = NULL, ret1 = NULL; + dw_loc_list_ref list_ret = NULL, list_ret1 = NULL; int have_address = 0; enum dwarf_location_atom op; @@ -11992,6 +12293,7 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) switch (TREE_CODE (loc)) { case ERROR_MARK: + expansion_failed (loc, NULL_RTX, "ERROR_MARK"); return 0; case PLACEHOLDER_EXPR: @@ -11999,25 +12301,32 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) position of other fields. We don't try to encode this here. The only user of this is Ada, which encodes the needed information using the names of types. */ + expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR"); return 0; case CALL_EXPR: + expansion_failed (loc, NULL_RTX, "CALL_EXPR"); + /* There are no opcodes for these operations. */ return 0; case PREINCREMENT_EXPR: case PREDECREMENT_EXPR: case POSTINCREMENT_EXPR: case POSTDECREMENT_EXPR: + expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT"); /* There are no opcodes for these operations. */ return 0; case ADDR_EXPR: /* If we already want an address, there's nothing we can do. */ if (want_address) - return 0; + { + expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR"); + return 0; + } /* Otherwise, process the argument and look for the address. */ - return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1); + return loc_list_from_tree (TREE_OPERAND (loc, 0), 1); case VAR_DECL: if (DECL_THREAD_LOCAL_P (loc)) @@ -12030,7 +12339,7 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) if (targetm.have_tls) { /* If this is not defined, we have no way to emit the - data. */ + data. */ if (!targetm.asm_out.output_dwarf_dtprel) return 0; @@ -12077,17 +12386,24 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) case PARM_DECL: if (DECL_HAS_VALUE_EXPR_P (loc)) - return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc), - want_address); + return loc_list_from_tree (DECL_VALUE_EXPR (loc), + want_address); /* FALLTHRU */ case RESULT_DECL: case FUNCTION_DECL: { rtx rtl = rtl_for_decl_location (loc); + var_loc_list *loc_list = lookup_decl_loc (loc); - if (rtl == NULL_RTX) - return 0; + if (loc_list && loc_list->first + && (list_ret = dw_loc_list (loc_list, loc, want_address == 2))) + have_address = 1; + else if (rtl == NULL_RTX) + { + expansion_failed (loc, NULL_RTX, "DECL has no RTL"); + return 0; + } else if (CONST_INT_P (rtl)) { HOST_WIDE_INT val = INTVAL (rtl); @@ -12096,7 +12412,10 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) ret = int_loc_descriptor (val); } else if (GET_CODE (rtl) == CONST_STRING) - return 0; + { + expansion_failed (loc, NULL_RTX, "CONST_STRING"); + return 0; + } else if (CONSTANT_P (rtl)) { ret = new_loc_descr (DW_OP_addr, 0, 0); @@ -12109,33 +12428,41 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) /* Certain constructs can only be represented at top-level. */ if (want_address == 2) - return loc_descriptor (rtl, VOIDmode, - VAR_INIT_STATUS_INITIALIZED); - - mode = GET_MODE (rtl); - if (MEM_P (rtl)) { - rtl = XEXP (rtl, 0); + ret = loc_descriptor (rtl, VOIDmode, + VAR_INIT_STATUS_INITIALIZED); have_address = 1; } - ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED); + else + { + mode = GET_MODE (rtl); + if (MEM_P (rtl)) + { + rtl = XEXP (rtl, 0); + have_address = 1; + } + ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED); + } + if (!ret) + expansion_failed (loc, rtl, + "failed to produce loc descriptor for rtl"); } } break; case INDIRECT_REF: - ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); + list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0); have_address = 1; break; case COMPOUND_EXPR: - return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address); + return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address); CASE_CONVERT: case VIEW_CONVERT_EXPR: case SAVE_EXPR: case MODIFY_EXPR: - return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address); + return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address); case COMPONENT_REF: case BIT_FIELD_REF: @@ -12151,26 +12478,35 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, &unsignedp, &volatilep, false); - if (obj == loc) - return 0; + gcc_assert (obj != loc); - ret = loc_descriptor_from_tree_1 (obj, 1); - if (ret == 0 - || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) + list_ret = loc_list_from_tree (obj, 1); + if (list_ret == 0) return 0; + if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) + { + expansion_failed (loc, NULL_RTX, + "bitfield access"); + return 0; + } if (offset != NULL_TREE) { /* Variable offset. */ - ret1 = loc_descriptor_from_tree_1 (offset, 0); - if (ret1 == 0) + list_ret1 = loc_list_from_tree (offset, 0); + if (list_ret1 == 0) return 0; - add_loc_descr (&ret, ret1); - add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); + add_loc_list (&list_ret, list_ret1); + if (!list_ret) + return 0; + add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0)); } bytepos = bitpos / BITS_PER_UNIT; - loc_descr_plus_const (&ret, bytepos); + if (bytepos > 0) + add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); + else if (bytepos < 0) + loc_list_plus_const (list_ret, bytepos); have_address = 1; break; @@ -12180,7 +12516,11 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) if (host_integerp (loc, 0)) ret = int_loc_descriptor (tree_low_cst (loc, 0)); else - return 0; + { + expansion_failed (loc, NULL_RTX, + "Integer operand is not host integer"); + return 0; + } break; case CONSTRUCTOR: @@ -12250,11 +12590,11 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST && host_integerp (TREE_OPERAND (loc, 1), 0)) { - ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); - if (ret == 0) + list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0); + if (list_ret == 0) return 0; - loc_descr_plus_const (&ret, tree_low_cst (TREE_OPERAND (loc, 1), 0)); + loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0)); break; } @@ -12298,13 +12638,15 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) goto do_binop; do_binop: - ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); - ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0); - if (ret == 0 || ret1 == 0) + list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0); + list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0); + if (list_ret == 0 || list_ret1 == 0) return 0; - add_loc_descr (&ret, ret1); - add_loc_descr (&ret, new_loc_descr (op, 0, 0)); + add_loc_list (&list_ret, list_ret1); + if (list_ret == 0) + return 0; + add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0)); break; case TRUTH_NOT_EXPR: @@ -12321,11 +12663,11 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) goto do_unop; do_unop: - ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); - if (ret == 0) + list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0); + if (list_ret == 0) return 0; - add_loc_descr (&ret, new_loc_descr (op, 0, 0)); + add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0)); break; case MIN_EXPR: @@ -12345,29 +12687,29 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) case COND_EXPR: { dw_loc_descr_ref lhs - = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0); - dw_loc_descr_ref rhs - = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0); + = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); + dw_loc_list_ref rhs + = loc_list_from_tree (TREE_OPERAND (loc, 2), 0); dw_loc_descr_ref bra_node, jump_node, tmp; - ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); - if (ret == 0 || lhs == 0 || rhs == 0) + list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0); + if (list_ret == 0 || lhs == 0 || rhs == 0) return 0; bra_node = new_loc_descr (DW_OP_bra, 0, 0); - add_loc_descr (&ret, bra_node); + add_loc_descr_to_each (list_ret, bra_node); - add_loc_descr (&ret, rhs); + add_loc_list (&list_ret, rhs); jump_node = new_loc_descr (DW_OP_skip, 0, 0); - add_loc_descr (&ret, jump_node); + add_loc_descr_to_each (list_ret, jump_node); - add_loc_descr (&ret, lhs); + add_loc_descr_to_each (list_ret, lhs); bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; bra_node->dw_loc_oprnd1.v.val_loc = lhs; /* ??? Need a node to point the skip at. Use a nop. */ tmp = new_loc_descr (DW_OP_nop, 0, 0); - add_loc_descr (&ret, tmp); + add_loc_descr_to_each (list_ret, tmp); jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; jump_node->dw_loc_oprnd1.v.val_loc = tmp; } @@ -12381,7 +12723,11 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) up, for instance, with the C STMT_EXPR. */ if ((unsigned int) TREE_CODE (loc) >= (unsigned int) LAST_AND_UNUSED_TREE_CODE) - return 0; + { + expansion_failed (loc, NULL_RTX, + "language specific tree node"); + return 0; + } #ifdef ENABLE_CHECKING /* Otherwise this is a generic code; we should just lists all of @@ -12394,32 +12740,60 @@ loc_descriptor_from_tree_1 (tree loc, int want_address) #endif } + if (!ret && !list_ret) + return 0; + /* Show if we can't fill the request for an address. */ if (want_address && !have_address) - return 0; + { + expansion_failed (loc, NULL_RTX, + "Want address and only have value"); + return 0; + } + + gcc_assert (!ret || !list_ret); /* If we've got an address and don't want one, dereference. */ - if (!want_address && have_address && ret) + if (!want_address && have_address) { HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); if (size > DWARF2_ADDR_SIZE || size == -1) - return 0; + { + expansion_failed (loc, NULL_RTX, + "DWARF address size mismatch"); + return 0; + } else if (size == DWARF2_ADDR_SIZE) op = DW_OP_deref; else op = DW_OP_deref_size; - add_loc_descr (&ret, new_loc_descr (op, size, 0)); + if (ret) + add_loc_descr (&ret, new_loc_descr (op, size, 0)); + else + add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0)); } + if (ret) + list_ret = single_element_loc_list (ret); - return ret; + return list_ret; } -static inline dw_loc_descr_ref -loc_descriptor_from_tree (tree loc) +/* Same as above but return only single location expression. */ +static dw_loc_descr_ref +loc_descriptor_from_tree (tree loc, int want_address) { - return loc_descriptor_from_tree_1 (loc, 2); + dw_loc_list_ref ret = loc_list_from_tree (loc, want_address); + if (!ret) + return NULL; + if (ret->dw_loc_next) + { + expansion_failed (loc, NULL_RTX, + "Location list where only loc descriptor needed"); + return NULL; + } + return ret->expr; } /* Given a value, round it up to the lowest multiple of `boundary' @@ -12529,9 +12903,9 @@ field_byte_offset (const_tree decl) field_size_tree = DECL_SIZE (decl); /* The size could be unspecified if there was an error, or for - a flexible array member. */ + a flexible array member. */ if (!field_size_tree) - field_size_tree = bitsize_zero_node; + field_size_tree = bitsize_zero_node; /* If the size of the field is not constant, use the type size. */ if (host_integerp (field_size_tree, 1)) @@ -12626,10 +13000,14 @@ field_byte_offset (const_tree decl) static inline void add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind, - dw_loc_descr_ref descr) + dw_loc_list_ref descr) { - if (descr != 0) - add_AT_loc (die, attr_kind, descr); + if (descr == 0) + return; + if (single_element_loc_list_p (descr)) + add_AT_loc (die, attr_kind, descr->expr); + else + add_AT_loc_list (die, attr_kind, descr); } /* Attach the specialized form of location attribute used for data members of @@ -13267,36 +13645,6 @@ rtl_for_decl_location (tree decl) return rtl; } -/* We need to figure out what section we should use as the base for the - address ranges where a given location is valid. - 1. If this particular DECL has a section associated with it, use that. - 2. If this function has a section associated with it, use that. - 3. Otherwise, use the text section. - XXX: If you split a variable across multiple sections, we won't notice. */ - -static const char * -secname_for_decl (const_tree decl) -{ - const char *secname; - - if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl)) - { - tree sectree = DECL_SECTION_NAME (decl); - secname = TREE_STRING_POINTER (sectree); - } - else if (current_function_decl && DECL_SECTION_NAME (current_function_decl)) - { - tree sectree = DECL_SECTION_NAME (current_function_decl); - secname = TREE_STRING_POINTER (sectree); - } - else if (cfun && in_cold_section_p) - secname = crtl->subsections.cold_section_label; - else - secname = text_section_label; - - return secname; -} - /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is returned. If so, the decl for the COMMON block is returned, and the value is the offset into the common block for the symbol. */ @@ -13347,60 +13695,6 @@ fortran_common (tree decl, HOST_WIDE_INT *value) return cvar; } -/* Dereference a location expression LOC if DECL is passed by invisible - reference. */ - -static dw_loc_descr_ref -loc_by_reference (dw_loc_descr_ref loc, tree decl) -{ - HOST_WIDE_INT size; - enum dwarf_location_atom op; - - if (loc == NULL) - return NULL; - - if ((TREE_CODE (decl) != PARM_DECL - && TREE_CODE (decl) != RESULT_DECL - && TREE_CODE (decl) != VAR_DECL) - || !DECL_BY_REFERENCE (decl)) - return loc; - - /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead - change it into corresponding DW_OP_breg{0...31,x} 0. Then the - location expression is considered to be address of a memory location, - rather than the register itself. */ - if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31) - || loc->dw_loc_opc == DW_OP_regx) - && (loc->dw_loc_next == NULL - || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit - && loc->dw_loc_next->dw_loc_next == NULL))) - { - if (loc->dw_loc_opc == DW_OP_regx) - { - loc->dw_loc_opc = DW_OP_bregx; - loc->dw_loc_oprnd2.v.val_int = 0; - } - else - { - loc->dw_loc_opc - = (enum dwarf_location_atom) - (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0)); - loc->dw_loc_oprnd1.v.val_int = 0; - } - return loc; - } - - size = int_size_in_bytes (TREE_TYPE (decl)); - if (size > DWARF2_ADDR_SIZE || size == -1) - return 0; - else if (size == DWARF2_ADDR_SIZE) - op = DW_OP_deref; - else - op = DW_OP_deref_size; - add_loc_descr (&loc, new_loc_descr (op, size, 0)); - return loc; -} - /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value data attribute for a variable or a parameter. We generate the DW_AT_const_value attribute only in those cases where the given variable @@ -13418,6 +13712,7 @@ add_location_or_const_value_attribute (dw_die_ref die, tree decl, { rtx rtl; dw_loc_descr_ref descr; + dw_loc_list_ref descr_list; var_loc_list *loc_list; struct var_loc_node *node; if (TREE_CODE (decl) == ERROR_MARK) @@ -13539,18 +13834,18 @@ add_location_or_const_value_attribute (dw_die_ref die, tree decl, if (descr) { descr = loc_by_reference (descr, decl); - add_AT_location_description (die, attr, descr); + add_AT_location_description (die, attr, single_element_loc_list (descr)); return; } } /* We couldn't get any rtl, so try directly generating the location description from the tree. */ - descr = loc_descriptor_from_tree (decl); - if (descr) + descr_list = loc_list_from_tree (decl, 2); + if (descr_list) { descr = loc_by_reference (descr, decl); - add_AT_location_description (die, attr, descr); + add_AT_location_description (die, attr, descr_list); return; } /* None of that worked, so it must not really have a location; @@ -13967,7 +14262,7 @@ add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree b case RESULT_DECL: { dw_die_ref decl_die = lookup_decl_die (bound); - dw_loc_descr_ref loc; + dw_loc_list_ref loc; /* ??? Can this happen, or should the variable have been bound first? Probably it can, since I imagine that we try to create @@ -13978,7 +14273,7 @@ add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree b add_AT_die_ref (subrange_die, bound_attr, decl_die); else { - loc = loc_descriptor_from_tree_1 (bound, 0); + loc = loc_list_from_tree (bound, 0); add_AT_location_description (subrange_die, bound_attr, loc); } break; @@ -13990,10 +14285,10 @@ add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree b evaluate the value of the array bound. */ dw_die_ref ctx, decl_die; - dw_loc_descr_ref loc; + dw_loc_list_ref list; - loc = loc_descriptor_from_tree (bound); - if (loc == NULL) + list = loc_list_from_tree (bound, 2); + if (list == NULL) break; if (current_function_decl == 0) @@ -14004,7 +14299,10 @@ add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree b decl_die = new_die (DW_TAG_variable, ctx, bound); add_AT_flag (decl_die, DW_AT_artificial, 1); add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); - add_AT_loc (decl_die, DW_AT_location, loc); + if (list->dw_loc_next) + add_AT_loc_list (decl_die, DW_AT_location, list); + else + add_AT_loc (decl_die, DW_AT_location, list->expr); add_AT_die_ref (subrange_die, bound_attr, decl_die); break; @@ -14610,12 +14908,12 @@ gen_array_type_die (tree type, dw_die_ref context_die) && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))) { tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); - dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl); + dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2); size = int_size_in_bytes (TREE_TYPE (szdecl)); if (loc && size > 0) { - add_AT_loc (array_die, DW_AT_string_length, loc); + add_AT_location_description (array_die, DW_AT_string_length, loc); if (size != DWARF2_ADDR_SIZE) add_AT_unsigned (array_die, DW_AT_byte_size, size); } @@ -14709,7 +15007,7 @@ descr_info_loc (tree val, tree base_decl) CASE_CONVERT: return descr_info_loc (TREE_OPERAND (val, 0), base_decl); case VAR_DECL: - return loc_descriptor_from_tree_1 (val, 0); + return loc_descriptor_from_tree (val, 0); case INTEGER_CST: if (host_integerp (val, 0)) return int_loc_descriptor (tree_low_cst (val, 0)); @@ -15015,7 +15313,7 @@ gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die) { tree type = TREE_TYPE (node); add_name_and_src_coords_attributes (parm_die, node); - if (DECL_BY_REFERENCE (node)) + if (decl_by_reference_p (node)) add_type_attribute (parm_die, TREE_TYPE (type), 0, 0, context_die); else @@ -15467,7 +15765,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) if (cfun->static_chain_decl) add_AT_location_description (subr_die, DW_AT_static_link, - loc_descriptor_from_tree (cfun->static_chain_decl)); + loc_list_from_tree (cfun->static_chain_decl, 2)); } /* Generate child dies for template paramaters. */ @@ -15637,7 +15935,7 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die) { tree field; dw_die_ref com_die; - dw_loc_descr_ref loc; + dw_loc_list_ref loc; die_node com_die_arg; var_die = lookup_decl_die (decl_or_origin); @@ -15645,22 +15943,23 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die) { if (get_AT (var_die, DW_AT_location) == NULL) { - loc = loc_descriptor_from_tree (com_decl); + loc = loc_list_from_tree (com_decl, off ? 1 : 2); if (loc) { if (off) { /* Optimize the common case. */ - if (loc->dw_loc_opc == DW_OP_addr - && loc->dw_loc_next == NULL - && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) + if (single_element_loc_list_p (loc) + && loc->expr->dw_loc_opc == DW_OP_addr + && loc->expr->dw_loc_next == NULL + && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF) - loc->dw_loc_oprnd1.v.val_addr - = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off); + loc->expr->dw_loc_oprnd1.v.val_addr + = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off); else - loc_descr_plus_const (&loc, off); + loc_list_plus_const (loc, off); } - add_AT_loc (var_die, DW_AT_location, loc); + add_AT_location_description (var_die, DW_AT_location, loc); remove_AT (var_die, DW_AT_declaration); } } @@ -15676,7 +15975,7 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die) com_die_arg.decl_id = DECL_UID (com_decl); com_die_arg.die_parent = context_die; com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg); - loc = loc_descriptor_from_tree (com_decl); + loc = loc_list_from_tree (com_decl, 2); if (com_die == NULL) { const char *cnam @@ -15687,10 +15986,10 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die) add_name_and_src_coords_attributes (com_die, com_decl); if (loc) { - add_AT_loc (com_die, DW_AT_location, loc); + add_AT_location_description (com_die, DW_AT_location, loc); /* Avoid sharing the same loc descriptor between DW_TAG_common_block and DW_TAG_variable. */ - loc = loc_descriptor_from_tree (com_decl); + loc = loc_list_from_tree (com_decl, 2); } else if (DECL_EXTERNAL (decl)) add_AT_flag (com_die, DW_AT_declaration, 1); @@ -15701,8 +16000,8 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die) } else if (get_AT (com_die, DW_AT_location) == NULL && loc) { - add_AT_loc (com_die, DW_AT_location, loc); - loc = loc_descriptor_from_tree (com_decl); + add_AT_location_description (com_die, DW_AT_location, loc); + loc = loc_list_from_tree (com_decl, 2); remove_AT (com_die, DW_AT_declaration); } var_die = new_die (DW_TAG_variable, com_die, decl); @@ -15715,15 +16014,16 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die) if (off) { /* Optimize the common case. */ - if (loc->dw_loc_opc == DW_OP_addr - && loc->dw_loc_next == NULL - && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF) - loc->dw_loc_oprnd1.v.val_addr - = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off); + if (single_element_loc_list_p (loc) + && loc->expr->dw_loc_opc == DW_OP_addr + && loc->expr->dw_loc_next == NULL + && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF) + loc->expr->dw_loc_oprnd1.v.val_addr + = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off); else - loc_descr_plus_const (&loc, off); + loc_list_plus_const (loc, off); } - add_AT_loc (var_die, DW_AT_location, loc); + add_AT_location_description (var_die, DW_AT_location, loc); } else if (DECL_EXTERNAL (decl)) add_AT_flag (var_die, DW_AT_declaration, 1); @@ -15786,10 +16086,7 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die) tree type = TREE_TYPE (decl); add_name_and_src_coords_attributes (var_die, decl); - if ((TREE_CODE (decl) == PARM_DECL - || TREE_CODE (decl) == RESULT_DECL - || TREE_CODE (decl) == VAR_DECL) - && DECL_BY_REFERENCE (decl)) + if (decl_by_reference_p (decl)) add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die); else add_type_attribute (var_die, type, TREE_READONLY (decl), @@ -17066,9 +17363,7 @@ gen_decl_die (tree decl, tree origin, dw_die_ref context_die) /* Output any DIEs that are needed to specify the type of this data object. */ - if ((TREE_CODE (decl_or_origin) == RESULT_DECL - || TREE_CODE (decl_or_origin) == VAR_DECL) - && DECL_BY_REFERENCE (decl_or_origin)) + if (decl_by_reference_p (decl_or_origin)) gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die); else gen_type_die (TREE_TYPE (decl_or_origin), context_die); diff --git a/gcc/final.c b/gcc/final.c index 3ecb415d795..cd36860455f 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -4304,7 +4304,7 @@ struct rtl_opt_pass pass_final = { { RTL_PASS, - NULL, /* name */ + "final", /* name */ NULL, /* gate */ rest_of_handle_final, /* execute */ NULL, /* sub */ diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c index ad64b8c3499..ccf539eb0dc 100644 --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -1654,45 +1654,26 @@ pdr_add_data_dimensions (ppl_Polyhedron_t accesses, data_reference_p dr, { tree ref = DR_REF (dr); int i, nb_subscripts = DR_NUM_DIMENSIONS (dr); - tree array_size; - HOST_WIDE_INT elt_size; - array_size = TYPE_SIZE (TREE_TYPE (ref)); - if (array_size == NULL_TREE - || TREE_CODE (array_size) != INTEGER_CST) - return; - - elt_size = int_cst_value (array_size); - - for (i = nb_subscripts - 1; i >= 0; i--) + for (i = nb_subscripts - 1; i >= 0; i--, ref = TREE_OPERAND (ref, 0)) { ppl_Linear_Expression_t expr; ppl_Constraint_t cstr; ppl_dimension_type subscript = dom_nb_dims + 1 + i; - int size; - - /* 0 <= subscript */ - ppl_new_Linear_Expression_with_dimension (&expr, accessp_nb_dims); - ppl_set_coef (expr, subscript, 1); - ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); - ppl_Polyhedron_add_constraint (accesses, cstr); - ppl_delete_Linear_Expression (expr); - ppl_delete_Constraint (cstr); + tree low, high; - ref = TREE_OPERAND (ref, 0); - array_size = TYPE_SIZE (TREE_TYPE (ref)); - if (array_size == NULL_TREE - || TREE_CODE (array_size) != INTEGER_CST) + if (TREE_CODE (ref) != ARRAY_REF) break; - /* subscript <= array_size */ - size = elt_size ? int_cst_value (array_size) / elt_size : 0; - if (size) + low = array_ref_low_bound (ref); + + /* subscript - low >= 0 */ + if (host_integerp (low, 0)) { ppl_new_Linear_Expression_with_dimension (&expr, accessp_nb_dims); - ppl_set_coef (expr, subscript, -1); + ppl_set_coef (expr, subscript, 1); - ppl_set_inhomogeneous (expr, size); + ppl_set_inhomogeneous (expr, -int_cst_value (low)); ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); ppl_Polyhedron_add_constraint (accesses, cstr); @@ -1700,7 +1681,23 @@ pdr_add_data_dimensions (ppl_Polyhedron_t accesses, data_reference_p dr, ppl_delete_Constraint (cstr); } - elt_size = int_cst_value (array_size); + high = array_ref_up_bound (ref); + + /* high - subscript >= 0 + XXX: 1-element arrays at end of structures may extend over their + declared size. */ + if (high && host_integerp (high, 0)) + { + ppl_new_Linear_Expression_with_dimension (&expr, accessp_nb_dims); + ppl_set_coef (expr, subscript, -1); + + ppl_set_inhomogeneous (expr, int_cst_value (high)); + + ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); + ppl_Polyhedron_add_constraint (accesses, cstr); + ppl_delete_Linear_Expression (expr); + ppl_delete_Constraint (cstr); + } } } diff --git a/gcc/opts.c b/gcc/opts.c index 878635f8ca3..cf49ef8f36c 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -898,6 +898,7 @@ decode_options (unsigned int argc, const char **argv) flag_tree_pre = opt2; flag_tree_switch_conversion = 1; flag_ipa_cp = opt2; + flag_ipa_sra = opt2; /* Track fields in field-sensitive alias analysis. */ set_param_value ("max-fields-for-field-sensitive", diff --git a/gcc/params.def b/gcc/params.def index ff3e41c2fbd..b2c1d3a9ba0 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -776,6 +776,12 @@ DEFPARAM (PARAM_MIN_NONDEBUG_INSN_UID, "The minimum UID to be used for a nondebug insn", 0, 1, 0) +DEFPARAM (PARAM_IPA_SRA_PTR_GROWTH_FACTOR, + "ipa-sra-ptr-growth-factor", + "maximum allowed growth of size of new parameters ipa-sra replaces " + "a pointer to an aggregate with", + 2, 0, 0) + /* Local variables: mode:c diff --git a/gcc/passes.c b/gcc/passes.c index fa2de037612..abfa04b9127 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -566,6 +566,7 @@ init_optimization_passes (void) NEXT_PASS (pass_copy_prop); NEXT_PASS (pass_merge_phi); NEXT_PASS (pass_cd_dce); + NEXT_PASS (pass_early_ipa_sra); NEXT_PASS (pass_tail_recursion); NEXT_PASS (pass_convert_switch); NEXT_PASS (pass_cleanup_eh); diff --git a/gcc/real.c b/gcc/real.c index f4c493bd041..eb4e25bba83 100644 --- a/gcc/real.c +++ b/gcc/real.c @@ -110,6 +110,9 @@ static int do_compare (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *, int); static void do_fix_trunc (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); static unsigned long rtd_divmod (REAL_VALUE_TYPE *, REAL_VALUE_TYPE *); +static void decimal_from_integer (REAL_VALUE_TYPE *); +static void decimal_integer_string (char *, const REAL_VALUE_TYPE *, + size_t); static const REAL_VALUE_TYPE * ten_to_ptwo (int); static const REAL_VALUE_TYPE * ten_to_mptwo (int); @@ -2168,10 +2171,70 @@ real_from_integer (REAL_VALUE_TYPE *r, enum machine_mode mode, normalize (r); } - if (mode != VOIDmode) + if (DECIMAL_FLOAT_MODE_P (mode)) + decimal_from_integer (r); + else if (mode != VOIDmode) real_convert (r, mode, r); } +/* Render R, an integral value, as a floating point constant with no + specified exponent. */ + +static void +decimal_integer_string (char *str, const REAL_VALUE_TYPE *r_orig, + size_t buf_size) +{ + int dec_exp, digit, digits; + REAL_VALUE_TYPE r, pten; + char *p; + bool sign; + + r = *r_orig; + + if (r.cl == rvc_zero) + { + strcpy (str, "0."); + return; + } + + sign = r.sign; + r.sign = 0; + + dec_exp = REAL_EXP (&r) * M_LOG10_2; + digits = dec_exp + 1; + gcc_assert ((digits + 2) < (int)buf_size); + + pten = *real_digit (1); + times_pten (&pten, dec_exp); + + p = str; + if (sign) + *p++ = '-'; + + digit = rtd_divmod (&r, &pten); + gcc_assert (digit >= 0 && digit <= 9); + *p++ = digit + '0'; + while (--digits > 0) + { + times_pten (&r, 1); + digit = rtd_divmod (&r, &pten); + *p++ = digit + '0'; + } + *p++ = '.'; + *p++ = '\0'; +} + +/* Convert a real with an integral value to decimal float. */ + +static void +decimal_from_integer (REAL_VALUE_TYPE *r) +{ + char str[256]; + + decimal_integer_string (str, r, sizeof (str) - 1); + decimal_real_from_string (r, str); +} + /* Returns 10**2**N. */ static const REAL_VALUE_TYPE * diff --git a/gcc/stmt.c b/gcc/stmt.c index 42f22b5868b..ffd180ec112 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -825,6 +825,8 @@ expand_asm_operands (tree string, tree outputs, tree inputs, { op = assign_temp (type, 0, 0, 1); op = validize_mem (op); + if (!MEM_P (op) && TREE_CODE (TREE_VALUE (tail)) == SSA_NAME) + set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (TREE_VALUE (tail)), op); TREE_VALUE (tail) = make_tree (type, op); } output_rtx[i] = op; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5730da14617..c53270b79ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,192 @@ +2009-09-17 Andrew Pinski <pinskia@gcc.gnu.org> + + PR c++/39365 + * typeck.c (cp_build_unary_op): Check TREE_CODE for bools instead of + using same_type_p. + (convert_for_assignment): Likewise. + * cvt.c (type_promotes_to): Likewise. + +2009-09-17 Janis Johnson <janis187@us.ibm.com> + + * gcc/testsuite/gcc.dg/dfp/dfp-dbg.h: Define EXTERN. + * gcc/testsuite/gcc.dg/dfp/signbit-2.c: Use it. + * gcc/testsuite/gcc.dg/dfp/func-vararg-alternate.h: Change two + arguments to unsigned int. + * gcc/testsuite/gcc.dg/dfp/convert-bfp-10.c: Don't include float.h. + * gcc/testsuite/gcc.dg/dfp/convert-bfp-fold.c: Include dfp-dbg.h. + * gcc/testsuite/gcc.dg/dfp/convert-dfp-fold.c: Ditto + * gcc/testsuite/gcc.dg/dfp/convert-int-max-fold.c: Ditto. + * gcc/testsuite/gcc.dg/dfp/operator-arith-fold.c: Ditto. + * gcc/testsuite/gcc.dg/dfp/pr39986.c: Ditto. + * gcc/testsuite/gcc.dg/dfp/usual-arith-conv-const.c: Ditto. + * gcc/testsuite/gcc.dg/dfp/pr31385.c: Use mode in typedef, not C type. + * gcc/testsuite/gcc.dg/dfp/pr35620.c: Define typedef for C++. + * gcc/testsuite/gcc.dg/dfp/convert-int.c: Define BOOL for C++. + * gcc/testsuite/gcc.dg/dfp/convert-int-fold.c: Ditto. + +2009-09-17 Jakub Jelinek <jakub@redhat.com> + + * gcc.dg/debug/dwarf2/struct-loc1.c: New test. + +2009-09-17 Janis Johnson <janis187@us.ibm.com> + + PR c/41049 + * dfp/pr41049.c: New test. + +2009-09-17 H.J. Lu <hongjiu.lu@intel.com> + + PR testsuite/41385 + * gcc.dg/dfp/dfp.exp: Properly save DEFAULT_CFLAGS. + +2009-09-17 Martin Jambor <mjambor@suse.cz> + + * gcc.dg/struct/wo_prof_escape_arg_to_local.c: Do not run IPA-SRA. + * gcc.dg/ipa/ipa-sra-1.c: New test. + * gcc.dg/ipa/ipa-sra-2.c: New test. + * gcc.dg/ipa/ipa-sra-3.c: New test. + * gcc.dg/ipa/ipa-sra-4.c: New test. + * gcc.dg/ipa/ipa-sra-5.c: New test. + * gcc.c-torture/execute/ipa-sra-1.c: New test. + * gcc.c-torture/execute/ipa-sra-2.c: New test. + +2009-09-17 Michael Matz <matz@suse.de> + + PR middle-end/41347 + * gfortran.dg/pr41347.f90: New test. + +2009-09-17 Andreas Krebbel <Andreas.Krebbel@de.ibm.com> + + * gcc.c-torture/compile/20090917-1.c: New testcase. + +2009-09-16 Uros Bizjak <ubizjak@gmail.com> + + * gfortran.dg/default_format_denormal_2.f90: Add ieee options. + * gfortran.dg/default_format_denormal_1.f90: Ditto. Remove + alpha*-*-* target from XFAIL list. + +2009-09-16 Janis Johnson <janis187@us.ibm.com> + + * gcc.dg/dfp/dfp.exp: Use appropriate default options. + * gcc.dg/dfp/dfp-dbg.h: New; define FAILURE, FINISH. + * gcc.dg/dfp/cast-bad.c: Use default options. + * gcc.dg/dfp/compare-rel-const.c: Ditto. + * gcc.dg/dfp/composite-type.c: Ditto. + * gcc.dg/dfp/constants.c: Ditto. + * gcc.dg/dfp/constants-hex.c: Ditto. + * gcc.dg/dfp/constants-pedantic.c: Ditto. + * gcc.dg/dfp/convert-bfp-fold.c: Ditto. + * gcc.dg/dfp/convert-dfp-fold.c: Ditto. + * gcc.dg/dfp/convert-int-max-fold.c: Ditto. + * gcc.dg/dfp/ctypes.c: Ditto. + * gcc.dg/dfp/ddmode-ice.c: Ditto. + * gcc.dg/dfp/dec-eval-method-2.c: Ditto. + * gcc.dg/dfp/float-constant-double.c: Ditto. + * gcc.dg/dfp/keywords-pedantic.c: Ditto. + * gcc.dg/dfp/keywords-reserved.c: Ditto. + * gcc.dg/dfp/modes.c: Ditto. + * gcc.dg/dfp/operator-bitwise.c: Ditto. + * gcc.dg/dfp/pr31344.c: Ditto. + * gcc.dg/dfp/pr31385.c: Ditto. + * gcc.dg/dfp/pr33466.c: Ditto. + * gcc.dg/dfp/pr35620.c: Ditto. + * gcc.dg/dfp/pr37435.c: Ditto. + * gcc.dg/dfp/pr39986.c: Ditto. + * gcc.dg/dfp/pragma-float-const-decimal64-1.c: Ditto. + * gcc.dg/dfp/pragma-float-const-decimal64-2.c: Ditto. + * gcc.dg/dfp/pragma-float-const-decimal64-3.c: Ditto. + * gcc.dg/dfp/pragma-float-const-decimal64-4.c: Ditto. + * gcc.dg/dfp/pragma-float-const-decimal64-7.c: Ditto. + * gcc.dg/dfp/pragma-float-const-decimal64-8.c: Ditto. + * gcc.dg/dfp/typespec.c: Ditto. + * gcc.dg/dfp/usual-arith-conv-bad.c: Ditto. + * gcc.dg/dfp/usual-arith-conv-bad-2.c: Ditto. + * gcc.dg/dfp/usual-arith-conv-const.c: Ditto. + * gcc.dg/dfp/Wbad-function-cast-1.c: Ditto. + * gcc.dg/dfp/Wtraditional-conversion-2.c: Ditto. + * gcc.dg/dfp/wtr-conversion-1.c: Ditto. + * gcc.dg/dfp/compare-eq.h: Define custom debug macros. + * gcc.dg/dfp/compare-rel.h: Ditto. + * gcc.dg/dfp/compare-special.h: Ditto. + * gcc.dg/dfp/convert.h: Ditto. + * gcc.dg/dfp/fe-check.h: Ditto. + * gcc.dg/dfp/call-by-value.c: Use default options and + debug macros. + * gcc.dg/dfp/cast.c: Ditto. + * gcc.dg/dfp/compare-eq-const.c: Ditto. + * gcc.dg/dfp/compare-eq-d32.c: Ditto. + * gcc.dg/dfp/compare-eq-d64.c: Ditto. + * gcc.dg/dfp/compare-eq-d128.c: Ditto. + * gcc.dg/dfp/compare-eq-dfp.c: Ditto. + * gcc.dg/dfp/compare-rel-d32.c: Ditto. + * gcc.dg/dfp/compare-rel-d64.c: Ditto. + * gcc.dg/dfp/compare-rel-d128.c: Ditto. + * gcc.dg/dfp/compare-rel-dfp.c: Ditto. + * gcc.dg/dfp/compare-special-d32.c: Ditto. + * gcc.dg/dfp/compare-special-d64.c: Ditto. + * gcc.dg/dfp/compare-special-d128.c: Ditto. + * gcc.dg/dfp/constants-zero.c: Ditto. + * gcc.dg/dfp/convert-bfp-2.c: Ditto. + * gcc.dg/dfp/convert-bfp-3.c: Ditto. + * gcc.dg/dfp/convert-bfp-4.c: Ditto. + * gcc.dg/dfp/convert-bfp-5.c: Ditto. + * gcc.dg/dfp/convert-bfp-6.c: Ditto. + * gcc.dg/dfp/convert-bfp-7.c: Ditto. + * gcc.dg/dfp/convert-bfp-8.c: Ditto. + * gcc.dg/dfp/convert-bfp-9.c: Ditto. + * gcc.dg/dfp/convert-bfp-10.c: Ditto. + * gcc.dg/dfp/convert-bfp-11.c: Ditto. + * gcc.dg/dfp/convert-bfp-12.c: Ditto. + * gcc.dg/dfp/convert-bfp-13.c: Ditto. + * gcc.dg/dfp/convert-bfp-14.c: Ditto. + * gcc.dg/dfp/convert-bfp.c: Ditto. + * gcc.dg/dfp/convert-complex.c: Ditto. + * gcc.dg/dfp/convert-dfp.c: Ditto. + * gcc.dg/dfp/convert-dfp-fold-2.c: Ditto. + * gcc.dg/dfp/convert-dfp-round.c: Ditto. + * gcc.dg/dfp/convert-int.c: Ditto. + * gcc.dg/dfp/convert-int-fold.c: Ditto. + * gcc.dg/dfp/convert-int-max.c: Ditto. + * gcc.dg/dfp/convert-int-saturate.c: Ditto. + * gcc.dg/dfp/decfloat-constants.c: Ditto. + * gcc.dg/dfp/fe-binop.c: Ditto. + * gcc.dg/dfp/fe-convert-1.c: Ditto. + * gcc.dg/dfp/fe-convert-2.c: Ditto. + * gcc.dg/dfp/fe-convert-3.c: Ditto. + * gcc.dg/dfp/func-array.c: Ditto. + * gcc.dg/dfp/func-deref.c: Ditto. + * gcc.dg/dfp/func-mixed.c: Ditto. + * gcc.dg/dfp/func-pointer.c: Ditto. + * gcc.dg/dfp/func-scalar.c: Ditto. + * gcc.dg/dfp/func-struct.c: Ditto. + * gcc.dg/dfp/func-vararg-alternate.h: Ditto. + * gcc.dg/dfp/func-vararg-alternate-d32.c: Ditto. + * gcc.dg/dfp/func-vararg-alternate-d64.c: Ditto. + * gcc.dg/dfp/func-vararg-alternate-d128.c: Ditto. + * gcc.dg/dfp/func-vararg-alternate-d128-2.c: Ditto. + * gcc.dg/dfp/func-vararg-dfp.c: Ditto. + * gcc.dg/dfp/func-vararg-mixed.c: Ditto. + * gcc.dg/dfp/func-vararg-mixed-2.c: Ditto. + * gcc.dg/dfp/func-vararg-size0.c: Ditto. + * gcc.dg/dfp/inf-1.c: Ditto. + * gcc.dg/dfp/loop-index.c: Ditto. + * gcc.dg/dfp/nan-1.c: Ditto. + * gcc.dg/dfp/nan-2.c: Ditto. + * gcc.dg/dfp/operator-arith-fold.c: Ditto. + * gcc.dg/dfp/operator-assignment.c: Ditto. + * gcc.dg/dfp/operator-comma.c: Ditto. + * gcc.dg/dfp/operator-cond.c: Ditto. + * gcc.dg/dfp/operator-logical.c: Ditto. + * gcc.dg/dfp/operator-unary.c: Ditto. + * gcc.dg/dfp/pr36800.c: Ditto. + * gcc.dg/dfp/pr39034.c: Ditto. + * gcc.dg/dfp/pr39035.c: Ditto. + * gcc.dg/dfp/pr39902.c: Ditto. + * gcc.dg/dfp/signbit-1.c: Ditto. + * gcc.dg/dfp/signbit-2.c: Ditto. + * gcc.dg/dfp/struct-layout-1.c: Ditto. + * gcc.dg/dfp/union-init.c: Ditto. + * gcc.dg/dfp/usual-arith-conv.c: Ditto. + 2009-09-16 Michael Matz <matz@suse.de> PR fortran/41212 diff --git a/gcc/testsuite/g++.dg/expr/bool3.C b/gcc/testsuite/g++.dg/expr/bool3.C new file mode 100644 index 00000000000..61669e27bef --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/bool3.C @@ -0,0 +1,21 @@ +// { dg-do run } +// PR C++/29295 +// make sure that a typedef for a bool will have the +// the same results as a bool itself. + +extern "C" void abort(); +typedef volatile bool my_bool; +int main() +{ + my_bool b = false; + int i; + + b++; + b++; + i = b; + if (i != 1) + abort (); + return 0; +} + + diff --git a/gcc/testsuite/g++.dg/expr/bool4.C b/gcc/testsuite/g++.dg/expr/bool4.C new file mode 100644 index 00000000000..dce51ec332e --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/bool4.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// make sure that a typedef for a bool will have the +// the same results as a bool itself. + + +typedef volatile bool my_bool; +int main() +{ + my_bool b = false; + b--; // { dg-error "" } + return 0; +} + diff --git a/gcc/testsuite/gcc.c-torture/compile/20090917-1.c b/gcc/testsuite/gcc.c-torture/compile/20090917-1.c new file mode 100644 index 00000000000..2b8c37148bd --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20090917-1.c @@ -0,0 +1,55 @@ +typedef int *loop_p; +typedef struct VEC_loop_p_base +{ + unsigned num; + loop_p vec[1]; +} +VEC_loop_p_base; + +__inline__ int +VEC_loop_p_base_iterate (const VEC_loop_p_base * vec_, unsigned ix_, + loop_p * ptr) +{ + if (vec_ && ix_ < vec_->num) + { + *ptr = vec_->vec[ix_]; + return 1; + } + else + { + return 0; + } +} + +typedef struct VEC_loop_p_heap +{ + VEC_loop_p_base base; +} +VEC_loop_p_heap; + + +static __inline__ int +am_vector_index_for_loop (VEC_loop_p_heap * loop_nest, int loop_num) +{ + int i; + loop_p l; + + for (i = 0; + VEC_loop_p_base_iterate ((loop_nest) ? &(loop_nest)->base : 0, i, + &(l)); i++) + if (l == loop_num) + return i; + + __builtin_unreachable (); +} + +unsigned char +build_access_matrix (unsigned max) +{ + unsigned i; + for (i = 0; i < max; i++) + { + if (am_vector_index_for_loop (foo (), 0)) + return 0; + } +} diff --git a/gcc/testsuite/gcc.c-torture/execute/ipa-sra-1.c b/gcc/testsuite/gcc.c-torture/execute/ipa-sra-1.c new file mode 100644 index 00000000000..777ed2a83d9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/ipa-sra-1.c @@ -0,0 +1,29 @@ +/* Trivially making sure IPA-SRA does not introduce segfaults where they should + not be. */ + +struct bovid +{ + float red; + int green; + void *blue; +}; + +static int +__attribute__((noinline)) +ox (int fail, struct bovid *cow) +{ + int r; + if (fail) + r = cow->red; + else + r = 0; + return r; +} + +int main (int argc, char *argv[]) +{ + int r; + + r = ox ((argc > 2000), (void *) 0); + return r; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/ipa-sra-2.c b/gcc/testsuite/gcc.c-torture/execute/ipa-sra-2.c new file mode 100644 index 00000000000..9d5ae440975 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/ipa-sra-2.c @@ -0,0 +1,41 @@ +struct big +{ + int data[1000000]; +}; + +struct small +{ + int data[10]; +}; + +union both +{ + struct big big; + struct small small; +}; + +extern void *malloc(__SIZE_TYPE__); +extern void free (void *); + +static int +__attribute__((noinline)) +foo (int fail, union both *agg) +{ + int r; + if (fail) + r = agg->big.data[999999]; + else + r = agg->small.data[0]; + return r; +} + +int main (int argc, char *argv[]) +{ + union both *agg = malloc (sizeof (struct small)); + int r; + + r = foo ((argc > 2000), agg); + + free (agg); + return r; +} diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/struct-loc1.c b/gcc/testsuite/gcc.dg/debug/dwarf2/struct-loc1.c new file mode 100644 index 00000000000..216a498e1ab --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/struct-loc1.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-g -O0 -dA -fno-merge-debug-strings" } */ + +struct foo; +struct foo *obj; +struct foo +{ + int x; +}; + +int +main () +{ + return 0; +} + +/* { dg-final { scan-assembler "DW_TAG_structure_type\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"foo\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0x)?6\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */ diff --git a/gcc/testsuite/gcc.dg/dfp/Wbad-function-cast-1.c b/gcc/testsuite/gcc.dg/dfp/Wbad-function-cast-1.c index 95e8ce19810..99d8f0655d7 100644 --- a/gcc/testsuite/gcc.dg/dfp/Wbad-function-cast-1.c +++ b/gcc/testsuite/gcc.dg/dfp/Wbad-function-cast-1.c @@ -2,7 +2,7 @@ /* Based on gcc.dg/Wbad-function-cast-1.c. */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wbad-function-cast" } */ +/* { dg-options "-Wbad-function-cast" } */ int if1(void); char if2(void); diff --git a/gcc/testsuite/gcc.dg/dfp/Wtraditional-conversion-2.c b/gcc/testsuite/gcc.dg/dfp/Wtraditional-conversion-2.c index 7e0d3ad994c..2436afc8ae5 100644 --- a/gcc/testsuite/gcc.dg/dfp/Wtraditional-conversion-2.c +++ b/gcc/testsuite/gcc.dg/dfp/Wtraditional-conversion-2.c @@ -2,7 +2,7 @@ (based on gcc.dg/Wtraditional-conversion-2.c). */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wtraditional-conversion" } */ +/* { dg-options "-Wtraditional-conversion" } */ void fsi(signed int); void fd32(_Decimal32); diff --git a/gcc/testsuite/gcc.dg/dfp/call-by-value.c b/gcc/testsuite/gcc.dg/dfp/call-by-value.c index 4232a30186c..74aec53aefb 100644 --- a/gcc/testsuite/gcc.dg/dfp/call-by-value.c +++ b/gcc/testsuite/gcc.dg/dfp/call-by-value.c @@ -1,11 +1,9 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.9.1(9) Function definitions; parameter has automatic storage. Test that actual parameters are passed by value and that modifications made within functions are lost on function return. */ -extern void abort (void); +#include "dfp-dbg.h" int foo32 (_Decimal32 z) { @@ -31,15 +29,15 @@ main () foo32 (d32); if (d32 != 1.1df) - abort (); + FAILURE foo64 (d64); if (d64 != 1.2dd) - abort (); + FAILURE foo128 (d128); if (d128 != 1.3dl) - abort (); + FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/cast-bad.c b/gcc/testsuite/gcc.dg/dfp/cast-bad.c index e99180824fe..e9e31ff3067 100644 --- a/gcc/testsuite/gcc.dg/dfp/cast-bad.c +++ b/gcc/testsuite/gcc.dg/dfp/cast-bad.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* C99 6.5.4 Cast operators. Test invalid casts involving decimal float. */ diff --git a/gcc/testsuite/gcc.dg/dfp/cast.c b/gcc/testsuite/gcc.dg/dfp/cast.c index 1e88bee7c8e..b6585d70c8b 100644 --- a/gcc/testsuite/gcc.dg/dfp/cast.c +++ b/gcc/testsuite/gcc.dg/dfp/cast.c @@ -1,17 +1,7 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.4 Cast operators. Test valid casts involving decimal float. */ -extern void abort (void); -int failcnt; - -#ifdef DBG -extern int printf (const char *, ...); -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" _Decimal32 d32; _Decimal64 d64; @@ -81,8 +71,5 @@ main (void) if (d128 != (_Decimal128) d) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-eq-const.c b/gcc/testsuite/gcc.dg/dfp/compare-eq-const.c index dd295200f2a..0c9ff200b28 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-eq-const.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-eq-const.c @@ -1,8 +1,8 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.9 Equality operators. Compare decimal float constants against each other. */ +#include "dfp-dbg.h" + extern void link_error (void); int @@ -24,5 +24,5 @@ main () if (1.4dd + 1.4dd + 1.4dd != 4.2dd) link_error (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-eq-d128.c b/gcc/testsuite/gcc.dg/dfp/compare-eq-d128.c index 158e2f90ba5..79fcac3195e 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-eq-d128.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-eq-d128.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.9 Equality operators. Compare decimal float values against each other at runtime. */ @@ -9,5 +9,6 @@ int main () { test_compares (); - return 0; + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-eq-d32.c b/gcc/testsuite/gcc.dg/dfp/compare-eq-d32.c index d5e3bb378c9..6b1a4c6d7c4 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-eq-d32.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-eq-d32.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.9 Equality operators. Compare decimal float values against each other at runtime. */ @@ -9,5 +9,6 @@ int main () { test_compares (); - return 0; + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-eq-d64.c b/gcc/testsuite/gcc.dg/dfp/compare-eq-d64.c index 8fa39dfcd8f..f1b463ebe6a 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-eq-d64.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-eq-d64.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.9 Equality operators. Compare decimal float values against each other at runtime. */ @@ -9,5 +9,6 @@ int main () { test_compares (); - return 0; + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-eq-dfp.c b/gcc/testsuite/gcc.dg/dfp/compare-eq-dfp.c index 4203470a4be..79a5691ebfc 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-eq-dfp.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-eq-dfp.c @@ -1,19 +1,9 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.9 Equality operators. Compare decimal float values against variables of different types. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" _Decimal32 d32; _Decimal64 d64; @@ -59,7 +49,5 @@ main () compare_dfp (); - if (failcnt) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-eq.h b/gcc/testsuite/gcc.dg/dfp/compare-eq.h index 809d642593c..830b3289bde 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-eq.h +++ b/gcc/testsuite/gcc.dg/dfp/compare-eq.h @@ -2,19 +2,18 @@ are not affected by rounding. */ #include <stdlib.h> - -static int failcnt; +#include "dfp-dbg.h" #define PASTE2(A,B) A ## B #define PASTE(A,B) PASTE2(A,B) +#undef FAILURE #ifdef DBG -#include <stdio.h> #define FAILURE(OP,KIND) \ { printf ("failed at line %d: %s for %s values\n", __LINE__, OP, KIND); \ - failcnt++; } + failures++; } #else -#define FAILURE(OP,KIND) abort (); +#define FAILURE(OP,KIND) __builtin_abort (); #endif #ifndef WIDTH @@ -90,7 +89,4 @@ test_compares (void) if (! (x != zero)) FAILURE ("!=", "greater") if (! (y != m_one)) FAILURE ("!=", "greater") if (! (z != m_two)) FAILURE ("!=", "greater") - - if (failcnt) - abort (); } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-rel-const.c b/gcc/testsuite/gcc.dg/dfp/compare-rel-const.c index d2dda48e614..8e99b4466dc 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-rel-const.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-rel-const.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.8 Relational operators. Compare decimal float constants against each other. */ diff --git a/gcc/testsuite/gcc.dg/dfp/compare-rel-d128.c b/gcc/testsuite/gcc.dg/dfp/compare-rel-d128.c index 0d46925c2bb..38c931a0207 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-rel-d128.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-rel-d128.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.8 Relational operators. Compare decimal float values against each other at runtime. */ @@ -10,5 +10,5 @@ int main () { test_compares (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-rel-d32.c b/gcc/testsuite/gcc.dg/dfp/compare-rel-d32.c index 257a3c2b4df..04128aab924 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-rel-d32.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-rel-d32.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.8 Relational operators. Compare decimal float values against each other at runtime. */ @@ -10,5 +10,5 @@ int main () { test_compares (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-rel-d64.c b/gcc/testsuite/gcc.dg/dfp/compare-rel-d64.c index 73cbcee44d7..92f904a8154 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-rel-d64.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-rel-d64.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.8 Relational operators. Compare decimal float values against each other at runtime. */ @@ -10,5 +10,5 @@ int main () { test_compares (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-rel-dfp.c b/gcc/testsuite/gcc.dg/dfp/compare-rel-dfp.c index 58523b6ab02..59cc2035306 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-rel-dfp.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-rel-dfp.c @@ -1,19 +1,9 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.8 Relational operators. Compare decimal float values against variables of different types. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" _Decimal32 d32; _Decimal64 d64; @@ -59,7 +49,5 @@ main () compare_dfp (); - if (failcnt) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-rel.h b/gcc/testsuite/gcc.dg/dfp/compare-rel.h index 06b2559bdb5..7840108142d 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-rel.h +++ b/gcc/testsuite/gcc.dg/dfp/compare-rel.h @@ -2,21 +2,20 @@ are not affected by rounding. */ #include <stdlib.h> +#include "dfp-dbg.h" -static int failcnt; - -#define PASTE2(A,B) A ## B -#define PASTE(A,B) PASTE2(A,B) - +#undef FAILURE #ifdef DBG -#include <stdio.h> #define FAILURE(OP,KIND) \ { printf ("failed at line %d: %s for %s values\n", __LINE__, OP, KIND); \ - failcnt++; } + failures++; } #else -#define FAILURE(OP,KIND) abort (); +#define FAILURE(OP,KIND) __builtin_abort (); #endif +#define PASTE2(A,B) A ## B +#define PASTE(A,B) PASTE2(A,B) + #ifndef WIDTH #error define WIDTH as decimal float size in bytes #endif @@ -130,7 +129,4 @@ test_compares (void) if (y > one) FAILURE (">", "greater") if (z > zero) FAILURE (">", "greater") if (z > one) FAILURE (">", "greater") - - if (failcnt) - abort (); } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-special-d128.c b/gcc/testsuite/gcc.dg/dfp/compare-special-d128.c index cef4670b766..d1f5bc5edd4 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-special-d128.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-special-d128.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.8 Relational operators. C99 6.5.9 Equality operators. @@ -11,5 +11,5 @@ int main () { test_compares (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-special-d32.c b/gcc/testsuite/gcc.dg/dfp/compare-special-d32.c index fa91d7edd33..377c65a5bb7 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-special-d32.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-special-d32.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.8 Relational operators. C99 6.5.9 Equality operators. @@ -11,5 +11,5 @@ int main () { test_compares (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-special-d64.c b/gcc/testsuite/gcc.dg/dfp/compare-special-d64.c index 2238e0190e3..16154eff323 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-special-d64.c +++ b/gcc/testsuite/gcc.dg/dfp/compare-special-d64.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.8 Relational operators. C99 6.5.9 Equality operators. @@ -11,5 +11,5 @@ int main () { test_compares (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/compare-special.h b/gcc/testsuite/gcc.dg/dfp/compare-special.h index c5bef234424..9c27d126c29 100644 --- a/gcc/testsuite/gcc.dg/dfp/compare-special.h +++ b/gcc/testsuite/gcc.dg/dfp/compare-special.h @@ -1,19 +1,19 @@ /* Basic test of runtime relational comparisons using NaNs and infinities. */ #include <stdlib.h> - -static int failcnt; +#include "dfp-dbg.h" #define PASTE2(A,B) A ## B #define PASTE(A,B) PASTE2(A,B) +/* Override FAILURE from dfp-dbg.h with one that provides additional info. */ +#undef FAILURE #ifdef DBG -#include <stdio.h> #define FAILURE(OP,KIND) \ { printf ("failed at line %d: %s for %s values\n", __LINE__, OP, KIND); \ - failcnt++; } + failures++; } #else -#define FAILURE(OP,KIND) abort (); +#define FAILURE(OP,KIND) __builtin_abort (); #endif #ifndef WIDTH @@ -281,7 +281,4 @@ test_compares (void) if (!(y != m_inf)) FAILURE ("!=", "inf") if (!(z != inf)) FAILURE ("!=", "inf") if (z != m_inf) FAILURE ("!=", "inf") - - if (failcnt) - abort (); } diff --git a/gcc/testsuite/gcc.dg/dfp/composite-type.c b/gcc/testsuite/gcc.dg/dfp/composite-type.c index 2abc8217595..508ebbd5e29 100644 --- a/gcc/testsuite/gcc.dg/dfp/composite-type.c +++ b/gcc/testsuite/gcc.dg/dfp/composite-type.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -O -Wall" } */ +/* { dg-options "-O -Wall" } */ /* C99 6.2.7: Compatible type and composite type. */ diff --git a/gcc/testsuite/gcc.dg/dfp/constants-hex.c b/gcc/testsuite/gcc.dg/dfp/constants-hex.c index 936f0ed8481..980eae012a8 100644 --- a/gcc/testsuite/gcc.dg/dfp/constants-hex.c +++ b/gcc/testsuite/gcc.dg/dfp/constants-hex.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* N1150 6: Constants. C99 6.4.4.2: Floating constants. diff --git a/gcc/testsuite/gcc.dg/dfp/constants-pedantic.c b/gcc/testsuite/gcc.dg/dfp/constants-pedantic.c index 540b7684035..be81b0fc44a 100644 --- a/gcc/testsuite/gcc.dg/dfp/constants-pedantic.c +++ b/gcc/testsuite/gcc.dg/dfp/constants-pedantic.c @@ -1,9 +1,11 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -pedantic" } */ +/* { dg-options "-pedantic" } */ /* N1150 6: Constants. C99 6.4.4.2: Floating constants. */ +#include "dfp-dbg.h" + _Decimal32 a = 1.1df; /* { dg-warning "GCC extension|ISO C" } */ _Decimal32 b = -.003DF; /* { dg-warning "GCC extension|ISO C" } */ _Decimal64 c = 11e-1dl; /* { dg-warning "GCC extension|ISO C" } */ diff --git a/gcc/testsuite/gcc.dg/dfp/constants-zero.c b/gcc/testsuite/gcc.dg/dfp/constants-zero.c index e0db28cc38f..64b0054d2d3 100644 --- a/gcc/testsuite/gcc.dg/dfp/constants-zero.c +++ b/gcc/testsuite/gcc.dg/dfp/constants-zero.c @@ -1,10 +1,10 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* Decimal float values can have significant trailing zeroes. This is true for zero values as well. Check that various representations of zero are handled correctly when specified as literal constants. */ -extern void abort (void); +#include "dfp-dbg.h" int big_endian; @@ -58,74 +58,74 @@ void dpd_tests (void) { if (! compare32 (0.DF, 0x22500000U)) - abort (); + FAILURE if (! compare32 (-0.DF, 0xa2500000U)) - abort (); + FAILURE if (! compare32 (0.E-4DF, 0x22100000U)) - abort (); + FAILURE if (! compare32 (0.E-7DF, 0x21e00000U)) - abort (); + FAILURE if (! compare32 (0.E+3DF, 0x22800000U)) - abort (); + FAILURE if (! compare64 (0.DD, 0x2238000000000000ULL)) - abort (); + FAILURE if (! compare64 (-0.DD, 0xa238000000000000ULL)) - abort (); + FAILURE if (! compare64 (0.E-6DD, 0x2220000000000000ULL)) - abort (); + FAILURE if (! compare64 (0.E-7DD, 0x221c000000000000ULL)) - abort (); + FAILURE if (! compare64 (0.E+2DD, 0x2240000000000000ULL)) - abort (); + FAILURE if (! compare128 (0.DL, 0x2208000000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE if (! compare128 (-0.DL, 0xa208000000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE if (! compare128 (0.E-3DL, 0x2207400000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE if (! compare128 (0.E-8DL, 0x2206000000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE if (! compare128 (0.E+2DL, 0x2208800000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE } void bid_tests (void) { if (! compare32 (0.DF, 0x32800000U)) - abort (); + FAILURE if (! compare32 (-0.DF, 0xb2800000U)) - abort (); + FAILURE if (! compare32 (0.E-4DF, 0x30800000U)) - abort (); + FAILURE if (! compare32 (0.E-7DF, 0x2f000000U)) - abort (); + FAILURE if (! compare32 (0.E+3DF, 0x34000000U)) - abort (); + FAILURE if (! compare64 (0.DD, 0x31c0000000000000ULL)) - abort (); + FAILURE if (! compare64 (-0.DD, 0xb1c0000000000000ULL)) - abort (); + FAILURE if (! compare64 (0.E-6DD, 0x3100000000000000ULL)) - abort (); + FAILURE if (! compare64 (0.E-7DD, 0x30e0000000000000ULL)) - abort (); + FAILURE if (! compare64 (0.E+2DD, 0x3200000000000000ULL)) - abort (); + FAILURE if (! compare128 (0.DL, 0x3040000000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE if (! compare128 (-0.DL, 0xb040000000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE if (! compare128 (0.E-3DL, 0x303a000000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE if (! compare128 (0.E-8DL, 0x3030000000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE if (! compare128 (0.E+2DL, 0x3044000000000000ULL, 0x0000000000000000ULL)) - abort (); + FAILURE } int @@ -138,7 +138,7 @@ main () if ((sizeof (_Decimal64) != sizeof (long long)) || (sizeof (_Decimal128) != 2 * sizeof (long long)) || (sizeof (_Decimal32) != sizeof (_Decimal32))) - abort (); + FAILURE u32.d = 1.DF; @@ -153,7 +153,7 @@ main () bid_tests (); } else - abort (); /* unknown format; test problem */ + FAILURE /* unknown format; test problem */ - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/constants.c b/gcc/testsuite/gcc.dg/dfp/constants.c index 50045ed9cec..bb61ea3352b 100644 --- a/gcc/testsuite/gcc.dg/dfp/constants.c +++ b/gcc/testsuite/gcc.dg/dfp/constants.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* N1150 6: Constants. C99 6.4.4.2: Floating constants. */ diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-10.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-10.c index dec7b515fcf..3fef98a3384 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-10.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-10.c @@ -1,10 +1,5 @@ -/* { dg-options "-std=gnu99" } */ - /* This test assumes IEEE float and double. */ -#define __STDC_WANT_DEC_FP__ -#include <float.h> - #include "convert.h" volatile _Decimal32 sd; @@ -108,7 +103,5 @@ main () convert_246 (); convert_247 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-11.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-11.c index 283f9bd4f88..d16919f81ac 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-11.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-11.c @@ -1,4 +1,3 @@ -/* { dg-options "-std=gnu99" } */ /* { dg-skip-if "" { ! "powerpc*-*-linux*" } { "*" } { "" } } */ /* Test decimal float conversions to and from IBM 128-bit long double. @@ -55,7 +54,5 @@ main () convert_311 (); convert_312 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-12.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-12.c index 96381415dce..7a909552afc 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-12.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-12.c @@ -1,9 +1,7 @@ /* Test for bug where fold wrongly removed conversions to double and replaced them by conversions to float. */ -/* { dg-options "-std=gnu99" } */ -extern void abort (void); -extern void exit (int); +#include "dfp-dbg.h" volatile float f = __builtin_inff (); volatile _Decimal32 d32 = 1e40DF; @@ -12,6 +10,7 @@ int main (void) { if ((double) f == (double) d32) - abort (); - exit (0); + FAILURE + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-13.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-13.c index 91a5b494884..259cc745ce3 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-13.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-13.c @@ -1,9 +1,7 @@ /* Test for bug where fold changed binary operation to decimal depending on typedefs. */ -/* { dg-options "-std=gnu99" } */ -extern void abort (void); -extern void exit (int); +#include "dfp-dbg.h" volatile double d = 1.2345675; @@ -15,6 +13,6 @@ main (void) _Decimal32 a = (d * d); d32 b = (d * d); if (a != b) - abort (); - exit (0); + FAILURE + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-14.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-14.c index a1312d2a0e6..858c92980b5 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-14.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-14.c @@ -1,9 +1,7 @@ /* Test for bug where fold narrowed decimal floating-point operations. */ -/* { dg-options "-std=gnu99" } */ -extern void abort (void); -extern void exit (int); +#include "dfp-dbg.h" volatile _Decimal32 f = 1.23456DF; volatile _Decimal64 d = 1.23456DD; @@ -12,6 +10,6 @@ int main (void) { if ((double)((_Decimal64)f * (_Decimal64)f) != (double)(d * d)) - abort (); - exit (0); + FAILURE + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-2.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-2.c index 28273512005..463d27f355f 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-2.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-2.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* This test assumes IEEE float and double. It also tests long double but makes no assumption about its size or range of values. */ @@ -31,7 +29,5 @@ main () CALL_VALID_ALL (t6) CALL_VALID_ALL (t7) - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-3.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-3.c index 67d31c33ac9..3e1d9d57a77 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-3.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-3.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* This test assumes IEEE float and double. It also tests long double but makes no assumption about its size or range of values. */ @@ -19,7 +17,5 @@ main () { CALL_ZEROES_ALL (t) - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-4.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-4.c index feba37a9eae..b97b9c6cb08 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-4.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-4.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* This test assumes IEEE float and double. It also tests long double but makes no assumption about its size or range of values. */ @@ -19,7 +17,5 @@ main () { CALL_INF_ALL (t) - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-5.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-5.c index cfb86fd015d..ada2d352cca 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-5.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-5.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* This test assumes IEEE float and double. It also tests long double but makes no assumption about its size or range of values. */ @@ -19,7 +17,5 @@ main () { CALL_NAN_ALL (t) - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-6.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-6.c index 7603f751992..64198a95f2a 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-6.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-6.c @@ -1,5 +1,5 @@ /* { dg-xfail-run-if "" { lax_strtofp } "*" "" } */ -/* { dg-options "-std=gnu99 -w" } */ +/* { dg-options "-w" } */ /* This test assumes IEEE float and double. */ @@ -174,7 +174,5 @@ main () convert_364 (); } - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-7.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-7.c index 0fb4f076d25..f51d696cee6 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-7.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-7.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -w" } */ +/* { dg-options "-w" } */ /* This test assumes IEEE float and double. */ @@ -79,7 +79,5 @@ main () convert_351 (); convert_352 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-8.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-8.c index 269fc37f208..532bd861314 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-8.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-8.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -w" } */ +/* { dg-options "-w" } */ /* This test assumes IEEE float and double. */ @@ -67,7 +67,5 @@ main () convert_443 (); convert_444 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-9.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-9.c index 90f0692136c..e609087525a 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-9.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-9.c @@ -1,5 +1,5 @@ /* { dg-xfail-run-if "" { lax_strtofp } "*" "" } */ -/* { dg-options "-std=gnu99 -w" } */ +/* { dg-options "-w" } */ /* This test assumes IEEE float and double. */ @@ -188,7 +188,5 @@ main () convert_419 (); convert_420 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp-fold.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp-fold.c index 8c20a52ee69..d62a7e4b21c 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp-fold.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp-fold.c @@ -1,9 +1,11 @@ -/* { dg-options "-std=gnu99 -O2" } */ +/* { dg-options "-O2" } */ /* N1150 5.2 Conversions among decimal floating types and between decimal floating types and generic floating types. C99 6.3.1.5(4) Conversions, arithmetic operands, real floating types. */ +#include "dfp-dbg.h" + _Decimal32 d32; _Decimal64 d64; _Decimal128 d128; diff --git a/gcc/testsuite/gcc.dg/dfp/convert-bfp.c b/gcc/testsuite/gcc.dg/dfp/convert-bfp.c index b2e8ca87b16..710538d467b 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-bfp.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-bfp.c @@ -1,23 +1,12 @@ -/* { dg-options "-std=gnu99" } */ - /* N1150 5.2 Conversions among decimal floating types and between decimal floating types and generic floating types. C99 6.3.1.5(4) Conversions, arithmetic operands, real floating types. */ /* Long double isn't supported yet at runtime, so disable those checks. */ -extern void abort (void); -static int failcnt; -static int skip_long_double; +#include "dfp-dbg.h" -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +static int skip_long_double; volatile _Decimal32 d32; volatile _Decimal64 d64; @@ -138,8 +127,5 @@ main () || df > (2.9802322387695312e-08 + 0.00000000001)) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-complex.c b/gcc/testsuite/gcc.dg/dfp/convert-complex.c index 0083b091880..76eef87cb7c 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-complex.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-complex.c @@ -3,17 +3,7 @@ /* N1150 5.3 Conversions between decimal floating and complex. C99 6.3.1.7 Conversions, arithmetic operands, real and complex. */ -extern void abort(void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" int main () @@ -124,8 +114,5 @@ main () if (d128 != 0.0625DL) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-dfp-fold-2.c b/gcc/testsuite/gcc.dg/dfp/convert-dfp-fold-2.c index 9f0927963a1..073f7abc4a6 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-dfp-fold-2.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-dfp-fold-2.c @@ -1,9 +1,7 @@ /* Test for bug where fold narrowed decimal floating-point operations. */ -/* { dg-options "-std=gnu99" } */ -extern void abort (void); -extern void exit (int); +#include "dfp-dbg.h" volatile _Decimal32 f = 1.23456DF; volatile _Decimal64 d = 1.23456DD; @@ -12,6 +10,6 @@ int main (void) { if ((_Decimal128)((_Decimal64)f * (_Decimal64)f) != (_Decimal128)(d * d)) - abort (); - exit (0); + FAILURE + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-dfp-fold.c b/gcc/testsuite/gcc.dg/dfp/convert-dfp-fold.c index a56f0dfc25e..67c9d71c224 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-dfp-fold.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-dfp-fold.c @@ -1,9 +1,11 @@ -/* { dg-options "-std=gnu99 -O2" } */ +/* { dg-options "-O2" } */ /* N1150 5.2 Conversions among decimal floating types and between decimal floating types and generic floating types. C99 6.3.1.5(3) New. */ +#include "dfp-dbg.h" + extern void link_error (); int diff --git a/gcc/testsuite/gcc.dg/dfp/convert-dfp-round.c b/gcc/testsuite/gcc.dg/dfp/convert-dfp-round.c index 9833abb7ff0..e3781bfc967 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-dfp-round.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-dfp-round.c @@ -1,4 +1,4 @@ -/* { dg-options "-O0 -std=gnu99" } */ +/* { dg-options "-O0" } */ /* { dg-skip-if "test is for emulation" { hard_dfp } { "*" } { "" } } */ /* N1150 5.2: Conversions among decimal floating types and between @@ -12,20 +12,9 @@ Normally this would not be part of compiler testing, but conversions are currently handled in libgcc via decNumber. */ +#include "dfp-dbg.h" #include "dfp-round.h" -extern void abort (void); -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif - _Decimal32 d32; _Decimal64 d64; _Decimal128 d128; @@ -131,7 +120,5 @@ main () if (!do_d128_to_d64 (-1.1111111111111125dl, -1.111111111111112dd)) FAILURE if (!do_d128_to_d64 (-1.1111111111111135dl, -1.111111111111113dd)) FAILURE - if (failcnt) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-dfp.c b/gcc/testsuite/gcc.dg/dfp/convert-dfp.c index 148dff60e3f..d52ba51b0be 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-dfp.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-dfp.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* N1150 5.2 Conversions among decimal floating types and between decimal floating types and generic floating types. @@ -10,20 +10,9 @@ #define __STDC_WANT_DEC_FP__ 1 #endif +#include "dfp-dbg.h" #include <float.h> -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif - volatile _Decimal32 d32; volatile _Decimal64 d64; volatile _Decimal128 d128; @@ -101,8 +90,5 @@ main () if (d64 != __builtin_infd64()) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-int-fold.c b/gcc/testsuite/gcc.dg/dfp/convert-int-fold.c index e550369be23..038559d41e4 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-int-fold.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-int-fold.c @@ -1,9 +1,17 @@ -/* { dg-options "-std=gnu99 -O2" } */ +/* { dg-options "-O2" } */ /* N1150 5.1 Conversion between decimal floating integer. C99 6.3.1.4(1a) New. These should all be folded at compile time. */ +#include "dfp-dbg.h" + +#ifdef __cplusplus +#define BOOL bool +#else +#define BOOL _Bool +#endif + extern void link_error (void); int @@ -18,11 +26,11 @@ main () int si; long sl; long long sll; - _Bool b; + BOOL b; /* C99 Section 6.7.2 Type specifiers. Type _Bool is mentioned in this section. Conversions between - _Bool and DFP types. */ + BOOL and DFP types. */ /* Decimal float to unsigned integer. */ d32 = 456.789df; @@ -61,7 +69,7 @@ main () /* Decimal float to signed integer. */ - /* Decimal float to _Bool. */ + /* Decimal float to BOOL. */ d32 = 1.23df; d64 = -3.4dd; d128 = 0.00003dl; @@ -146,7 +154,7 @@ main () if (d128 != -1234567.dl) link_error (); - /* _Bool to decimal float. */ + /* BOOL to decimal float. */ d32 = 0.0DF; d64 = 0.0DD; d128 = 0.0DL; diff --git a/gcc/testsuite/gcc.dg/dfp/convert-int-max-fold.c b/gcc/testsuite/gcc.dg/dfp/convert-int-max-fold.c index 7e016918ad2..3f6faae34cc 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-int-max-fold.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-int-max-fold.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O2" } */ +/* { dg-options "-O2 -w" } */ /* N1150 5.1 Conversions from decimal float to integer. */ @@ -7,6 +7,8 @@ 64-bit long long (there's a check for that below). This version tests conversions during compilation. */ +#include "dfp-dbg.h" + extern void link_error (void); void diff --git a/gcc/testsuite/gcc.dg/dfp/convert-int-max.c b/gcc/testsuite/gcc.dg/dfp/convert-int-max.c index cb0c428a164..724627d3763 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-int-max.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-int-max.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0 -w" } */ /* N1150 5.1 Conversions from decimal float to integer. */ @@ -6,15 +6,7 @@ what will fit into the destination type. This assumes 32-bit int and 64-bit long long (there's a check for that below). */ -extern void abort (void); -int failcnt; - -#ifdef DBG -extern int printf (const char *, ...); -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" volatile _Decimal32 d32; volatile _Decimal64 d64; @@ -150,7 +142,5 @@ main () doit (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-int-saturate.c b/gcc/testsuite/gcc.dg/dfp/convert-int-saturate.c index ab4c8d268ad..c92502d56ad 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-int-saturate.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-int-saturate.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* N1150 5.1 Conversion between decimal floating integer. C99 6.3.1.4(1a) New. Test integer saturation. */ @@ -8,11 +6,10 @@ #define __STDC_WANT_DEC_FP__ 1 #endif +#include "dfp-dbg.h" #include <float.h> #include <limits.h> -extern void abort (void); - volatile _Decimal32 d32; volatile _Decimal64 d64; volatile _Decimal128 d128; @@ -28,40 +25,40 @@ main () /* Unsigned. */ usi = DEC32_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (usi != UINT_MAX) - abort (); + FAILURE usi = DEC64_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (usi != UINT_MAX) - abort (); + FAILURE usi = DEC128_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (usi != UINT_MAX) - abort (); + FAILURE /* Signed. */ si = DEC32_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (si != INT_MAX) - abort (); + FAILURE si = DEC64_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (si != INT_MAX) - abort (); + FAILURE si = DEC128_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (si != INT_MAX) - abort (); + FAILURE si = - DEC32_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (si != INT_MIN) - abort (); + FAILURE si = - DEC64_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (si != INT_MIN) - abort (); + FAILURE si = - DEC128_MAX; /* { dg-warning "overflow in implicit constant conversion" } */ if (si != INT_MIN) - abort (); + FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert-int.c b/gcc/testsuite/gcc.dg/dfp/convert-int.c index 45efe32a5e8..1525d5760a4 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert-int.c +++ b/gcc/testsuite/gcc.dg/dfp/convert-int.c @@ -1,16 +1,14 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* N1150 5.1 Conversion between decimal floating types and integer. C99 6.3.1.4(1a) New. */ -extern void abort (void); -int failcnt; +#include "dfp-dbg.h" -#ifdef DBG -extern int printf (const char *, ...); -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } +#ifdef __cplusplus +#define BOOL bool #else -#define FAILURE abort (); +#define BOOL _Bool #endif _Decimal32 d32; @@ -22,7 +20,7 @@ unsigned long long ull; int si; long sl; long long sll; -_Bool b; +BOOL b; void init_dfp_1 (void) @@ -68,7 +66,7 @@ main () { /* C99 Section 6.7.2 Type specifiers. Type _Bool is mentioned in this section. Conversions between - _Bool and DFP types. */ + BOOL and DFP types. */ /* Decimal float to unsigned integer. */ init_dfp_1 (); @@ -105,7 +103,7 @@ main () /* Decimal float to signed integer. */ - /* Decimal float to _Bool. */ + /* Decimal float to BOOL. */ init_dfp_2 (); b = d32; @@ -184,7 +182,7 @@ main () if (d128 != -1234567.dl) FAILURE - /* _Bool to decimal float. */ + /* BOOL to decimal float. */ init_dfp_3 (); b = d32; @@ -197,8 +195,5 @@ main () if (b) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/convert.h b/gcc/testsuite/gcc.dg/dfp/convert.h index bc9ef42f4dd..304164ff627 100644 --- a/gcc/testsuite/gcc.dg/dfp/convert.h +++ b/gcc/testsuite/gcc.dg/dfp/convert.h @@ -1,5 +1,4 @@ -extern void abort (void); -static int failcnt = 0; +#include "dfp-dbg.h" /* Macros are set up to skip using long double, which doesn't necessarily map to TF mode. If there's a reason to skip those for a test, the @@ -8,14 +7,16 @@ static int failcnt = 0; #define USE_TF 1 #endif -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ +/* Provide more information with FAILURE than what is available with + the version of that macro in dfp-dbg.h. */ + +#undef FAILURE #if defined(DBG) || defined(DBG2) #include <stdio.h> #define FAILURE(NUM) \ - { printf ("failed for test %s\n", NUM); failcnt++; } + { printf ("failed for test %s\n", NUM); failures++; } #else -#define FAILURE(N) abort (); +#define FAILURE(N) __builtin_abort (); #endif /* This is useful when modifying the test to make sure that tests are diff --git a/gcc/testsuite/gcc.dg/dfp/ctypes.c b/gcc/testsuite/gcc.dg/dfp/ctypes.c index 6afacd5173d..ca8fe954e5e 100644 --- a/gcc/testsuite/gcc.dg/dfp/ctypes.c +++ b/gcc/testsuite/gcc.dg/dfp/ctypes.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* N1150 3: Decimal floating types. C99 6.7.2: Type specifiers */ diff --git a/gcc/testsuite/gcc.dg/dfp/ddmode-ice.c b/gcc/testsuite/gcc.dg/dfp/ddmode-ice.c index 979dabe11e2..19f3038010b 100644 --- a/gcc/testsuite/gcc.dg/dfp/ddmode-ice.c +++ b/gcc/testsuite/gcc.dg/dfp/ddmode-ice.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -O1" } */ +/* { dg-options "-O1" } */ /* This used to result in an ICE. */ diff --git a/gcc/testsuite/gcc.dg/dfp/dec-eval-method-2.c b/gcc/testsuite/gcc.dg/dfp/dec-eval-method-2.c index 55001cc3822..b87f159bf3b 100644 --- a/gcc/testsuite/gcc.dg/dfp/dec-eval-method-2.c +++ b/gcc/testsuite/gcc.dg/dfp/dec-eval-method-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -D__STDC_WANT_DEC_FP__" } */ +/* { dg-options "-D__STDC_WANT_DEC_FP__" } */ /* N1107 4: Characteristics of decimal floating types <float.h>. C99 5.2.4.2.2a[2] (New). diff --git a/gcc/testsuite/gcc.dg/dfp/decfloat-constants.c b/gcc/testsuite/gcc.dg/dfp/decfloat-constants.c index ec9d3816706..c72933f4233 100644 --- a/gcc/testsuite/gcc.dg/dfp/decfloat-constants.c +++ b/gcc/testsuite/gcc.dg/dfp/decfloat-constants.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* N1150 4: Characteristics of decimal floating types <float.h>. C99 5.2.4.2.2a[3]: New. @@ -11,20 +9,9 @@ #define __STDC_WANT_DEC_FP__ 1 #endif +#include "dfp-dbg.h" #include <float.h> -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif - int main () { if (DEC32_MANT_DIG != 7) FAILURE @@ -56,8 +43,5 @@ int main () if (DEC128_SUBNORMAL_MIN != 0.000000000000000000000000000000001E-6143DL) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/dfp-dbg.h b/gcc/testsuite/gcc.dg/dfp/dfp-dbg.h new file mode 100644 index 00000000000..253a9d05f57 --- /dev/null +++ b/gcc/testsuite/gcc.dg/dfp/dfp-dbg.h @@ -0,0 +1,12 @@ +#define EXTERN extern + +int failures; + +#ifdef DBG +extern int printf (const char *, ...); +#define FAILURE { printf ("failed at line %d\n", __LINE__); failures++; } +#define FINISH if (failures != 0) __builtin_abort (); return 0; +#else +#define FAILURE __builtin_abort (); +#define FINISH return 0; +#endif diff --git a/gcc/testsuite/gcc.dg/dfp/dfp.exp b/gcc/testsuite/gcc.dg/dfp/dfp.exp index 2619a94122f..ce6668fb66f 100644 --- a/gcc/testsuite/gcc.dg/dfp/dfp.exp +++ b/gcc/testsuite/gcc.dg/dfp/dfp.exp @@ -37,12 +37,14 @@ if { ![check_effective_target_dfprt] } { } verbose "dfp.exp: dg-do-what-default is ${dg-do-what-default}" 2 -# If a testcase doesn't have special options, use these. global DEFAULT_CFLAGS -if ![info exists DEFAULT_CFLAGS] then { - set DEFAULT_CFLAGS " -ansi -pedantic-errors" +if [info exists DEFAULT_CFLAGS] then { + set save_default_cflags $DEFAULT_CFLAGS } +# If a testcase doesn't have special options, use these. +set DEFAULT_CFLAGS "-std=gnu99" + # Initialize `dg'. dg-init @@ -55,3 +57,6 @@ dg-finish set dg-do-what-default ${save-dg-do-what-default} verbose "dfp.exp: dg-do-what-default is ${dg-do-what-default}" 2 +if [info exists save_default_cflags] { + set DEFAULT_CFLAGS $save_default_cflags +} diff --git a/gcc/testsuite/gcc.dg/dfp/fe-binop.c b/gcc/testsuite/gcc.dg/dfp/fe-binop.c index 23f137818ed..eb0da1b2c6e 100644 --- a/gcc/testsuite/gcc.dg/dfp/fe-binop.c +++ b/gcc/testsuite/gcc.dg/dfp/fe-binop.c @@ -1,4 +1,3 @@ -/* { dg-options "-std=gnu99" } */ /* { dg-skip-if "test is for emulation" { hard_dfp } { "*" } { "" } } */ /* Touch tests that check for raising appropriate exceptions for binary @@ -102,7 +101,5 @@ main () binop_501 (); binop_502 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/fe-check.h b/gcc/testsuite/gcc.dg/dfp/fe-check.h index 0e072aa9fa1..9c5f0ff8c59 100644 --- a/gcc/testsuite/gcc.dg/dfp/fe-check.h +++ b/gcc/testsuite/gcc.dg/dfp/fe-check.h @@ -2,19 +2,17 @@ are raised for decimal float operations. These tests are here to test the software decimal float support in libgcc. */ +#include "dfp-dbg.h" #include "dfp-except.h" -extern void abort (void); -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ #if defined(DBG) || defined(DBG2) #include <stdio.h> +#undef FAILURE #define FAILURE(NUM,KIND,EXCEPT) \ - { printf ("failed for test %d: %s %s\n", NUM, KIND, EXCEPT); failcnt++; } + { printf ("failed for test %d: %s %s\n", NUM, KIND, EXCEPT); failures++; } #else -#define FAILURE(N,K,E) abort (); +#undef FAILURE +#define FAILURE(N,K,E) __builtin_abort (); #endif /* This is useful when modifying the test to make sure that tests are diff --git a/gcc/testsuite/gcc.dg/dfp/fe-convert-1.c b/gcc/testsuite/gcc.dg/dfp/fe-convert-1.c index f65cf7870ae..b6528029b40 100644 --- a/gcc/testsuite/gcc.dg/dfp/fe-convert-1.c +++ b/gcc/testsuite/gcc.dg/dfp/fe-convert-1.c @@ -1,4 +1,3 @@ -/* { dg-options "-std=gnu99" } */ /* { dg-skip-if "test is for emulation" { hard_dfp } { "*" } { "" } } */ /* Check that appropriate exceptions are raised for conversions involving @@ -37,7 +36,5 @@ main () convert_121 (); convert_122 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/fe-convert-2.c b/gcc/testsuite/gcc.dg/dfp/fe-convert-2.c index 83b490d54be..4abce24c608 100644 --- a/gcc/testsuite/gcc.dg/dfp/fe-convert-2.c +++ b/gcc/testsuite/gcc.dg/dfp/fe-convert-2.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* Check that appropriate exceptions are raised for BFP to DFP conversions. The test only uses double and _Decimal32; tests for conversions to _Decimal64 would need 128-bit long double. */ @@ -29,7 +27,5 @@ main () convert_104 (); convert_105 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/fe-convert-3.c b/gcc/testsuite/gcc.dg/dfp/fe-convert-3.c index e3fe30eeb11..5938edb94e7 100644 --- a/gcc/testsuite/gcc.dg/dfp/fe-convert-3.c +++ b/gcc/testsuite/gcc.dg/dfp/fe-convert-3.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* Check that appropriate exceptions are raised for int to DFP conversions. */ #include "fe-check.h" @@ -43,7 +41,5 @@ main () convert_210 (); convert_211 (); - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/float-constant-double.c b/gcc/testsuite/gcc.dg/dfp/float-constant-double.c index 3f8de656bf6..52c5d712665 100644 --- a/gcc/testsuite/gcc.dg/dfp/float-constant-double.c +++ b/gcc/testsuite/gcc.dg/dfp/float-constant-double.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* Constant float values of type double in <float.h> are suffixed with L and cast to double so they can be used within code that uses pragma diff --git a/gcc/testsuite/gcc.dg/dfp/func-array.c b/gcc/testsuite/gcc.dg/dfp/func-array.c index 93713486baa..6d158f35523 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-array.c +++ b/gcc/testsuite/gcc.dg/dfp/func-array.c @@ -1,19 +1,7 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.2.2 Function calls. Test passing array elements involving decimal floating point types. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" /* A handful of functions that return the Nth _Decimal32 argument of an incoming array. */ @@ -165,8 +153,5 @@ int main() if (arg4_128 (d128) != 4.0dl) FAILURE if (arg5_128 (d128) != 5.0dl) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-deref.c b/gcc/testsuite/gcc.dg/dfp/func-deref.c index d16e70d29d5..81a48a9f8e8 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-deref.c +++ b/gcc/testsuite/gcc.dg/dfp/func-deref.c @@ -1,20 +1,8 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.2.2 Function calls. Test scalar passing and return values involving decimal floating point types and dereferenced pointers. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" /* A handful of functions that return their Nth _Decimal32 argument. */ @@ -213,8 +201,5 @@ main () if (arg5_128 (*pdl0, *pdl1, *pdl2, *pdl3, *pdl4, *pdl5) != 5.0dl) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-mixed.c b/gcc/testsuite/gcc.dg/dfp/func-mixed.c index 620d342e980..6f7e2eb4157 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-mixed.c +++ b/gcc/testsuite/gcc.dg/dfp/func-mixed.c @@ -1,20 +1,10 @@ -/* { dg-options "-std=gnu99 -Wall" } */ +/* { dg-options "-Wall" } */ /* C99 6.5.2.2 Function calls. Test scalar passing and return values involving decimal floating point types. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" /* A handful of functions that return their Nth _Decimal32 argument with mixed types in parameter list. */ @@ -180,8 +170,5 @@ main () if (arg4_128 (0, -1, 2.0f, 3.0, 4.0dl, 5.0l) != 4.0dl) FAILURE if (arg5_128 (0, -1, 2.0f, 3.0, 4.0l, 5.0dl) != 5.0dl) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-pointer.c b/gcc/testsuite/gcc.dg/dfp/func-pointer.c index e1faceb63f0..cfdf2356c9d 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-pointer.c +++ b/gcc/testsuite/gcc.dg/dfp/func-pointer.c @@ -1,20 +1,8 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.2.2 Function calls. Test pointer argument passing and return values involving decimal floating point types. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" /* A handful of functions that return their Nth pointer to Decimal32 argument. */ @@ -213,8 +201,5 @@ main () if (*arg5_128 (pdl0, pdl1, pdl2, pdl3, pdl4, pdl5) != 5.0dl) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-scalar.c b/gcc/testsuite/gcc.dg/dfp/func-scalar.c index bbda52c0773..370c21b20e2 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-scalar.c +++ b/gcc/testsuite/gcc.dg/dfp/func-scalar.c @@ -1,20 +1,8 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.2.2 Function calls. Test scalar passing and return values involving decimal floating point types. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" /* A handful of functions that return their Nth _Decimal32 argument. */ @@ -200,8 +188,5 @@ main () if (arg5_128 (0.0dl, 1.0dl, 2.0dl, 3.0dl, 4.0dl, 5.0dl) != 5.0dl) FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-struct.c b/gcc/testsuite/gcc.dg/dfp/func-struct.c index f022f181659..ad0224d6cad 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-struct.c +++ b/gcc/testsuite/gcc.dg/dfp/func-struct.c @@ -1,20 +1,8 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.2.2 Function calls. Test structure passing and return values involving decimal floating point types. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" struct example { @@ -101,8 +89,5 @@ main () if (ptr_dummy1_field (&nums) != 'a') FAILURE if (ptr_dummy2_field (&nums) != 'b') FAILURE - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d128-2.c b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d128-2.c index 167da24b889..2960c357ade 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d128-2.c +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d128-2.c @@ -1,5 +1,5 @@ /* { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */ -/* { dg-options "-std=gnu99 -mpreferred-stack-boundary=2" } */ +/* { dg-options "-mpreferred-stack-boundary=2" } */ /* Simple test of vararg passing for problematic types with and without double values passed between them. */ @@ -17,5 +17,6 @@ int main () { doit (); - return 0; + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d128.c b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d128.c index e8fc0271dcb..8d452eadc38 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d128.c +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d128.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* Simple test of vararg passing for problematic types with and without double values passed between them. */ @@ -16,5 +14,6 @@ int main () { doit (); - return 0; + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d32.c b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d32.c index cd6853cc985..651b7e8c50f 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d32.c +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d32.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* Simple test of vararg passing for problematic types with and without double values passed between them. */ @@ -16,5 +14,6 @@ int main () { doit (); - return 0; + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d64.c b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d64.c index 39470013ecd..86b475d2ada 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d64.c +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate-d64.c @@ -1,5 +1,3 @@ -/* { dg-options "-std=gnu99" } */ - /* Simple test of vararg passing for problematic types with and without double values passed between them. */ @@ -16,5 +14,6 @@ int main () { doit (); - return 0; + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate.h b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate.h index 393111b33bc..5ba0ab0dc1f 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate.h +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-alternate.h @@ -1,14 +1,9 @@ /* Simple test of vararg passing for problematic types with and without double values passed between them. */ +#include "dfp-dbg.h" #include <stdarg.h> -#ifdef DBG -#include <stdio.h> -#endif -extern void abort (void); - -int failcnt; DTYPE a[10]; double b[10]; @@ -18,7 +13,7 @@ union U { }; void -compare (double r, double s, int *p, int *q, int n, int line) +compare (double r, double s, unsigned int *p, unsigned int *q, int n, int line) { int i; @@ -28,6 +23,7 @@ compare (double r, double s, int *p, int *q, int n, int line) { int j; + failures++; printf ("line %-3d", line); for (j = 0; j < n; j++) printf (" %08x", p[j]); @@ -39,7 +35,7 @@ compare (double r, double s, int *p, int *q, int n, int line) return; } #else - abort (); + __builtin_abort (); #endif } @@ -102,7 +98,7 @@ doit () printf ("test error: INTS = %d, sizeof (DTYPE) = %d\n", INTS, sizeof (DTYPE)); #endif - abort (); + __builtin_abort (); } x = ONE / THREE; @@ -144,7 +140,4 @@ doit () u1.d = x; u2.d = a[0]; compare (1.5, b[0], u1.i, u2.i, INTS, __LINE__); u1.d = y; u2.d = a[1]; compare (2.5, b[1], u1.i, u2.i, INTS, __LINE__); u1.d = z; u2.d = a[2]; compare (3.5, b[2], u1.i, u2.i, INTS, __LINE__); - - if (failcnt != 0) - abort (); } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-dfp.c b/gcc/testsuite/gcc.dg/dfp/func-vararg-dfp.c index 1a681bcaf9b..5add1f7fd38 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-dfp.c +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-dfp.c @@ -1,21 +1,8 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.2.2 Function calls. Test passing varargs of the decimal float types. */ #include <stdarg.h> - -extern void abort (void); -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" static _Decimal32 vararg32 (unsigned arg, ...) @@ -104,7 +91,5 @@ int main() if (vararg128 (5, 0.0dl, 1.0dl, 2.0dl, 3.0dl, 4.0dl, 5.0dl) != 5.0dl) FAILURE - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-mixed-2.c b/gcc/testsuite/gcc.dg/dfp/func-vararg-mixed-2.c index c1b349c6728..893cdae27ff 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-mixed-2.c +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-mixed-2.c @@ -1,23 +1,12 @@ /* { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */ -/* { dg-options "-std=gnu99 -mpreferred-stack-boundary=2" } */ +/* { dg-options "-mpreferred-stack-boundary=2" } */ /* C99 6.5.2.2 Function calls. Test passing varargs of the combination of decimal float types and other types. */ #include <stdarg.h> - -extern void abort (void); -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" /* Supposing the list of varying number of arguments is: unsigned int, _Decimal128, double, _Decimal32, _Decimal64. */ @@ -112,7 +101,5 @@ main () if (vararg_int (0, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 0) FAILURE if (vararg_double (2, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 2.0) FAILURE - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-mixed.c b/gcc/testsuite/gcc.dg/dfp/func-vararg-mixed.c index b5a5be45d7e..1669eaf959a 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-mixed.c +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-mixed.c @@ -1,22 +1,9 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.2.2 Function calls. Test passing varargs of the combination of decimal float types and other types. */ #include <stdarg.h> - -extern void abort (void); -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" /* Supposing the list of varying number of arguments is: unsigned int, _Decimal128, double, _Decimal32, _Decimal64. */ @@ -111,7 +98,5 @@ main () if (vararg_int (0, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 0) FAILURE if (vararg_double (2, 0, 1.0dl, 2.0, 3.0df, 4.0dd) != 2.0) FAILURE - if (failcnt != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/func-vararg-size0.c b/gcc/testsuite/gcc.dg/dfp/func-vararg-size0.c index dc94709c108..bc8b20fd484 100644 --- a/gcc/testsuite/gcc.dg/dfp/func-vararg-size0.c +++ b/gcc/testsuite/gcc.dg/dfp/func-vararg-size0.c @@ -1,10 +1,7 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.2.2 Function calls. */ #include <stdarg.h> - -extern void abort (void); +#include "dfp-dbg.h" struct S1 { @@ -38,7 +35,7 @@ main () struct S1 a1[5]; if (check_var(5, 1.0, s1, 2LL, a1[2], a1[2]) == 0) - abort (); + FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/inf-1.c b/gcc/testsuite/gcc.dg/dfp/inf-1.c index 86aa9e4cfaa..c4f8cd79610 100644 --- a/gcc/testsuite/gcc.dg/dfp/inf-1.c +++ b/gcc/testsuite/gcc.dg/dfp/inf-1.c @@ -1,63 +1,61 @@ -/* { dg-options "-std=gnu99" } */ - /* N1150 4: Characteristics of decimal floating types (not explicit) C99 5.2.4.2.2: Characteristics of floating types. A few simple checks on arithmetic operations. */ -extern void abort (void); +#include "dfp-dbg.h" int main() { /* Assumes rounding mode. */ if (9999999.E90DF + 1.E90df != __builtin_infd32 ()) - abort (); + FAILURE if (!__builtin_isinfd32 (9999999.E90DF + 1.E90df)) - abort (); + FAILURE if (9.999999999999999E384dd + .000000000000001e384dd != __builtin_infd32 ()) - abort (); + FAILURE if (-9999999.E90DF - 1.E90df != -__builtin_infd32 ()) - abort (); + FAILURE if (!__builtin_isinfd32 (9.999999999999999E384dd + .000000000000001e384dd)) - abort (); + FAILURE if (7.999999999999999999999999999999999E6144dl + 3.0E6144dl != __builtin_infd32 ()) - abort (); + FAILURE if (__builtin_infd32 () * __builtin_infd32 () != __builtin_infd32 ()) - abort (); + FAILURE if (__builtin_infd32 () * 2 != __builtin_infd32 ()) - abort (); + FAILURE if (__builtin_infd64 () * -5 != -__builtin_infd32 ()) - abort (); + FAILURE if (!__builtin_isinfd128 (__builtin_infd32 () / 4)) - abort (); + FAILURE if (__builtin_infd64 () != __builtin_infd128 ()) - abort (); + FAILURE if (!__builtin_isinfd64 (__builtin_infd128 ())) - abort (); + FAILURE if (__builtin_finited64 (__builtin_infd32 () * 4)) - abort (); + FAILURE if (!__builtin_finited128 (9.999999E90DL - 1.E90dd)) - abort (); + FAILURE if (__builtin_finited128 (__builtin_infd32 () *__builtin_infd128 ())) - abort (); + FAILURE if (__builtin_finited32 (__builtin_nand32 (""))) - abort (); - - return 0; + FAILURE + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/keywords-pedantic.c b/gcc/testsuite/gcc.dg/dfp/keywords-pedantic.c index 9492c798555..bca51066be3 100644 --- a/gcc/testsuite/gcc.dg/dfp/keywords-pedantic.c +++ b/gcc/testsuite/gcc.dg/dfp/keywords-pedantic.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -pedantic" } */ +/* { dg-options "-pedantic" } */ /* Decimal float is a GCC extension. */ diff --git a/gcc/testsuite/gcc.dg/dfp/keywords-reserved.c b/gcc/testsuite/gcc.dg/dfp/keywords-reserved.c index 4a042adf4c2..1117ae8d937 100644 --- a/gcc/testsuite/gcc.dg/dfp/keywords-reserved.c +++ b/gcc/testsuite/gcc.dg/dfp/keywords-reserved.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* N1150 3: Decimal floating types. C99 6.4.1(2): Keywords. diff --git a/gcc/testsuite/gcc.dg/dfp/loop-index.c b/gcc/testsuite/gcc.dg/dfp/loop-index.c index ff52189bc15..a944042a79b 100644 --- a/gcc/testsuite/gcc.dg/dfp/loop-index.c +++ b/gcc/testsuite/gcc.dg/dfp/loop-index.c @@ -1,9 +1,8 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.8.5.2: The for statement. */ #include <stdio.h> #include <stdlib.h> +#include "dfp-dbg.h" void f32 (void) @@ -15,7 +14,7 @@ f32 (void) i++; if (i != 5) - abort(); + FAILURE } void @@ -28,7 +27,7 @@ f64 (void) i++; if (i != 5) - abort(); + FAILURE } void @@ -41,7 +40,7 @@ f128 (void) i++; if (i != 5) - abort(); + FAILURE } int @@ -53,5 +52,6 @@ main () f64 (); f128 (); + FINISH return (0); } diff --git a/gcc/testsuite/gcc.dg/dfp/modes.c b/gcc/testsuite/gcc.dg/dfp/modes.c index ff2382b1c75..09d4a15c264 100644 --- a/gcc/testsuite/gcc.dg/dfp/modes.c +++ b/gcc/testsuite/gcc.dg/dfp/modes.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ typedef float decimal32 __attribute__ ((mode (SD))); typedef float decimal64 __attribute__ ((mode (DD))); diff --git a/gcc/testsuite/gcc.dg/dfp/nan-1.c b/gcc/testsuite/gcc.dg/dfp/nan-1.c index 50972e0eb00..8961777c79b 100644 --- a/gcc/testsuite/gcc.dg/dfp/nan-1.c +++ b/gcc/testsuite/gcc.dg/dfp/nan-1.c @@ -1,108 +1,106 @@ -/* { dg-options "-std=gnu99" } */ - /* N1150 4: Characteristics of decimal floating types (not explicit) C99 5.2.4.2.2: Characteristics of floating types. A few simple checks on arithmetic operations. */ -extern void abort (void); +#include "dfp-dbg.h" int main() { /* Some possibly non-obvious tests, but most logical operations on NaN return false, including NaN == NaN. */ if (__builtin_nand32("") == __builtin_nand32("")) - abort(); + FAILURE if (__builtin_nand64("") == __builtin_nand64("")) - abort(); + FAILURE if (__builtin_nand128("") == __builtin_nand128("")) - abort(); + FAILURE if (!(__builtin_nand32("") != __builtin_nand32(""))) - abort(); + FAILURE if (!(__builtin_nand64("") != __builtin_nand64(""))) - abort(); + FAILURE if (!(__builtin_nand128("") != __builtin_nand128(""))) - abort(); + FAILURE if (__builtin_nand32("") > __builtin_nand32("")) - abort(); + FAILURE if (__builtin_nand64("") >= __builtin_nand64("")) - abort(); + FAILURE if (__builtin_nand128("") < __builtin_nand128("")) - abort(); + FAILURE if (-__builtin_nand128("") < +__builtin_nand128("")) - abort(); + FAILURE /* 0.0/0.0 => NaN, but NaN != NaN. */ if (0.0df/0.0dl == __builtin_nand32("")) - abort(); + FAILURE /* 0.0 * INF => NaN. */ if (!__builtin_isnand32 (0.0df * __builtin_infd32())) - abort (); + FAILURE if (!__builtin_isnand64 (0.0dd * __builtin_infd64())) - abort (); + FAILURE if (!__builtin_isnand128 (0.0dd * __builtin_infd128())) - abort (); + FAILURE /* INF - INF => NaN. */ if (!__builtin_isnand32 (__builtin_infd32() - __builtin_infd32())) - abort (); + FAILURE if (!__builtin_isnand64 (__builtin_infd64() - __builtin_infd64())) - abort (); + FAILURE if (!__builtin_isnand128 (__builtin_infd128() - __builtin_infd128())) - abort (); + FAILURE /* INF/INF => NaN. */ if (!__builtin_isnand32 (__builtin_infd32()/__builtin_infd32()) ) - abort (); + FAILURE if (!__builtin_isnand64 (__builtin_infd64()/__builtin_infd64()) ) - abort (); + FAILURE if (!__builtin_isnand128 (__builtin_infd128()/__builtin_infd128()) ) - abort (); + FAILURE /* 0.0/0.0 => NaN, but NaN != NaN. */ if ((0.0dd/0.0df) == (0.0dd/0.0df)) - abort(); + FAILURE if (__builtin_nand32("") < __builtin_infd32()) - abort(); + FAILURE if (__builtin_nand32("") >= __builtin_infd32()) - abort(); + FAILURE /* Fixme: Add sqrtdf(-x.df) test when sqrt is supported. */ if (!__builtin_isnand32(__builtin_nand32(""))) - abort(); + FAILURE if (!__builtin_isnand64(__builtin_nand64(""))) - abort(); + FAILURE if (!__builtin_isnand128(__builtin_nand128(""))) - abort(); + FAILURE if (!__builtin_isnand128(8.0df * __builtin_nand128(""))) - abort(); + FAILURE if (!__builtin_isnand32(8.1dl - __builtin_nand32(""))) - abort(); + FAILURE if (!__builtin_isnand128(__builtin_nand64("") + __builtin_nand128(""))) - abort(); + FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/nan-2.c b/gcc/testsuite/gcc.dg/dfp/nan-2.c index e8a663e74e1..ec9d18e1000 100644 --- a/gcc/testsuite/gcc.dg/dfp/nan-2.c +++ b/gcc/testsuite/gcc.dg/dfp/nan-2.c @@ -1,11 +1,9 @@ -/* { dg-options "-std=gnu99" } */ - /* N1150 4: Characteristics of decimal floating types (not explicit) C99 5.2.4.2.2: Characteristics of floating types. A few simple checks on arithmetic operations. Based on nan-1.c with the consideration of negative zero. */ -extern void abort (void); +#include "dfp-dbg.h" int main() { @@ -17,39 +15,39 @@ int main() result. */ d32 = 123.45f; if (d32/-0.0df != -__builtin_infd32()) - abort(); + FAILURE if (123.45df/-0.0df != -__builtin_infd32()) - abort(); + FAILURE d64 = 123.45f; if (d64/-0.0dd != -__builtin_infd64()) - abort(); + FAILURE if (123.45dd/-0.0dd != -__builtin_infd64()) - abort(); + FAILURE d128 = 123.45f; if (d128/-0.0dl != -__builtin_infd64()) - abort(); + FAILURE if (123.45dl/-0.0dl != -__builtin_infd128()) - abort(); + FAILURE d32 = 0.0df; if (!__builtin_isnand32(-(d32/-0.0df))) - abort(); + FAILURE if (!__builtin_isnand32(-(0.0df/-0.0df))) - abort(); + FAILURE d64 = 0.0dd; if (!__builtin_isnand64(-(d64/-0.0dd))) - abort(); + FAILURE if (!__builtin_isnand64(-(0.0dd/-0.0dd))) - abort(); + FAILURE d128 = 0.0dl; if (!__builtin_isnand128(-(d128/-0.0dl))) - abort(); + FAILURE if (!__builtin_isnand128(-(0.0dl/-0.0dl))) - abort(); + FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/operator-arith-fold.c b/gcc/testsuite/gcc.dg/dfp/operator-arith-fold.c index ad398d9b67c..c4aa4cbb27e 100644 --- a/gcc/testsuite/gcc.dg/dfp/operator-arith-fold.c +++ b/gcc/testsuite/gcc.dg/dfp/operator-arith-fold.c @@ -1,8 +1,10 @@ -/* { dg-options "-std=gnu99 -O2" } */ +/* { dg-options "-O2" } */ /* C99 6.5.5: Multiplicative operators. C99 6.5.6: Additive operators. */ +#include "dfp-dbg.h" + extern void link_error (void); int diff --git a/gcc/testsuite/gcc.dg/dfp/operator-assignment.c b/gcc/testsuite/gcc.dg/dfp/operator-assignment.c index 49d15d2382d..faadf1e8650 100644 --- a/gcc/testsuite/gcc.dg/dfp/operator-assignment.c +++ b/gcc/testsuite/gcc.dg/dfp/operator-assignment.c @@ -1,21 +1,9 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.16 Assignment operators. Verify the compound assignment operator for decimal float types, using it with other decimal float types, integers, and other binary float types cast to decimal float types. */ -extern void abort (void); -static int failcnt; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" #define OPERATE(OPRD1,OPRT,OPRD2,RLT) \ if (( OPRD1 OPRT OPRD2 )!= RLT) \ @@ -64,8 +52,5 @@ main () DECIMAL_COMPOUND_ASSIGNMENT(64, d64); DECIMAL_COMPOUND_ASSIGNMENT(128, d128); - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/operator-bitwise.c b/gcc/testsuite/gcc.dg/dfp/operator-bitwise.c index 8523cb91a5f..f895a970578 100644 --- a/gcc/testsuite/gcc.dg/dfp/operator-bitwise.c +++ b/gcc/testsuite/gcc.dg/dfp/operator-bitwise.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* C99 6.5.10: Bitwise AND operator. C99 6.5.11: Bitwise exclusive OR operator. @@ -7,8 +6,6 @@ Test that these operators do not accept decimal float operands. */ -extern void abort (void); - #define OPERATE(OPRD1,OPRT,OPRD2) \ do \ { \ diff --git a/gcc/testsuite/gcc.dg/dfp/operator-comma.c b/gcc/testsuite/gcc.dg/dfp/operator-comma.c index 904f9b3a676..be6bf6f8cd1 100644 --- a/gcc/testsuite/gcc.dg/dfp/operator-comma.c +++ b/gcc/testsuite/gcc.dg/dfp/operator-comma.c @@ -1,19 +1,9 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.17: Comma operator. Test with decimal float operands. */ -extern void abort (void); -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" volatile _Decimal32 d32a, d32b, d32c; volatile _Decimal64 d64a, d64b, d64c; @@ -53,5 +43,5 @@ main () if (d64a != 12.0dd) FAILURE; - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/operator-cond.c b/gcc/testsuite/gcc.dg/dfp/operator-cond.c index 5230134f637..140dd95074a 100644 --- a/gcc/testsuite/gcc.dg/dfp/operator-cond.c +++ b/gcc/testsuite/gcc.dg/dfp/operator-cond.c @@ -1,19 +1,9 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* C99 6.5.15 Conditional operator. Test with decimal float operands. */ -extern void abort (void); -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" volatile _Decimal32 d32a, d32b, d32c; volatile _Decimal64 d64a, d64b, d64c; @@ -63,5 +53,5 @@ main () if (d128a != d128b) FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/operator-logical.c b/gcc/testsuite/gcc.dg/dfp/operator-logical.c index 90a94b078fa..c784468c77a 100644 --- a/gcc/testsuite/gcc.dg/dfp/operator-logical.c +++ b/gcc/testsuite/gcc.dg/dfp/operator-logical.c @@ -1,16 +1,14 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 Logical AND operator. C99 Logical OR operator. Test with decimal float operands. */ -extern void abort (void); +#include "dfp-dbg.h" #define OPERATE(OPRD1,OPRT,OPRD2,RLT) \ do \ { \ if (( (OPRD1) OPRT (OPRD2) )!= RLT) \ - abort (); \ + __builtin_abort (); \ } while (0) #define DECIMAL_LOGICAL_OR(OPRD) \ diff --git a/gcc/testsuite/gcc.dg/dfp/operator-unary.c b/gcc/testsuite/gcc.dg/dfp/operator-unary.c index bcf50683c0c..65f0be074d9 100644 --- a/gcc/testsuite/gcc.dg/dfp/operator-unary.c +++ b/gcc/testsuite/gcc.dg/dfp/operator-unary.c @@ -1,23 +1,21 @@ -/* { dg-options "-std=gnu99" } */ - /* C99 6.5.3 Unary operators. */ -extern void abort (void); +#include "dfp-dbg.h" #define AUTO_INCREASE_DECREASE(TYPE,SUFFIX) \ do \ { \ - _Decimal##TYPE in_de_d##TYPE = 0.0##SUFFIX; \ - if (in_de_d##TYPE++) abort (); \ - if (--in_de_d##TYPE) abort (); \ - if (++in_de_d##TYPE == 0.0##SUFFIX) abort (); \ - if (in_de_d##TYPE-- == 0.0##SUFFIX) abort (); \ + _Decimal##TYPE in_de_d##TYPE = 0.0##SUFFIX; \ + if (in_de_d##TYPE++) FAILURE \ + if (--in_de_d##TYPE) FAILURE \ + if (++in_de_d##TYPE == 0.0##SUFFIX) FAILURE \ + if (in_de_d##TYPE-- == 0.0##SUFFIX) FAILURE \ } while(0) #define UNARY_OPERATOR(TYPE,SUFFIX) \ do \ { \ - _Decimal##TYPE unary_d##TYPE = 1.0##SUFFIX; \ + _Decimal##TYPE unary_d##TYPE = 1.0##SUFFIX; \ _Decimal##TYPE* unary_dp##TYPE; \ /* & operator. */ \ unary_dp##TYPE = &(unary_d##TYPE); \ @@ -25,11 +23,11 @@ do \ unary_d##TYPE = *(unary_dp##TYPE); \ /* - operator. */ \ unary_d##TYPE = -unary_d##TYPE; \ - if (unary_d##TYPE != -1.0##SUFFIX) abort (); \ + if (unary_d##TYPE != -1.0##SUFFIX) FAILURE \ /* + operator. */ \ unary_d##TYPE = +unary_d##TYPE; \ - if (unary_d##TYPE != -1.0##SUFFIX) abort (); \ - if (!unary_d##TYPE) abort (); /*! operator. */ \ + if (unary_d##TYPE != -1.0##SUFFIX) FAILURE \ + if (!unary_d##TYPE) FAILURE /*! operator. */ \ } while (0) int @@ -46,9 +44,9 @@ main () UNARY_OPERATOR(128, DL); /* C99 6.5.3 Unary operators for zero values. */ - if (- +0.df != -0.df) abort (); - if (+ -0.df != -0.df) abort (); - if (- -0.df != +0.df) abort (); + if (- +0.df != -0.df) FAILURE + if (+ -0.df != -0.df) FAILURE + if (- -0.df != +0.df) FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/pr31344.c b/gcc/testsuite/gcc.dg/dfp/pr31344.c index de76a72f937..0f5e21ecdff 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr31344.c +++ b/gcc/testsuite/gcc.dg/dfp/pr31344.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-O -std=gnu99 -mtune=i386" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */ -/* { dg-options "-O -std=gnu99" } */ +/* { dg-options "-O -mtune=i386" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */ +/* { dg-options "-O" } */ typedef struct { diff --git a/gcc/testsuite/gcc.dg/dfp/pr31385.c b/gcc/testsuite/gcc.dg/dfp/pr31385.c index 63a23c4bb75..fc024a3e6b8 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr31385.c +++ b/gcc/testsuite/gcc.dg/dfp/pr31385.c @@ -1,7 +1,7 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -O2" } */ +/* { dg-options "-O2" } */ -typedef _Decimal32 fp_t; +typedef float fp_t __attribute__((mode(SD))); extern fp_t g(fp_t); diff --git a/gcc/testsuite/gcc.dg/dfp/pr33466.c b/gcc/testsuite/gcc.dg/dfp/pr33466.c index c8ac1116558..e1cd76b74ff 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr33466.c +++ b/gcc/testsuite/gcc.dg/dfp/pr33466.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* The suffix for a decimal float constant must use a single case. diff --git a/gcc/testsuite/gcc.dg/dfp/pr35620.c b/gcc/testsuite/gcc.dg/dfp/pr35620.c index 90f9500c384..37a9c4044ed 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr35620.c +++ b/gcc/testsuite/gcc.dg/dfp/pr35620.c @@ -1,5 +1,9 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -O2" } */ +/* { dg-options "-O2" } */ + +#ifdef __cplusplus +typedef float _Decimal32 __attribute__((mode(SD))); +#endif extern void foo (_Decimal32); _Decimal32 *p; diff --git a/gcc/testsuite/gcc.dg/dfp/pr36800.c b/gcc/testsuite/gcc.dg/dfp/pr36800.c index 5b899cf0e7f..76ff28c9815 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr36800.c +++ b/gcc/testsuite/gcc.dg/dfp/pr36800.c @@ -1,26 +1,25 @@ /* { dg-do run } */ -/* { dg-options "-std=gnu99" } */ #include <stdarg.h> -extern void abort (void); +#include "dfp-dbg.h" void f (int a, ...) { va_list ap; if (a != 0) - abort (); + FAILURE va_start (ap, a); if (va_arg (ap, _Decimal128) != 1.2DL) - abort (); + FAILURE if (va_arg (ap, _Decimal128) != 2.34DL) - abort (); + FAILURE if (va_arg (ap, _Decimal128) != 3.456DL) - abort (); + FAILURE if (va_arg (ap, _Decimal128) != 4.567DL) - abort (); + FAILURE if (va_arg (ap, double) != 5.125) - abort (); + FAILURE va_end (ap); } @@ -28,5 +27,6 @@ int main (void) { f (0, 1.2DL, 2.34DL, 3.456DL, 4.567DL, 5.125); - return 0; + + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/pr37435.c b/gcc/testsuite/gcc.dg/dfp/pr37435.c index 98acc9c118b..867fdd26bc4 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr37435.c +++ b/gcc/testsuite/gcc.dg/dfp/pr37435.c @@ -1,5 +1,5 @@ /* { dg-do compile { target fpic } } */ -/* { dg-options "-std=gnu99 -O2 -fPIC" } */ +/* { dg-options "-O2 -fPIC" } */ volatile _Decimal32 d; volatile int i; diff --git a/gcc/testsuite/gcc.dg/dfp/pr39034.c b/gcc/testsuite/gcc.dg/dfp/pr39034.c index 6a261c9ddc2..2a7eedbdbe2 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr39034.c +++ b/gcc/testsuite/gcc.dg/dfp/pr39034.c @@ -1,19 +1,10 @@ /* { dg-do run } */ -/* { dg-options "-std=gnu99 -O" } */ +/* { dg-options "-O" } */ /* DFP TR 24732 == WG14 / N1176, N1312 */ /* Based on a test from Fred Tydeman. */ -extern void abort (void); -int failures = 0; - -#ifdef DBG -#include <stdio.h> -#define FAILURE(MSG) { printf ("line %d: %s\n", __LINE__, MSG); failures++; } -#else -#define FAILURE(MSG) failures++; -#endif - +#include "dfp-dbg.h" /* Test runtime computations. */ @@ -25,9 +16,9 @@ runtime32 (void) _Decimal32 d32 = (float)((v1/v2-v3) - (v4/v5-v6)); if (b32) - FAILURE ("runtime: b32 should be zero") + FAILURE if (d32) - FAILURE ("runtime: d32 should be zero") + FAILURE } void @@ -38,9 +29,9 @@ runtime64 (void) _Decimal64 d64 = (double)((v1/v2-v3) - (v4/v5-v6)); if (b64) - FAILURE ("runtime: b64 should be zero") + FAILURE if (d64) - FAILURE ("runtime: d64 should be zero") + FAILURE } void @@ -52,9 +43,9 @@ runtime128 (void) _Decimal128 d128 = (long double)((v1/v2-v3) - (v4/v5-v6)); if (b128) - FAILURE ("runtime: b128 should be zero") + FAILURE if (d128) - FAILURE ("runtime: d128 should be zero") + FAILURE } /* Test constant folding. */ @@ -66,9 +57,9 @@ fold32 (void) _Decimal32 b32 = (float)((28.f/3.f-9.f) - (31.f/3.f-10.f)); if (b32) - FAILURE ("fold: b32 should be zero") + FAILURE if (d32) - FAILURE ("fold: d32 should be zero") + FAILURE } void @@ -78,9 +69,9 @@ fold64 (void) _Decimal64 d64 = (double)((28./3.-9.) - (31./3.-10.)); if (b64) - FAILURE ("fold: b64 should be zero") + FAILURE if (d64) - FAILURE ("fold: d64 should be zero") + FAILURE } void @@ -90,9 +81,9 @@ fold128 (void) _Decimal128 d128 = (long double)((28./3.-9.) - (31./3.-10.)); if (b128) - FAILURE ("fold: b128 should be zero") + FAILURE if (d128) - FAILURE ("fold: d128 should be zero") + FAILURE } int @@ -105,7 +96,5 @@ main () fold64 (); fold128 (); - if (failures != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/pr39035.c b/gcc/testsuite/gcc.dg/dfp/pr39035.c index 2d44e06a432..2c9e8b386ed 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr39035.c +++ b/gcc/testsuite/gcc.dg/dfp/pr39035.c @@ -1,18 +1,10 @@ /* { dg-do run } */ -/* { dg-options "-std=gnu99 -O" } */ +/* { dg-options "-O" } */ /* DFP TR 24732 == WG14 / N1176, N1312 */ /* Based on a test from Fred Tydeman. */ -extern void abort (void); -int failures = 0; - -#ifdef DBG -#include <stdio.h> -#define FAILURE(MSG) { printf ("line %d: %s\n", __LINE__, MSG); failures++; } -#else -#define FAILURE(MSG) failures++; -#endif +#include "dfp-dbg.h" /* Test runtime computations. */ @@ -22,7 +14,7 @@ runtime32 (void) volatile _Decimal32 d; d = 0.0DF; if (d) - FAILURE ("0.0DF should be zero") + FAILURE } void @@ -31,7 +23,7 @@ runtime64 (void) volatile _Decimal64 d; d = 0.0DD; if (d) - FAILURE ("0.0DD should be zero") + FAILURE } void @@ -40,28 +32,28 @@ runtime128 (void) volatile _Decimal128 d; d = 0.0DL; if (d) - FAILURE ("0.0DL should be zero") + FAILURE } void fold32 (void) { if (0.0DF) - FAILURE ("0.0DF should be zero") + FAILURE } void fold64 (void) { if (0.0DD) - FAILURE ("0.0DD should be zero") + FAILURE } void fold128 (void) { if (0.0DL) - FAILURE ("0.0DL should be zero") + FAILURE } int @@ -75,7 +67,5 @@ main(void) fold64 (); fold128 (); - if (failures != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/pr39902.c b/gcc/testsuite/gcc.dg/dfp/pr39902.c index 120610c3779..847069966e3 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr39902.c +++ b/gcc/testsuite/gcc.dg/dfp/pr39902.c @@ -1,18 +1,8 @@ -/* { dg-options "--std=gnu99" } */ - /* Check that optimizations like (x * 1) to x, or (x * -1) to -x, do not apply to decimal float computations where trailing zeroes are significant. */ -extern void abort (void); -int failcnt; - -#ifdef DBG -extern int printf (const char *, ...); -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" #define COMPARE32(A,B) \ A.i == B.i @@ -232,8 +222,5 @@ main (void) doit64 (); doit128 (); - if (failcnt != 0) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/pr39986.c b/gcc/testsuite/gcc.dg/dfp/pr39986.c index 53bda3c824a..e7c9ce98283 100644 --- a/gcc/testsuite/gcc.dg/dfp/pr39986.c +++ b/gcc/testsuite/gcc.dg/dfp/pr39986.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ + +#include "dfp-dbg.h" /* Check that the compiler generates the correct decimal float constants. */ diff --git a/gcc/testsuite/gcc.dg/dfp/pr41049.c b/gcc/testsuite/gcc.dg/dfp/pr41049.c new file mode 100644 index 00000000000..6187481eca1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/dfp/pr41049.c @@ -0,0 +1,562 @@ +/* { dg-options "-std=gnu99" } */ + +/* The preferred exponent of the result of a conversion from an + integral type to a decimal float type is zero. A conversion at + either compile time or runtime should not change the number of + trailing zeroes. */ + +#include "dfp-dbg.h" + +#define PASTE2(A,B) A ## B +#define PASTE(A,B) PASTE2(A,B) + +#define TESTVAL_NEG(VAL,SUF,SIZE) \ + x = PASTE(PASTE(VAL,.),SUF); \ + si = VAL; \ + sll = PASTE(VAL,LL); \ + a = si; \ + b = sll; \ + c = VAL; \ + d = PASTE(VAL,LL); \ + if ((__builtin_memcmp ((void *)&x, (void *)&a, SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&b,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&c,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&d,SIZE) != 0)) \ + FAILURE + +#define TESTVAL_NEG_BIG(VAL,SUF,SIZE) \ + x = PASTE(PASTE(VAL,.),SUF); \ + sll = PASTE(VAL,LL); \ + a = sll; \ + b = PASTE(VAL,LL); \ + if ((__builtin_memcmp ((void *)&x, (void *)&a, SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&b,SIZE) != 0)) \ + FAILURE + +#define TESTVAL_NONNEG(VAL,SUF,SIZE) \ + x = PASTE(PASTE(VAL,.),SUF); \ + si = VAL; \ + ui = VAL; \ + sll = PASTE(VAL,LL); \ + ull = PASTE(VAL,ULL); \ + a = si; \ + b = sll; \ + c = ui; \ + d = ull; \ + e = VAL; \ + f = VAL; \ + g = PASTE(VAL,LL); \ + h = PASTE(VAL,ULL); \ + if ((__builtin_memcmp ((void *)&x, (void *)&a, SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&b,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&c,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&d,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&e,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&f,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&g,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&x, (void *)&h,SIZE) != 0)) \ + FAILURE + +#define TESTVAL_NONNEG_BIG(VAL,SUF,SIZE) \ + x = PASTE(PASTE(VAL,.),SUF); \ + sll = PASTE(VAL,LL); \ + ull = PASTE(VAL,ULL); \ + b = sll; \ + d = ull; \ + f = PASTE(VAL,LL); \ + g = PASTE(VAL,ULL); \ + if ((__builtin_memcmp ((void *)&x, (void *)&b, SIZE) != 0) \ + || (__builtin_memcmp ((void *)&d, (void *)&d,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&f, (void *)&d,SIZE) != 0) \ + || (__builtin_memcmp ((void *)&g, (void *)&d,SIZE) != 0)) \ + FAILURE + +#undef SUFFIX +#define SUFFIX DF +#undef TYPE +#define TYPE _Decimal32 + +void +zeroes_32 (void) +{ + volatile TYPE x, a, b, c, d, e, f, g, h; + volatile int si; + volatile unsigned int ui; + volatile long long sll; + volatile unsigned long long ull; + + TESTVAL_NONNEG (0, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000000000, SUFFIX, sizeof (TYPE)); + + TESTVAL_NEG (0, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000000000, SUFFIX, sizeof (TYPE)); +} + +void +round_32 (void) +{ + volatile TYPE x, a, b, c, d, e, f, g, h; + volatile int si; + volatile unsigned int ui; + volatile long long sll; + volatile unsigned long long ull; + + TESTVAL_NONNEG (10000049, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000050, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000051, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000001, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000002, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000003, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000004, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100000049, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100000051, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000006, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000007, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000008, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000009, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000010, SUFFIX, sizeof (TYPE)); + + TESTVAL_NEG (-10000049, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000050, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000051, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000001, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000002, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000003, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000004, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100000049, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100000051, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000006, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000007, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000008, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000009, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000010, SUFFIX, sizeof (TYPE)); +} + +#undef SUFFIX +#define SUFFIX DD +#undef TYPE +#define TYPE _Decimal64 + +void +zeroes_64 (void) +{ + volatile TYPE x, a, b, c, d, e, f, g, h; + volatile int si; + volatile unsigned int ui; + volatile long long sll; + volatile unsigned long long ull; + + TESTVAL_NONNEG (0, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000000000, SUFFIX, sizeof (TYPE)); + + TESTVAL_NEG (0, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000000000, SUFFIX, sizeof (TYPE)); +} + +void +round_64 (void) +{ + volatile TYPE x, a, b, c, d, e, f, g, h; + volatile int si; + volatile unsigned int ui; + volatile long long sll; + volatile unsigned long long ull; + + TESTVAL_NONNEG_BIG (10000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000001, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000002, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000003, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000004, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000000049, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000000051, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000006, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000007, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000008, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000009, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000010, SUFFIX, sizeof (TYPE)); + + TESTVAL_NEG_BIG (-10000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000001, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000002, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000003, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000004, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000000049, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000000051, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000006, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000007, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000008, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000009, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000010, SUFFIX, sizeof (TYPE)); +} + +#undef SUFFIX +#define SUFFIX DL +#undef TYPE +#define TYPE _Decimal128 + +void +zeroes_128 (void) +{ + volatile TYPE x, a, b, c, d, e, f, g, h; + volatile int si; + volatile unsigned int ui; + volatile long long sll; + volatile unsigned long long ull; + + TESTVAL_NONNEG (0, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (5000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (9000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (10000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (50000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (90000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (100000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (500000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (900000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG (1000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (10000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (50000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (90000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (100000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (500000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (900000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (1000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (5000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NONNEG_BIG (9000000000000000000, SUFFIX, sizeof (TYPE)); + + TESTVAL_NEG (0, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-5000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-9000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-10000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-50000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-90000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-100000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-500000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-900000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG (-1000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-10000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-50000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-90000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-100000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-500000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-900000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-1000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-5000000000000000000, SUFFIX, sizeof (TYPE)); + TESTVAL_NEG_BIG (-9000000000000000000, SUFFIX, sizeof (TYPE)); +} + + +int +main () +{ + zeroes_32 (); + zeroes_64 (); + zeroes_128 (); + round_32 (); + round_64 (); + + FINISH +} diff --git a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-1.c b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-1.c index 79fabf34484..62d85b6d349 100644 --- a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-1.c +++ b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wall" } */ +/* { dg-options "-Wall" } */ /* N1312 7.1.1: The FLOAT_CONST_DECIMAL64 pragma. C99 6.4.4.2a (New). diff --git a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-2.c b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-2.c index 212748c6c78..8bc49f77106 100644 --- a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-2.c +++ b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wall" } */ +/* { dg-options "-Wall" } */ /* N1312 7.1.1: The FLOAT_CONST_DECIMAL64 pragma. C99 6.4.4.2a (New). diff --git a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-3.c b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-3.c index b9286aac11a..19599867035 100644 --- a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-3.c +++ b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wall" } */ +/* { dg-options "-Wall" } */ /* N1312 7.1.1: The FLOAT_CONST_DECIMAL64 pragma. C99 6.4.4.2a (New). */ diff --git a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-4.c b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-4.c index 86cec1dbd45..af0398daf79 100644 --- a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-4.c +++ b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-4.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* N1312 7.1.1: The FLOAT_CONST_DECIMAL64 pragma. C99 6.4.4.2a (New). diff --git a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-7.c b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-7.c index 7533ee7f0de..55e0d661c03 100644 --- a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-7.c +++ b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-7.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wall" } */ +/* { dg-options "-Wall" } */ /* N1312 7.1.1: The FLOAT_CONST_DECIMAL64 pragma. C99 6.4.4.2a (New). diff --git a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-8.c b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-8.c index 5dbbda5b8f2..39d38c1d8f0 100644 --- a/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-8.c +++ b/gcc/testsuite/gcc.dg/dfp/pragma-float-const-decimal64-8.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wall" } */ +/* { dg-options "-Wall" } */ /* N1312 7.1.1: The FLOAT_CONST_DECIMAL64 pragma. C99 6.4.4.2a (New). diff --git a/gcc/testsuite/gcc.dg/dfp/signbit-1.c b/gcc/testsuite/gcc.dg/dfp/signbit-1.c index cde28f9ba84..d83d2a48ed7 100644 --- a/gcc/testsuite/gcc.dg/dfp/signbit-1.c +++ b/gcc/testsuite/gcc.dg/dfp/signbit-1.c @@ -1,16 +1,8 @@ -/* { dg-options "-O0 -std=gnu99" } */ +/* { dg-options "-O0" } */ /* Decimal float versions of __builtin_signbit. */ -extern void abort (void); -int failures; - -#ifdef DBG -extern int printf (const char *, ...); -#define FAILURE { printf ("failed at line %d\n", __LINE__); failures++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" #define CHECK32(D,I) \ if ((__builtin_signbitd32 (D) != 0) != I) FAILURE @@ -44,7 +36,5 @@ main () td = 0.0dl; CHECK128 (td, 0) td = -0.0dl; CHECK128 (td, 1) - if (failures != 0) - abort (); - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/signbit-2.c b/gcc/testsuite/gcc.dg/dfp/signbit-2.c index 6f9a2276b8a..e51bf918bf4 100644 --- a/gcc/testsuite/gcc.dg/dfp/signbit-2.c +++ b/gcc/testsuite/gcc.dg/dfp/signbit-2.c @@ -1,9 +1,9 @@ -/* { dg-options "-O0 -std=gnu99" } */ +/* { dg-options "-O0" } */ /* Check that the compiler uses builtins for signbit; if not the link will fail because library functions are in libm. */ -extern void abort (void); +#include "dfp-dbg.h" volatile _Decimal32 sd = 2.3df; volatile _Decimal64 dd = -4.5dd; @@ -12,22 +12,22 @@ volatile float f = 1.2f; volatile double d = -7.8; volatile long double ld = 3.4L; -extern int signbitf (float); -extern int signbit (double); -extern int signbitl (long double); -extern int signbitd32 (_Decimal32); -extern int signbitd64 (_Decimal64); -extern int signbitd128 (_Decimal128); +EXTERN int signbitf (float); +EXTERN int signbit (double); +EXTERN int signbitl (long double); +EXTERN int signbitd32 (_Decimal32); +EXTERN int signbitd64 (_Decimal64); +EXTERN int signbitd128 (_Decimal128); int main () { - if (signbitf (f) != 0) abort (); - if (signbit (d) == 0) abort (); - if (signbitl (ld) != 0) abort (); - if (signbitd32 (sd) != 0) abort (); - if (signbitd64 (dd) == 0) abort (); - if (signbitd128 (tf) != 0) abort (); + if (signbitf (f) != 0) FAILURE + if (signbit (d) == 0) FAILURE + if (signbitl (ld) != 0) FAILURE + if (signbitd32 (sd) != 0) FAILURE + if (signbitd64 (dd) == 0) FAILURE + if (signbitd128 (tf) != 0) FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/struct-layout-1.c b/gcc/testsuite/gcc.dg/dfp/struct-layout-1.c index 9e54e48c726..2a9d7304fd1 100644 --- a/gcc/testsuite/gcc.dg/dfp/struct-layout-1.c +++ b/gcc/testsuite/gcc.dg/dfp/struct-layout-1.c @@ -1,8 +1,5 @@ -/* { dg-options "-std=gnu99" } */ - #include <stdarg.h> - -extern void abort (void); +#include "dfp-dbg.h" struct S1 { @@ -39,20 +36,6 @@ struct S5 } a; }; -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE do \ -{ printf ("failed at line %d\n", __LINE__); \ - failcnt++; \ -}while(0) -#else -#define FAILURE abort () -#endif - int check_var (int z, ...) { long long result; @@ -84,8 +67,5 @@ int main () if (check_var (2, s5, 2LL) == 0) FAILURE; - if (failcnt) - abort (); - - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/typespec.c b/gcc/testsuite/gcc.dg/dfp/typespec.c index c7fc343ec43..a4545d5d921 100644 --- a/gcc/testsuite/gcc.dg/dfp/typespec.c +++ b/gcc/testsuite/gcc.dg/dfp/typespec.c @@ -1,7 +1,6 @@ /* Test for valid and invalid combinations of type specifiers. Based off gcc.dg/test-spec-1.c */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ typedef char type; void _Decimal32 *x0; /* { dg-error "" "void _Decimal32" } */ diff --git a/gcc/testsuite/gcc.dg/dfp/union-init.c b/gcc/testsuite/gcc.dg/dfp/union-init.c index fede76ba328..6896ece99b2 100644 --- a/gcc/testsuite/gcc.dg/dfp/union-init.c +++ b/gcc/testsuite/gcc.dg/dfp/union-init.c @@ -1,8 +1,6 @@ -/* { dg-options "-std=gnu99" } */ - /* Cast to union is a GNU C extension. */ -extern void abort (void); +#include "dfp-dbg.h" union u { @@ -30,10 +28,10 @@ int main () double d; if (u1.d128 != 0.0dl) - abort (); + FAILURE if (u2.d128 != 4.2dl) - abort (); + FAILURE /* cast decimal floating point to union type. */ d128 = 1.23dl; @@ -42,19 +40,19 @@ int main () u4 = (union u) d128; if (u4.d128 != 1.23dl) - abort (); + FAILURE u4 = (union u) d; if (u4.d != 3.25) - abort (); + FAILURE n1 = (union n) d64; if (n1.d64 != 4.56dd) - abort (); + FAILURE n1 = (union n)d; if (n1.d != 3.25) - abort (); + FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad-2.c b/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad-2.c index 4693abc90d9..7bd0f64f136 100644 --- a/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad-2.c +++ b/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad-2.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* This used to result in an ICE. */ diff --git a/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad.c b/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad.c index e4033ca50f4..e14c7b20a12 100644 --- a/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad.c +++ b/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad.c @@ -1,5 +1,4 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* N1150 5.4: Usual arithmetic conversions. C99 6.3.1.8[1] (New). diff --git a/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-const.c b/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-const.c index 3f06e4753ff..2d72bba4235 100644 --- a/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-const.c +++ b/gcc/testsuite/gcc.dg/dfp/usual-arith-conv-const.c @@ -1,8 +1,9 @@ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ /* Test various conversions involving decimal floating types. */ +#include "dfp-dbg.h" + /* Assertion that constant C is of type T. */ #define ASSERT_CONST_TYPE(C, T) \ do { \ diff --git a/gcc/testsuite/gcc.dg/dfp/usual-arith-conv.c b/gcc/testsuite/gcc.dg/dfp/usual-arith-conv.c index 584058b8cc4..baff06bc175 100644 --- a/gcc/testsuite/gcc.dg/dfp/usual-arith-conv.c +++ b/gcc/testsuite/gcc.dg/dfp/usual-arith-conv.c @@ -1,4 +1,4 @@ -/* { dg-options "-std=gnu99 -O0" } */ +/* { dg-options "-O0" } */ /* N1150 5.4: Usual arithmetic conversions. C99 6.3.1.8[1] (New). @@ -6,17 +6,7 @@ Test arithmetic operators with different decimal float types, and between decimal float types and integer types. */ -extern void abort (void); -static int failcnt = 0; - -/* Support compiling the test to report individual failures; default is - to abort as soon as a check fails. */ -#ifdef DBG -#include <stdio.h> -#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; } -#else -#define FAILURE abort (); -#endif +#include "dfp-dbg.h" volatile _Decimal32 d32a, d32b, d32c; volatile _Decimal64 d64a, d64b, d64c; @@ -123,5 +113,5 @@ main () if (d128a != d128c / 2.0dl) FAILURE - return 0; + FINISH } diff --git a/gcc/testsuite/gcc.dg/dfp/wtr-conversion-1.c b/gcc/testsuite/gcc.dg/dfp/wtr-conversion-1.c index 0994c65783e..2b50fe6a56e 100644 --- a/gcc/testsuite/gcc.dg/dfp/wtr-conversion-1.c +++ b/gcc/testsuite/gcc.dg/dfp/wtr-conversion-1.c @@ -3,7 +3,7 @@ Based on gcc.dg/wtr-conversion-1.c */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wtraditional" } */ +/* { dg-options "-Wtraditional" } */ extern void foo_i (int); extern void foo_f (float); diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-sra-1.c b/gcc/testsuite/gcc.dg/ipa/ipa-sra-1.c new file mode 100644 index 00000000000..2dea78ddd1c --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-sra-1.c @@ -0,0 +1,41 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fdump-tree-eipa_sra-details" } */ + +struct bovid +{ + float red; + int green; + void *blue; +}; + +extern int printf (const char *, ...); +extern void abort (void); + +static int +__attribute__((noinline)) +ox (struct bovid cow) +{ + if (cow.green != 6) + abort (); + + printf ("green: %f\nblue: %p\nblue again: %p\n", cow.green, + cow.blue, cow.blue); + return 0; +} + +int +main (int argc, char *argv[]) +{ + struct bovid cow; + + cow.red = 7.4; + cow.green = 6; + cow.blue = &cow; + + ox (cow); + return 0; +} + +/* { dg-final { scan-tree-dump "About to replace expr cow.green with ISRA" "eipa_sra" } } */ +/* { dg-final { scan-tree-dump "About to replace expr cow.blue with ISRA" "eipa_sra" } } */ +/* { dg-final { cleanup-tree-dump "eipa_sra" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-sra-2.c b/gcc/testsuite/gcc.dg/ipa/ipa-sra-2.c new file mode 100644 index 00000000000..0e382015686 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-sra-2.c @@ -0,0 +1,52 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-eipa_sra-details" } */ + +struct bovid +{ + float red; + int green; + void *blue; +}; + +static int +__attribute__((noinline)) +ox (struct bovid *cow) +{ + cow->red = cow->red + cow->green + cow->green; + return 0; +} + +int something; + +static int +__attribute__((noinline)) +ox_improved (struct bovid *calf) +{ + if (something > 0) + calf->red = calf->red + calf->green; + else + calf->red = calf->green + 87; + something = 77; + return 0; +} + + +int main (int argc, char *argv[]) +{ + struct bovid cow; + + cow.red = 7.4; + cow.green = 6; + cow.blue = &cow; + + ox (&cow); + + ox_improved (&cow); + return 0; +} + +/* { dg-final { scan-tree-dump "About to replace expr cow_.*D.->red with \\*ISRA" "eipa_sra" } } */ +/* { dg-final { scan-tree-dump "About to replace expr cow_.*D.->green with ISRA" "eipa_sra" } } */ +/* { dg-final { scan-tree-dump "About to replace expr calf_.*D.->red with \\*ISRA" "eipa_sra" } } */ +/* { dg-final { scan-tree-dump "About to replace expr calf_.*D.->green with ISRA" "eipa_sra" } } */ +/* { dg-final { cleanup-tree-dump "eipa_sra" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-sra-3.c b/gcc/testsuite/gcc.dg/ipa/ipa-sra-3.c new file mode 100644 index 00000000000..f4e91bbe563 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-sra-3.c @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-eipa_sra-details" } */ + +struct bovid +{ + float red; + int green; + void *blue; +}; + +extern void foo (float, void *, void *, long); + +static int +__attribute__((noinline)) +ox (struct bovid cow, int z, struct bovid calf, long l) +{ + foo (cow.red, cow.blue, cow.blue, l); + return 0; +} + +void caller (void) +{ + struct bovid cow, calf; + + cow.red = 7.4; + cow.green = 6; + cow.blue = &cow; + + calf.red = 8.4; + calf.green = 5; + calf.blue = &cow; + + ox (cow,4,calf,2); + return; +} + +/* { dg-final { scan-tree-dump "base: z, remove_param" "eipa_sra" } } */ +/* { dg-final { scan-tree-dump "base: calf, remove_param" "eipa_sra" } } */ +/* { dg-final { cleanup-tree-dump "eipa_sra" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-sra-4.c b/gcc/testsuite/gcc.dg/ipa/ipa-sra-4.c new file mode 100644 index 00000000000..a832329b6ae --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-sra-4.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-eipa_sra-details" } */ + +static int +__attribute__((noinline)) +ox (int *i) +{ + return *i+4**i; +} + +int *holder; + +static int +__attribute__((noinline)) +ox_ctrl_1 (int *j) +{ + holder = j; + return *j+4 * *j+1; +} + +static void +__attribute__((noinline)) +ox_ctrl_2 (int *k) +{ + *k = 8; +} + +static int zzz[10]; + +static int +__attribute__((noinline)) +ox_improved (int recurse, int *l) +{ + int r = 0; + + r = *l; + + if (recurse) + { + if (recurse > 2) + l = &zzz[3]; + else + l = zzz; + + ox_improved (0, l); + } + + return r; +} + +void caller (void) +{ + int a = 1; + int b = 10; + int c; + + ox (&a); + ox_ctrl_1 (&a); + ox_ctrl_2 (&a); + *holder = ox_improved (1, &b); + return; +} + +/* { dg-final { scan-tree-dump "About to replace expr \\*i_.*D. with ISRA" "eipa_sra" } } */ +/* { dg-final { scan-tree-dump "About to replace expr \\*l_.*D. with ISRA" "eipa_sra" } } */ +/* { dg-final { scan-tree-dump-times "About to replace expr \*j_.*D. with ISRA" 0 "eipa_sra" } } */ +/* { dg-final { scan-tree-dump-times "About to replace expr \*k_.*D. with ISRA" 0 "eipa_sra" } } */ +/* { dg-final { cleanup-tree-dump "eipa_sra" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-sra-5.c b/gcc/testsuite/gcc.dg/ipa/ipa-sra-5.c new file mode 100644 index 00000000000..317e9b5aedd --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-sra-5.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-eipa_sra-details" } */ + +static int * +__attribute__((noinline,used)) + ox (int *i, int *j) +{ + return i; +} + +int a; + +int *caller (void) +{ + int b = 10; + + return ox (&a, &b); +} +/* { dg-final { scan-tree-dump-times "base: j, remove_param" 0 "eipa_sra" } } */ +/* { dg-final { cleanup-tree-dump "eipa_sra" } } */ diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_escape_arg_to_local.c b/gcc/testsuite/gcc.dg/struct/wo_prof_escape_arg_to_local.c index 43ca58b9ef2..29630252e00 100644 --- a/gcc/testsuite/gcc.dg/struct/wo_prof_escape_arg_to_local.c +++ b/gcc/testsuite/gcc.dg/struct/wo_prof_escape_arg_to_local.c @@ -1,4 +1,4 @@ -/* { dg-options "-O3 -fno-inline -fipa-type-escape -fdump-ipa-all -fipa-struct-reorg -fwhole-program -combine" } */ +/* { dg-options "-O3 -fno-inline -fno-ipa-sra -fipa-type-escape -fdump-ipa-all -fipa-struct-reorg -fwhole-program -combine" } */ /* { dg-do compile } */ /* { dg-do run } */ diff --git a/gcc/testsuite/gfortran.dg/default_format_denormal_1.f90 b/gcc/testsuite/gfortran.dg/default_format_denormal_1.f90 index debc113ffc1..9709c508c50 100644 --- a/gcc/testsuite/gfortran.dg/default_format_denormal_1.f90 +++ b/gcc/testsuite/gfortran.dg/default_format_denormal_1.f90 @@ -1,4 +1,4 @@ -! { dg-do run { xfail alpha*-*-* *-*-darwin[89]* *-*-freebsd* *-*-mingw* *-*-cygwin* spu-*-* } } +! { dg-do run { xfail *-*-darwin[89]* *-*-freebsd* *-*-mingw* *-*-cygwin* spu-*-* } } ! Test XFAILed on these platforms because the system's printf() lacks ! proper support for denormals. ! @@ -6,6 +6,8 @@ ! wide enough and have enough precision, by checking that values can ! be written and read back. ! +! { dg-add-options ieee } + include "default_format_1.inc" program main diff --git a/gcc/testsuite/gfortran.dg/default_format_denormal_2.f90 b/gcc/testsuite/gfortran.dg/default_format_denormal_2.f90 index 0ae32f8cb60..ae2f71f42e7 100644 --- a/gcc/testsuite/gfortran.dg/default_format_denormal_2.f90 +++ b/gcc/testsuite/gfortran.dg/default_format_denormal_2.f90 @@ -7,6 +7,8 @@ ! wide enough and have enough precision, by checking that values can ! be written and read back. ! +! { dg-add-options ieee } + include "default_format_2.inc" program main diff --git a/gcc/testsuite/gfortran.dg/pr41347.f90 b/gcc/testsuite/gfortran.dg/pr41347.f90 new file mode 100644 index 00000000000..ae48857d507 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr41347.f90 @@ -0,0 +1,32 @@ +! { dg-do compile } +! { dg-options "-O3" } +module hsl_ma41_m + + implicit none + + contains + + subroutine solve_ma41 + integer, dimension(20) :: info + call prininfo(15, info) + end subroutine solve_ma41 + + subroutine prininfo (ni, info) + integer, intent(in) :: ni + integer, intent(in), dimension(:) :: info + + integer i + + call prinfo + + contains + + subroutine prinfo + do i = 1, ni + write(*,'(i5,1x,i0)') i, info(i) + end do + end subroutine prinfo + + end subroutine prininfo + +end module hsl_ma41_m diff --git a/gcc/timevar.def b/gcc/timevar.def index 2deafd885c9..eca17e7ef29 100644 --- a/gcc/timevar.def +++ b/gcc/timevar.def @@ -46,6 +46,7 @@ DEFTIMEVAR (TV_IPA_REFERENCE , "ipa reference") DEFTIMEVAR (TV_IPA_PURE_CONST , "ipa pure const") DEFTIMEVAR (TV_IPA_TYPE_ESCAPE , "ipa type escape") DEFTIMEVAR (TV_IPA_PTA , "ipa points-to") +DEFTIMEVAR (TV_IPA_SRA , "ipa SRA") DEFTIMEVAR (TV_IPA_FREE_LANG_DATA , "ipa free lang data") /* Time spent by constructing CFG. */ DEFTIMEVAR (TV_CFG , "cfg construction") diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 5ada378700f..feb749985c2 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -342,6 +342,10 @@ remap_type_1 (tree type, copy_body_data *id) new_tree = build_pointer_type_for_mode (remap_type (TREE_TYPE (type), id), TYPE_MODE (type), TYPE_REF_CAN_ALIAS_ALL (type)); + if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type)) + new_tree = build_type_attribute_qual_variant (new_tree, + TYPE_ATTRIBUTES (type), + TYPE_QUALS (type)); insert_decl_map (id, type, new_tree); return new_tree; } @@ -350,6 +354,10 @@ remap_type_1 (tree type, copy_body_data *id) new_tree = build_reference_type_for_mode (remap_type (TREE_TYPE (type), id), TYPE_MODE (type), TYPE_REF_CAN_ALIAS_ALL (type)); + if (TYPE_ATTRIBUTES (type) || TYPE_QUALS (type)) + new_tree = build_type_attribute_qual_variant (new_tree, + TYPE_ATTRIBUTES (type), + TYPE_QUALS (type)); insert_decl_map (id, type, new_tree); return new_tree; } diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index bcf971143cf..fe938d913e1 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -2047,9 +2047,7 @@ convert_all_function_calls (struct nesting_info *root) bool any_changed; /* First, optimistically set no_static_chain for all decls that haven't - used the static chain already for variable access. Notice that we - do this pre-order, because we want inner functions to be processed - first in the LIFO worklist. */ + used the static chain already for variable access. */ FOR_EACH_NEST_INFO (n, root) { tree decl = n->context; diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 9ea70e35fb7..97f1d340a15 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -327,6 +327,7 @@ extern struct gimple_opt_pass pass_cleanup_eh; extern struct gimple_opt_pass pass_fixup_cfg; extern struct gimple_opt_pass pass_sra; extern struct gimple_opt_pass pass_sra_early; +extern struct gimple_opt_pass pass_early_ipa_sra; extern struct gimple_opt_pass pass_tail_recursion; extern struct gimple_opt_pass pass_tail_calls; extern struct gimple_opt_pass pass_tree_loop; diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 00686c8a219..92dab57a2f8 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -78,6 +78,7 @@ along with GCC; see the file COPYING3. If not see #include "tm.h" #include "tree.h" #include "gimple.h" +#include "cgraph.h" #include "tree-flow.h" #include "ipa-prop.h" #include "diagnostic.h" @@ -89,8 +90,9 @@ along with GCC; see the file COPYING3. If not see #include "flags.h" /* Enumeration of all aggregate reductions we can do. */ -enum sra_mode { SRA_MODE_EARLY_INTRA, /* early intraprocedural SRA */ - SRA_MODE_INTRA }; /* late intraprocedural SRA */ +enum sra_mode { SRA_MODE_EARLY_IPA, /* early call regularization */ + SRA_MODE_EARLY_INTRA, /* early intraprocedural SRA */ + SRA_MODE_INTRA }; /* late intraprocedural SRA */ /* Global variable describing which aggregate reduction we are performing at the moment. */ @@ -128,6 +130,9 @@ struct access /* Type. */ tree type; + /* The statement this access belongs to. */ + gimple stmt; + /* Next group representative for this aggregate. */ struct access *next_grp; @@ -159,26 +164,33 @@ struct access /* Is this access currently in the work queue? */ unsigned grp_queued : 1; + /* Does this group contain a write access? This flag is propagated down the access tree. */ unsigned grp_write : 1; + /* Does this group contain a read access? This flag is propagated down the access tree. */ unsigned grp_read : 1; + /* Other passes of the analysis use this bit to make function analyze_access_subtree create scalar replacements for this group if possible. */ unsigned grp_hint : 1; + /* Is the subtree rooted in this access fully covered by scalar replacements? */ unsigned grp_covered : 1; + /* If set to true, this access and all below it in an access tree must not be scalarized. */ unsigned grp_unscalarizable_region : 1; + /* Whether data have been written to parts of the aggregate covered by this access which is not to be scalarized. This flag is propagated up in the access tree. */ unsigned grp_unscalarized_data : 1; + /* Does this access and/or group contain a write access through a BIT_FIELD_REF? */ unsigned grp_partial_lhs : 1; @@ -187,6 +199,19 @@ struct access the decision and creation at different places because create_tmp_var cannot be called from within FOR_EACH_REFERENCED_VAR. */ unsigned grp_to_be_replaced : 1; + + /* Is it possible that the group refers to data which might be (directly or + otherwise) modified? */ + unsigned grp_maybe_modified : 1; + + /* Set when this is a representative of a pointer to scalar (i.e. by + reference) parameter which we consider for turning into a plain scalar + (i.e. a by value parameter). */ + unsigned grp_scalar_ptr : 1; + + /* Set when we discover that this pointer is not safe to dereference in the + caller. */ + unsigned grp_not_necessarilly_dereferenced : 1; }; typedef struct access *access_p; @@ -212,8 +237,9 @@ static alloc_pool link_pool; /* Base (tree) -> Vector (VEC(access_p,heap) *) map. */ static struct pointer_map_t *base_access_vec; -/* Bitmap of bases (candidates). */ +/* Bitmap of candidates. */ static bitmap candidate_bitmap; + /* Obstack for creation of fancy names. */ static struct obstack name_obstack; @@ -221,12 +247,42 @@ static struct obstack name_obstack; propagated to their assignment counterparts. */ static struct access *work_queue_head; +/* Number of parameters of the analyzed function when doing early ipa SRA. */ +static int func_param_count; + +/* scan_function sets the following to true if it encounters a call to + __builtin_apply_args. */ +static bool encountered_apply_args; + +/* This is a table in which for each basic block and parameter there is a + distance (offset + size) in that parameter which is dereferenced and + accessed in that BB. */ +static HOST_WIDE_INT *bb_dereferences; +/* Bitmap of BBs that can cause the function to "stop" progressing by + returning, throwing externally, looping infinitely or calling a function + which might abort etc.. */ +static bitmap final_bbs; + +/* Representative of no accesses at all. */ +static struct access no_accesses_representant; + +/* Predicate to test the special value. */ + +static inline bool +no_accesses_p (struct access *access) +{ + return access == &no_accesses_representant; +} + /* Dump contents of ACCESS to file F in a human friendly way. If GRP is true, representative fields are dumped, otherwise those which only describe the individual access are. */ static struct { + /* Number of processed aggregates is readily available in + analyze_all_variable_accesses and so is not stored here. */ + /* Number of created scalar replacements. */ int replacements; @@ -248,8 +304,19 @@ static struct references. */ int separate_lhs_rhs_handling; - /* Number of processed aggregates is readily available in - analyze_all_variable_accesses and so is not stored here. */ + /* Number of parameters that were removed because they were unused. */ + int deleted_unused_parameters; + + /* Number of scalars passed as parameters by reference that have been + converted to be passed by value. */ + int scalar_by_ref_to_by_val; + + /* Number of aggregate parameters that were replaced by one or more of their + components. */ + int aggregate_params_reduced; + + /* Numbber of components created when splitting aggregate parameters. */ + int param_reductions_created; } sra_stats; static void @@ -268,11 +335,13 @@ dump_access (FILE *f, struct access *access, bool grp) fprintf (f, ", grp_write = %d, grp_read = %d, grp_hint = %d, " "grp_covered = %d, grp_unscalarizable_region = %d, " "grp_unscalarized_data = %d, grp_partial_lhs = %d, " - "grp_to_be_replaced = %d\n", + "grp_to_be_replaced = %d\n grp_maybe_modified = %d, " + "grp_not_necessarilly_dereferenced = %d\n", access->grp_write, access->grp_read, access->grp_hint, access->grp_covered, access->grp_unscalarizable_region, access->grp_unscalarized_data, access->grp_partial_lhs, - access->grp_to_be_replaced); + access->grp_to_be_replaced, access->grp_maybe_modified, + access->grp_not_necessarilly_dereferenced); else fprintf (f, ", write = %d, grp_partial_lhs = %d\n", access->write, access->grp_partial_lhs); @@ -471,6 +540,7 @@ sra_initialize (void) link_pool = create_alloc_pool ("SRA links", sizeof (struct assign_link), 16); base_access_vec = pointer_map_create (); memset (&sra_stats, 0, sizeof (sra_stats)); + encountered_apply_args = false; } /* Hook fed to pointer_map_traverse, deallocate stored vectors. */ @@ -560,34 +630,105 @@ type_internals_preclude_sra_p (tree type) } } +/* If T is an SSA_NAME, return NULL if it is not a default def or return its + base variable if it is. Return T if it is not an SSA_NAME. */ + +static tree +get_ssa_base_param (tree t) +{ + if (TREE_CODE (t) == SSA_NAME) + { + if (SSA_NAME_IS_DEFAULT_DEF (t)) + return SSA_NAME_VAR (t); + else + return NULL_TREE; + } + return t; +} + +/* Mark a dereference of BASE of distance DIST in a basic block tht STMT + belongs to, unless the BB has already been marked as a potentially + final. */ + +static void +mark_parm_dereference (tree base, HOST_WIDE_INT dist, gimple stmt) +{ + basic_block bb = gimple_bb (stmt); + int idx, parm_index = 0; + tree parm; + + if (bitmap_bit_p (final_bbs, bb->index)) + return; + + for (parm = DECL_ARGUMENTS (current_function_decl); + parm && parm != base; + parm = TREE_CHAIN (parm)) + parm_index++; + + gcc_assert (parm_index < func_param_count); + + idx = bb->index * func_param_count + parm_index; + if (bb_dereferences[idx] < dist) + bb_dereferences[idx] = dist; +} + /* Create and insert access for EXPR. Return created access, or NULL if it is not possible. */ static struct access * -create_access (tree expr, bool write) +create_access (tree expr, gimple stmt, bool write) { struct access *access; void **slot; VEC (access_p,heap) *vec; HOST_WIDE_INT offset, size, max_size; tree base = expr; - bool unscalarizable_region = false; + bool ptr, unscalarizable_region = false; base = get_ref_base_and_extent (expr, &offset, &size, &max_size); + if (sra_mode == SRA_MODE_EARLY_IPA && INDIRECT_REF_P (base)) + { + base = get_ssa_base_param (TREE_OPERAND (base, 0)); + if (!base) + return NULL; + ptr = true; + } + else + ptr = false; + if (!DECL_P (base) || !bitmap_bit_p (candidate_bitmap, DECL_UID (base))) return NULL; - if (size != max_size) + if (sra_mode == SRA_MODE_EARLY_IPA) { - size = max_size; - unscalarizable_region = true; - } + if (size < 0 || size != max_size) + { + disqualify_candidate (base, "Encountered a variable sized access."); + return NULL; + } + if ((offset % BITS_PER_UNIT) != 0 || (size % BITS_PER_UNIT) != 0) + { + disqualify_candidate (base, + "Encountered an acces not aligned to a byte."); + return NULL; + } - if (size < 0) + if (ptr) + mark_parm_dereference (base, offset + size, stmt); + } + else { - disqualify_candidate (base, "Encountered an unconstrained access."); - return NULL; + if (size != max_size) + { + size = max_size; + unscalarizable_region = true; + } + if (size < 0) + { + disqualify_candidate (base, "Encountered an unconstrained access."); + return NULL; + } } access = (struct access *) pool_alloc (access_pool); @@ -600,6 +741,7 @@ create_access (tree expr, bool write) access->type = TREE_TYPE (expr); access->write = write; access->grp_unscalarizable_region = unscalarizable_region; + access->stmt = stmt; slot = pointer_map_contains (base_access_vec, base); if (slot) @@ -625,7 +767,14 @@ disqualify_base_of_expr (tree t, const char *reason) while (handled_component_p (t)) t = TREE_OPERAND (t, 0); - if (DECL_P (t)) + if (sra_mode == SRA_MODE_EARLY_IPA) + { + if (INDIRECT_REF_P (t)) + t = TREE_OPERAND (t, 0); + t = get_ssa_base_param (t); + } + + if (t && DECL_P (t)) disqualify_candidate (t, reason); } @@ -634,7 +783,7 @@ disqualify_base_of_expr (tree t, const char *reason) created. */ static struct access * -build_access_from_expr_1 (tree *expr_ptr, bool write) +build_access_from_expr_1 (tree *expr_ptr, gimple stmt, bool write) { struct access *ret = NULL; tree expr = *expr_ptr; @@ -666,13 +815,17 @@ build_access_from_expr_1 (tree *expr_ptr, bool write) switch (TREE_CODE (expr)) { + case INDIRECT_REF: + if (sra_mode != SRA_MODE_EARLY_IPA) + return NULL; + /* fall through */ case VAR_DECL: case PARM_DECL: case RESULT_DECL: case COMPONENT_REF: case ARRAY_REF: case ARRAY_RANGE_REF: - ret = create_access (expr, write); + ret = create_access (expr, stmt, write); break; default: @@ -694,7 +847,7 @@ build_access_from_expr (tree *expr_ptr, gimple_stmt_iterator *gsi ATTRIBUTE_UNUSED, bool write, void *data ATTRIBUTE_UNUSED) { - return build_access_from_expr_1 (expr_ptr, write) != NULL; + return build_access_from_expr_1 (expr_ptr, gsi_stmt (*gsi), write) != NULL; } /* Disqualify LHS and RHS for scalarization if STMT must end its basic block in @@ -705,7 +858,8 @@ build_access_from_expr (tree *expr_ptr, static bool disqualify_ops_if_throwing_stmt (gimple stmt, tree lhs, tree rhs) { - if (stmt_can_throw_internal (stmt) || stmt_ends_bb_p (stmt)) + if ((sra_mode == SRA_MODE_EARLY_INTRA || sra_mode == SRA_MODE_INTRA) + && (stmt_can_throw_internal (stmt) || stmt_ends_bb_p (stmt))) { disqualify_base_of_expr (lhs, "LHS of a throwing stmt."); if (rhs) @@ -746,10 +900,11 @@ build_accesses_from_assign (gimple *stmt_ptr, if (disqualify_ops_if_throwing_stmt (stmt, *lhs_ptr, *rhs_ptr)) return SRA_SA_NONE; - racc = build_access_from_expr_1 (rhs_ptr, false); - lacc = build_access_from_expr_1 (lhs_ptr, true); + racc = build_access_from_expr_1 (rhs_ptr, stmt, false); + lacc = build_access_from_expr_1 (lhs_ptr, stmt, true); if (lacc && racc + && (sra_mode == SRA_MODE_EARLY_INTRA || sra_mode == SRA_MODE_INTRA) && !lacc->grp_unscalarizable_region && !racc->grp_unscalarizable_region && AGGREGATE_TYPE_P (TREE_TYPE (*lhs_ptr)) @@ -792,12 +947,11 @@ asm_visit_addr (gimple stmt ATTRIBUTE_UNUSED, tree op, those deemed entirely unsuitable for some reason (all operands in such statements and expression are removed from candidate_bitmap). SCAN_ASSIGN is a callback called on all assign statements, HANDLE_SSA_DEFS is a callback - called on assign statements and those call statements which have a lhs and - it is the only callback which can be NULL. ANALYSIS_STAGE is true when - running in the analysis stage of a pass and thus no statement is being - modified. DATA is a pointer passed to all callbacks. If any single - callback returns true, this function also returns true, otherwise it returns - false. */ + called on assign statements and those call statements which have a lhs, it + can be NULL. ANALYSIS_STAGE is true when running in the analysis stage of a + pass and thus no statement is being modified. DATA is a pointer passed to + all callbacks. If any single callback returns true, this function also + returns true, otherwise it returns false. */ static bool scan_function (bool (*scan_expr) (tree *, gimple_stmt_iterator *, bool, void *), @@ -817,6 +971,10 @@ scan_function (bool (*scan_expr) (tree *, gimple_stmt_iterator *, bool, void *), { bool bb_changed = false; + if (handle_ssa_defs) + for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + ret |= handle_ssa_defs (gsi_stmt (gsi), data); + gsi = gsi_start_bb (bb); while (!gsi_end_p (gsi)) { @@ -824,12 +982,16 @@ scan_function (bool (*scan_expr) (tree *, gimple_stmt_iterator *, bool, void *), enum scan_assign_result assign_result; bool any = false, deleted = false; + if (analysis_stage && final_bbs && stmt_can_throw_external (stmt)) + bitmap_set_bit (final_bbs, bb->index); switch (gimple_code (stmt)) { case GIMPLE_RETURN: t = gimple_return_retval_ptr (stmt); if (*t != NULL_TREE) any |= scan_expr (t, &gsi, false, data); + if (analysis_stage && final_bbs) + bitmap_set_bit (final_bbs, bb->index); break; case GIMPLE_ASSIGN: @@ -848,6 +1010,21 @@ scan_function (bool (*scan_expr) (tree *, gimple_stmt_iterator *, bool, void *), any |= scan_expr (argp, &gsi, false, data); } + if (analysis_stage) + { + tree dest = gimple_call_fndecl (stmt); + int flags = gimple_call_flags (stmt); + + if (dest + && DECL_BUILT_IN_CLASS (dest) == BUILT_IN_NORMAL + && DECL_FUNCTION_CODE (dest) == BUILT_IN_APPLY_ARGS) + encountered_apply_args = true; + + if (final_bbs + && (flags & (ECF_CONST | ECF_PURE)) == 0) + bitmap_set_bit (final_bbs, bb->index); + } + if (gimple_call_lhs (stmt)) { tree *lhs_ptr = gimple_call_lhs_ptr (stmt); @@ -863,10 +1040,13 @@ scan_function (bool (*scan_expr) (tree *, gimple_stmt_iterator *, bool, void *), break; case GIMPLE_ASM: - if (analysis_stage) - walk_stmt_load_store_addr_ops (stmt, NULL, NULL, NULL, - asm_visit_addr); + { + walk_stmt_load_store_addr_ops (stmt, NULL, NULL, NULL, + asm_visit_addr); + if (final_bbs) + bitmap_set_bit (final_bbs, bb->index); + } for (i = 0; i < gimple_asm_ninputs (stmt); i++) { tree *op = &TREE_VALUE (gimple_asm_input_op (stmt, i)); @@ -877,6 +1057,7 @@ scan_function (bool (*scan_expr) (tree *, gimple_stmt_iterator *, bool, void *), tree *op = &TREE_VALUE (gimple_asm_output_op (stmt, i)); any |= scan_expr (op, &gsi, true, data); } + break; default: break; @@ -885,10 +1066,10 @@ scan_function (bool (*scan_expr) (tree *, gimple_stmt_iterator *, bool, void *), if (any) { ret = true; - bb_changed = true; if (!analysis_stage) { + bb_changed = true; update_stmt (stmt); maybe_clean_eh_stmt (stmt); } @@ -901,7 +1082,7 @@ scan_function (bool (*scan_expr) (tree *, gimple_stmt_iterator *, bool, void *), ret = true; } } - if (!analysis_stage && bb_changed) + if (!analysis_stage && bb_changed && sra_mode == SRA_MODE_EARLY_IPA) gimple_purge_dead_eh_edges (bb); } @@ -2372,8 +2553,7 @@ perform_intra_sra (void) if (!analyze_all_variable_accesses ()) goto out; - scan_function (sra_modify_expr, sra_modify_assign, NULL, - false, NULL); + scan_function (sra_modify_expr, sra_modify_assign, NULL, false, NULL); initialize_parameter_reductions (); statistics_counter_event (cfun, "Scalar replacements created", @@ -2440,7 +2620,6 @@ struct gimple_opt_pass pass_sra_early = } }; - struct gimple_opt_pass pass_sra = { { @@ -2462,3 +2641,1188 @@ struct gimple_opt_pass pass_sra = | TODO_verify_ssa /* todo_flags_finish */ } }; + + +/* Return true iff PARM (which must be a parm_decl) is an unused scalar + parameter. */ + +static bool +is_unused_scalar_param (tree parm) +{ + tree name; + return (is_gimple_reg (parm) + && (!(name = gimple_default_def (cfun, parm)) + || has_zero_uses (name))); +} + +/* Scan immediate uses of a default definition SSA name of a parameter PARM and + examine whether there are any direct or otherwise infeasible ones. If so, + return true, otherwise return false. PARM must be a gimple register with a + non-NULL default definition. */ + +static bool +ptr_parm_has_direct_uses (tree parm) +{ + imm_use_iterator ui; + gimple stmt; + tree name = gimple_default_def (cfun, parm); + bool ret = false; + + FOR_EACH_IMM_USE_STMT (stmt, ui, name) + { + if (gimple_assign_single_p (stmt)) + { + tree rhs = gimple_assign_rhs1 (stmt); + if (rhs == name) + ret = true; + else if (TREE_CODE (rhs) == ADDR_EXPR) + { + do + { + rhs = TREE_OPERAND (rhs, 0); + } + while (handled_component_p (rhs)); + if (INDIRECT_REF_P (rhs) && TREE_OPERAND (rhs, 0) == name) + ret = true; + } + } + else if (gimple_code (stmt) == GIMPLE_RETURN) + { + tree t = gimple_return_retval (stmt); + if (t == name) + ret = true; + } + else if (is_gimple_call (stmt)) + { + unsigned i; + for (i = 0; i < gimple_call_num_args (stmt); i++) + { + tree arg = gimple_call_arg (stmt, i); + if (arg == name) + { + ret = true; + break; + } + } + } + else if (!is_gimple_debug (stmt)) + ret = true; + + if (ret) + BREAK_FROM_IMM_USE_STMT (ui); + } + + return ret; +} + +/* Identify candidates for reduction for IPA-SRA based on their type and mark + them in candidate_bitmap. Note that these do not necessarily include + parameter which are unused and thus can be removed. Return true iff any + such candidate has been found. */ + +static bool +find_param_candidates (void) +{ + tree parm; + int count = 0; + bool ret = false; + + for (parm = DECL_ARGUMENTS (current_function_decl); + parm; + parm = TREE_CHAIN (parm)) + { + tree type; + + count++; + if (TREE_THIS_VOLATILE (parm) + || TREE_ADDRESSABLE (parm)) + continue; + + if (is_unused_scalar_param (parm)) + { + ret = true; + continue; + } + + type = TREE_TYPE (parm); + if (POINTER_TYPE_P (type)) + { + type = TREE_TYPE (type); + + if (TREE_CODE (type) == FUNCTION_TYPE + || TYPE_VOLATILE (type) + || !is_gimple_reg (parm) + || ptr_parm_has_direct_uses (parm)) + continue; + } + else if (!AGGREGATE_TYPE_P (type)) + continue; + + if (!COMPLETE_TYPE_P (type) + || !host_integerp (TYPE_SIZE (type), 1) + || tree_low_cst (TYPE_SIZE (type), 1) == 0 + || (AGGREGATE_TYPE_P (type) + && type_internals_preclude_sra_p (type))) + continue; + + bitmap_set_bit (candidate_bitmap, DECL_UID (parm)); + ret = true; + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Candidate (%d): ", DECL_UID (parm)); + print_generic_expr (dump_file, parm, 0); + fprintf (dump_file, "\n"); + } + } + + func_param_count = count; + return ret; +} + +/* Callback of walk_aliased_vdefs, marks the access passed as DATA as + maybe_modified. */ + +static bool +mark_maybe_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED, + void *data) +{ + struct access *repr = (struct access *) data; + + repr->grp_maybe_modified = 1; + return true; +} + +/* Analyze what representatives (in linked lists accessible from + REPRESENTATIVES) can be modified by side effects of statements in the + current function. */ + +static void +analyze_modified_params (VEC (access_p, heap) *representatives) +{ + int i; + + for (i = 0; i < func_param_count; i++) + { + struct access *repr = VEC_index (access_p, representatives, i); + VEC (access_p, heap) *access_vec; + int j, access_count; + tree parm; + + if (!repr || no_accesses_p (repr)) + continue; + parm = repr->base; + if (!POINTER_TYPE_P (TREE_TYPE (parm)) + || repr->grp_maybe_modified) + continue; + + access_vec = get_base_access_vector (parm); + access_count = VEC_length (access_p, access_vec); + for (j = 0; j < access_count; j++) + { + struct access *access; + ao_ref ar; + + /* All accesses are read ones, otherwise grp_maybe_modified would be + trivially set. */ + access = VEC_index (access_p, access_vec, j); + ao_ref_init (&ar, access->expr); + walk_aliased_vdefs (&ar, gimple_vuse (access->stmt), + mark_maybe_modified, repr, NULL); + if (repr->grp_maybe_modified) + break; + } + } +} + +/* Propagate distances in bb_dereferences in the opposite direction than the + control flow edges, in each step storing the maximum of the current value + and the minimum of all successors. These steps are repeated until the table + stabilizes. Note that BBs which might terminate the functions (according to + final_bbs bitmap) never updated in this way. */ + +static void +propagate_dereference_distances (void) +{ + VEC (basic_block, heap) *queue; + basic_block bb; + + queue = VEC_alloc (basic_block, heap, last_basic_block_for_function (cfun)); + VEC_quick_push (basic_block, queue, ENTRY_BLOCK_PTR); + FOR_EACH_BB (bb) + { + VEC_quick_push (basic_block, queue, bb); + bb->aux = bb; + } + + while (!VEC_empty (basic_block, queue)) + { + edge_iterator ei; + edge e; + bool change = false; + int i; + + bb = VEC_pop (basic_block, queue); + bb->aux = NULL; + + if (bitmap_bit_p (final_bbs, bb->index)) + continue; + + for (i = 0; i < func_param_count; i++) + { + int idx = bb->index * func_param_count + i; + bool first = true; + HOST_WIDE_INT inh = 0; + + FOR_EACH_EDGE (e, ei, bb->succs) + { + int succ_idx = e->dest->index * func_param_count + i; + + if (e->src == EXIT_BLOCK_PTR) + continue; + + if (first) + { + first = false; + inh = bb_dereferences [succ_idx]; + } + else if (bb_dereferences [succ_idx] < inh) + inh = bb_dereferences [succ_idx]; + } + + if (!first && bb_dereferences[idx] < inh) + { + bb_dereferences[idx] = inh; + change = true; + } + } + + if (change && !bitmap_bit_p (final_bbs, bb->index)) + FOR_EACH_EDGE (e, ei, bb->preds) + { + if (e->src->aux) + continue; + + e->src->aux = e->src; + VEC_quick_push (basic_block, queue, e->src); + } + } + + VEC_free (basic_block, heap, queue); +} + +/* Dump a dereferences TABLE with heading STR to file F. */ + +static void +dump_dereferences_table (FILE *f, const char *str, HOST_WIDE_INT *table) +{ + basic_block bb; + + fprintf (dump_file, str); + FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb) + { + fprintf (f, "%4i %i ", bb->index, bitmap_bit_p (final_bbs, bb->index)); + if (bb != EXIT_BLOCK_PTR) + { + int i; + for (i = 0; i < func_param_count; i++) + { + int idx = bb->index * func_param_count + i; + fprintf (f, " %4" HOST_WIDE_INT_PRINT "d", table[idx]); + } + } + fprintf (f, "\n"); + } + fprintf (dump_file, "\n"); +} + +/* Determine what (parts of) parameters passed by reference that are not + assigned to are not certainly dereferenced in this function and thus the + dereferencing cannot be safely moved to the caller without potentially + introducing a segfault. Mark such REPRESENTATIVES as + grp_not_necessarilly_dereferenced. + + The dereferenced maximum "distance," i.e. the offset + size of the accessed + part is calculated rather than simple booleans are calculated for each + pointer parameter to handle cases when only a fraction of the whole + aggregate is allocated (see testsuite/gcc.c-torture/execute/ipa-sra-2.c for + an example). + + The maximum dereference distances for each pointer parameter and BB are + already stored in bb_dereference. This routine simply propagates these + values upwards by propagate_dereference_distances and then compares the + distances of individual parameters in the ENTRY BB to the equivalent + distances of each representative of a (fraction of a) parameter. */ + +static void +analyze_caller_dereference_legality (VEC (access_p, heap) *representatives) +{ + int i; + + if (dump_file && (dump_flags & TDF_DETAILS)) + dump_dereferences_table (dump_file, + "Dereference table before propagation:\n", + bb_dereferences); + + propagate_dereference_distances (); + + if (dump_file && (dump_flags & TDF_DETAILS)) + dump_dereferences_table (dump_file, + "Dereference table after propagation:\n", + bb_dereferences); + + for (i = 0; i < func_param_count; i++) + { + struct access *repr = VEC_index (access_p, representatives, i); + int idx = ENTRY_BLOCK_PTR->index * func_param_count + i; + + if (!repr || no_accesses_p (repr)) + continue; + + do + { + if ((repr->offset + repr->size) > bb_dereferences[idx]) + repr->grp_not_necessarilly_dereferenced = 1; + repr = repr->next_grp; + } + while (repr); + } +} + +/* Return the representative access for the parameter declaration PARM if it is + a scalar passed by reference which is not written to and the pointer value + is not used directly. Thus, if it is legal to dereference it in the caller + and we can rule out modifications through aliases, such parameter should be + turned into one passed by value. Return NULL otherwise. */ + +static struct access * +unmodified_by_ref_scalar_representative (tree parm) +{ + int i, access_count; + struct access *access; + VEC (access_p, heap) *access_vec; + + access_vec = get_base_access_vector (parm); + gcc_assert (access_vec); + access_count = VEC_length (access_p, access_vec); + + for (i = 0; i < access_count; i++) + { + access = VEC_index (access_p, access_vec, i); + if (access->write) + return NULL; + } + + access = VEC_index (access_p, access_vec, 0); + access->grp_read = 1; + access->grp_scalar_ptr = 1; + return access; +} + +/* Sort collected accesses for parameter PARM, identify representatives for + each accessed region and link them together. Return NULL if there are + different but overlapping accesses, return the special ptr value meaning + there are no accesses for this parameter if that is the case and return the + first representative otherwise. Set *RO_GRP if there is a group of accesses + with only read (i.e. no write) accesses. */ + +static struct access * +splice_param_accesses (tree parm, bool *ro_grp) +{ + int i, j, access_count, group_count; + int agg_size, total_size = 0; + struct access *access, *res, **prev_acc_ptr = &res; + VEC (access_p, heap) *access_vec; + + access_vec = get_base_access_vector (parm); + if (!access_vec) + return &no_accesses_representant; + access_count = VEC_length (access_p, access_vec); + + qsort (VEC_address (access_p, access_vec), access_count, sizeof (access_p), + compare_access_positions); + + i = 0; + total_size = 0; + group_count = 0; + while (i < access_count) + { + bool modification; + access = VEC_index (access_p, access_vec, i); + modification = access->write; + + /* Access is about to become group representative unless we find some + nasty overlap which would preclude us from breaking this parameter + apart. */ + + j = i + 1; + while (j < access_count) + { + struct access *ac2 = VEC_index (access_p, access_vec, j); + if (ac2->offset != access->offset) + { + /* All or nothing law for parameters. */ + if (access->offset + access->size > ac2->offset) + return NULL; + else + break; + } + else if (ac2->size != access->size) + return NULL; + + modification |= ac2->write; + j++; + } + + group_count++; + access->grp_maybe_modified = modification; + if (!modification) + *ro_grp = true; + *prev_acc_ptr = access; + prev_acc_ptr = &access->next_grp; + total_size += access->size; + i = j; + } + + if (POINTER_TYPE_P (TREE_TYPE (parm))) + agg_size = tree_low_cst (TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))), 1); + else + agg_size = tree_low_cst (TYPE_SIZE (TREE_TYPE (parm)), 1); + if (total_size >= agg_size) + return NULL; + + gcc_assert (group_count > 0); + return res; +} + +/* Decide whether parameters with representative accesses given by REPR should + be reduced into components. */ + +static int +decide_one_param_reduction (struct access *repr) +{ + int total_size, cur_parm_size, agg_size, new_param_count, parm_size_limit; + bool by_ref; + tree parm; + + parm = repr->base; + cur_parm_size = tree_low_cst (TYPE_SIZE (TREE_TYPE (parm)), 1); + gcc_assert (cur_parm_size > 0); + + if (POINTER_TYPE_P (TREE_TYPE (parm))) + { + by_ref = true; + agg_size = tree_low_cst (TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))), 1); + } + else + { + by_ref = false; + agg_size = cur_parm_size; + } + + if (dump_file) + { + struct access *acc; + fprintf (dump_file, "Evaluating PARAM group sizes for "); + print_generic_expr (dump_file, parm, 0); + fprintf (dump_file, " (UID: %u): \n", DECL_UID (parm)); + for (acc = repr; acc; acc = acc->next_grp) + dump_access (dump_file, acc, true); + } + + total_size = 0; + new_param_count = 0; + + for (; repr; repr = repr->next_grp) + { + gcc_assert (parm == repr->base); + new_param_count++; + + if (!by_ref || (!repr->grp_maybe_modified + && !repr->grp_not_necessarilly_dereferenced)) + total_size += repr->size; + else + total_size += cur_parm_size; + } + + gcc_assert (new_param_count > 0); + + if (optimize_function_for_size_p (cfun)) + parm_size_limit = cur_parm_size; + else + parm_size_limit = (PARAM_VALUE (PARAM_IPA_SRA_PTR_GROWTH_FACTOR) + * cur_parm_size); + + if (total_size < agg_size + && total_size <= parm_size_limit) + { + if (dump_file) + fprintf (dump_file, " ....will be split into %i components\n", + new_param_count); + return new_param_count; + } + else + return 0; +} + +/* The order of the following enums is important, we need to do extra work for + UNUSED_PARAMS, BY_VAL_ACCESSES and UNMODIF_BY_REF_ACCESSES. */ +enum ipa_splicing_result { NO_GOOD_ACCESS, UNUSED_PARAMS, BY_VAL_ACCESSES, + MODIF_BY_REF_ACCESSES, UNMODIF_BY_REF_ACCESSES }; + +/* Identify representatives of all accesses to all candidate parameters for + IPA-SRA. Return result based on what representatives have been found. */ + +static enum ipa_splicing_result +splice_all_param_accesses (VEC (access_p, heap) **representatives) +{ + enum ipa_splicing_result result = NO_GOOD_ACCESS; + tree parm; + struct access *repr; + + *representatives = VEC_alloc (access_p, heap, func_param_count); + + for (parm = DECL_ARGUMENTS (current_function_decl); + parm; + parm = TREE_CHAIN (parm)) + { + if (is_unused_scalar_param (parm)) + { + VEC_quick_push (access_p, *representatives, + &no_accesses_representant); + if (result == NO_GOOD_ACCESS) + result = UNUSED_PARAMS; + } + else if (POINTER_TYPE_P (TREE_TYPE (parm)) + && is_gimple_reg_type (TREE_TYPE (TREE_TYPE (parm))) + && bitmap_bit_p (candidate_bitmap, DECL_UID (parm))) + { + repr = unmodified_by_ref_scalar_representative (parm); + VEC_quick_push (access_p, *representatives, repr); + if (repr) + result = UNMODIF_BY_REF_ACCESSES; + } + else if (bitmap_bit_p (candidate_bitmap, DECL_UID (parm))) + { + bool ro_grp = false; + repr = splice_param_accesses (parm, &ro_grp); + VEC_quick_push (access_p, *representatives, repr); + + if (repr && !no_accesses_p (repr)) + { + if (POINTER_TYPE_P (TREE_TYPE (parm))) + { + if (ro_grp) + result = UNMODIF_BY_REF_ACCESSES; + else if (result < MODIF_BY_REF_ACCESSES) + result = MODIF_BY_REF_ACCESSES; + } + else if (result < BY_VAL_ACCESSES) + result = BY_VAL_ACCESSES; + } + else if (no_accesses_p (repr) && (result == NO_GOOD_ACCESS)) + result = UNUSED_PARAMS; + } + else + VEC_quick_push (access_p, *representatives, NULL); + } + + if (result == NO_GOOD_ACCESS) + { + VEC_free (access_p, heap, *representatives); + *representatives = NULL; + return NO_GOOD_ACCESS; + } + + return result; +} + +/* Return the index of BASE in PARMS. Abort if it is not found. */ + +static inline int +get_param_index (tree base, VEC(tree, heap) *parms) +{ + int i, len; + + len = VEC_length (tree, parms); + for (i = 0; i < len; i++) + if (VEC_index (tree, parms, i) == base) + return i; + gcc_unreachable (); +} + +/* Convert the decisions made at the representative level into compact + parameter adjustments. REPRESENTATIVES are pointers to first + representatives of each param accesses, ADJUSTMENTS_COUNT is the expected + final number of adjustments. */ + +static ipa_parm_adjustment_vec +turn_representatives_into_adjustments (VEC (access_p, heap) *representatives, + int adjustments_count) +{ + VEC (tree, heap) *parms; + ipa_parm_adjustment_vec adjustments; + tree parm; + int i; + + gcc_assert (adjustments_count > 0); + parms = ipa_get_vector_of_formal_parms (current_function_decl); + adjustments = VEC_alloc (ipa_parm_adjustment_t, heap, adjustments_count); + parm = DECL_ARGUMENTS (current_function_decl); + for (i = 0; i < func_param_count; i++, parm = TREE_CHAIN (parm)) + { + struct access *repr = VEC_index (access_p, representatives, i); + + if (!repr || no_accesses_p (repr)) + { + struct ipa_parm_adjustment *adj; + + adj = VEC_quick_push (ipa_parm_adjustment_t, adjustments, NULL); + memset (adj, 0, sizeof (*adj)); + adj->base_index = get_param_index (parm, parms); + adj->base = parm; + if (!repr) + adj->copy_param = 1; + else + adj->remove_param = 1; + } + else + { + struct ipa_parm_adjustment *adj; + int index = get_param_index (parm, parms); + + for (; repr; repr = repr->next_grp) + { + adj = VEC_quick_push (ipa_parm_adjustment_t, adjustments, NULL); + memset (adj, 0, sizeof (*adj)); + gcc_assert (repr->base == parm); + adj->base_index = index; + adj->base = repr->base; + adj->type = repr->type; + adj->offset = repr->offset; + adj->by_ref = (POINTER_TYPE_P (TREE_TYPE (repr->base)) + && (repr->grp_maybe_modified + || repr->grp_not_necessarilly_dereferenced)); + + } + } + } + VEC_free (tree, heap, parms); + return adjustments; +} + +/* Analyze the collected accesses and produce a plan what to do with the + parameters in the form of adjustments, NULL meaning nothing. */ + +static ipa_parm_adjustment_vec +analyze_all_param_acesses (void) +{ + enum ipa_splicing_result repr_state; + bool proceed = false; + int i, adjustments_count = 0; + VEC (access_p, heap) *representatives; + ipa_parm_adjustment_vec adjustments; + + repr_state = splice_all_param_accesses (&representatives); + if (repr_state == NO_GOOD_ACCESS) + return NULL; + + /* If there are any parameters passed by reference which are not modified + directly, we need to check whether they can be modified indirectly. */ + if (repr_state == UNMODIF_BY_REF_ACCESSES) + { + analyze_caller_dereference_legality (representatives); + analyze_modified_params (representatives); + } + + for (i = 0; i < func_param_count; i++) + { + struct access *repr = VEC_index (access_p, representatives, i); + + if (repr && !no_accesses_p (repr)) + { + if (repr->grp_scalar_ptr) + { + adjustments_count++; + if (repr->grp_not_necessarilly_dereferenced + || repr->grp_maybe_modified) + VEC_replace (access_p, representatives, i, NULL); + else + { + proceed = true; + sra_stats.scalar_by_ref_to_by_val++; + } + } + else + { + int new_components = decide_one_param_reduction (repr); + + if (new_components == 0) + { + VEC_replace (access_p, representatives, i, NULL); + adjustments_count++; + } + else + { + adjustments_count += new_components; + sra_stats.aggregate_params_reduced++; + sra_stats.param_reductions_created += new_components; + proceed = true; + } + } + } + else + { + if (no_accesses_p (repr)) + { + proceed = true; + sra_stats.deleted_unused_parameters++; + } + adjustments_count++; + } + } + + if (!proceed && dump_file) + fprintf (dump_file, "NOT proceeding to change params.\n"); + + if (proceed) + adjustments = turn_representatives_into_adjustments (representatives, + adjustments_count); + else + adjustments = NULL; + + VEC_free (access_p, heap, representatives); + return adjustments; +} + +/* If a parameter replacement identified by ADJ does not yet exist in the form + of declaration, create it and record it, otherwise return the previously + created one. */ + +static tree +get_replaced_param_substitute (struct ipa_parm_adjustment *adj) +{ + tree repl; + if (!adj->new_ssa_base) + { + char *pretty_name = make_fancy_name (adj->base); + + repl = make_rename_temp (TREE_TYPE (adj->base), "ISR"); + DECL_NAME (repl) = get_identifier (pretty_name); + obstack_free (&name_obstack, pretty_name); + + get_var_ann (repl); + add_referenced_var (repl); + adj->new_ssa_base = repl; + } + else + repl = adj->new_ssa_base; + return repl; +} + +/* Find the first adjustment for a particular parameter BASE in a vector of + ADJUSTMENTS which is not a copy_param. Return NULL if there is no such + adjustment. */ + +static struct ipa_parm_adjustment * +get_adjustment_for_base (ipa_parm_adjustment_vec adjustments, tree base) +{ + int i, len; + + len = VEC_length (ipa_parm_adjustment_t, adjustments); + for (i = 0; i < len; i++) + { + struct ipa_parm_adjustment *adj; + + adj = VEC_index (ipa_parm_adjustment_t, adjustments, i); + if (!adj->copy_param && adj->base == base) + return adj; + } + + return NULL; +} + +/* Callback for scan_function. If the statement STMT defines an SSA_NAME of a + parameter which is to be removed because its value is not used, replace the + SSA_NAME with a one relating to a created VAR_DECL and replace all of its + uses too. DATA is a pointer to an adjustments vector. */ + +static bool +replace_removed_params_ssa_names (gimple stmt, void *data) +{ + VEC (ipa_parm_adjustment_t, heap) *adjustments; + struct ipa_parm_adjustment *adj; + tree lhs, decl, repl, name; + + adjustments = (VEC (ipa_parm_adjustment_t, heap) *) data; + if (gimple_code (stmt) == GIMPLE_PHI) + lhs = gimple_phi_result (stmt); + else if (is_gimple_assign (stmt)) + lhs = gimple_assign_lhs (stmt); + else if (is_gimple_call (stmt)) + lhs = gimple_call_lhs (stmt); + else + gcc_unreachable (); + + if (TREE_CODE (lhs) != SSA_NAME) + return false; + decl = SSA_NAME_VAR (lhs); + if (TREE_CODE (decl) != PARM_DECL) + return false; + + adj = get_adjustment_for_base (adjustments, decl); + if (!adj) + return false; + + repl = get_replaced_param_substitute (adj); + name = make_ssa_name (repl, stmt); + + if (dump_file) + { + fprintf (dump_file, "replacing an SSA name of a removed param "); + print_generic_expr (dump_file, lhs, 0); + fprintf (dump_file, " with "); + print_generic_expr (dump_file, name, 0); + fprintf (dump_file, "\n"); + } + + if (is_gimple_assign (stmt)) + gimple_assign_set_lhs (stmt, name); + else if (is_gimple_call (stmt)) + gimple_call_set_lhs (stmt, name); + else + gimple_phi_set_result (stmt, name); + + replace_uses_by (lhs, name); + return true; +} + +/* Callback for scan_function. If the expression *EXPR should be replaced by a + reduction of a parameter, do so. DATA is a pointer to a vector of + adjustments. */ + +static bool +sra_ipa_modify_expr (tree *expr, gimple_stmt_iterator *gsi ATTRIBUTE_UNUSED, + bool write ATTRIBUTE_UNUSED, void *data) +{ + ipa_parm_adjustment_vec adjustments; + int i, len; + struct ipa_parm_adjustment *adj, *cand = NULL; + HOST_WIDE_INT offset, size, max_size; + tree base, src; + + adjustments = (VEC (ipa_parm_adjustment_t, heap) *) data; + len = VEC_length (ipa_parm_adjustment_t, adjustments); + + if (TREE_CODE (*expr) == BIT_FIELD_REF + || TREE_CODE (*expr) == IMAGPART_EXPR + || TREE_CODE (*expr) == REALPART_EXPR) + expr = &TREE_OPERAND (*expr, 0); + while (TREE_CODE (*expr) == NOP_EXPR + || TREE_CODE (*expr) == VIEW_CONVERT_EXPR) + expr = &TREE_OPERAND (*expr, 0); + + base = get_ref_base_and_extent (*expr, &offset, &size, &max_size); + if (!base || size == -1 || max_size == -1) + return false; + + if (INDIRECT_REF_P (base)) + base = TREE_OPERAND (base, 0); + + base = get_ssa_base_param (base); + if (!base || TREE_CODE (base) != PARM_DECL) + return false; + + for (i = 0; i < len; i++) + { + adj = VEC_index (ipa_parm_adjustment_t, adjustments, i); + + if (adj->base == base && + (adj->offset == offset || adj->remove_param)) + { + cand = adj; + break; + } + } + if (!cand || cand->copy_param || cand->remove_param) + return false; + + if (cand->by_ref) + { + tree folded; + src = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (cand->reduction)), + cand->reduction); + folded = gimple_fold_indirect_ref (src); + if (folded) + src = folded; + } + else + src = cand->reduction; + + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "About to replace expr "); + print_generic_expr (dump_file, *expr, 0); + fprintf (dump_file, " with "); + print_generic_expr (dump_file, src, 0); + fprintf (dump_file, "\n"); + } + + if (!useless_type_conversion_p (TREE_TYPE (*expr), cand->type)) + { + tree vce = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (*expr), src); + *expr = vce; + } + else + *expr = src; + return true; +} + +/* Callback for scan_function to process assign statements. Performs + essentially the same function like sra_ipa_modify_expr. */ + +static enum scan_assign_result +sra_ipa_modify_assign (gimple *stmt_ptr, + gimple_stmt_iterator *gsi ATTRIBUTE_UNUSED, void *data) +{ + gimple stmt = *stmt_ptr; + bool any = false; + + if (!gimple_assign_single_p (stmt)) + return SRA_SA_NONE; + + any |= sra_ipa_modify_expr (gimple_assign_rhs1_ptr (stmt), gsi, false, + data); + any |= sra_ipa_modify_expr (gimple_assign_lhs_ptr (stmt), gsi, true, data); + + return any ? SRA_SA_PROCESSED : SRA_SA_NONE; +} + +/* Call gimple_debug_bind_reset_value on all debug statements describing + gimple register parameters that are being removed or replaced. */ + +static void +sra_ipa_reset_debug_stmts (ipa_parm_adjustment_vec adjustments) +{ + int i, len; + + len = VEC_length (ipa_parm_adjustment_t, adjustments); + for (i = 0; i < len; i++) + { + struct ipa_parm_adjustment *adj; + imm_use_iterator ui; + gimple stmt; + tree name; + + adj = VEC_index (ipa_parm_adjustment_t, adjustments, i); + if (adj->copy_param || !is_gimple_reg (adj->base)) + continue; + name = gimple_default_def (cfun, adj->base); + if (!name) + continue; + FOR_EACH_IMM_USE_STMT (stmt, ui, name) + { + /* All other users must have been removed by scan_function. */ + gcc_assert (is_gimple_debug (stmt)); + gimple_debug_bind_reset_value (stmt); + update_stmt (stmt); + } + } +} + +/* Convert all callers of NODE to pass parameters as given in ADJUSTMENTS. */ + +static void +convert_callers (struct cgraph_node *node, ipa_parm_adjustment_vec adjustments) +{ + tree old_cur_fndecl = current_function_decl; + struct cgraph_edge *cs; + basic_block this_block; + + for (cs = node->callers; cs; cs = cs->next_caller) + { + current_function_decl = cs->caller->decl; + push_cfun (DECL_STRUCT_FUNCTION (cs->caller->decl)); + + if (dump_file) + fprintf (dump_file, "Adjusting call %s -> %s\n", + cgraph_node_name (cs->caller), + cgraph_node_name (cs->callee)); + + ipa_modify_call_arguments (cs, cs->call_stmt, adjustments); + compute_inline_parameters (cs->caller); + + pop_cfun (); + } + current_function_decl = old_cur_fndecl; + FOR_EACH_BB (this_block) + { + gimple_stmt_iterator gsi; + + for (gsi = gsi_start_bb (this_block); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple stmt = gsi_stmt (gsi); + if (gimple_code (stmt) == GIMPLE_CALL + && gimple_call_fndecl (stmt) == node->decl) + { + if (dump_file) + fprintf (dump_file, "Adjusting recursive call"); + ipa_modify_call_arguments (NULL, stmt, adjustments); + } + } + } + + return; +} + +/* Perform all the modification required in IPA-SRA for NODE to have parameters + as given in ADJUSTMENTS. */ + +static void +modify_function (struct cgraph_node *node, ipa_parm_adjustment_vec adjustments) +{ + ipa_modify_formal_parameters (current_function_decl, adjustments, "ISRA"); + scan_function (sra_ipa_modify_expr, sra_ipa_modify_assign, + replace_removed_params_ssa_names, false, adjustments); + sra_ipa_reset_debug_stmts (adjustments); + convert_callers (node, adjustments); + cgraph_make_node_local (node); + return; +} + +/* Return false the function is apparently unsuitable for IPA-SRA based on it's + attributes, return true otherwise. NODE is the cgraph node of the current + function. */ + +static bool +ipa_sra_preliminary_function_checks (struct cgraph_node *node) +{ + if (!cgraph_node_can_be_local_p (node)) + { + if (dump_file) + fprintf (dump_file, "Function not local to this compilation unit.\n"); + return false; + } + + if (DECL_VIRTUAL_P (current_function_decl)) + { + if (dump_file) + fprintf (dump_file, "Function is a virtual method.\n"); + return false; + } + + if ((DECL_COMDAT (node->decl) || DECL_EXTERNAL (node->decl)) + && node->global.size >= MAX_INLINE_INSNS_AUTO) + { + if (dump_file) + fprintf (dump_file, "Function too big to be made truly local.\n"); + return false; + } + + if (!node->callers) + { + if (dump_file) + fprintf (dump_file, + "Function has no callers in this compilation unit.\n"); + return false; + } + + if (cfun->stdarg) + { + if (dump_file) + fprintf (dump_file, "Function uses stdarg. \n"); + return false; + } + + return true; +} + +/* Perform early interprocedural SRA. */ + +static unsigned int +ipa_early_sra (void) +{ + struct cgraph_node *node = cgraph_node (current_function_decl); + ipa_parm_adjustment_vec adjustments; + int ret = 0; + + if (!ipa_sra_preliminary_function_checks (node)) + return 0; + + sra_initialize (); + sra_mode = SRA_MODE_EARLY_IPA; + + if (!find_param_candidates ()) + { + if (dump_file) + fprintf (dump_file, "Function has no IPA-SRA candidates.\n"); + goto simple_out; + } + + bb_dereferences = XCNEWVEC (HOST_WIDE_INT, + func_param_count + * last_basic_block_for_function (cfun)); + final_bbs = BITMAP_ALLOC (NULL); + + scan_function (build_access_from_expr, build_accesses_from_assign, + NULL, true, NULL); + if (encountered_apply_args) + { + if (dump_file) + fprintf (dump_file, "Function calls __builtin_apply_args().\n"); + goto out; + } + + adjustments = analyze_all_param_acesses (); + if (!adjustments) + goto out; + if (dump_file) + ipa_dump_param_adjustments (dump_file, adjustments, current_function_decl); + + modify_function (node, adjustments); + VEC_free (ipa_parm_adjustment_t, heap, adjustments); + ret = TODO_update_ssa; + + statistics_counter_event (cfun, "Unused parameters deleted", + sra_stats.deleted_unused_parameters); + statistics_counter_event (cfun, "Scalar parameters converted to by-value", + sra_stats.scalar_by_ref_to_by_val); + statistics_counter_event (cfun, "Aggregate parameters broken up", + sra_stats.aggregate_params_reduced); + statistics_counter_event (cfun, "Aggregate parameter components created", + sra_stats.param_reductions_created); + + out: + BITMAP_FREE (final_bbs); + free (bb_dereferences); + simple_out: + sra_deinitialize (); + return ret; +} + +/* Return if early ipa sra shall be performed. */ +static bool +ipa_early_sra_gate (void) +{ + return flag_ipa_sra; +} + +struct gimple_opt_pass pass_early_ipa_sra = +{ + { + GIMPLE_PASS, + "eipa_sra", /* name */ + ipa_early_sra_gate, /* gate */ + ipa_early_sra, /* execute */ + NULL, /* sub */ + NULL, /* next */ + 0, /* static_pass_number */ + TV_IPA_SRA, /* tv_id */ + 0, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + TODO_dump_func | TODO_dump_cgraph /* todo_flags_finish */ + } +}; + + diff --git a/gcc/tree.c b/gcc/tree.c index d2243e5d1bd..846dd983ea7 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -4034,7 +4034,7 @@ iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2) Record such modified types already made so we don't make duplicates. */ -static tree +tree build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) { if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) diff --git a/gcc/tree.h b/gcc/tree.h index 09ce8fa125c..afb1d4260a0 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3997,6 +3997,7 @@ extern tree make_tree (tree, rtx); extern tree build_type_attribute_variant (tree, tree); extern tree build_decl_attribute_variant (tree, tree); +extern tree build_type_attribute_qual_variant (tree, tree, int); /* Structure describing an attribute and a function to handle it. */ struct attribute_spec diff --git a/libffi/ChangeLog b/libffi/ChangeLog index 684a0e88fce..3600fd9e954 100644 --- a/libffi/ChangeLog +++ b/libffi/ChangeLog @@ -1,3 +1,9 @@ +2009-09-17 Loren J. Rittle <ljrittle@acm.org> + + PR testsuite/32843 (strikes again) + * src/x86/ffi.c (ffi_prep_cif_machdep): Add X86_FREEBSD to + enable proper extension on char and short. + 2009-09-15 David Daney <ddaney@caviumnetworks.com> * src/java_raw_api.c (ffi_java_raw_to_rvalue): Remove special diff --git a/libffi/src/x86/ffi.c b/libffi/src/x86/ffi.c index a5f506db19c..594235a6df2 100644 --- a/libffi/src/x86/ffi.c +++ b/libffi/src/x86/ffi.c @@ -155,7 +155,7 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) #ifdef X86 case FFI_TYPE_STRUCT: #endif -#if defined(X86) || defined (X86_WIN32) || defined(X86_DARWIN) || defined(X86_WIN64) +#if defined(X86) || defined (X86_WIN32) || defined(X86_FREEBSD) || defined(X86_DARWIN) || defined(X86_WIN64) case FFI_TYPE_UINT8: case FFI_TYPE_UINT16: case FFI_TYPE_SINT8: diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index d94cb78d24c..3572d1794de 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,7 @@ +2009-09-17 Alexander Monakov <amonakov@ispras.ru> + + * testsuite/libgomp.graphite/bounds.c: New test. + 2009-09-11 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> * Makefile.am (libgomp_la_LINK): New. diff --git a/libgomp/testsuite/libgomp.graphite/bounds.c b/libgomp/testsuite/libgomp.graphite/bounds.c new file mode 100644 index 00000000000..bd36c0f8a22 --- /dev/null +++ b/libgomp/testsuite/libgomp.graphite/bounds.c @@ -0,0 +1,13 @@ +int foo(int *a, int n) +{ + int i; + for (i = 2; i < n; i++) + a[i] += a[i+1]; +} + +/* Check that Graphite dependency checking notes the dependency. */ +/* { dg-do compile } */ +/* { dg-final { scan-tree-dump-times "0 loops carried no dependency" 1 "graphite" } } */ +/* { dg-final { cleanup-tree-dump "graphite" } } */ +/* { dg-final { cleanup-tree-dump "parloops" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 03c26b61ac8..b58bc9966bb 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,8 @@ +2009-09-16 Jonathan Yong <jon_y@users.sourceforge.net> + + * gnu/java/security/jce/prng/natVMSecureRandomWin32.cc: Correct + UnsupportedOperationException namespace. + 2009-09-16 Andrew Haley <aph@redhat.com> * libgcj_bc.c (__data_start, data_start, _end): Add dummy usage. diff --git a/libjava/gnu/java/security/jce/prng/natVMSecureRandomWin32.cc b/libjava/gnu/java/security/jce/prng/natVMSecureRandomWin32.cc index 66eaf82215f..1a9d0d355e2 100755 --- a/libjava/gnu/java/security/jce/prng/natVMSecureRandomWin32.cc +++ b/libjava/gnu/java/security/jce/prng/natVMSecureRandomWin32.cc @@ -26,7 +26,7 @@ jint gnu::java::security::jce::prng::VMSecureRandom::natGenerateSeed(jbyteArray byte_array, jint offset, jint length) { if (length != 0) - throw new UnsupportedOperationException ( + throw new java::lang::UnsupportedOperationException ( JvNewStringLatin1 ("natGenerateSeed is not available for Win32 target.")); return 0; } diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8b007d8c585..32a48157936 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,66 @@ +2009-09-17 Joseph Myers <joseph@codesourcery.com> + + * testsuite/lib/libstdc++.exp (check_v3_target_binary_io): New. + * testsuite/lib/dg-options.exp (dg-require-binary-io): New. + * testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc, + testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc, + testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc, + testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc, + testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc, + testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc, + testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc, + testsuite/27_io/basic_istream/readsome/char/6746-2.cc, + testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc, + testsuite/27_io/objects/char/10.cc: Use dg-require-binary-io. + +2009-09-17 Joseph Myers <joseph@codesourcery.com> + + * include/ext/vstring.h (to_wstring(long long), + to_wstring(unsigned long long), to_wstring(long double)): Disable + for _GLIBCXX_HAVE_BROKEN_VSWPRINTF. + +2009-09-17 Johannes Singler <singler@ira.uka.de> + + * include/parallel/algobase.h: Replace tabs by spaces; + correct line breaks. + * include/parallel/algorithmfwd.h: Likewise. + * include/parallel/balanced_quicksort.h: Likewise. + * include/parallel/base.h: Likewise. + * include/parallel/checkers.h: Likewise. + * include/parallel/compatibility.h: Likewise. + * include/parallel/equally_split.h: Likewise. + * include/parallel/find.h: Likewise. + * include/parallel/for_each.h: Likewise. + * include/parallel/for_each_selectors.h: Likewise. + * include/parallel/iterator.h: Likewise. + * include/parallel/list_partition.h: Likewise. + * include/parallel/losertree.h: Likewise. + * include/parallel/merge.h: Likewise. + * include/parallel/multiseq_selection.h: Likewise. + * include/parallel/multiway_merge.h: Likewise. + * include/parallel/multiway_mergesort.h: Likewise. + * include/parallel/numeric: Likewise. + * include/parallel/numericfwd.h: Likewise. + * include/parallel/omp_loop.h: Likewise. + * include/parallel/omp_loop_static.h: Likewise. + * include/parallel/par_loop.h: Likewise. + * include/parallel/partial_sum.h: Likewise. + * include/parallel/partition.h: Likewise. + * include/parallel/queue.h: Likewise. + * include/parallel/quicksort.h: Likewise. + * include/parallel/random_number.h: Likewise. + * include/parallel/random_shuffle.h: Likewise. + * include/parallel/search.h: Likewise. + * include/parallel/set_operations.h: Likewise. + * include/parallel/settings.h: Likewise. + * include/parallel/sort.h: Likewise. + * include/parallel/types.h: Likewise. + * include/parallel/unique_copy.h: Likewise. + * include/parallel/workstealing.h: Likewise. + * include/parallel/algo.h: Likewise; + shorten _ForwardIterator to _FIterator. + * include/parallel/find_selectors.h: Likewise. + 2009-09-16 Johannes Singler <singler@ira.uka.de> * include/parallel/base.h: Correct some comments accidentally changed diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index cfce575dc72..61e6ae49fea 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -2523,6 +2523,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) stold(const __wvstring& __str, std::size_t* __idx = 0) { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } +#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF inline __wvstring to_wstring(long long __val) { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, @@ -2543,6 +2544,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) L"%Lf", __val); } #endif +#endif _GLIBCXX_END_NAMESPACE diff --git a/libstdc++-v3/include/parallel/algo.h b/libstdc++-v3/include/parallel/algo.h index a94962d13f5..1a75d24b917 100644 --- a/libstdc++-v3/include/parallel/algo.h +++ b/libstdc++-v3/include/parallel/algo.h @@ -94,9 +94,10 @@ namespace __parallel __gnu_parallel::__for_each_selector<_RAIter> __functionality; return __gnu_parallel:: - __for_each_template_random_access(__begin, __end, __f, __functionality, - __gnu_parallel::_DummyReduct(), - true, __dummy, -1, __parallelism_tag); + __for_each_template_random_access( + __begin, __end, __f, __functionality, + __gnu_parallel::_DummyReduct(), true, __dummy, -1, + __parallelism_tag); } else return for_each(__begin, __end, __f, __gnu_parallel::sequential_tag()); @@ -151,9 +152,9 @@ namespace __parallel { binder2nd<__gnu_parallel::equal_to<_ValueType, const _Tp&> > __comp(__gnu_parallel::equal_to<_ValueType, const _Tp&>(), __val); - return __gnu_parallel::__find_template(__begin, __end, __begin, __comp, - __gnu_parallel:: - __find_if_selector()).first; + return __gnu_parallel::__find_template( + __begin, __end, __begin, __comp, + __gnu_parallel::__find_if_selector()).first; } else return _GLIBCXX_STD_P::find(__begin, __end, __val); @@ -190,7 +191,7 @@ namespace __parallel _Predicate __pred, random_access_iterator_tag) { if (_GLIBCXX_PARALLEL_CONDITION(true)) - return __gnu_parallel::__find_template(__begin, __end, __begin, __pred, + return __gnu_parallel::__find_template(__begin, __end, __begin, __pred, __gnu_parallel:: __find_if_selector()).first; else @@ -208,69 +209,71 @@ namespace __parallel } // Sequential fallback - template<typename _IIter, typename _ForwardIterator> + template<typename _IIter, typename _FIterator> inline _IIter find_first_of(_IIter __begin1, _IIter __end1, - _ForwardIterator __begin2, _ForwardIterator __end2, + _FIterator __begin2, _FIterator __end2, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::find_first_of(__begin1, __end1, __begin2, __end2); } + { return _GLIBCXX_STD_P::find_first_of(__begin1, __end1, __begin2, __end2); + } // Sequential fallback - template<typename _IIter, typename _ForwardIterator, + template<typename _IIter, typename _FIterator, typename _BinaryPredicate> inline _IIter find_first_of(_IIter __begin1, _IIter __end1, - _ForwardIterator __begin2, _ForwardIterator __end2, + _FIterator __begin2, _FIterator __end2, _BinaryPredicate __comp, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::find_first_of(__begin1, __end1, __begin2, __end2, __comp); } + { return _GLIBCXX_STD_P::find_first_of( + __begin1, __end1, __begin2, __end2, __comp); } // Sequential fallback for input iterator type - template<typename _IIter, typename _ForwardIterator, + template<typename _IIter, typename _FIterator, typename _IteratorTag1, typename _IteratorTag2> inline _IIter __find_first_of_switch(_IIter __begin1, _IIter __end1, - _ForwardIterator __begin2, _ForwardIterator __end2, + _FIterator __begin2, _FIterator __end2, _IteratorTag1, _IteratorTag2) { return find_first_of(__begin1, __end1, __begin2, __end2, __gnu_parallel::sequential_tag()); } // Parallel algorithm for random access iterators - template<typename _RAIter, typename _ForwardIterator, + template<typename _RAIter, typename _FIterator, typename _BinaryPredicate, typename _IteratorTag> inline _RAIter __find_first_of_switch(_RAIter __begin1, _RAIter __end1, - _ForwardIterator __begin2, _ForwardIterator __end2, + _FIterator __begin2, _FIterator __end2, _BinaryPredicate __comp, random_access_iterator_tag, _IteratorTag) { return __gnu_parallel:: __find_template(__begin1, __end1, __begin1, __comp, __gnu_parallel::__find_first_of_selector - <_ForwardIterator>(__begin2, __end2)).first; + <_FIterator>(__begin2, __end2)).first; } // Sequential fallback for input iterator type - template<typename _IIter, typename _ForwardIterator, + template<typename _IIter, typename _FIterator, typename _BinaryPredicate, typename _IteratorTag1, typename _IteratorTag2> inline _IIter __find_first_of_switch(_IIter __begin1, _IIter __end1, - _ForwardIterator __begin2, _ForwardIterator __end2, + _FIterator __begin2, _FIterator __end2, _BinaryPredicate __comp, _IteratorTag1, _IteratorTag2) { return find_first_of(__begin1, __end1, __begin2, __end2, __comp, __gnu_parallel::sequential_tag()); } // Public interface - template<typename _IIter, typename _ForwardIterator, + template<typename _IIter, typename _FIterator, typename _BinaryPredicate> inline _IIter find_first_of(_IIter __begin1, _IIter __end1, - _ForwardIterator __begin2, _ForwardIterator __end2, + _FIterator __begin2, _FIterator __end2, _BinaryPredicate __comp) { typedef std::iterator_traits<_IIter> _IIterTraits; - typedef std::iterator_traits<_ForwardIterator> iteratorf_traits; + typedef std::iterator_traits<_FIterator> iteratorf_traits; typedef typename _IIterTraits::iterator_category _IIteratorCategory; typedef typename iteratorf_traits::iterator_category iteratorf_category; @@ -279,13 +282,13 @@ namespace __parallel } // Public interface, insert default comparator - template<typename _IIter, typename _ForwardIterator> + template<typename _IIter, typename _FIterator> inline _IIter find_first_of(_IIter __begin1, _IIter __end1, - _ForwardIterator __begin2, _ForwardIterator __end2) + _FIterator __begin2, _FIterator __end2) { typedef std::iterator_traits<_IIter> _IIterTraits; - typedef std::iterator_traits<_ForwardIterator> iteratorf_traits; + typedef std::iterator_traits<_FIterator> iteratorf_traits; typedef typename _IIterTraits::value_type _IValueType; typedef typename iteratorf_traits::value_type _FValueType; @@ -328,7 +331,8 @@ namespace __parallel if (_GLIBCXX_PARALLEL_CONDITION( static_cast<__gnu_parallel::_SequenceIndex>(__last - __begin) > __gnu_parallel::_Settings::get().unique_copy_minimal_n)) - return __gnu_parallel::__parallel_unique_copy(__begin, __last, __out, __pred); + return __gnu_parallel::__parallel_unique_copy( + __begin, __last, __out, __pred); else return _GLIBCXX_STD_P::unique_copy(__begin, __last, __out, __pred); } @@ -344,8 +348,9 @@ namespace __parallel typedef typename _IIterTraits::value_type _ValueType; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __unique_copy_switch(__begin1, __end1, __out, equal_to<_ValueType>(), - _IIteratorCategory(), _OIterCategory()); + return __unique_copy_switch( + __begin1, __end1, __out, equal_to<_ValueType>(), + _IIteratorCategory(), _OIterCategory()); } // Public interface @@ -359,8 +364,9 @@ namespace __parallel typedef typename _IIterTraits::iterator_category _IIteratorCategory; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __unique_copy_switch(__begin1, __end1, __out, __pred, _IIteratorCategory(), - _OIterCategory()); + return __unique_copy_switch( + __begin1, __end1, __out, __pred, + _IIteratorCategory(), _OIterCategory()); } // Sequential fallback @@ -370,7 +376,8 @@ namespace __parallel set_union(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, _IIter2 __end2, _OutputIterator __out, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::set_union(__begin1, __end1, __begin2, __end2, __out); } + { return _GLIBCXX_STD_P::set_union( + __begin1, __end1, __begin2, __end2, __out); } // Sequential fallback template<typename _IIter1, typename _IIter2, @@ -384,14 +391,14 @@ namespace __parallel __begin2, __end2, __out, __pred); } // Sequential fallback for input iterator case - template<typename _IIter1, typename _IIter2, - typename _Predicate, typename _OutputIterator, - typename _IteratorTag1, typename _IteratorTag2, typename _IteratorTag3> + template<typename _IIter1, typename _IIter2, typename _Predicate, + typename _OutputIterator, typename _IteratorTag1, + typename _IteratorTag2, typename _IteratorTag3> inline _OutputIterator - __set_union_switch(_IIter1 __begin1, _IIter1 __end1, - _IIter2 __begin2, _IIter2 __end2, - _OutputIterator __result, _Predicate __pred, _IteratorTag1, - _IteratorTag2, _IteratorTag3) + __set_union_switch( + _IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, _IIter2 __end2, + _OutputIterator __result, _Predicate __pred, + _IteratorTag1, _IteratorTag2, _IteratorTag3) { return _GLIBCXX_STD_P::set_union(__begin1, __end1, __begin2, __end2, __result, __pred); } @@ -410,8 +417,8 @@ namespace __parallel >= __gnu_parallel::_Settings::get().set_union_minimal_n || static_cast<__gnu_parallel::_SequenceIndex>(__end2 - __begin2) >= __gnu_parallel::_Settings::get().set_union_minimal_n)) - return __gnu_parallel::__parallel_set_union(__begin1, __end1, - __begin2, __end2, __result, __pred); + return __gnu_parallel::__parallel_set_union( + __begin1, __end1, __begin2, __end2, __result, __pred); else return _GLIBCXX_STD_P::set_union(__begin1, __end1, __begin2, __end2, __result, __pred); @@ -435,10 +442,10 @@ namespace __parallel typedef typename _IIterTraits1::value_type _ValueType1; typedef typename _IIterTraits2::value_type _ValueType2; - return __set_union_switch(__begin1, __end1, __begin2, __end2, __out, - __gnu_parallel::_Less<_ValueType1, _ValueType2>(), - _IIterCategory1(), _IIterCategory2(), - _OIterCategory()); + return __set_union_switch( + __begin1, __end1, __begin2, __end2, __out, + __gnu_parallel::_Less<_ValueType1, _ValueType2>(), + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } // Public interface @@ -458,9 +465,9 @@ namespace __parallel _IIterCategory2; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __set_union_switch(__begin1, __end1, __begin2, __end2, __out, __pred, - _IIterCategory1(), _IIterCategory2(), - _OIterCategory()); + return __set_union_switch( + __begin1, __end1, __begin2, __end2, __out, __pred, + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } // Sequential fallback. @@ -481,8 +488,8 @@ namespace __parallel _IIter2 __begin2, _IIter2 __end2, _OutputIterator __out, _Predicate __pred, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::set_intersection(__begin1, __end1, __begin2, __end2, - __out, __pred); } + { return _GLIBCXX_STD_P::set_intersection( + __begin1, __end1, __begin2, __end2, __out, __pred); } // Sequential fallback for input iterator case template<typename _IIter1, typename _IIter2, @@ -490,11 +497,11 @@ namespace __parallel typename _IteratorTag1, typename _IteratorTag2, typename _IteratorTag3> inline _OutputIterator - __set_intersection_switch(_IIter1 __begin1, _IIter1 __end1, - _IIter2 __begin2, _IIter2 __end2, - _OutputIterator __result, _Predicate __pred, - _IteratorTag1, _IteratorTag2, _IteratorTag3) - { return _GLIBCXX_STD_P::set_intersection(__begin1, __end1, __begin2, + __set_intersection_switch(_IIter1 __begin1, _IIter1 __end1, + _IIter2 __begin2, _IIter2 __end2, + _OutputIterator __result, _Predicate __pred, + _IteratorTag1, _IteratorTag2, _IteratorTag3) + { return _GLIBCXX_STD_P::set_intersection(__begin1, __end1, __begin2, __end2, __result, __pred); } // Parallel set_intersection for random access iterators @@ -516,11 +523,11 @@ namespace __parallel >= __gnu_parallel::_Settings::get().set_union_minimal_n || static_cast<__gnu_parallel::_SequenceIndex>(__end2 - __begin2) >= __gnu_parallel::_Settings::get().set_union_minimal_n)) - return __gnu_parallel::__parallel_set_intersection(__begin1, __end1, __begin2, - __end2, __result, __pred); + return __gnu_parallel::__parallel_set_intersection( + __begin1, __end1, __begin2, __end2, __result, __pred); else - return _GLIBCXX_STD_P::set_intersection(__begin1, __end1, __begin2, - __end2, __result, __pred); + return _GLIBCXX_STD_P::set_intersection( + __begin1, __end1, __begin2, __end2, __result, __pred); } // Public interface @@ -542,12 +549,10 @@ namespace __parallel typedef typename _IIterTraits1::value_type _ValueType1; typedef typename _IIterTraits2::value_type _ValueType2; - return __set_intersection_switch(__begin1, __end1, __begin2, __end2, __out, - __gnu_parallel:: - _Less<_ValueType1, _ValueType2>(), - _IIterCategory1(), - _IIterCategory2(), - _OIterCategory()); + return __set_intersection_switch( + __begin1, __end1, __begin2, __end2, __out, + __gnu_parallel::_Less<_ValueType1, _ValueType2>(), + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } template<typename _IIter1, typename _IIter2, @@ -566,10 +571,9 @@ namespace __parallel _IIterCategory2; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __set_intersection_switch(__begin1, __end1, __begin2, __end2, __out, __pred, - _IIterCategory1(), - _IIterCategory2(), - _OIterCategory()); + return __set_intersection_switch( + __begin1, __end1, __begin2, __end2, __out, __pred, + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } // Sequential fallback @@ -580,8 +584,8 @@ namespace __parallel _IIter2 __begin2, _IIter2 __end2, _OutputIterator __out, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::set_symmetric_difference(__begin1,__end1, - __begin2, __end2, __out); } + { return _GLIBCXX_STD_P::set_symmetric_difference( + __begin1, __end1, __begin2, __end2, __out); } // Sequential fallback template<typename _IIter1, typename _IIter2, @@ -591,8 +595,8 @@ namespace __parallel _IIter2 __begin2, _IIter2 __end2, _OutputIterator __out, _Predicate __pred, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::set_symmetric_difference(__begin1, __end1, __begin2, - __end2, __out, __pred); } + { return _GLIBCXX_STD_P::set_symmetric_difference( + __begin1, __end1, __begin2, __end2, __out, __pred); } // Sequential fallback for input iterator case template<typename _IIter1, typename _IIter2, @@ -600,15 +604,12 @@ namespace __parallel typename _IteratorTag1, typename _IteratorTag2, typename _IteratorTag3> inline _OutputIterator - __set_symmetric_difference_switch(_IIter1 __begin1, - _IIter1 __end1, - _IIter2 __begin2, - _IIter2 __end2, - _OutputIterator __result, _Predicate __pred, - _IteratorTag1, _IteratorTag2, _IteratorTag3) - { return _GLIBCXX_STD_P::set_symmetric_difference(__begin1, __end1, - __begin2, __end2, - __result, __pred); } + __set_symmetric_difference_switch( + _IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, _IIter2 __end2, + _OutputIterator __result, _Predicate __pred, + _IteratorTag1, _IteratorTag2, _IteratorTag3) + { return _GLIBCXX_STD_P::set_symmetric_difference( + __begin1, __end1, __begin2, __end2, __result, __pred); } // Parallel set_symmetric_difference for random access iterators template<typename _RAIter1, typename _RAIter2, @@ -629,13 +630,11 @@ namespace __parallel >= __gnu_parallel::_Settings::get().set_symmetric_difference_minimal_n || static_cast<__gnu_parallel::_SequenceIndex>(__end2 - __begin2) >= __gnu_parallel::_Settings::get().set_symmetric_difference_minimal_n)) - return __gnu_parallel::__parallel_set_symmetric_difference(__begin1, __end1, - __begin2, __end2, - __result, __pred); + return __gnu_parallel::__parallel_set_symmetric_difference( + __begin1, __end1, __begin2, __end2, __result, __pred); else - return _GLIBCXX_STD_P::set_symmetric_difference(__begin1, __end1, - __begin2, __end2, - __result, __pred); + return _GLIBCXX_STD_P::set_symmetric_difference( + __begin1, __end1, __begin2, __end2, __result, __pred); } // Public interface. @@ -657,12 +656,10 @@ namespace __parallel typedef typename _IIterTraits1::value_type _ValueType1; typedef typename _IIterTraits2::value_type _ValueType2; - return __set_symmetric_difference_switch(__begin1, __end1, __begin2, __end2, __out, - __gnu_parallel:: - _Less<_ValueType1, _ValueType2>(), - _IIterCategory1(), - _IIterCategory2(), - _OIterCategory()); + return __set_symmetric_difference_switch( + __begin1, __end1, __begin2, __end2, __out, + __gnu_parallel::_Less<_ValueType1, _ValueType2>(), + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } // Public interface. @@ -682,10 +679,9 @@ namespace __parallel _IIterCategory2; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __set_symmetric_difference_switch(__begin1, __end1, __begin2, __end2, __out, - __pred, _IIterCategory1(), - _IIterCategory2(), - _OIterCategory()); + return __set_symmetric_difference_switch( + __begin1, __end1, __begin2, __end2, __out, __pred, + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } // Sequential fallback. @@ -695,7 +691,8 @@ namespace __parallel set_difference(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, _IIter2 __end2, _OutputIterator __out, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::set_difference(__begin1,__end1, __begin2, __end2, __out); } + { return _GLIBCXX_STD_P::set_difference( + __begin1,__end1, __begin2, __end2, __out); } // Sequential fallback. template<typename _IIter1, typename _IIter2, @@ -709,16 +706,16 @@ namespace __parallel __begin2, __end2, __out, __pred); } // Sequential fallback for input iterator case. - template<typename _IIter1, typename _IIter2, - typename _Predicate, typename _OutputIterator, - typename _IteratorTag1, typename _IteratorTag2, typename _IteratorTag3> + template<typename _IIter1, typename _IIter2, typename _Predicate, + typename _OutputIterator, typename _IteratorTag1, + typename _IteratorTag2, typename _IteratorTag3> inline _OutputIterator __set_difference_switch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, _IIter2 __end2, _OutputIterator __result, _Predicate __pred, _IteratorTag1, _IteratorTag2, _IteratorTag3) - { return _GLIBCXX_STD_P::set_difference(__begin1, __end1, - __begin2, __end2, __result, __pred); } + { return _GLIBCXX_STD_P::set_difference( + __begin1, __end1, __begin2, __end2, __result, __pred); } // Parallel set_difference for random access iterators template<typename _RAIter1, typename _RAIter2, @@ -738,12 +735,11 @@ namespace __parallel >= __gnu_parallel::_Settings::get().set_difference_minimal_n || static_cast<__gnu_parallel::_SequenceIndex>(__end2 - __begin2) >= __gnu_parallel::_Settings::get().set_difference_minimal_n)) - return __gnu_parallel::__parallel_set_difference(__begin1, __end1, - __begin2, __end2, - __result, __pred); + return __gnu_parallel::__parallel_set_difference( + __begin1, __end1, __begin2, __end2, __result, __pred); else - return _GLIBCXX_STD_P::set_difference(__begin1, __end1, - __begin2, __end2, __result, __pred); + return _GLIBCXX_STD_P::set_difference( + __begin1, __end1, __begin2, __end2, __result, __pred); } // Public interface @@ -765,12 +761,10 @@ namespace __parallel typedef typename _IIterTraits1::value_type _ValueType1; typedef typename _IIterTraits2::value_type _ValueType2; - return __set_difference_switch(__begin1, __end1, __begin2, __end2, __out, - __gnu_parallel:: - _Less<_ValueType1, _ValueType2>(), - _IIterCategory1(), - _IIterCategory2(), - _OIterCategory()); + return __set_difference_switch( + __begin1, __end1, __begin2, __end2, __out, + __gnu_parallel::_Less<_ValueType1, _ValueType2>(), + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } // Public interface @@ -790,24 +784,24 @@ namespace __parallel _IIterCategory2; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __set_difference_switch(__begin1, __end1, __begin2, __end2, __out, __pred, - _IIterCategory1(), - _IIterCategory2(), - _OIterCategory()); + return __set_difference_switch( + __begin1, __end1, __begin2, __end2, __out, __pred, + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } // Sequential fallback - template<typename _ForwardIterator> - inline _ForwardIterator - adjacent_find(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator> + inline _FIterator + adjacent_find(_FIterator __begin, _FIterator __end, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::adjacent_find(__begin, __end); } // Sequential fallback - template<typename _ForwardIterator, typename _BinaryPredicate> - inline _ForwardIterator - adjacent_find(_ForwardIterator __begin, _ForwardIterator __end, - _BinaryPredicate __binary_pred, __gnu_parallel::sequential_tag) + template<typename _FIterator, typename _BinaryPredicate> + inline _FIterator + adjacent_find(_FIterator __begin, _FIterator __end, + _BinaryPredicate __binary_pred, + __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::adjacent_find(__begin, __end, __binary_pred); } // Parallel algorithm for random access iterators @@ -822,8 +816,10 @@ namespace __parallel if (_GLIBCXX_PARALLEL_CONDITION(true)) { _RAIter spot = __gnu_parallel:: - __find_template(__begin, __end - 1, __begin, equal_to<_ValueType>(), - __gnu_parallel::__adjacent_find_selector()).first; + __find_template( + __begin, __end - 1, __begin, equal_to<_ValueType>(), + __gnu_parallel::__adjacent_find_selector()) + .first; if (spot == (__end - 1)) return __end; else @@ -834,27 +830,27 @@ namespace __parallel } // Sequential fallback for input iterator case - template<typename _ForwardIterator, typename _IteratorTag> - inline _ForwardIterator - __adjacent_find_switch(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator, typename _IteratorTag> + inline _FIterator + __adjacent_find_switch(_FIterator __begin, _FIterator __end, _IteratorTag) { return adjacent_find(__begin, __end, __gnu_parallel::sequential_tag()); } // Public interface - template<typename _ForwardIterator> - inline _ForwardIterator - adjacent_find(_ForwardIterator __begin, _ForwardIterator __end) + template<typename _FIterator> + inline _FIterator + adjacent_find(_FIterator __begin, _FIterator __end) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; return __adjacent_find_switch(__begin, __end, _IteratorCategory()); } // Sequential fallback for input iterator case - template<typename _ForwardIterator, typename _BinaryPredicate, + template<typename _FIterator, typename _BinaryPredicate, typename _IteratorTag> - inline _ForwardIterator - __adjacent_find_switch(_ForwardIterator __begin, _ForwardIterator __end, + inline _FIterator + __adjacent_find_switch(_FIterator __begin, _FIterator __end, _BinaryPredicate __pred, _IteratorTag) { return adjacent_find(__begin, __end, __pred, __gnu_parallel::sequential_tag()); } @@ -866,7 +862,7 @@ namespace __parallel _BinaryPredicate __pred, random_access_iterator_tag) { if (_GLIBCXX_PARALLEL_CONDITION(true)) - return __gnu_parallel::__find_template(__begin, __end, __begin, __pred, + return __gnu_parallel::__find_template(__begin, __end, __begin, __pred, __gnu_parallel:: __adjacent_find_selector()).first; else @@ -875,14 +871,15 @@ namespace __parallel } // Public interface - template<typename _ForwardIterator, typename _BinaryPredicate> - inline _ForwardIterator - adjacent_find(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator, typename _BinaryPredicate> + inline _FIterator + adjacent_find(_FIterator __begin, _FIterator __end, _BinaryPredicate __pred) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; - return __adjacent_find_switch(__begin, __end, __pred, _IteratorCategory()); + return __adjacent_find_switch(__begin, __end, __pred, + _IteratorCategory()); } // Sequential fallback @@ -914,14 +911,15 @@ namespace __parallel __functionality; _DifferenceType __res = 0; __gnu_parallel:: - __for_each_template_random_access(__begin, __end, __value, - __functionality, - std::plus<_SequenceIndex>(), - __res, __res, -1, __parallelism_tag); + __for_each_template_random_access( + __begin, __end, __value, __functionality, + std::plus<_SequenceIndex>(), __res, __res, -1, + __parallelism_tag); return __res; } else - return count(__begin, __end, __value, __gnu_parallel::sequential_tag()); + return count(__begin, __end, __value, + __gnu_parallel::sequential_tag()); } // Sequential fallback for input iterator case. @@ -929,7 +927,8 @@ namespace __parallel inline typename iterator_traits<_IIter>::difference_type __count_switch(_IIter __begin, _IIter __end, const _Tp& __value, _IteratorTag) - { return count(__begin, __end, __value, __gnu_parallel::sequential_tag()); } + { return count(__begin, __end, __value, __gnu_parallel::sequential_tag()); + } // Public interface. template<typename _IIter, typename _Tp> @@ -939,8 +938,8 @@ namespace __parallel { typedef iterator_traits<_IIter> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; - return __count_switch(__begin, __end, __value, _IteratorCategory(), - __parallelism_tag); + return __count_switch(__begin, __end, __value, _IteratorCategory(), + __parallelism_tag); } template<typename _IIter, typename _Tp> @@ -964,7 +963,7 @@ namespace __parallel template<typename _RAIter, typename _Predicate> typename iterator_traits<_RAIter>::difference_type __count_if_switch(_RAIter __begin, _RAIter __end, - _Predicate __pred, random_access_iterator_tag, + _Predicate __pred, random_access_iterator_tag, __gnu_parallel::_Parallelism __parallelism_tag = __gnu_parallel::parallel_unbalanced) { @@ -983,14 +982,15 @@ namespace __parallel __count_if_selector<_RAIter, _DifferenceType> __functionality; __gnu_parallel:: - __for_each_template_random_access(__begin, __end, __pred, - __functionality, - std::plus<_SequenceIndex>(), - __res, __res, -1, __parallelism_tag); + __for_each_template_random_access( + __begin, __end, __pred, __functionality, + std::plus<_SequenceIndex>(), __res, __res, -1, + __parallelism_tag); return __res; } else - return count_if(__begin, __end, __pred, __gnu_parallel::sequential_tag()); + return count_if(__begin, __end, __pred, + __gnu_parallel::sequential_tag()); } // Sequential fallback for input iterator case. @@ -998,7 +998,8 @@ namespace __parallel inline typename iterator_traits<_IIter>::difference_type __count_if_switch(_IIter __begin, _IIter __end, _Predicate __pred, _IteratorTag) - { return count_if(__begin, __end, __pred, __gnu_parallel::sequential_tag()); } + { return count_if(__begin, __end, __pred, + __gnu_parallel::sequential_tag()); } // Public interface. template<typename _IIter, typename _Predicate> @@ -1023,10 +1024,10 @@ namespace __parallel // Sequential fallback. - template<typename ForwardIterator1, typename ForwardIterator2> - inline ForwardIterator1 - search(ForwardIterator1 __begin1, ForwardIterator1 __end1, - ForwardIterator2 __begin2, ForwardIterator2 __end2, + template<typename _FIterator1, typename _FIterator2> + inline _FIterator1 + search(_FIterator1 __begin1, _FIterator1 __end1, + _FIterator2 __begin2, _FIterator2 __end2, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::search(__begin1, __end1, __begin2, __end2); } @@ -1044,32 +1045,33 @@ namespace __parallel if (_GLIBCXX_PARALLEL_CONDITION(true)) return __gnu_parallel:: - __search_template(__begin1, __end1, __begin2, __end2, __gnu_parallel:: - equal_to<_ValueType1, _ValueType2>()); + __search_template( + __begin1, __end1, __begin2, __end2, + __gnu_parallel::equal_to<_ValueType1, _ValueType2>()); else return search(__begin1, __end1, __begin2, __end2, __gnu_parallel::sequential_tag()); } // Sequential fallback for input iterator case - template<typename ForwardIterator1, typename ForwardIterator2, + template<typename _FIterator1, typename _FIterator2, typename _IteratorTag1, typename _IteratorTag2> - inline ForwardIterator1 - __search_switch(ForwardIterator1 __begin1, ForwardIterator1 __end1, - ForwardIterator2 __begin2, ForwardIterator2 __end2, + inline _FIterator1 + __search_switch(_FIterator1 __begin1, _FIterator1 __end1, + _FIterator2 __begin2, _FIterator2 __end2, _IteratorTag1, _IteratorTag2) { return search(__begin1, __end1, __begin2, __end2, __gnu_parallel::sequential_tag()); } // Public interface. - template<typename ForwardIterator1, typename ForwardIterator2> - inline ForwardIterator1 - search(ForwardIterator1 __begin1, ForwardIterator1 __end1, - ForwardIterator2 __begin2, ForwardIterator2 __end2) + template<typename _FIterator1, typename _FIterator2> + inline _FIterator1 + search(_FIterator1 __begin1, _FIterator1 __end1, + _FIterator2 __begin2, _FIterator2 __end2) { - typedef std::iterator_traits<ForwardIterator1> iterator1_traits; + typedef std::iterator_traits<_FIterator1> iterator1_traits; typedef typename iterator1_traits::iterator_category _IteratorCategory1; - typedef std::iterator_traits<ForwardIterator2> iterator2_traits; + typedef std::iterator_traits<_FIterator2> iterator2_traits; typedef typename iterator2_traits::iterator_category _IteratorCategory2; return __search_switch(__begin1, __end1, __begin2, __end2, @@ -1077,13 +1079,14 @@ namespace __parallel } // Public interface. - template<typename ForwardIterator1, typename ForwardIterator2, + template<typename _FIterator1, typename _FIterator2, typename _BinaryPredicate> - inline ForwardIterator1 - search(ForwardIterator1 __begin1, ForwardIterator1 __end1, - ForwardIterator2 __begin2, ForwardIterator2 __end2, + inline _FIterator1 + search(_FIterator1 __begin1, _FIterator1 __end1, + _FIterator2 __begin2, _FIterator2 __end2, _BinaryPredicate __pred, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::search(__begin1, __end1, __begin2, __end2, __pred); } + { return _GLIBCXX_STD_P::search( + __begin1, __end1, __begin2, __end2, __pred); } // Parallel algorithm for random access iterator. template<typename _RAIter1, typename _RAIter2, @@ -1103,55 +1106,56 @@ namespace __parallel } // Sequential fallback for input iterator case - template<typename ForwardIterator1, typename ForwardIterator2, + template<typename _FIterator1, typename _FIterator2, typename _BinaryPredicate, typename _IteratorTag1, typename _IteratorTag2> - inline ForwardIterator1 - __search_switch(ForwardIterator1 __begin1, ForwardIterator1 __end1, - ForwardIterator2 __begin2, ForwardIterator2 __end2, + inline _FIterator1 + __search_switch(_FIterator1 __begin1, _FIterator1 __end1, + _FIterator2 __begin2, _FIterator2 __end2, _BinaryPredicate __pred, _IteratorTag1, _IteratorTag2) { return search(__begin1, __end1, __begin2, __end2, __pred, __gnu_parallel::sequential_tag()); } // Public interface - template<typename ForwardIterator1, typename ForwardIterator2, + template<typename _FIterator1, typename _FIterator2, typename _BinaryPredicate> - inline ForwardIterator1 - search(ForwardIterator1 __begin1, ForwardIterator1 __end1, - ForwardIterator2 __begin2, ForwardIterator2 __end2, + inline _FIterator1 + search(_FIterator1 __begin1, _FIterator1 __end1, + _FIterator2 __begin2, _FIterator2 __end2, _BinaryPredicate __pred) { - typedef std::iterator_traits<ForwardIterator1> iterator1_traits; + typedef std::iterator_traits<_FIterator1> iterator1_traits; typedef typename iterator1_traits::iterator_category _IteratorCategory1; - typedef std::iterator_traits<ForwardIterator2> iterator2_traits; + typedef std::iterator_traits<_FIterator2> iterator2_traits; typedef typename iterator2_traits::iterator_category _IteratorCategory2; return __search_switch(__begin1, __end1, __begin2, __end2, __pred, _IteratorCategory1(), _IteratorCategory2()); } // Sequential fallback - template<typename _ForwardIterator, typename _Integer, typename _Tp> - inline _ForwardIterator - search_n(_ForwardIterator __begin, _ForwardIterator __end, _Integer count, + template<typename _FIterator, typename _Integer, typename _Tp> + inline _FIterator + search_n(_FIterator __begin, _FIterator __end, _Integer count, const _Tp& __val, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::search_n(__begin, __end, count, __val); } // Sequential fallback - template<typename _ForwardIterator, typename _Integer, typename _Tp, + template<typename _FIterator, typename _Integer, typename _Tp, typename _BinaryPredicate> - inline _ForwardIterator - search_n(_ForwardIterator __begin, _ForwardIterator __end, _Integer count, + inline _FIterator + search_n(_FIterator __begin, _FIterator __end, _Integer count, const _Tp& __val, _BinaryPredicate __binary_pred, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::search_n(__begin, __end, count, __val, __binary_pred); } + { return _GLIBCXX_STD_P::search_n( + __begin, __end, count, __val, __binary_pred); } // Public interface. - template<typename _ForwardIterator, typename _Integer, typename _Tp> - inline _ForwardIterator - search_n(_ForwardIterator __begin, _ForwardIterator __end, _Integer count, + template<typename _FIterator, typename _Integer, typename _Tp> + inline _FIterator + search_n(_FIterator __begin, _FIterator __end, _Integer count, const _Tp& __val) { - typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; + typedef typename iterator_traits<_FIterator>::value_type _ValueType; return search_n(__begin, __end, count, __val, __gnu_parallel::equal_to<_ValueType, _Tp>()); } @@ -1160,15 +1164,15 @@ namespace __parallel template<typename _RAIter, typename _Integer, typename _Tp, typename _BinaryPredicate> _RAIter - __search_n_switch(_RAIter __begin, _RAIter __end, - _Integer count, const _Tp& __val, _BinaryPredicate __binary_pred, - random_access_iterator_tag) + __search_n_switch(_RAIter __begin, _RAIter __end, _Integer count, + const _Tp& __val, _BinaryPredicate __binary_pred, + random_access_iterator_tag) { if (_GLIBCXX_PARALLEL_CONDITION(true)) { __gnu_parallel::_PseudoSequence<_Tp, _Integer> __ps(__val, count); - return __gnu_parallel::__search_template(__begin, __end, __ps.begin(), - __ps.end(), __binary_pred); + return __gnu_parallel::__search_template( + __begin, __end, __ps.begin(), __ps.end(), __binary_pred); } else return std::__search_n(__begin, __end, count, __val, @@ -1176,22 +1180,24 @@ namespace __parallel } // Sequential fallback for input iterator case. - template<typename _ForwardIterator, typename _Integer, typename _Tp, + template<typename _FIterator, typename _Integer, typename _Tp, typename _BinaryPredicate, typename _IteratorTag> - inline _ForwardIterator - __search_n_switch(_ForwardIterator __begin, _ForwardIterator __end, _Integer count, - const _Tp& __val, _BinaryPredicate __binary_pred, _IteratorTag) - { return __search_n(__begin, __end, count, __val, __binary_pred, _IteratorTag()); } + inline _FIterator + __search_n_switch(_FIterator __begin, _FIterator __end, _Integer count, + const _Tp& __val, _BinaryPredicate __binary_pred, + _IteratorTag) + { return __search_n(__begin, __end, count, __val, __binary_pred, + _IteratorTag()); } // Public interface. - template<typename _ForwardIterator, typename _Integer, typename _Tp, + template<typename _FIterator, typename _Integer, typename _Tp, typename _BinaryPredicate> - inline _ForwardIterator - search_n(_ForwardIterator __begin, _ForwardIterator __end, _Integer count, + inline _FIterator + search_n(_FIterator __begin, _FIterator __end, _Integer count, const _Tp& __val, _BinaryPredicate __binary_pred) { return __search_n_switch(__begin, __end, count, __val, __binary_pred, - typename std::iterator_traits<_ForwardIterator>:: + typename std::iterator_traits<_FIterator>:: iterator_category()); } @@ -1222,13 +1228,14 @@ namespace __parallel bool __dummy = true; typedef __gnu_parallel::_IteratorPair<_RAIter1, _RAIter2, random_access_iterator_tag> _ItTrip; - _ItTrip begin_pair(__begin, __result), end_pair(__end, __result + (__end - __begin)); + _ItTrip begin_pair(__begin, __result), + end_pair(__end, __result + (__end - __begin)); __gnu_parallel::__transform1_selector<_ItTrip> __functionality; __gnu_parallel:: - __for_each_template_random_access(begin_pair, end_pair, - unary_op, __functionality, - __gnu_parallel::_DummyReduct(), - __dummy, __dummy, -1, __parallelism_tag); + __for_each_template_random_access( + begin_pair, end_pair, unary_op, __functionality, + __gnu_parallel::_DummyReduct(), + __dummy, __dummy, -1, __parallelism_tag); return __functionality._M_finish_iterator; } else @@ -1358,9 +1365,10 @@ namespace __parallel typedef std::iterator_traits<_OutputIterator> _OIterTraits; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __transform2_switch(__begin1, __end1, __begin2, __result, __binary_op, - _IIterCategory1(), _IIterCategory2(), - _OIterCategory(), __parallelism_tag); + return __transform2_switch( + __begin1, __end1, __begin2, __result, __binary_op, + _IIterCategory1(), _IIterCategory2(), _OIterCategory(), + __parallelism_tag); } template<typename _IIter1, typename _IIter2, @@ -1379,23 +1387,24 @@ namespace __parallel typedef std::iterator_traits<_OutputIterator> _OIterTraits; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __transform2_switch(__begin1, __end1, __begin2, __result, __binary_op, - _IIterCategory1(), _IIterCategory2(), - _OIterCategory()); + return __transform2_switch( + __begin1, __end1, __begin2, __result, __binary_op, + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } // Sequential fallback - template<typename _ForwardIterator, typename _Tp> + template<typename _FIterator, typename _Tp> inline void - replace(_ForwardIterator __begin, _ForwardIterator __end, const _Tp& __old_value, + replace(_FIterator __begin, _FIterator __end, const _Tp& __old_value, const _Tp& __new_value, __gnu_parallel::sequential_tag) { _GLIBCXX_STD_P::replace(__begin, __end, __old_value, __new_value); } // Sequential fallback for input iterator case - template<typename _ForwardIterator, typename _Tp, typename _IteratorTag> + template<typename _FIterator, typename _Tp, typename _IteratorTag> inline void - __replace_switch(_ForwardIterator __begin, _ForwardIterator __end, - const _Tp& __old_value, const _Tp& __new_value, _IteratorTag) + __replace_switch(_FIterator __begin, _FIterator __end, + const _Tp& __old_value, const _Tp& __new_value, + _IteratorTag) { replace(__begin, __end, __old_value, __new_value, __gnu_parallel::sequential_tag()); } @@ -1414,40 +1423,43 @@ namespace __parallel } // Public interface - template<typename _ForwardIterator, typename _Tp> + template<typename _FIterator, typename _Tp> inline void - replace(_ForwardIterator __begin, _ForwardIterator __end, const _Tp& __old_value, - const _Tp& __new_value, __gnu_parallel::_Parallelism __parallelism_tag) + replace(_FIterator __begin, _FIterator __end, const _Tp& __old_value, + const _Tp& __new_value, + __gnu_parallel::_Parallelism __parallelism_tag) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; - __replace_switch(__begin, __end, __old_value, __new_value, _IteratorCategory(), + __replace_switch(__begin, __end, __old_value, __new_value, + _IteratorCategory(), __parallelism_tag); } - template<typename _ForwardIterator, typename _Tp> + template<typename _FIterator, typename _Tp> inline void - replace(_ForwardIterator __begin, _ForwardIterator __end, const _Tp& __old_value, + replace(_FIterator __begin, _FIterator __end, const _Tp& __old_value, const _Tp& __new_value) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; - __replace_switch(__begin, __end, __old_value, __new_value, _IteratorCategory()); + __replace_switch(__begin, __end, __old_value, __new_value, + _IteratorCategory()); } // Sequential fallback - template<typename _ForwardIterator, typename _Predicate, typename _Tp> + template<typename _FIterator, typename _Predicate, typename _Tp> inline void - replace_if(_ForwardIterator __begin, _ForwardIterator __end, _Predicate __pred, + replace_if(_FIterator __begin, _FIterator __end, _Predicate __pred, const _Tp& __new_value, __gnu_parallel::sequential_tag) { _GLIBCXX_STD_P::replace_if(__begin, __end, __pred, __new_value); } // Sequential fallback for input iterator case - template<typename _ForwardIterator, typename _Predicate, typename _Tp, + template<typename _FIterator, typename _Predicate, typename _Tp, typename _IteratorTag> inline void - __replace_if_switch(_ForwardIterator __begin, _ForwardIterator __end, + __replace_if_switch(_FIterator __begin, _FIterator __end, _Predicate __pred, const _Tp& __new_value, _IteratorTag) { replace_if(__begin, __end, __pred, __new_value, __gnu_parallel::sequential_tag()); } @@ -1471,10 +1483,10 @@ namespace __parallel __replace_if_selector<_RAIter, _Predicate, _Tp> __functionality(__new_value); __gnu_parallel:: - __for_each_template_random_access(__begin, __end, __pred, - __functionality, - __gnu_parallel::_DummyReduct(), - true, __dummy, -1, __parallelism_tag); + __for_each_template_random_access( + __begin, __end, __pred, __functionality, + __gnu_parallel::_DummyReduct(), + true, __dummy, -1, __parallelism_tag); } else replace_if(__begin, __end, __pred, __new_value, @@ -1482,39 +1494,40 @@ namespace __parallel } // Public interface. - template<typename _ForwardIterator, typename _Predicate, typename _Tp> + template<typename _FIterator, typename _Predicate, typename _Tp> inline void - replace_if(_ForwardIterator __begin, _ForwardIterator __end, + replace_if(_FIterator __begin, _FIterator __end, _Predicate __pred, const _Tp& __new_value, __gnu_parallel::_Parallelism __parallelism_tag) { - typedef std::iterator_traits<_ForwardIterator> _IteratorTraits; + typedef std::iterator_traits<_FIterator> _IteratorTraits; typedef typename _IteratorTraits::iterator_category _IteratorCategory; - __replace_if_switch(__begin, __end, __pred, __new_value, _IteratorCategory(), - __parallelism_tag); + __replace_if_switch(__begin, __end, __pred, __new_value, + _IteratorCategory(), __parallelism_tag); } - template<typename _ForwardIterator, typename _Predicate, typename _Tp> + template<typename _FIterator, typename _Predicate, typename _Tp> inline void - replace_if(_ForwardIterator __begin, _ForwardIterator __end, + replace_if(_FIterator __begin, _FIterator __end, _Predicate __pred, const _Tp& __new_value) { - typedef std::iterator_traits<_ForwardIterator> _IteratorTraits; + typedef std::iterator_traits<_FIterator> _IteratorTraits; typedef typename _IteratorTraits::iterator_category _IteratorCategory; - __replace_if_switch(__begin, __end, __pred, __new_value, _IteratorCategory()); + __replace_if_switch(__begin, __end, __pred, __new_value, + _IteratorCategory()); } // Sequential fallback - template<typename _ForwardIterator, typename Generator> + template<typename _FIterator, typename Generator> inline void - generate(_ForwardIterator __begin, _ForwardIterator __end, Generator __gen, + generate(_FIterator __begin, _FIterator __end, Generator __gen, __gnu_parallel::sequential_tag) { _GLIBCXX_STD_P::generate(__begin, __end, __gen); } // Sequential fallback for input iterator case. - template<typename _ForwardIterator, typename Generator, typename _IteratorTag> + template<typename _FIterator, typename Generator, typename _IteratorTag> inline void - __generate_switch(_ForwardIterator __begin, _ForwardIterator __end, Generator __gen, + __generate_switch(_FIterator __begin, _FIterator __end, Generator __gen, _IteratorTag) { generate(__begin, __end, __gen, __gnu_parallel::sequential_tag()); } @@ -1535,30 +1548,32 @@ namespace __parallel __gnu_parallel::__generate_selector<_RAIter> __functionality; __gnu_parallel:: - __for_each_template_random_access(__begin, __end, __gen, __functionality, - __gnu_parallel::_DummyReduct(), - true, __dummy, -1, __parallelism_tag); + __for_each_template_random_access( + __begin, __end, __gen, __functionality, + __gnu_parallel::_DummyReduct(), + true, __dummy, -1, __parallelism_tag); } else generate(__begin, __end, __gen, __gnu_parallel::sequential_tag()); } // Public interface. - template<typename _ForwardIterator, typename Generator> + template<typename _FIterator, typename Generator> inline void - generate(_ForwardIterator __begin, _ForwardIterator __end, + generate(_FIterator __begin, _FIterator __end, Generator __gen, __gnu_parallel::_Parallelism __parallelism_tag) { - typedef std::iterator_traits<_ForwardIterator> _IteratorTraits; + typedef std::iterator_traits<_FIterator> _IteratorTraits; typedef typename _IteratorTraits::iterator_category _IteratorCategory; - __generate_switch(__begin, __end, __gen, _IteratorCategory(), __parallelism_tag); + __generate_switch(__begin, __end, __gen, _IteratorCategory(), + __parallelism_tag); } - template<typename _ForwardIterator, typename Generator> + template<typename _FIterator, typename Generator> inline void - generate(_ForwardIterator __begin, _ForwardIterator __end, Generator __gen) + generate(_FIterator __begin, _FIterator __end, Generator __gen) { - typedef std::iterator_traits<_ForwardIterator> _IteratorTraits; + typedef std::iterator_traits<_FIterator> _IteratorTraits; typedef typename _IteratorTraits::iterator_category _IteratorCategory; __generate_switch(__begin, __end, __gen, _IteratorCategory()); } @@ -1575,8 +1590,10 @@ namespace __parallel template<typename _OutputIterator, typename _Size, typename Generator, typename _IteratorTag> inline _OutputIterator - __generate_n_switch(_OutputIterator __begin, _Size __n, Generator __gen, _IteratorTag) - { return generate_n(__begin, __n, __gen, __gnu_parallel::sequential_tag()); } + __generate_n_switch(_OutputIterator __begin, _Size __n, Generator __gen, + _IteratorTag) + { return generate_n(__begin, __n, __gen, + __gnu_parallel::sequential_tag()); } // Parallel algorithm for random access iterators. template<typename _RAIter, typename _Size, typename Generator> @@ -1587,7 +1604,7 @@ namespace __parallel = __gnu_parallel::parallel_balanced) { // XXX parallel version is where? - return generate_n(__begin, __n, __gen, __gnu_parallel::sequential_tag()); + return generate_n(__begin, __n, __gen, __gnu_parallel::sequential_tag()); } // Public interface. @@ -1623,7 +1640,8 @@ namespace __parallel template<typename _RAIter, typename RandomNumberGenerator> inline void random_shuffle(_RAIter __begin, _RAIter __end, - RandomNumberGenerator& __rand, __gnu_parallel::sequential_tag) + RandomNumberGenerator& __rand, + __gnu_parallel::sequential_tag) { _GLIBCXX_STD_P::random_shuffle(__begin, __end, __rand); } @@ -1663,18 +1681,19 @@ namespace __parallel } // Sequential fallback. - template<typename _ForwardIterator, typename _Predicate> - inline _ForwardIterator - partition(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator, typename _Predicate> + inline _FIterator + partition(_FIterator __begin, _FIterator __end, _Predicate __pred, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::partition(__begin, __end, __pred); } // Sequential fallback for input iterator case. - template<typename _ForwardIterator, typename _Predicate, typename _IteratorTag> - inline _ForwardIterator - __partition_switch(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator, typename _Predicate, typename _IteratorTag> + inline _FIterator + __partition_switch(_FIterator __begin, _FIterator __end, _Predicate __pred, _IteratorTag) - { return partition(__begin, __end, __pred, __gnu_parallel::sequential_tag()); } + { return partition(__begin, __end, __pred, + __gnu_parallel::sequential_tag()); } // Parallel algorithm for random access iterators. template<typename _RAIter, typename _Predicate> @@ -1694,15 +1713,16 @@ namespace __parallel return __begin + __middle; } else - return partition(__begin, __end, __pred, __gnu_parallel::sequential_tag()); + return partition(__begin, __end, __pred, + __gnu_parallel::sequential_tag()); } // Public interface. - template<typename _ForwardIterator, typename _Predicate> - inline _ForwardIterator - partition(_ForwardIterator __begin, _ForwardIterator __end, _Predicate __pred) + template<typename _FIterator, typename _Predicate> + inline _FIterator + partition(_FIterator __begin, _FIterator __end, _Predicate __pred) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; return __partition_switch(__begin, __end, __pred, _IteratorCategory()); } @@ -1739,7 +1759,8 @@ namespace __parallel if (_GLIBCXX_PARALLEL_CONDITION( static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) >= __gnu_parallel::_Settings::get().sort_minimal_n)) - __gnu_parallel::parallel_sort<false>(__begin, __end, __comp, __parallelism); + __gnu_parallel::parallel_sort<false>( + __begin, __end, __comp, __parallelism); else sort(__begin, __end, __comp, __gnu_parallel::sequential_tag()); } @@ -1877,9 +1898,11 @@ namespace __parallel if (_GLIBCXX_PARALLEL_CONDITION( static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) >= __gnu_parallel::_Settings::get().sort_minimal_n)) - __gnu_parallel::parallel_sort<true>(__begin, __end, __comp, __parallelism); + __gnu_parallel::parallel_sort<true>( + __begin, __end, __comp, __parallelism); else - stable_sort(__begin, __end, __comp, __gnu_parallel::sequential_tag()); + stable_sort(__begin, __end, __comp, + __gnu_parallel::sequential_tag()); } } @@ -1957,51 +1980,10 @@ namespace __parallel { typedef iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; - stable_sort(__begin, __end, __comp, __gnu_parallel::default_parallel_tag()); + stable_sort( + __begin, __end, __comp, __gnu_parallel::default_parallel_tag()); } - -// // Sequential fallback -// template<typename _RAIter> -// inline void -// stable_sort(_RAIter __begin, _RAIter __end, -// __gnu_parallel::sequential_tag) -// { return _GLIBCXX_STD_P::stable_sort(__begin, __end); } -// -// // Sequential fallback -// template<typename _RAIter, typename _Compare> -// inline void -// stable_sort(_RAIter __begin, _RAIter __end, -// _Compare __comp, __gnu_parallel::sequential_tag) -// { return _GLIBCXX_STD_P::stable_sort(__begin, __end, __comp); } -// -// template<typename _RAIter> -// void -// stable_sort(_RAIter __begin, _RAIter __end) -// { -// typedef iterator_traits<_RAIter> _TraitsType; -// typedef typename _TraitsType::value_type _ValueType; -// stable_sort(__begin, __end, std::less<_ValueType>()); -// } -// -// // Parallel algorithm for random access iterators -// template<typename _RAIter, typename _Compare> -// void -// stable_sort(_RAIter __begin, _RAIter __end, -// _Compare __comp) -// { -// if (__begin != __end) -// { -// if (_GLIBCXX_PARALLEL_CONDITION( -// static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) >= -// __gnu_parallel::_Settings::get().sort_minimal_n)) -// __gnu_parallel::parallel_sort(__begin, __end, __comp, -// __gnu_parallel::parallel_tag()); -// else -// stable_sort(__begin, __end, __comp, __gnu_parallel::sequential_tag()); -// } -// } - // Sequential fallback template<typename _IIter1, typename _IIter2, typename _OutputIterator> @@ -2009,7 +1991,8 @@ namespace __parallel merge(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, _IIter2 __end2, _OutputIterator __result, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::merge(__begin1, __end1, __begin2, __end2, __result); } + { return _GLIBCXX_STD_P::merge( + __begin1, __end1, __begin2, __end2, __result); } // Sequential fallback template<typename _IIter1, typename _IIter2, @@ -2018,12 +2001,13 @@ namespace __parallel merge(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, _IIter2 __end2, _OutputIterator __result, _Compare __comp, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::merge(__begin1, __end1, __begin2, __end2, __result, __comp); } + { return _GLIBCXX_STD_P::merge( + __begin1, __end1, __begin2, __end2, __result, __comp); } // Sequential fallback for input iterator case - template<typename _IIter1, typename _IIter2, - typename _OutputIterator, typename _Compare, - typename _IteratorTag1, typename _IteratorTag2, typename _IteratorTag3> + template<typename _IIter1, typename _IIter2, typename _OutputIterator, + typename _Compare, typename _IteratorTag1, + typename _IteratorTag2, typename _IteratorTag3> inline _OutputIterator __merge_switch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, _IIter2 __end2, @@ -2047,14 +2031,13 @@ namespace __parallel >= __gnu_parallel::_Settings::get().merge_minimal_n || static_cast<__gnu_parallel::_SequenceIndex>(__end2 - __begin2) >= __gnu_parallel::_Settings::get().merge_minimal_n))) - return __gnu_parallel::__parallel_merge_advance(__begin1, __end1, - __begin2, __end2, - __result, (__end1 - __begin1) - + (__end2 - __begin2), __comp); + return __gnu_parallel::__parallel_merge_advance( + __begin1, __end1, __begin2, __end2, __result, + (__end1 - __begin1) + (__end2 - __begin2), __comp); else - return __gnu_parallel::__merge_advance(__begin1, __end1, __begin2, __end2, - __result, (__end1 - __begin1) - + (__end2 - __begin2), __comp); + return __gnu_parallel::__merge_advance( + __begin1, __end1, __begin2, __end2, __result, + (__end1 - __begin1) + (__end2 - __begin2), __comp); } // Public interface @@ -2075,9 +2058,9 @@ namespace __parallel _IIterCategory2; typedef typename _OIterTraits::iterator_category _OIterCategory; - return __merge_switch(__begin1, __end1, __begin2, __end2, __result, __comp, - _IIterCategory1(), _IIterCategory2(), - _OIterCategory()); + return __merge_switch( + __begin1, __end1, __begin2, __end2, __result, __comp, + _IIterCategory1(), _IIterCategory2(), _OIterCategory()); } @@ -2123,7 +2106,8 @@ namespace __parallel >= __gnu_parallel::_Settings::get().nth_element_minimal_n)) __gnu_parallel::parallel_nth_element(__begin, __nth, __end, __comp); else - nth_element(__begin, __nth, __end, __comp, __gnu_parallel::sequential_tag()); + nth_element(__begin, __nth, __end, __comp, + __gnu_parallel::sequential_tag()); } // Public interface, insert default comparator @@ -2161,7 +2145,8 @@ namespace __parallel if (_GLIBCXX_PARALLEL_CONDITION( static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) >= __gnu_parallel::_Settings::get().partial_sort_minimal_n)) - __gnu_parallel::parallel_partial_sort(__begin, __middle, __end, __comp); + __gnu_parallel:: + parallel_partial_sort(__begin, __middle, __end, __comp); else partial_sort(__begin, __middle, __end, __comp, __gnu_parallel::sequential_tag()); @@ -2179,25 +2164,26 @@ namespace __parallel } // Sequential fallback - template<typename _ForwardIterator> - inline _ForwardIterator - max_element(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator> + inline _FIterator + max_element(_FIterator __begin, _FIterator __end, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::max_element(__begin, __end); } // Sequential fallback - template<typename _ForwardIterator, typename _Compare> - inline _ForwardIterator - max_element(_ForwardIterator __begin, _ForwardIterator __end, _Compare __comp, + template<typename _FIterator, typename _Compare> + inline _FIterator + max_element(_FIterator __begin, _FIterator __end, _Compare __comp, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::max_element(__begin, __end, __comp); } // Sequential fallback for input iterator case - template<typename _ForwardIterator, typename _Compare, typename _IteratorTag> - inline _ForwardIterator - __max_element_switch(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator, typename _Compare, typename _IteratorTag> + inline _FIterator + __max_element_switch(_FIterator __begin, _FIterator __end, _Compare __comp, _IteratorTag) - { return max_element(__begin, __end, __comp, __gnu_parallel::sequential_tag()); } + { return max_element(__begin, __end, __comp, + __gnu_parallel::sequential_tag()); } // Parallel algorithm for random access iterators template<typename _RAIter, typename _Compare> @@ -2216,79 +2202,79 @@ namespace __parallel __gnu_parallel::__identity_selector<_RAIter> __functionality; __gnu_parallel:: - __for_each_template_random_access(__begin, __end, - __gnu_parallel::_Nothing(), - __functionality, - __gnu_parallel:: - __max_element_reduct<_Compare, - _RAIter>(__comp), - __res, __res, -1, __parallelism_tag); + __for_each_template_random_access( + __begin, __end, __gnu_parallel::_Nothing(), __functionality, + __gnu_parallel::__max_element_reduct<_Compare, _RAIter>(__comp), + __res, __res, -1, __parallelism_tag); return __res; } else - return max_element(__begin, __end, __comp, __gnu_parallel::sequential_tag()); + return max_element(__begin, __end, __comp, + __gnu_parallel::sequential_tag()); } // Public interface, insert default comparator - template<typename _ForwardIterator> - inline _ForwardIterator - max_element(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator> + inline _FIterator + max_element(_FIterator __begin, _FIterator __end, __gnu_parallel::_Parallelism __parallelism_tag) { - typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - return max_element(__begin, __end, std::less<_ValueType>(), __parallelism_tag); + typedef typename iterator_traits<_FIterator>::value_type _ValueType; + return max_element(__begin, __end, std::less<_ValueType>(), + __parallelism_tag); } - template<typename _ForwardIterator> - inline _ForwardIterator - max_element(_ForwardIterator __begin, _ForwardIterator __end) + template<typename _FIterator> + inline _FIterator + max_element(_FIterator __begin, _FIterator __end) { - typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; + typedef typename iterator_traits<_FIterator>::value_type _ValueType; return max_element(__begin, __end, std::less<_ValueType>()); } // Public interface - template<typename _ForwardIterator, typename _Compare> - inline _ForwardIterator - max_element(_ForwardIterator __begin, _ForwardIterator __end, _Compare __comp, + template<typename _FIterator, typename _Compare> + inline _FIterator + max_element(_FIterator __begin, _FIterator __end, _Compare __comp, __gnu_parallel::_Parallelism __parallelism_tag) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; return __max_element_switch(__begin, __end, __comp, _IteratorCategory(), - __parallelism_tag); + __parallelism_tag); } - template<typename _ForwardIterator, typename _Compare> - inline _ForwardIterator - max_element(_ForwardIterator __begin, _ForwardIterator __end, _Compare __comp) + template<typename _FIterator, typename _Compare> + inline _FIterator + max_element(_FIterator __begin, _FIterator __end, _Compare __comp) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; return __max_element_switch(__begin, __end, __comp, _IteratorCategory()); } // Sequential fallback - template<typename _ForwardIterator> - inline _ForwardIterator - min_element(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator> + inline _FIterator + min_element(_FIterator __begin, _FIterator __end, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::min_element(__begin, __end); } // Sequential fallback - template<typename _ForwardIterator, typename _Compare> - inline _ForwardIterator - min_element(_ForwardIterator __begin, _ForwardIterator __end, _Compare __comp, + template<typename _FIterator, typename _Compare> + inline _FIterator + min_element(_FIterator __begin, _FIterator __end, _Compare __comp, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::min_element(__begin, __end, __comp); } // Sequential fallback for input iterator case - template<typename _ForwardIterator, typename _Compare, typename _IteratorTag> - inline _ForwardIterator - __min_element_switch(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator, typename _Compare, typename _IteratorTag> + inline _FIterator + __min_element_switch(_FIterator __begin, _FIterator __end, _Compare __comp, _IteratorTag) - { return min_element(__begin, __end, __comp, __gnu_parallel::sequential_tag()); } + { return min_element(__begin, __end, __comp, + __gnu_parallel::sequential_tag()); } // Parallel algorithm for random access iterators template<typename _RAIter, typename _Compare> @@ -2307,54 +2293,53 @@ namespace __parallel __gnu_parallel::__identity_selector<_RAIter> __functionality; __gnu_parallel:: - __for_each_template_random_access(__begin, __end, - __gnu_parallel::_Nothing(), - __functionality, - __gnu_parallel:: - __min_element_reduct<_Compare, - _RAIter>(__comp), - __res, __res, -1, __parallelism_tag); + __for_each_template_random_access( + __begin, __end, __gnu_parallel::_Nothing(), __functionality, + __gnu_parallel::__min_element_reduct<_Compare, _RAIter>(__comp), + __res, __res, -1, __parallelism_tag); return __res; } else - return min_element(__begin, __end, __comp, __gnu_parallel::sequential_tag()); + return min_element(__begin, __end, __comp, + __gnu_parallel::sequential_tag()); } // Public interface, insert default comparator - template<typename _ForwardIterator> - inline _ForwardIterator - min_element(_ForwardIterator __begin, _ForwardIterator __end, + template<typename _FIterator> + inline _FIterator + min_element(_FIterator __begin, _FIterator __end, __gnu_parallel::_Parallelism __parallelism_tag) { - typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - return min_element(__begin, __end, std::less<_ValueType>(), __parallelism_tag); + typedef typename iterator_traits<_FIterator>::value_type _ValueType; + return min_element(__begin, __end, std::less<_ValueType>(), + __parallelism_tag); } - template<typename _ForwardIterator> - inline _ForwardIterator - min_element(_ForwardIterator __begin, _ForwardIterator __end) + template<typename _FIterator> + inline _FIterator + min_element(_FIterator __begin, _FIterator __end) { - typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; + typedef typename iterator_traits<_FIterator>::value_type _ValueType; return min_element(__begin, __end, std::less<_ValueType>()); } // Public interface - template<typename _ForwardIterator, typename _Compare> - inline _ForwardIterator - min_element(_ForwardIterator __begin, _ForwardIterator __end, _Compare __comp, + template<typename _FIterator, typename _Compare> + inline _FIterator + min_element(_FIterator __begin, _FIterator __end, _Compare __comp, __gnu_parallel::_Parallelism __parallelism_tag) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; return __min_element_switch(__begin, __end, __comp, _IteratorCategory(), __parallelism_tag); } - template<typename _ForwardIterator, typename _Compare> - inline _ForwardIterator - min_element(_ForwardIterator __begin, _ForwardIterator __end, _Compare __comp) + template<typename _FIterator, typename _Compare> + inline _FIterator + min_element(_FIterator __begin, _FIterator __end, _Compare __comp) { - typedef iterator_traits<_ForwardIterator> _TraitsType; + typedef iterator_traits<_FIterator> _TraitsType; typedef typename _TraitsType::iterator_category _IteratorCategory; return __min_element_switch(__begin, __end, __comp, _IteratorCategory()); } diff --git a/libstdc++-v3/include/parallel/algobase.h b/libstdc++-v3/include/parallel/algobase.h index b50068d2967..b0571a47933 100644 --- a/libstdc++-v3/include/parallel/algobase.h +++ b/libstdc++-v3/include/parallel/algobase.h @@ -53,44 +53,41 @@ namespace __parallel template<typename _IIter1, typename _IIter2> inline pair<_IIter1, _IIter2> mismatch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, - __gnu_parallel::sequential_tag) + __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::mismatch(__begin1, __end1, __begin2); } // Sequential fallback - template<typename _IIter1, typename _IIter2, - typename _Predicate> + template<typename _IIter1, typename _IIter2, typename _Predicate> inline pair<_IIter1, _IIter2> mismatch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, - _Predicate __pred, __gnu_parallel::sequential_tag) + _Predicate __pred, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::mismatch(__begin1, __end1, __begin2, __pred); } // Sequential fallback for input iterator case template<typename _IIter1, typename _IIter2, - typename _Predicate, typename _IteratorTag1, typename _IteratorTag2> + typename _Predicate, typename _IteratorTag1, typename _IteratorTag2> inline pair<_IIter1, _IIter2> - __mismatch_switch(_IIter1 __begin1, _IIter1 __end1, - _IIter2 __begin2, _Predicate __pred, _IteratorTag1, - _IteratorTag2) + __mismatch_switch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, + _Predicate __pred, _IteratorTag1, _IteratorTag2) { return _GLIBCXX_STD_P::mismatch(__begin1, __end1, __begin2, __pred); } // Parallel mismatch for random access iterators - template<typename _RAIter1, typename _RAIter2, - typename _Predicate> + template<typename _RAIter1, typename _RAIter2, typename _Predicate> pair<_RAIter1, _RAIter2> __mismatch_switch(_RAIter1 __begin1, _RAIter1 __end1, - _RAIter2 __begin2, _Predicate __pred, - random_access_iterator_tag, random_access_iterator_tag) + _RAIter2 __begin2, _Predicate __pred, + random_access_iterator_tag, random_access_iterator_tag) { if (_GLIBCXX_PARALLEL_CONDITION(true)) - { - _RAIter1 __res = - __gnu_parallel::__find_template(__begin1, __end1, __begin2, __pred, - __gnu_parallel:: - __mismatch_selector()).first; - return make_pair(__res , __begin2 + (__res - __begin1)); - } + { + _RAIter1 __res = + __gnu_parallel::__find_template(__begin1, __end1, __begin2, __pred, + __gnu_parallel:: + __mismatch_selector()).first; + return make_pair(__res , __begin2 + (__res - __begin1)); + } else - return _GLIBCXX_STD_P::mismatch(__begin1, __end1, __begin2, __pred); + return _GLIBCXX_STD_P::mismatch(__begin1, __end1, __begin2, __pred); } // Public interface @@ -108,38 +105,36 @@ namespace __parallel typedef __gnu_parallel::equal_to<_ValueType1, _ValueType2> equal_to_type; return __mismatch_switch(__begin1, __end1, __begin2, equal_to_type(), - _IteratorCategory1(), _IteratorCategory2()); + _IteratorCategory1(), _IteratorCategory2()); } // Public interface - template<typename _IIter1, typename _IIter2, - typename _Predicate> + template<typename _IIter1, typename _IIter2, typename _Predicate> inline pair<_IIter1, _IIter2> mismatch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, - _Predicate __pred) + _Predicate __pred) { typedef std::iterator_traits<_IIter1> iterator1_traits; typedef std::iterator_traits<_IIter2> iterator2_traits; typedef typename iterator1_traits::iterator_category _IteratorCategory1; typedef typename iterator2_traits::iterator_category _IteratorCategory2; - return __mismatch_switch(__begin1, __end1, __begin2, __pred, _IteratorCategory1(), - _IteratorCategory2()); + return __mismatch_switch(__begin1, __end1, __begin2, __pred, + _IteratorCategory1(), _IteratorCategory2()); } // Sequential fallback template<typename _IIter1, typename _IIter2> inline bool equal(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, - __gnu_parallel::sequential_tag) + __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::equal(__begin1, __end1, __begin2); } // Sequential fallback - template<typename _IIter1, typename _IIter2, - typename _Predicate> + template<typename _IIter1, typename _IIter2, typename _Predicate> inline bool equal(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, - _Predicate __pred, __gnu_parallel::sequential_tag) + _Predicate __pred, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::equal(__begin1, __end1, __begin2, __pred); } // Public interface @@ -149,99 +144,97 @@ namespace __parallel { return mismatch(__begin1, __end1, __begin2).first == __end1; } // Public interface - template<typename _IIter1, typename _IIter2, - typename _Predicate> + template<typename _IIter1, typename _IIter2, typename _Predicate> inline bool equal(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, - _Predicate __pred) + _Predicate __pred) { return mismatch(__begin1, __end1, __begin2, __pred).first == __end1; } // Sequential fallback template<typename _IIter1, typename _IIter2> inline bool lexicographical_compare(_IIter1 __begin1, _IIter1 __end1, - _IIter2 __begin2, _IIter2 __end2, - __gnu_parallel::sequential_tag) + _IIter2 __begin2, _IIter2 __end2, + __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::lexicographical_compare(__begin1, __end1, - __begin2, __end2); } + __begin2, __end2); } // Sequential fallback - template<typename _IIter1, typename _IIter2, - typename _Predicate> + template<typename _IIter1, typename _IIter2, typename _Predicate> inline bool lexicographical_compare(_IIter1 __begin1, _IIter1 __end1, - _IIter2 __begin2, _IIter2 __end2, - _Predicate __pred, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::lexicographical_compare(__begin1, __end1, - __begin2, __end2, __pred); } + _IIter2 __begin2, _IIter2 __end2, + _Predicate __pred, __gnu_parallel::sequential_tag) + { return _GLIBCXX_STD_P::lexicographical_compare( + __begin1, __end1, __begin2, __end2, __pred); } // Sequential fallback for input iterator case template<typename _IIter1, typename _IIter2, - typename _Predicate, typename _IteratorTag1, typename _IteratorTag2> + typename _Predicate, typename _IteratorTag1, typename _IteratorTag2> inline bool - __lexicographical_compare_switch(_IIter1 __begin1, _IIter1 __end1, - _IIter2 __begin2, _IIter2 __end2, - _Predicate __pred, _IteratorTag1, _IteratorTag2) - { return _GLIBCXX_STD_P::lexicographical_compare(__begin1, __end1, - __begin2, __end2, __pred); } + __lexicographical_compare_switch(_IIter1 __begin1, _IIter1 __end1, + _IIter2 __begin2, _IIter2 __end2, + _Predicate __pred, + _IteratorTag1, _IteratorTag2) + { return _GLIBCXX_STD_P::lexicographical_compare( + __begin1, __end1, __begin2, __end2, __pred); } // Parallel lexicographical_compare for random access iterators // Limitation: Both valuetypes must be the same - template<typename _RAIter1, typename _RAIter2, - typename _Predicate> + template<typename _RAIter1, typename _RAIter2, typename _Predicate> bool - __lexicographical_compare_switch(_RAIter1 __begin1, - _RAIter1 __end1, - _RAIter2 __begin2, - _RAIter2 __end2, _Predicate __pred, - random_access_iterator_tag, - random_access_iterator_tag) + __lexicographical_compare_switch(_RAIter1 __begin1, _RAIter1 __end1, + _RAIter2 __begin2, _RAIter2 __end2, + _Predicate __pred, + random_access_iterator_tag, + random_access_iterator_tag) { if (_GLIBCXX_PARALLEL_CONDITION(true)) - { - typedef iterator_traits<_RAIter1> _TraitsType1; - typedef typename _TraitsType1::value_type _ValueType1; - - typedef iterator_traits<_RAIter2> _TraitsType2; - typedef typename _TraitsType2::value_type _ValueType2; - - typedef __gnu_parallel::_EqualFromLess<_Predicate, _ValueType1, - _ValueType2> _EqualFromLessCompare; - - // Longer sequence in first place. - if ((__end1 - __begin1) < (__end2 - __begin2)) - { - typedef pair<_RAIter1, _RAIter2> - _SpotType; - _SpotType __mm = __mismatch_switch(__begin1, __end1, __begin2, - _EqualFromLessCompare(__pred), - random_access_iterator_tag(), - random_access_iterator_tag()); - - return (__mm.first == __end1) || bool(__pred(*__mm.first, *__mm.second)); - } - else - { - typedef pair<_RAIter2, _RAIter1> - _SpotType; - _SpotType __mm = __mismatch_switch(__begin2, __end2, __begin1, - _EqualFromLessCompare(__pred), - random_access_iterator_tag(), - random_access_iterator_tag()); - - return (__mm.first != __end2) && bool(__pred(*__mm.second, *__mm.first)); - } - } + { + typedef iterator_traits<_RAIter1> _TraitsType1; + typedef typename _TraitsType1::value_type _ValueType1; + + typedef iterator_traits<_RAIter2> _TraitsType2; + typedef typename _TraitsType2::value_type _ValueType2; + + typedef __gnu_parallel:: + _EqualFromLess<_Predicate, _ValueType1, _ValueType2> + _EqualFromLessCompare; + + // Longer sequence in first place. + if ((__end1 - __begin1) < (__end2 - __begin2)) + { + typedef pair<_RAIter1, _RAIter2> _SpotType; + _SpotType __mm = __mismatch_switch(__begin1, __end1, __begin2, + _EqualFromLessCompare(__pred), + random_access_iterator_tag(), + random_access_iterator_tag()); + + return (__mm.first == __end1) + || bool(__pred(*__mm.first, *__mm.second)); + } + else + { + typedef pair<_RAIter2, _RAIter1> _SpotType; + _SpotType __mm = __mismatch_switch(__begin2, __end2, __begin1, + _EqualFromLessCompare(__pred), + random_access_iterator_tag(), + random_access_iterator_tag()); + + return (__mm.first != __end2) + && bool(__pred(*__mm.second, *__mm.first)); + } + } else - return _GLIBCXX_STD_P::lexicographical_compare(__begin1, __end1, - __begin2, __end2, __pred); + return _GLIBCXX_STD_P::lexicographical_compare( + __begin1, __end1, __begin2, __end2, __pred); } // Public interface template<typename _IIter1, typename _IIter2> inline bool lexicographical_compare(_IIter1 __begin1, _IIter1 __end1, - _IIter2 __begin2, _IIter2 __end2) + _IIter2 __begin2, _IIter2 __end2) { typedef iterator_traits<_IIter1> _TraitsType1; typedef typename _TraitsType1::value_type _ValueType1; @@ -252,18 +245,17 @@ namespace __parallel typedef typename _TraitsType2::iterator_category _IteratorCategory2; typedef __gnu_parallel::_Less<_ValueType1, _ValueType2> _LessType; - return __lexicographical_compare_switch(__begin1, __end1, __begin2, __end2, - _LessType(), _IteratorCategory1(), - _IteratorCategory2()); + return __lexicographical_compare_switch( + __begin1, __end1, __begin2, __end2, _LessType(), + _IteratorCategory1(), _IteratorCategory2()); } // Public interface - template<typename _IIter1, typename _IIter2, - typename _Predicate> + template<typename _IIter1, typename _IIter2, typename _Predicate> inline bool lexicographical_compare(_IIter1 __begin1, _IIter1 __end1, - _IIter2 __begin2, _IIter2 __end2, - _Predicate __pred) + _IIter2 __begin2, _IIter2 __end2, + _Predicate __pred) { typedef iterator_traits<_IIter1> _TraitsType1; typedef typename _TraitsType1::iterator_category _IteratorCategory1; @@ -271,9 +263,9 @@ namespace __parallel typedef iterator_traits<_IIter2> _TraitsType2; typedef typename _TraitsType2::iterator_category _IteratorCategory2; - return __lexicographical_compare_switch(__begin1, __end1, __begin2, __end2, __pred, - _IteratorCategory1(), - _IteratorCategory2()); + return __lexicographical_compare_switch( + __begin1, __end1, __begin2, __end2, __pred, + _IteratorCategory1(), _IteratorCategory2()); } } // end namespace } // end namespace diff --git a/libstdc++-v3/include/parallel/algorithmfwd.h b/libstdc++-v3/include/parallel/algorithmfwd.h index c85959ecf64..5c93615da26 100644 --- a/libstdc++-v3/include/parallel/algorithmfwd.h +++ b/libstdc++-v3/include/parallel/algorithmfwd.h @@ -62,7 +62,7 @@ namespace __parallel template<typename _FIter, typename _BiPredicate> _FIter adjacent_find(_FIter, _FIter, _BiPredicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _FIter, typename _BiPredicate, typename _IterTag> _FIter @@ -71,7 +71,7 @@ namespace __parallel template<typename _RAIter, typename _BiPredicate> _RAIter __adjacent_find_switch(_RAIter, _RAIter, _BiPredicate, - random_access_iterator_tag); + random_access_iterator_tag); template<typename _IIter, typename _Tp> @@ -93,8 +93,8 @@ namespace __parallel template<typename _RAIter, typename _Tp> typename iterator_traits<_RAIter>::difference_type __count_switch(_RAIter, _RAIter, const _Tp&, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_unbalanced); + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_unbalanced); template<typename _IIter, typename _Predicate> @@ -116,8 +116,8 @@ namespace __parallel template<typename _RAIter, typename _Predicate> typename iterator_traits<_RAIter>::difference_type __count_if_switch(_RAIter, _RAIter, _Predicate, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_unbalanced); + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_unbalanced); // algobase.h template<typename _IIter1, typename _IIter2> @@ -127,7 +127,7 @@ namespace __parallel template<typename _IIter1, typename _IIter2, typename _Predicate> bool equal(_IIter1, _IIter1, _IIter2, _Predicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2> bool @@ -172,12 +172,12 @@ namespace __parallel template<typename _IIter, typename _FIter> _IIter find_first_of(_IIter, _IIter, _FIter, _FIter, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter, typename _FIter, typename _BiPredicate> _IIter find_first_of(_IIter, _IIter, _FIter, _FIter, _BiPredicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter, typename _FIter, typename _BiPredicate> _IIter @@ -188,21 +188,22 @@ namespace __parallel find_first_of(_IIter, _IIter, _FIter, _FIter); template<typename _IIter, typename _FIter, - typename _IterTag1, typename _IterTag2> + typename _IterTag1, typename _IterTag2> _IIter - __find_first_of_switch(_IIter, _IIter, _FIter, _FIter, _IterTag1, _IterTag2); + __find_first_of_switch( + _IIter, _IIter, _FIter, _FIter, _IterTag1, _IterTag2); template<typename _RAIter, typename _FIter, typename _BiPredicate, - typename _IterTag> + typename _IterTag> _RAIter __find_first_of_switch(_RAIter, _RAIter, _FIter, _FIter, _BiPredicate, - random_access_iterator_tag, _IterTag); + random_access_iterator_tag, _IterTag); template<typename _IIter, typename _FIter, typename _BiPredicate, - typename _IterTag1, typename _IterTag2> + typename _IterTag1, typename _IterTag2> _IIter __find_first_of_switch(_IIter, _IIter, _FIter, _FIter, _BiPredicate, - _IterTag1, _IterTag2); + _IterTag1, _IterTag2); template<typename _IIter, typename _Function> @@ -223,9 +224,9 @@ namespace __parallel template<typename _RAIter, typename _Function> _Function - __for_each_switch(_RAIter, _RAIter, _Function, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_balanced); + __for_each_switch(_RAIter, _RAIter, _Function, random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_balanced); template<typename _FIter, typename _Generator> @@ -246,9 +247,9 @@ namespace __parallel template<typename _RAIter, typename _Generator> void - __generate_switch(_RAIter, _RAIter, _Generator, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_balanced); + __generate_switch(_RAIter, _RAIter, _Generator, random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_balanced); template<typename _OIter, typename _Size, typename _Generator> _OIter @@ -263,25 +264,25 @@ namespace __parallel generate_n(_OIter, _Size, _Generator, __gnu_parallel::_Parallelism); template<typename _OIter, typename _Size, typename _Generator, - typename _IterTag> + typename _IterTag> _OIter __generate_n_switch(_OIter, _Size, _Generator, _IterTag); template<typename _RAIter, typename _Size, typename _Generator> _RAIter - __generate_n_switch(_RAIter, _Size, _Generator, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_balanced); + __generate_n_switch(_RAIter, _Size, _Generator, random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_balanced); template<typename _IIter1, typename _IIter2> bool lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _Predicate> bool lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, _Predicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2> bool @@ -292,16 +293,16 @@ namespace __parallel lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, _Predicate); template<typename _IIter1, typename _IIter2, - typename _Predicate, typename _IterTag1, typename _IterTag2> + typename _Predicate, typename _IterTag1, typename _IterTag2> bool __lexicographical_compare_switch(_IIter1, _IIter1, _IIter2, _IIter2, - _Predicate, _IterTag1, _IterTag2); + _Predicate, _IterTag1, _IterTag2); template<typename _RAIter1, typename _RAIter2, typename _Predicate> bool __lexicographical_compare_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, - _Predicate, random_access_iterator_tag, - random_access_iterator_tag); + _Predicate, random_access_iterator_tag, + random_access_iterator_tag); // algo.h template<typename _IIter1, typename _IIter2> @@ -311,7 +312,7 @@ namespace __parallel template<typename _IIter1, typename _IIter2, typename _Predicate> pair<_IIter1, _IIter2> mismatch(_IIter1, _IIter1, _IIter2, _Predicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2> pair<_IIter1, _IIter2> @@ -322,15 +323,15 @@ namespace __parallel mismatch(_IIter1, _IIter1, _IIter2, _Predicate); template<typename _IIter1, typename _IIter2, typename _Predicate, - typename _IterTag1, typename _IterTag2> + typename _IterTag1, typename _IterTag2> pair<_IIter1, _IIter2> __mismatch_switch(_IIter1, _IIter1, _IIter2, _Predicate, - _IterTag1, _IterTag2); + _IterTag1, _IterTag2); template<typename _RAIter1, typename _RAIter2, typename _Predicate> pair<_RAIter1, _RAIter2> __mismatch_switch(_RAIter1, _RAIter1, _RAIter2, _Predicate, - random_access_iterator_tag, random_access_iterator_tag); + random_access_iterator_tag, random_access_iterator_tag); template<typename _FIter1, typename _FIter2> _FIter1 @@ -343,7 +344,7 @@ namespace __parallel template<typename _FIter1, typename _FIter2, typename _BiPredicate> _FIter1 search(_FIter1, _FIter1, _FIter2, _FIter2, _BiPredicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _FIter1, typename _FIter2, typename _BiPredicate> _FIter1 @@ -352,55 +353,55 @@ namespace __parallel template<typename _RAIter1, typename _RAIter2> _RAIter1 __search_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, - random_access_iterator_tag, random_access_iterator_tag); + random_access_iterator_tag, random_access_iterator_tag); template<typename _FIter1, typename _FIter2, typename _IterTag1, - typename _IterTag2> + typename _IterTag2> _FIter1 __search_switch(_FIter1, _FIter1, _FIter2, _FIter2, _IterTag1, _IterTag2); template<typename _RAIter1, typename _RAIter2, typename _BiPredicate> _RAIter1 __search_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, _BiPredicate, - random_access_iterator_tag, random_access_iterator_tag); + random_access_iterator_tag, random_access_iterator_tag); template<typename _FIter1, typename _FIter2, typename _BiPredicate, - typename _IterTag1, typename _IterTag2> + typename _IterTag1, typename _IterTag2> _FIter1 __search_switch(_FIter1, _FIter1, _FIter2, _FIter2, _BiPredicate, - _IterTag1, _IterTag2); + _IterTag1, _IterTag2); template<typename _FIter, typename _Integer, typename _Tp> _FIter search_n(_FIter, _FIter, _Integer, const _Tp&, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _FIter, typename _Integer, typename _Tp, - typename _BiPredicate> + typename _BiPredicate> _FIter search_n(_FIter, _FIter, _Integer, const _Tp&, _BiPredicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _FIter, typename _Integer, typename _Tp> _FIter search_n(_FIter, _FIter, _Integer, const _Tp&); template<typename _FIter, typename _Integer, typename _Tp, - typename _BiPredicate> + typename _BiPredicate> _FIter search_n(_FIter, _FIter, _Integer, const _Tp&, _BiPredicate); template<typename _RAIter, typename _Integer, typename _Tp, - typename _BiPredicate> + typename _BiPredicate> _RAIter __search_n_switch(_RAIter, _RAIter, _Integer, const _Tp&, - _BiPredicate, random_access_iterator_tag); + _BiPredicate, random_access_iterator_tag); template<typename _FIter, typename _Integer, typename _Tp, - typename _BiPredicate, typename _IterTag> + typename _BiPredicate, typename _IterTag> _FIter __search_n_switch(_FIter, _FIter, _Integer, const _Tp&, - _BiPredicate, _IterTag); + _BiPredicate, _IterTag); template<typename _IIter, typename _OIter, typename _UnaryOperation> @@ -410,60 +411,60 @@ namespace __parallel template<typename _IIter, typename _OIter, typename _UnaryOperation> _OIter transform(_IIter, _IIter, _OIter, _UnaryOperation, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter, typename _OIter, typename _UnaryOperation> _OIter transform(_IIter, _IIter, _OIter, _UnaryOperation, - __gnu_parallel::_Parallelism); + __gnu_parallel::_Parallelism); template<typename _IIter, typename _OIter, typename _UnaryOperation, - typename _IterTag1, typename _IterTag2> + typename _IterTag1, typename _IterTag2> _OIter __transform1_switch(_IIter, _IIter, _OIter, _UnaryOperation, - _IterTag1, _IterTag2); + _IterTag1, _IterTag2); template<typename _RAIIter, typename _RAOIter, typename _UnaryOperation> _RAOIter __transform1_switch(_RAIIter, _RAIIter, _RAOIter, _UnaryOperation, - random_access_iterator_tag, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_balanced); + random_access_iterator_tag, random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_balanced); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _BiOperation> + typename _BiOperation> _OIter transform(_IIter1, _IIter1, _IIter2, _OIter, _BiOperation); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _BiOperation> + typename _BiOperation> _OIter transform(_IIter1, _IIter1, _IIter2, _OIter, _BiOperation, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _BiOperation> + typename _BiOperation> _OIter transform(_IIter1, _IIter1, _IIter2, _OIter, _BiOperation, - __gnu_parallel::_Parallelism); + __gnu_parallel::_Parallelism); template<typename _RAIter1, typename _RAIter2, typename _RAIter3, - typename _BiOperation> + typename _BiOperation> _RAIter3 __transform2_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter3, _BiOperation, - random_access_iterator_tag, random_access_iterator_tag, - random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_balanced); + random_access_iterator_tag, random_access_iterator_tag, + random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_balanced); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _BiOperation, typename _Tag1, - typename _Tag2, typename _Tag3> + typename _BiOperation, typename _Tag1, + typename _Tag2, typename _Tag3> _OIter __transform2_switch(_IIter1, _IIter1, _IIter2, _OIter, _BiOperation, - _Tag1, _Tag2, _Tag3); + _Tag1, _Tag2, _Tag3); template<typename _FIter, typename _Tp> @@ -473,12 +474,12 @@ namespace __parallel template<typename _FIter, typename _Tp> void replace(_FIter, _FIter, const _Tp&, const _Tp&, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _FIter, typename _Tp> void replace(_FIter, _FIter, const _Tp&, const _Tp&, - __gnu_parallel::_Parallelism); + __gnu_parallel::_Parallelism); template<typename _FIter, typename _Tp, typename _IterTag> void @@ -487,7 +488,7 @@ namespace __parallel template<typename _RAIter, typename _Tp> void __replace_switch(_RAIter, _RAIter, const _Tp&, const _Tp&, - random_access_iterator_tag, __gnu_parallel::_Parallelism); + random_access_iterator_tag, __gnu_parallel::_Parallelism); template<typename _FIter, typename _Predicate, typename _Tp> @@ -497,23 +498,23 @@ namespace __parallel template<typename _FIter, typename _Predicate, typename _Tp> void replace_if(_FIter, _FIter, _Predicate, const _Tp&, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _FIter, typename _Predicate, typename _Tp> void replace_if(_FIter, _FIter, _Predicate, const _Tp&, - __gnu_parallel::_Parallelism); + __gnu_parallel::_Parallelism); template<typename _FIter, typename _Predicate, typename _Tp, - typename _IterTag> + typename _IterTag> void __replace_if_switch(_FIter, _FIter, _Predicate, const _Tp&, _IterTag); template<typename _RAIter, typename _Predicate, typename _Tp> void __replace_if_switch(_RAIter, _RAIter, _Predicate, const _Tp&, - random_access_iterator_tag, - __gnu_parallel::_Parallelism); + random_access_iterator_tag, + __gnu_parallel::_Parallelism); template<typename _FIter> @@ -546,24 +547,25 @@ namespace __parallel template<typename _RAIter, typename _Compare> _RAIter - __max_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_balanced); + __max_element_switch( + _RAIter, _RAIter, _Compare, random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_balanced); template<typename _IIter1, typename _IIter2, typename _OIter> _OIter merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Compare> + typename _Compare> _OIter merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Compare> + typename _Compare> _OIter merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare); @@ -572,18 +574,18 @@ namespace __parallel merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Compare, typename _IterTag1, typename _IterTag2, - typename _IterTag3> + typename _Compare, typename _IterTag1, typename _IterTag2, + typename _IterTag3> _OIter __merge_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare, - _IterTag1, _IterTag2, _IterTag3); + _IterTag1, _IterTag2, _IterTag3); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Compare> + typename _Compare> _OIter __merge_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare, - random_access_iterator_tag, random_access_iterator_tag, - random_access_iterator_tag); + random_access_iterator_tag, random_access_iterator_tag, + random_access_iterator_tag); template<typename _FIter> @@ -596,7 +598,8 @@ namespace __parallel template<typename _FIter> _FIter - min_element(_FIter, _FIter, __gnu_parallel::_Parallelism __parallelism_tag); + min_element(_FIter, _FIter, + __gnu_parallel::_Parallelism __parallelism_tag); template<typename _FIter, typename _Compare> _FIter @@ -616,9 +619,10 @@ namespace __parallel template<typename _RAIter, typename _Compare> _RAIter - __min_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_balanced); + __min_element_switch( + _RAIter, _RAIter, _Compare, random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_balanced); template<typename _RAIter> void @@ -627,7 +631,7 @@ namespace __parallel template<typename _RAIter, typename _Compare> void nth_element(_RAIter, _RAIter, _RAIter, _Compare, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _RAIter, typename _Compare> void @@ -640,7 +644,7 @@ namespace __parallel template<typename _RAIter, typename _Compare> void partial_sort(_RAIter, _RAIter, _RAIter, _Compare, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _RAIter> void @@ -668,7 +672,8 @@ namespace __parallel template<typename _RAIter, typename _Predicate> _RAIter - __partition_switch(_RAIter, _RAIter, _Predicate, random_access_iterator_tag); + __partition_switch( + _RAIter, _RAIter, _Predicate, random_access_iterator_tag); template<typename _RAIter> void @@ -677,7 +682,7 @@ namespace __parallel template<typename _RAIter, typename _RandomNumberGenerator> void random_shuffle(_RAIter, _RAIter, _RandomNumberGenerator&, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _RAIter> void @@ -690,147 +695,147 @@ namespace __parallel template<typename _IIter1, typename _IIter2, typename _OIter> _OIter set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Predicate> + typename _Predicate> _OIter set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Predicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter> _OIter set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Predicate> + typename _Predicate> _OIter set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Predicate); template<typename _IIter1, typename _IIter2, typename _Predicate, - typename _OIter, typename _IterTag1, typename _IterTag2, - typename _IterTag3> + typename _OIter, typename _IterTag1, typename _IterTag2, + typename _IterTag3> _OIter __set_union_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - _Predicate, _IterTag1, _IterTag2, _IterTag3); + _Predicate, _IterTag1, _IterTag2, _IterTag3); template<typename _RAIter1, typename _RAIter2, typename _Output_RAIter, - typename _Predicate> + typename _Predicate> _Output_RAIter __set_union_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, _Output_RAIter, - _Predicate, random_access_iterator_tag, - random_access_iterator_tag, random_access_iterator_tag); + _Predicate, random_access_iterator_tag, + random_access_iterator_tag, random_access_iterator_tag); template<typename _IIter1, typename _IIter2, typename _OIter> _OIter set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Predicate> + typename _Predicate> _OIter set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Predicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter> _OIter set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Predicate> + typename _Predicate> _OIter set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Predicate); template<typename _IIter1, typename _IIter2, typename _Predicate, - typename _OIter, typename _IterTag1, typename _IterTag2, - typename _IterTag3> + typename _OIter, typename _IterTag1, typename _IterTag2, + typename _IterTag3> _OIter __set_intersection_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - _Predicate, _IterTag1, _IterTag2, _IterTag3); + _Predicate, _IterTag1, _IterTag2, _IterTag3); template<typename _RAIter1, typename _RAIter2, typename _Output_RAIter, - typename _Predicate> + typename _Predicate> _Output_RAIter __set_intersection_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, - _Output_RAIter, _Predicate, - random_access_iterator_tag, - random_access_iterator_tag, - random_access_iterator_tag); + _Output_RAIter, _Predicate, + random_access_iterator_tag, + random_access_iterator_tag, + random_access_iterator_tag); template<typename _IIter1, typename _IIter2, typename _OIter> _OIter set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Predicate> + typename _Predicate> _OIter set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - _Predicate, __gnu_parallel::sequential_tag); + _Predicate, __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter> _OIter set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Predicate> + typename _Predicate> _OIter set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - _Predicate); + _Predicate); template<typename _IIter1, typename _IIter2, typename _Predicate, - typename _OIter, typename _IterTag1, typename _IterTag2, - typename _IterTag3> + typename _OIter, typename _IterTag1, typename _IterTag2, + typename _IterTag3> _OIter __set_symmetric_difference_switch(_IIter1, _IIter1, _IIter2, _IIter2, - _OIter, _Predicate, _IterTag1, _IterTag2, - _IterTag3); + _OIter, _Predicate, _IterTag1, _IterTag2, + _IterTag3); template<typename _RAIter1, typename _RAIter2, typename _Output_RAIter, - typename _Predicate> + typename _Predicate> _Output_RAIter __set_symmetric_difference_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, - _Output_RAIter, _Predicate, - random_access_iterator_tag, - random_access_iterator_tag, - random_access_iterator_tag); + _Output_RAIter, _Predicate, + random_access_iterator_tag, + random_access_iterator_tag, + random_access_iterator_tag); template<typename _IIter1, typename _IIter2, typename _OIter> _OIter set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Predicate> + typename _Predicate> _OIter set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Predicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _OIter> _OIter set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); template<typename _IIter1, typename _IIter2, typename _OIter, - typename _Predicate> + typename _Predicate> _OIter set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Predicate); template<typename _IIter1, typename _IIter2, typename _Predicate, - typename _OIter, typename _IterTag1, typename _IterTag2, - typename _IterTag3> + typename _OIter, typename _IterTag1, typename _IterTag2, + typename _IterTag3> _OIter __set_difference_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, - _Predicate, _IterTag1, _IterTag2, _IterTag3); + _Predicate, _IterTag1, _IterTag2, _IterTag3); template<typename _RAIter1, typename _RAIter2, typename _Output_RAIter, - typename _Predicate> + typename _Predicate> _Output_RAIter __set_difference_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, - _Output_RAIter, _Predicate, - random_access_iterator_tag, - random_access_iterator_tag, - random_access_iterator_tag); + _Output_RAIter, _Predicate, + random_access_iterator_tag, + random_access_iterator_tag, + random_access_iterator_tag); template<typename _RAIter> @@ -872,7 +877,7 @@ namespace __parallel template<typename _IIter, typename _OIter, typename _Predicate> _OIter unique_copy(_IIter, _IIter, _OIter, _Predicate, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter, typename _OIter> _OIter @@ -883,15 +888,15 @@ namespace __parallel unique_copy(_IIter, _IIter, _OIter, _Predicate); template<typename _IIter, typename _OIter, typename _Predicate, - typename _IterTag1, typename _IterTag2> + typename _IterTag1, typename _IterTag2> _OIter __unique_copy_switch(_IIter, _IIter, _OIter, _Predicate, - _IterTag1, _IterTag2); + _IterTag1, _IterTag2); template<typename _RAIter, typename _RandomAccess_OIter, typename _Predicate> _RandomAccess_OIter __unique_copy_switch(_RAIter, _RAIter, _RandomAccess_OIter, _Predicate, - random_access_iterator_tag, random_access_iterator_tag); + random_access_iterator_tag, random_access_iterator_tag); } // end namespace __parallel } // end namespace std diff --git a/libstdc++-v3/include/parallel/balanced_quicksort.h b/libstdc++-v3/include/parallel/balanced_quicksort.h index 6a6f6a240ec..85e4d699e26 100644 --- a/libstdc++-v3/include/parallel/balanced_quicksort.h +++ b/libstdc++-v3/include/parallel/balanced_quicksort.h @@ -108,19 +108,25 @@ template<typename _RAIter, typename _Compare> _RAIter __pivot_pos = __median_of_three_iterators(__begin, __begin + (__end - __begin) / 2, - __end - 1, __comp); + __end - 1, __comp); #if defined(_GLIBCXX_ASSERTIONS) // Must be in between somewhere. _DifferenceType __n = __end - __begin; _GLIBCXX_PARALLEL_ASSERT( - (!__comp(*__pivot_pos, *__begin) && !__comp(*(__begin + __n / 2), *__pivot_pos)) - || (!__comp(*__pivot_pos, *__begin) && !__comp(*(__end - 1), *__pivot_pos)) - || (!__comp(*__pivot_pos, *(__begin + __n / 2)) && !__comp(*__begin, *__pivot_pos)) - || (!__comp(*__pivot_pos, *(__begin + __n / 2)) && !__comp(*(__end - 1), *__pivot_pos)) - || (!__comp(*__pivot_pos, *(__end - 1)) && !__comp(*__begin, *__pivot_pos)) - || (!__comp(*__pivot_pos, *(__end - 1)) && !__comp(*(__begin + __n / 2), *__pivot_pos))); + (!__comp(*__pivot_pos, *__begin) && + !__comp(*(__begin + __n / 2), *__pivot_pos)) + || (!__comp(*__pivot_pos, *__begin) && + !__comp(*(__end - 1), *__pivot_pos)) + || (!__comp(*__pivot_pos, *(__begin + __n / 2)) && + !__comp(*__begin, *__pivot_pos)) + || (!__comp(*__pivot_pos, *(__begin + __n / 2)) && + !__comp(*(__end - 1), *__pivot_pos)) + || (!__comp(*__pivot_pos, *(__end - 1)) && + !__comp(*__begin, *__pivot_pos)) + || (!__comp(*__pivot_pos, *(__end - 1)) && + !__comp(*(__begin + __n / 2), *__pivot_pos))); #endif // Swap pivot value to end. @@ -183,15 +189,17 @@ template<typename _RAIter, typename _Compare> } // Divide step. - _DifferenceType __split_pos = __qsb_divide(__begin, __end, __comp, __num_threads); + _DifferenceType __split_pos = + __qsb_divide(__begin, __end, __comp, __num_threads); #if _GLIBCXX_ASSERTIONS - _GLIBCXX_PARALLEL_ASSERT(0 <= __split_pos && __split_pos < (__end - __begin)); + _GLIBCXX_PARALLEL_ASSERT(0 <= __split_pos && + __split_pos < (__end - __begin)); #endif _ThreadIndex __num_threads_leftside = std::max<_ThreadIndex>(1, std::min<_ThreadIndex>( - __num_threads - 1, __split_pos * __num_threads / __n)); + __num_threads - 1, __split_pos * __num_threads / __n)); # pragma omp atomic *__tls[__iam]->_M_elements_leftover -= (_DifferenceType)1; @@ -284,11 +292,13 @@ template<typename _RAIter, typename _Compare> // Divide, leave pivot unchanged in last place. _RAIter __split_pos1, __split_pos2; - __split_pos1 = __gnu_sequential::partition(__begin, __end - 1, __pred); + __split_pos1 = + __gnu_sequential::partition(__begin, __end - 1, __pred); // Left side: < __pivot_pos; __right side: >= __pivot_pos. #if _GLIBCXX_ASSERTIONS - _GLIBCXX_PARALLEL_ASSERT(__begin <= __split_pos1 && __split_pos1 < __end); + _GLIBCXX_PARALLEL_ASSERT(__begin <= __split_pos1 + && __split_pos1 < __end); #endif // Swap pivot back to middle. if (__split_pos1 != __pivot_pos) @@ -302,14 +312,14 @@ template<typename _RAIter, typename _Compare> // Very unequal split, one part smaller than one 128th // elements not strictly larger than the pivot. __gnu_parallel::__unary_negate<__gnu_parallel::__binder1st - <_Compare, _ValueType, _ValueType, bool>, _ValueType> - __pred(__gnu_parallel::__binder1st - <_Compare, _ValueType, _ValueType, bool>(__comp, - *__pivot_pos)); + <_Compare, _ValueType, _ValueType, bool>, _ValueType> + __pred(__gnu_parallel::__binder1st + <_Compare, _ValueType, _ValueType, bool>( + __comp, *__pivot_pos)); // Find other end of pivot-equal range. __split_pos2 = __gnu_sequential::partition(__split_pos1 + 1, - __end, __pred); + __end, __pred); } else // Only skip the pivot. @@ -325,10 +335,10 @@ template<typename _RAIter, typename _Compare> { // Right side larger. if ((__split_pos2) != __end) - __tl._M_leftover_parts.push_front(std::make_pair(__split_pos2, - __end)); + __tl._M_leftover_parts.push_front( + std::make_pair(__split_pos2, __end)); - //__current.first = __begin; //already set anyway + //__current.first = __begin; //already set anyway __current.second = __split_pos1; continue; } @@ -337,10 +347,10 @@ template<typename _RAIter, typename _Compare> // Left side larger. if (__begin != __split_pos1) __tl._M_leftover_parts.push_front(std::make_pair(__begin, - __split_pos1)); + __split_pos1)); __current.first = __split_pos2; - //__current.second = __end; //already set anyway + //__current.second = __end; //already set anyway continue; } } @@ -367,10 +377,11 @@ template<typename _RAIter, typename _Compare> // Look for new work. bool __successfully_stolen = false; - while (__wait && *__tl._M_elements_leftover > 0 && !__successfully_stolen + while (__wait && *__tl._M_elements_leftover > 0 + && !__successfully_stolen #if _GLIBCXX_ASSERTIONS - // Possible dead-lock. - && (omp_get_wtime() < (__search_start + 1.0)) + // Possible dead-lock. + && (omp_get_wtime() < (__search_start + 1.0)) #endif ) { @@ -392,7 +403,7 @@ template<typename _RAIter, typename _Compare> { sleep(1); _GLIBCXX_PARALLEL_ASSERT(omp_get_wtime() - < (__search_start + 1.0)); + < (__search_start + 1.0)); } #endif if (!__successfully_stolen) @@ -439,11 +450,13 @@ template<typename _RAIter, typename _Compare> // Initialize thread local storage _TLSType** __tls = new _TLSType*[__num_threads]; - _DifferenceType __queue_size = __num_threads * (_ThreadIndex)(log2(__n) + 1); + _DifferenceType __queue_size = + __num_threads * (_ThreadIndex)(log2(__n) + 1); for (_ThreadIndex __t = 0; __t < __num_threads; ++__t) __tls[__t] = new _QSBThreadLocal<_RAIter>(__queue_size); - // There can never be more than ceil(log2(__n)) ranges on the stack, because + // There can never be more than ceil(log2(__n)) ranges on the stack, + // because // 1. Only one processor pushes onto the stack // 2. The largest range has at most length __n // 3. Each range is larger than half of the range remaining @@ -459,13 +472,15 @@ template<typename _RAIter, typename _Compare> } // Main recursion call. - __qsb_conquer(__tls, __begin, __begin + __n, __comp, 0, __num_threads, true); + __qsb_conquer( + __tls, __begin, __begin + __n, __comp, 0, __num_threads, true); #if _GLIBCXX_ASSERTIONS // All stack must be empty. _Piece __dummy; for (int __i = 1; __i < __num_threads; ++__i) - _GLIBCXX_PARALLEL_ASSERT(!__tls[__i]->_M_leftover_parts.pop_back(__dummy)); + _GLIBCXX_PARALLEL_ASSERT( + !__tls[__i]->_M_leftover_parts.pop_back(__dummy)); #endif for (int __i = 0; __i < __num_threads; ++__i) diff --git a/libstdc++-v3/include/parallel/base.h b/libstdc++-v3/include/parallel/base.h index 92f787404ad..6925696a72e 100644 --- a/libstdc++-v3/include/parallel/base.h +++ b/libstdc++-v3/include/parallel/base.h @@ -119,7 +119,7 @@ template<typename _Size> * @see decode2 */ inline _CASable -__encode2(int __a, int __b) //must all be non-negative, actually +__encode2(int __a, int __b) //must all be non-negative, actually { return (((_CASable)__a) << (_CASable_bits / 2)) | (((_CASable)__b) << 0); } @@ -192,7 +192,7 @@ template<typename _Predicate, typename argument_type> /** @brief Similar to std::__binder1st, * but giving the argument types explicitly. */ template<typename _Operation, typename _FirstArgumentType, - typename _SecondArgumentType, typename _ResultType> + typename _SecondArgumentType, typename _ResultType> class __binder1st : public std::unary_function<_SecondArgumentType, _ResultType> { @@ -221,7 +221,7 @@ template<typename _Operation, typename _FirstArgumentType, * explicitly. */ template<typename _Operation, typename _FirstArgumentType, - typename _SecondArgumentType, typename _ResultType> + typename _SecondArgumentType, typename _ResultType> class binder2nd : public std::unary_function<_FirstArgumentType, _ResultType> { @@ -281,7 +281,7 @@ template<typename _Tp1, typename _Tp2> struct _Plus : public std::binary_function<_Tp1, _Tp2, _Tp1> { typedef __typeof__(*static_cast<_Tp1*>(NULL) - + *static_cast<_Tp2*>(NULL)) __result; + + *static_cast<_Tp2*>(NULL)) __result; __result operator()(const _Tp1& __x, const _Tp2& __y) const @@ -293,7 +293,7 @@ template<typename _Tp> struct _Plus<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, _Tp> { typedef __typeof__(*static_cast<_Tp*>(NULL) - + *static_cast<_Tp*>(NULL)) __result; + + *static_cast<_Tp*>(NULL)) __result; __result operator()(const _Tp& __x, const _Tp& __y) const @@ -306,7 +306,7 @@ template<typename _Tp1, typename _Tp2> struct _Multiplies : public std::binary_function<_Tp1, _Tp2, _Tp1> { typedef __typeof__(*static_cast<_Tp1*>(NULL) - * *static_cast<_Tp2*>(NULL)) __result; + * *static_cast<_Tp2*>(NULL)) __result; __result operator()(const _Tp1& __x, const _Tp2& __y) const @@ -318,7 +318,7 @@ template<typename _Tp> struct _Multiplies<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, _Tp> { typedef __typeof__(*static_cast<_Tp*>(NULL) - * *static_cast<_Tp*>(NULL)) __result; + * *static_cast<_Tp*>(NULL)) __result; __result operator()(const _Tp& __x, const _Tp& __y) const diff --git a/libstdc++-v3/include/parallel/checkers.h b/libstdc++-v3/include/parallel/checkers.h index 47d21749a86..5d3acfa4b8d 100644 --- a/libstdc++-v3/include/parallel/checkers.h +++ b/libstdc++-v3/include/parallel/checkers.h @@ -39,7 +39,8 @@ namespace __gnu_parallel { /** - * @brief Check whether @__c [__begin, @__c __end) is sorted according to @__c __comp. + * @brief Check whether @__c [__begin, @__c __end) is sorted according + * to @__c __comp. * @param __begin Begin iterator of sequence. * @param __end End iterator of sequence. * @param __comp Comparator. @@ -49,33 +50,34 @@ namespace __gnu_parallel template<typename _IIter, typename _Compare> bool __is_sorted(_IIter __begin, _IIter __end, - _Compare __comp - = std::less<typename std::iterator_traits<_IIter>:: - _ValueType>()) + _Compare __comp + = std::less<typename std::iterator_traits<_IIter>:: + _ValueType>()) { if (__begin == __end) - return true; + return true; _IIter __current(__begin), __recent(__begin); unsigned long long __position = 1; for (__current++; __current != __end; __current++) - { - if (__comp(*__current, *__recent)) - { - printf("__is_sorted: check failed before position %__i.\n", - __position); - return false; - } - __recent = __current; - __position++; - } + { + if (__comp(*__current, *__recent)) + { + printf("__is_sorted: check failed before position %__i.\n", + __position); + return false; + } + __recent = __current; + __position++; + } return true; } /** - * @brief Check whether @__c [__begin, @__c __end) is sorted according to @__c __comp. + * @brief Check whether @__c [__begin, @__c __end) is sorted according to + * @__c __comp. * Prints the position in case an unordered pair is found. * @param __begin Begin iterator of sequence. * @param __end End iterator of sequence. @@ -87,36 +89,37 @@ namespace __gnu_parallel template<typename _IIter, typename _Compare> bool is_sorted_failure(_IIter __begin, _IIter __end, - _IIter& __first_failure, - _Compare __comp - = std::less<typename std::iterator_traits<_IIter>:: - _ValueType>()) + _IIter& __first_failure, + _Compare __comp + = std::less<typename std::iterator_traits<_IIter>:: + _ValueType>()) { if (__begin == __end) - return true; + return true; _IIter __current(__begin), __recent(__begin); unsigned long long __position = 1; for (__current++; __current != __end; __current++) - { - if (__comp(*__current, *__recent)) - { - __first_failure = __current; - printf("__is_sorted: check failed before position %lld.\n", - __position); - return false; - } - __recent = __current; - __position++; - } + { + if (__comp(*__current, *__recent)) + { + __first_failure = __current; + printf("__is_sorted: check failed before position %lld.\n", + __position); + return false; + } + __recent = __current; + __position++; + } __first_failure = __end; return true; } /** - * @brief Check whether @__c [__begin, @__c __end) is sorted according to @__c __comp. + * @brief Check whether @__c [__begin, @__c __end) is sorted according to + * @__c __comp. * Prints all unordered pair, including the surrounding two elements. * @param __begin Begin iterator of sequence. * @param __end End iterator of sequence. @@ -127,26 +130,26 @@ namespace __gnu_parallel bool // XXX Compare default template argument is_sorted_print_failures(_IIter __begin, _IIter __end, - _Compare __comp - = std::less<typename std::iterator_traits - <_IIter>::value_type>()) + _Compare __comp + = std::less<typename std::iterator_traits + <_IIter>::value_type>()) { if (__begin == __end) - return true; + return true; _IIter __recent(__begin); bool __ok = true; for (_IIter __pos(__begin + 1); __pos != __end; __pos++) - { - if (__comp(*__pos, *__recent)) - { - printf("%ld: %d %d %d %d\n", __pos - __begin, *(__pos - 2), - *(__pos- 1), *__pos, *(__pos + 1)); - __ok = false; - } - __recent = __pos; - } + { + if (__comp(*__pos, *__recent)) + { + printf("%ld: %d %d %d %d\n", __pos - __begin, *(__pos - 2), + *(__pos- 1), *__pos, *(__pos + 1)); + __ok = false; + } + __recent = __pos; + } return __ok; } } diff --git a/libstdc++-v3/include/parallel/compatibility.h b/libstdc++-v3/include/parallel/compatibility.h index 2dc02a8898c..e10370b6f54 100644 --- a/libstdc++-v3/include/parallel/compatibility.h +++ b/libstdc++-v3/include/parallel/compatibility.h @@ -65,9 +65,9 @@ namespace __gnu_parallel int32 __faa32(int32* __x, int32 __inc) { asm volatile("lock xadd %0,%1" - : "=__r" (__inc), "=__m" (*__x) - : "0" (__inc) - : "memory"); + : "=__r" (__inc), "=__m" (*__x) + : "0" (__inc) + : "memory"); return __inc; } #if defined(__x86_64) @@ -75,9 +75,9 @@ namespace __gnu_parallel int64 __faa64(int64* __x, int64 __inc) { asm volatile("lock xadd %0,%1" - : "=__r" (__inc), "=__m" (*__x) - : "0" (__inc) - : "memory"); + : "=__r" (__inc), "=__m" (*__x) + : "0" (__inc) + : "memory"); return __inc; } #endif @@ -94,25 +94,25 @@ namespace __gnu_parallel inline int32 __fetch_and_add_32(volatile int32* __ptr, int32 __addend) { -#if defined(__ICC) //x86 version +#if defined(__ICC) //x86 version return _InterlockedExchangeAdd((void*)__ptr, __addend); -#elif defined(__ECC) //IA-64 version +#elif defined(__ECC) //IA-64 version return _InterlockedExchangeAdd((void*)__ptr, __addend); #elif defined(__ICL) || defined(_MSC_VER) return _InterlockedExchangeAdd(reinterpret_cast<volatile long*>(__ptr), - __addend); + __addend); #elif defined(__GNUC__) return __sync_fetch_and_add(__ptr, __addend); #elif defined(__SUNPRO_CC) && defined(__sparc) volatile int32 __before, __after; do { - __before = *__ptr; - __after = __before + __addend; + __before = *__ptr; + __after = __before + __addend; } while (atomic_cas_32((volatile unsigned int*)__ptr, __before, - __after) != __before); + __after) != __before); return __before; -#else //fallback, slow +#else //fallback, slow #pragma message("slow __fetch_and_add_32") int32 __res; #pragma omp critical @@ -133,32 +133,32 @@ namespace __gnu_parallel inline int64 __fetch_and_add_64(volatile int64* __ptr, int64 __addend) { -#if defined(__ICC) && defined(__x86_64) //x86 version +#if defined(__ICC) && defined(__x86_64) //x86 version return __faa64<int>((int64*)__ptr, __addend); -#elif defined(__ECC) //IA-64 version +#elif defined(__ECC) //IA-64 version return _InterlockedExchangeAdd64((void*)__ptr, __addend); #elif defined(__ICL) || defined(_MSC_VER) #ifndef _WIN64 - _GLIBCXX_PARALLEL_ASSERT(false); //not available in this case + _GLIBCXX_PARALLEL_ASSERT(false); //not available in this case return 0; #else return _InterlockedExchangeAdd64(__ptr, __addend); #endif #elif defined(__GNUC__) && defined(__x86_64) return __sync_fetch_and_add(__ptr, __addend); -#elif defined(__GNUC__) && defined(__i386) && \ +#elif defined(__GNUC__) && defined(__i386) && \ (defined(__i686) || defined(__pentium4) || defined(__athlon)) return __sync_fetch_and_add(__ptr, __addend); #elif defined(__SUNPRO_CC) && defined(__sparc) volatile int64 __before, __after; do { - __before = *__ptr; - __after = __before + __addend; + __before = *__ptr; + __after = __before + __addend; } while (atomic_cas_64((volatile unsigned long long*)__ptr, __before, - __after) != __before); + __after) != __before); return __before; -#else //fallback, slow +#else //fallback, slow #if defined(__GNUC__) && defined(__i386) // XXX doesn'__t work with -march=native //#warning "please compile with -march=i686 or better" @@ -201,9 +201,10 @@ namespace __gnu_parallel { int32 __before; __asm__ __volatile__("lock; cmpxchgl %1,%2" - : "=a"(__before) - : "q"(__nw), "__m"(*(volatile long long*)(__ptr)), "0"(__old) - : "memory"); + : "=a"(__before) + : "q"(__nw), "__m"(*(volatile long long*)(__ptr)), + "0"(__old) + : "memory"); return __before; } @@ -214,9 +215,10 @@ namespace __gnu_parallel { int64 __before; __asm__ __volatile__("lock; cmpxchgq %1,%2" - : "=a"(__before) - : "q"(__nw), "__m"(*(volatile long long*)(__ptr)), "0"(__old) - : "memory"); + : "=a"(__before) + : "q"(__nw), "__m"(*(volatile long long*)(__ptr)), + "0"(__old) + : "memory"); return __before; } #endif @@ -232,32 +234,35 @@ namespace __gnu_parallel * @param __replacement Replacement value. */ inline bool - __compare_and_swap_32(volatile int32* __ptr, int32 __comparand, int32 __replacement) + __compare_and_swap_32(volatile int32* __ptr, int32 __comparand, + int32 __replacement) { -#if defined(__ICC) //x86 version +#if defined(__ICC) //x86 version return _InterlockedCompareExchange((void*)__ptr, __replacement, - __comparand) == __comparand; -#elif defined(__ECC) //IA-64 version + __comparand) == __comparand; +#elif defined(__ECC) //IA-64 version return _InterlockedCompareExchange((void*)__ptr, __replacement, - __comparand) == __comparand; + __comparand) == __comparand; #elif defined(__ICL) || defined(_MSC_VER) - return _InterlockedCompareExchange(reinterpret_cast<volatile long*>(__ptr), - __replacement, __comparand) == __comparand; + return _InterlockedCompareExchange( + reinterpret_cast<volatile long*>(__ptr), + __replacement, __comparand) + == __comparand; #elif defined(__GNUC__) return __sync_bool_compare_and_swap(__ptr, __comparand, __replacement); #elif defined(__SUNPRO_CC) && defined(__sparc) return atomic_cas_32((volatile unsigned int*)__ptr, __comparand, - __replacement) == __comparand; + __replacement) == __comparand; #else #pragma message("slow __compare_and_swap_32") bool __res = false; #pragma omp critical { if (*__ptr == __comparand) - { - *__ptr = __replacement; - __res = true; - } + { + *__ptr = __replacement; + __res = true; + } } return __res; #endif @@ -272,30 +277,31 @@ namespace __gnu_parallel * @param __replacement Replacement value. */ inline bool - __compare_and_swap_64(volatile int64* __ptr, int64 __comparand, int64 __replacement) + __compare_and_swap_64(volatile int64* __ptr, int64 __comparand, + int64 __replacement) { -#if defined(__ICC) && defined(__x86_64) //x86 version +#if defined(__ICC) && defined(__x86_64) //x86 version return __cas64<int>(__ptr, __comparand, __replacement) == __comparand; -#elif defined(__ECC) //IA-64 version +#elif defined(__ECC) //IA-64 version return _InterlockedCompareExchange64((void*)__ptr, __replacement, - __comparand) == __comparand; + __comparand) == __comparand; #elif defined(__ICL) || defined(_MSC_VER) #ifndef _WIN64 - _GLIBCXX_PARALLEL_ASSERT(false); //not available in this case + _GLIBCXX_PARALLEL_ASSERT(false); //not available in this case return 0; #else return _InterlockedCompareExchange64(__ptr, __replacement, - __comparand) == __comparand; + __comparand) == __comparand; #endif #elif defined(__GNUC__) && defined(__x86_64) return __sync_bool_compare_and_swap(__ptr, __comparand, __replacement); -#elif defined(__GNUC__) && defined(__i386) && \ +#elif defined(__GNUC__) && defined(__i386) && \ (defined(__i686) || defined(__pentium4) || defined(__athlon)) return __sync_bool_compare_and_swap(__ptr, __comparand, __replacement); #elif defined(__SUNPRO_CC) && defined(__sparc) return atomic_cas_64((volatile unsigned long long*)__ptr, - __comparand, __replacement) == __comparand; + __comparand, __replacement) == __comparand; #else #if defined(__GNUC__) && defined(__i386) // XXX -march=native @@ -306,10 +312,10 @@ namespace __gnu_parallel #pragma omp critical { if (*__ptr == __comparand) - { - *__ptr = __replacement; - __res = true; - } + { + *__ptr = __replacement; + __res = true; + } } return __res; #endif @@ -327,9 +333,11 @@ namespace __gnu_parallel __compare_and_swap(volatile _Tp* __ptr, _Tp __comparand, _Tp __replacement) { if (sizeof(_Tp) == sizeof(int32)) - return __compare_and_swap_32((volatile int32*) __ptr, (int32)__comparand, (int32)__replacement); + return __compare_and_swap_32((volatile int32*) __ptr, (int32)__comparand, + (int32)__replacement); else if (sizeof(_Tp) == sizeof(int64)) - return __compare_and_swap_64((volatile int64*) __ptr, (int64)__comparand, (int64)__replacement); + return __compare_and_swap_64((volatile int64*) __ptr, (int64)__comparand, + (int64)__replacement); else _GLIBCXX_PARALLEL_ASSERT(false); } diff --git a/libstdc++-v3/include/parallel/equally_split.h b/libstdc++-v3/include/parallel/equally_split.h index 11672c4579a..a41ed6ec41e 100644 --- a/libstdc++-v3/include/parallel/equally_split.h +++ b/libstdc++-v3/include/parallel/equally_split.h @@ -45,7 +45,8 @@ namespace __gnu_parallel * @returns End of splitter sequence, i.e. @__c __s+__num_threads+1 */ template<typename _DifferenceType, typename _OutputIterator> _OutputIterator - equally_split(_DifferenceType __n, _ThreadIndex __num_threads, _OutputIterator __s) + equally_split(_DifferenceType __n, _ThreadIndex __num_threads, + _OutputIterator __s) { _DifferenceType __chunk_length = __n / __num_threads; _DifferenceType __num_longer_chunks = __n % __num_threads; @@ -53,7 +54,8 @@ template<typename _DifferenceType, typename _OutputIterator> for (_ThreadIndex __i = 0; __i < __num_threads; ++__i) { *__s++ = __pos; - __pos += (__i < __num_longer_chunks) ? (__chunk_length + 1) : __chunk_length; + __pos += (__i < __num_longer_chunks) ? + (__chunk_length + 1) : __chunk_length; } *__s++ = __n; return __s; diff --git a/libstdc++-v3/include/parallel/find.h b/libstdc++-v3/include/parallel/find.h index 6c84981a8c3..e7f0d839086 100644 --- a/libstdc++-v3/include/parallel/find.h +++ b/libstdc++-v3/include/parallel/find.h @@ -53,9 +53,9 @@ namespace __gnu_parallel * @return Place of finding in both sequences. */ template<typename _RAIter1, - typename _RAIter2, - typename _Pred, - typename _Selector> + typename _RAIter2, + typename _Pred, + typename _Selector> inline std::pair<_RAIter1, _RAIter2> __find_template(_RAIter1 __begin1, _RAIter1 __end1, _RAIter2 __begin2, _Pred __pred, _Selector __selector) @@ -64,13 +64,13 @@ template<typename _RAIter1, { case GROWING_BLOCKS: return __find_template(__begin1, __end1, __begin2, __pred, __selector, - growing_blocks_tag()); + growing_blocks_tag()); case CONSTANT_SIZE_BLOCKS: return __find_template(__begin1, __end1, __begin2, __pred, __selector, - constant_size_blocks_tag()); + constant_size_blocks_tag()); case EQUAL_SPLIT: return __find_template(__begin1, __end1, __begin2, __pred, __selector, - equal_split_tag()); + equal_split_tag()); default: _GLIBCXX_PARALLEL_ASSERT(false); return std::make_pair(__begin1, __begin2); @@ -90,9 +90,9 @@ template<typename _RAIter1, * @return Place of finding in both sequences. */ template<typename _RAIter1, - typename _RAIter2, - typename _Pred, - typename _Selector> + typename _RAIter2, + typename _Pred, + typename _Selector> std::pair<_RAIter1, _RAIter2> __find_template(_RAIter1 __begin1, _RAIter1 __end1, @@ -125,7 +125,8 @@ template<typename _RAIter1, } //single _ThreadIndex __iam = omp_get_thread_num(); - _DifferenceType __start = __borders[__iam], __stop = __borders[__iam + 1]; + _DifferenceType __start = __borders[__iam], + __stop = __borders[__iam + 1]; _RAIter1 __i1 = __begin1 + __start; _RAIter2 __i2 = __begin2 + __start; @@ -153,8 +154,7 @@ template<typename _RAIter1, delete[] __borders; return - std::pair<_RAIter1, _RAIter2>(__begin1 + __result, - __begin2 + __result); + std::pair<_RAIter1, _RAIter2>(__begin1 + __result, __begin2 + __result); } #endif @@ -178,15 +178,14 @@ template<typename _RAIter1, * There are two main differences between the growing blocks and * the constant-size blocks variants. * 1. For GB, the block size grows; for CSB, the block size is fixed. - * 2. For GB, the blocks are allocated dynamically; * for CSB, the blocks are allocated in a predetermined manner, * namely spacial round-robin. */ template<typename _RAIter1, - typename _RAIter2, - typename _Pred, - typename _Selector> + typename _RAIter2, + typename _Pred, + typename _Selector> std::pair<_RAIter1, _RAIter2> __find_template(_RAIter1 __begin1, _RAIter1 __end1, _RAIter2 __begin2, _Pred __pred, _Selector __selector, @@ -231,7 +230,7 @@ template<typename _RAIter1, _DifferenceType __block_size = __s.find_initial_block_size; _DifferenceType __start = - __fetch_and_add<_DifferenceType>(&__next_block_start, __block_size); + __fetch_and_add<_DifferenceType>(&__next_block_start, __block_size); // Get new block, update pointer to next block. _DifferenceType __stop = @@ -250,7 +249,8 @@ template<typename _RAIter1, } __local_result = __selector._M_sequential_algorithm( - __begin1 + __start, __begin1 + __stop, __begin2 + __start, __pred); + __begin1 + __start, __begin1 + __stop, + __begin2 + __start, __pred); if (__local_result.first != (__begin1 + __stop)) { omp_set_lock(&__result_lock); @@ -259,20 +259,22 @@ template<typename _RAIter1, __result = __local_result.first - __begin1; // Result cannot be in future blocks, stop algorithm. - __fetch_and_add<_DifferenceType>(&__next_block_start, __length); + __fetch_and_add<_DifferenceType>( + &__next_block_start, __length); } omp_unset_lock(&__result_lock); } - __block_size = - std::min<_DifferenceType>(__block_size * __s.find_increasing_factor, - __s.find_maximum_block_size); + __block_size = std::min<_DifferenceType>( + __block_size * __s.find_increasing_factor, + __s.find_maximum_block_size); // Get new block, update pointer to next block. __start = - __fetch_and_add<_DifferenceType>(&__next_block_start, __block_size); + __fetch_and_add<_DifferenceType>( + &__next_block_start, __block_size); __stop = ((__length < (__start + __block_size)) - ? __length : (__start + __block_size)); + ? __length : (__start + __block_size)); } } //parallel @@ -280,8 +282,7 @@ template<typename _RAIter1, // Return iterator on found element. return - std::pair<_RAIter1, _RAIter2>(__begin1 + __result, - __begin2 + __result); + std::pair<_RAIter1, _RAIter2>(__begin1 + __result, __begin2 + __result); } #endif @@ -307,9 +308,9 @@ template<typename _RAIter1, * round-robin. */ template<typename _RAIter1, - typename _RAIter2, - typename _Pred, - typename _Selector> + typename _RAIter2, + typename _Pred, + typename _Selector> std::pair<_RAIter1, _RAIter2> __find_template(_RAIter1 __begin1, _RAIter1 __end1, _RAIter2 __begin2, _Pred __pred, _Selector __selector, @@ -329,8 +330,8 @@ template<typename _RAIter1, // Try it sequentially first. std::pair<_RAIter1, _RAIter2> __find_seq_result = - __selector._M_sequential_algorithm(__begin1, __begin1 + __sequential_search_size, - __begin2, __pred); + __selector._M_sequential_algorithm( + __begin1, __begin1 + __sequential_search_size, __begin2, __pred); if (__find_seq_result.first != (__begin1 + __sequential_search_size)) return __find_seq_result; @@ -384,7 +385,8 @@ template<typename _RAIter1, // Where to work. __start = __iteration_start + __iam * __block_size; - __stop = std::min<_DifferenceType>(__length, __start + __block_size); + __stop = std::min<_DifferenceType>( + __length, __start + __block_size); } } //parallel @@ -392,8 +394,7 @@ template<typename _RAIter1, // Return iterator on found element. return - std::pair<_RAIter1, _RAIter2>(__begin1 + __result, - __begin2 + __result); + std::pair<_RAIter1, _RAIter2>(__begin1 + __result, __begin2 + __result); } #endif } // end namespace diff --git a/libstdc++-v3/include/parallel/find_selectors.h b/libstdc++-v3/include/parallel/find_selectors.h index 9445d51d45a..2b1e118a64f 100644 --- a/libstdc++-v3/include/parallel/find_selectors.h +++ b/libstdc++-v3/include/parallel/find_selectors.h @@ -55,7 +55,7 @@ namespace __gnu_parallel * @param __pred Find predicate. */ template<typename _RAIter1, typename _RAIter2, - typename _Pred> + typename _Pred> bool operator()(_RAIter1 __i1, _RAIter2 __i2, _Pred __pred) { return __pred(*__i1); } @@ -67,13 +67,13 @@ namespace __gnu_parallel * @param __pred Find predicate. */ template<typename _RAIter1, typename _RAIter2, - typename _Pred> + typename _Pred> std::pair<_RAIter1, _RAIter2> _M_sequential_algorithm(_RAIter1 __begin1, - _RAIter1 __end1, - _RAIter2 __begin2, _Pred __pred) + _RAIter1 __end1, + _RAIter2 __begin2, _Pred __pred) { return std::make_pair(find_if(__begin1, __end1, __pred, - sequential_tag()), __begin2); } + sequential_tag()), __begin2); } }; /** @brief Test predicate on two adjacent elements. */ @@ -85,12 +85,12 @@ namespace __gnu_parallel * @param __pred Find predicate. */ template<typename _RAIter1, typename _RAIter2, - typename _Pred> + typename _Pred> bool operator()(_RAIter1 __i1, _RAIter2 __i2, _Pred __pred) { - // Passed end iterator is one short. - return __pred(*__i1, *(__i1 + 1)); + // Passed end iterator is one short. + return __pred(*__i1, *(__i1 + 1)); } /** @brief Corresponding sequential algorithm on a sequence. @@ -100,18 +100,18 @@ namespace __gnu_parallel * @param __pred Find predicate. */ template<typename _RAIter1, typename _RAIter2, - typename _Pred> + typename _Pred> std::pair<_RAIter1, _RAIter2> _M_sequential_algorithm(_RAIter1 __begin1, - _RAIter1 __end1, - _RAIter2 __begin2, _Pred __pred) + _RAIter1 __end1, + _RAIter2 __begin2, _Pred __pred) { - // Passed end iterator is one short. - _RAIter1 spot = adjacent_find(__begin1, __end1 + 1, - __pred, sequential_tag()); - if (spot == (__end1 + 1)) - spot = __end1; - return std::make_pair(spot, __begin2); + // Passed end iterator is one short. + _RAIter1 spot = adjacent_find(__begin1, __end1 + 1, + __pred, sequential_tag()); + if (spot == (__end1 + 1)) + spot = __end1; + return std::make_pair(spot, __begin2); } }; @@ -125,7 +125,7 @@ namespace __gnu_parallel * @param __pred Find predicate. */ template<typename _RAIter1, typename _RAIter2, - typename _Pred> + typename _Pred> bool operator()(_RAIter1 __i1, _RAIter2 __i2, _Pred __pred) { return !__pred(*__i1, *__i2); } @@ -138,23 +138,24 @@ namespace __gnu_parallel * @param __pred Find predicate. */ template<typename _RAIter1, typename _RAIter2, - typename _Pred> + typename _Pred> std::pair<_RAIter1, _RAIter2> _M_sequential_algorithm(_RAIter1 __begin1, - _RAIter1 __end1, - _RAIter2 __begin2, _Pred __pred) - { return mismatch(__begin1, __end1, __begin2, __pred, sequential_tag()); } + _RAIter1 __end1, + _RAIter2 __begin2, _Pred __pred) + { return mismatch(__begin1, __end1, __begin2, __pred, sequential_tag()); + } }; /** @brief Test predicate on several elements. */ - template<typename _ForwardIterator> + template<typename _FIterator> struct __find_first_of_selector : public __generic_find_selector { - _ForwardIterator _M_begin; - _ForwardIterator _M_end; + _FIterator _M_begin; + _FIterator _M_end; - explicit __find_first_of_selector(_ForwardIterator __begin, _ForwardIterator __end) + explicit __find_first_of_selector(_FIterator __begin, _FIterator __end) : _M_begin(__begin), _M_end(__end) { } /** @brief Test on one position. @@ -162,15 +163,15 @@ namespace __gnu_parallel * @param __i2 _Iterator on second sequence (unused). * @param __pred Find predicate. */ template<typename _RAIter1, typename _RAIter2, - typename _Pred> + typename _Pred> bool operator()(_RAIter1 __i1, _RAIter2 __i2, _Pred __pred) { - for (_ForwardIterator __pos_in_candidates = _M_begin; - __pos_in_candidates != _M_end; ++__pos_in_candidates) - if (__pred(*__i1, *__pos_in_candidates)) - return true; - return false; + for (_FIterator __pos_in_candidates = _M_begin; + __pos_in_candidates != _M_end; ++__pos_in_candidates) + if (__pred(*__i1, *__pos_in_candidates)) + return true; + return false; } /** @brief Corresponding sequential algorithm on a sequence. @@ -179,13 +180,16 @@ namespace __gnu_parallel * @param __begin2 Begin iterator of second sequence. * @param __pred Find predicate. */ template<typename _RAIter1, typename _RAIter2, - typename _Pred> + typename _Pred> std::pair<_RAIter1, _RAIter2> _M_sequential_algorithm(_RAIter1 __begin1, - _RAIter1 __end1, - _RAIter2 __begin2, _Pred __pred) - { return std::make_pair(find_first_of(__begin1, __end1, _M_begin, _M_end, __pred, - sequential_tag()), __begin2); } + _RAIter1 __end1, + _RAIter2 __begin2, _Pred __pred) + { + return std::make_pair( + find_first_of(__begin1, __end1, _M_begin, _M_end, __pred, + sequential_tag()), __begin2); + } }; } diff --git a/libstdc++-v3/include/parallel/for_each.h b/libstdc++-v3/include/parallel/for_each.h index 77162ed07c6..f1c9c23b8a5 100644 --- a/libstdc++-v3/include/parallel/for_each.h +++ b/libstdc++-v3/include/parallel/for_each.h @@ -56,41 +56,44 @@ namespace __gnu_parallel * @param __bound Maximum number of elements processed. * @param __parallelism_tag Parallelization method */ template<typename _IIter, typename _UserOp, - typename _Functionality, typename _Red, typename _Result> + typename _Functionality, typename _Red, typename _Result> _UserOp __for_each_template_random_access(_IIter __begin, _IIter __end, - _UserOp __user_op, - _Functionality& __functionality, - _Red __reduction, _Result __reduction_start, - _Result& __output, typename - std::iterator_traits<_IIter>:: - difference_type __bound, - _Parallelism __parallelism_tag) + _UserOp __user_op, + _Functionality& __functionality, + _Red __reduction, + _Result __reduction_start, + _Result& __output, typename + std::iterator_traits<_IIter>:: + difference_type __bound, + _Parallelism __parallelism_tag) { if (__parallelism_tag == parallel_unbalanced) - return for_each_template_random_access_ed(__begin, __end, __user_op, - __functionality, __reduction, - __reduction_start, - __output, __bound); + return for_each_template_random_access_ed(__begin, __end, __user_op, + __functionality, __reduction, + __reduction_start, + __output, __bound); else if (__parallelism_tag == parallel_omp_loop) - return for_each_template_random_access_omp_loop(__begin, __end, __user_op, - __functionality, - __reduction, - __reduction_start, - __output, __bound); + return for_each_template_random_access_omp_loop( + __begin, __end, __user_op, + __functionality, + __reduction, + __reduction_start, + __output, __bound); else if (__parallelism_tag == parallel_omp_loop_static) - return for_each_template_random_access_omp_loop(__begin, __end, __user_op, - __functionality, - __reduction, - __reduction_start, - __output, __bound); - else //e. g. parallel_balanced - return for_each_template_random_access_workstealing(__begin, __end, - __user_op, - __functionality, - __reduction, - __reduction_start, - __output, __bound); + return for_each_template_random_access_omp_loop( + __begin, __end, __user_op, + __functionality, + __reduction, + __reduction_start, + __output, __bound); + else //e. g. parallel_balanced + return for_each_template_random_access_workstealing(__begin, __end, + __user_op, + __functionality, + __reduction, + __reduction_start, + __output, __bound); } } diff --git a/libstdc++-v3/include/parallel/for_each_selectors.h b/libstdc++-v3/include/parallel/for_each_selectors.h index ae12c945d3c..9b3bb6b5703 100644 --- a/libstdc++-v3/include/parallel/for_each_selectors.h +++ b/libstdc++-v3/include/parallel/for_each_selectors.h @@ -59,10 +59,10 @@ namespace __gnu_parallel template<typename _Op> bool operator()(_Op& __o, _It __i) - { - __o(*__i); - return true; - } + { + __o(*__i); + return true; + } }; /** @brief std::generate() selector. */ @@ -76,9 +76,9 @@ namespace __gnu_parallel bool operator()(_Op& __o, _It __i) { - *__i = __o(); - return true; - } + *__i = __o(); + return true; + } }; /** @brief std::fill() selector. */ @@ -91,10 +91,10 @@ namespace __gnu_parallel template<typename Val> bool operator()(Val& __v, _It __i) - { - *__i = __v; - return true; - } + { + *__i = __v; + return true; + } }; /** @brief std::transform() __selector, one input sequence variant. */ @@ -107,10 +107,10 @@ namespace __gnu_parallel template<typename _Op> bool operator()(_Op& __o, _It __i) - { - *__i.second = __o(*__i.first); - return true; - } + { + *__i.second = __o(*__i.first); + return true; + } }; /** @brief std::transform() __selector, two input sequences variant. */ @@ -123,10 +123,10 @@ namespace __gnu_parallel template<typename _Op> bool operator()(_Op& __o, _It __i) - { - *__i._M_third = __o(*__i._M_first, *__i._M_second); - return true; - } + { + *__i._M_third = __o(*__i._M_first, *__i._M_second); + return true; + } }; /** @brief std::replace() selector. */ @@ -147,9 +147,9 @@ namespace __gnu_parallel bool operator()(_Tp& __v, _It __i) { - if (*__i == __v) - *__i = __new_val; - return true; + if (*__i == __v) + *__i = __new_val; + return true; } }; @@ -171,9 +171,9 @@ namespace __gnu_parallel bool operator()(_Op& __o, _It __i) { - if (__o(*__i)) - *__i = __new_val; - return true; + if (__o(*__i)) + *__i = __new_val; + return true; } }; @@ -188,7 +188,7 @@ namespace __gnu_parallel template<typename Val> _Diff operator()(Val& __v, _It __i) - { return (__v == *__i) ? 1 : 0; } + { return (__v == *__i) ? 1 : 0; } }; /** @brief std::count_if () selector. */ @@ -202,7 +202,7 @@ namespace __gnu_parallel template<typename _Op> _Diff operator()(_Op& __o, _It __i) - { return (__o(*__i)) ? 1 : 0; } + { return (__o(*__i)) ? 1 : 0; } }; /** @brief std::accumulate() selector. */ @@ -214,8 +214,9 @@ namespace __gnu_parallel * @param __i iterator referencing object. * @return The current value. */ template<typename _Op> - typename std::iterator_traits<_It>::value_type operator()(_Op __o, _It __i) - { return *__i; } + typename std::iterator_traits<_It>::value_type + operator()(_Op __o, _It __i) + { return *__i; } }; /** @brief std::inner_product() selector. */ @@ -242,11 +243,11 @@ namespace __gnu_parallel template<typename _Op> _Tp operator()(_Op __mult, _It __current) - { - typename std::iterator_traits<_It>::difference_type __position - = __current - __begin1_iterator; - return __mult(*__current, *(begin2_iterator + __position)); - } + { + typename std::iterator_traits<_It>::difference_type __position + = __current - __begin1_iterator; + return __mult(*__current, *(begin2_iterator + __position)); + } }; /** @brief Selector that just returns the passed iterator. */ @@ -260,24 +261,25 @@ namespace __gnu_parallel template<typename _Op> _It operator()(_Op __o, _It __i) - { return __i; } + { return __i; } }; /** @brief Selector that returns the difference between two adjacent * __elements. */ template<typename _It> - struct __adjacent_difference_selector : public __generic_for_each_selector<_It> + struct __adjacent_difference_selector : + public __generic_for_each_selector<_It> { template<typename _Op> bool operator()(_Op& __o, _It __i) - { - typename _It::first_type __go_back_one = __i.first; - --__go_back_one; - *__i.__second = __o(*__i.__first, *__go_back_one); - return true; - } + { + typename _It::first_type __go_back_one = __i.first; + --__go_back_one; + *__i.__second = __o(*__i.__first, *__go_back_one); + return true; + } }; // XXX move into type_traits? @@ -315,10 +317,10 @@ namespace __gnu_parallel _It operator()(_It __x, _It __y) { - if (__comp(*__x, *__y)) - return __x; - else - return __y; + if (__comp(*__x, *__y)) + return __x; + else + return __y; } }; @@ -334,10 +336,10 @@ namespace __gnu_parallel _It operator()(_It __x, _It __y) { - if (__comp(*__x, *__y)) - return __y; - else - return __x; + if (__comp(*__x, *__y)) + return __y; + else + return __x; } }; @@ -353,7 +355,7 @@ namespace __gnu_parallel template<typename _Result, typename _Addend> _Result operator()(const _Result& __x, const _Addend& __y) - { return __binop(__x, __y); } + { return __binop(__x, __y); } }; } diff --git a/libstdc++-v3/include/parallel/iterator.h b/libstdc++-v3/include/parallel/iterator.h index c49ade2ca75..013855076f4 100644 --- a/libstdc++-v3/include/parallel/iterator.h +++ b/libstdc++-v3/include/parallel/iterator.h @@ -40,7 +40,8 @@ namespace __gnu_parallel /** @brief A pair of iterators. The usual iterator operations are * applied to both child iterators. */ - template<typename _Iterator1, typename _Iterator2, typename _IteratorCategory> + template<typename _Iterator1, typename _Iterator2, + typename _IteratorCategory> class _IteratorPair : public std::pair<_Iterator1, _Iterator2> { private: @@ -57,16 +58,16 @@ namespace __gnu_parallel _IteratorPair() { } - _IteratorPair(const _Iterator1& __first, const _Iterator2& __second) + _IteratorPair(const _Iterator1& __first, const _Iterator2& __second) : _Base(__first, __second) { } // Pre-increment operator. _IteratorPair& operator++() { - ++_Base::first; - ++_Base::second; - return *this; + ++_Base::first; + ++_Base::second; + return *this; } // Post-increment operator. @@ -78,9 +79,9 @@ namespace __gnu_parallel _IteratorPair& operator--() { - --_Base::first; - --_Base::second; - return *this; + --_Base::first; + --_Base::second; + return *this; } // Post-decrement operator. @@ -95,14 +96,15 @@ namespace __gnu_parallel _IteratorPair& operator=(const _IteratorPair& __other) { - _Base::first = __other.first; - _Base::second = __other.second; - return *this; + _Base::first = __other.first; + _Base::second = __other.second; + return *this; } _IteratorPair operator+(difference_type __delta) const - { return _IteratorPair(_Base::first + __delta, _Base::second + __delta); } + { return _IteratorPair(_Base::first + __delta, _Base::second + __delta); + } difference_type operator-(const _IteratorPair& __other) const @@ -114,7 +116,7 @@ namespace __gnu_parallel applied to all three child iterators. */ template<typename _Iterator1, typename _Iterator2, typename _Iterator3, - typename _IteratorCategory> + typename _IteratorCategory> class _IteratorTriple { public: @@ -132,21 +134,21 @@ namespace __gnu_parallel _IteratorTriple() { } _IteratorTriple(const _Iterator1& __first, const _Iterator2& __second, - const _Iterator3& __third) + const _Iterator3& __third) { - _M_first = __first; - _M_second = __second; - _M_third = __third; + _M_first = __first; + _M_second = __second; + _M_third = __third; } // Pre-increment operator. _IteratorTriple& operator++() { - ++_M_first; - ++_M_second; - ++_M_third; - return *this; + ++_M_first; + ++_M_second; + ++_M_third; + return *this; } // Post-increment operator. @@ -158,10 +160,10 @@ namespace __gnu_parallel _IteratorTriple& operator--() { - --_M_first; - --_M_second; - --_M_third; - return *this; + --_M_first; + --_M_second; + --_M_third; + return *this; } // Post-decrement operator. @@ -176,15 +178,16 @@ namespace __gnu_parallel _IteratorTriple& operator=(const _IteratorTriple& __other) { - _M_first = __other._M_first; - _M_second = __other._M_second; - _M_third = __other._M_third; - return *this; + _M_first = __other._M_first; + _M_second = __other._M_second; + _M_third = __other._M_third; + return *this; } _IteratorTriple operator+(difference_type __delta) const - { return _IteratorTriple(_M_first + __delta, _M_second + __delta, _M_third + __delta); } + { return _IteratorTriple(_M_first + __delta, _M_second + __delta, + _M_third + __delta); } difference_type operator-(const _IteratorTriple& __other) const diff --git a/libstdc++-v3/include/parallel/list_partition.h b/libstdc++-v3/include/parallel/list_partition.h index 5065a86f9a0..7eed96b4a0d 100644 --- a/libstdc++-v3/include/parallel/list_partition.h +++ b/libstdc++-v3/include/parallel/list_partition.h @@ -48,17 +48,17 @@ namespace __gnu_parallel template<typename _IIter> void __shrink_and_double(std::vector<_IIter>& __os_starts, - size_t& __count_to_two, size_t& __range_length, - const bool __make_twice) + size_t& __count_to_two, size_t& __range_length, + const bool __make_twice) { ++__count_to_two; if (not __make_twice or __count_to_two < 2) - __shrink(__os_starts, __count_to_two, __range_length); + __shrink(__os_starts, __count_to_two, __range_length); else - { - __os_starts.resize((__os_starts.size() - 1) * 2 + 1); - __count_to_two = 0; - } + { + __os_starts.resize((__os_starts.size() - 1) * 2 + 1); + __count_to_two = 0; + } } /** @brief Combines two ranges into one and thus halves the number of ranges. @@ -68,11 +68,11 @@ namespace __gnu_parallel template<typename _IIter> void __shrink(std::vector<_IIter>& __os_starts, size_t& __count_to_two, - size_t& __range_length) + size_t& __range_length) { for (typename std::vector<_IIter>::size_type __i = 0; - __i <= (__os_starts.size() / 2); ++__i) - __os_starts[__i] = __os_starts[__i * 2]; + __i <= (__os_starts.size() / 2); ++__i) + __os_starts[__i] = __os_starts[__i * 2]; __range_length *= 2; } @@ -98,17 +98,17 @@ namespace __gnu_parallel template<typename _IIter, typename _FunctorType> size_t list_partition(const _IIter __begin, const _IIter __end, - _IIter* __starts, size_t* __lengths, const int __num_parts, - _FunctorType& __f, int __oversampling = 0) + _IIter* __starts, size_t* __lengths, const int __num_parts, + _FunctorType& __f, int __oversampling = 0) { bool __make_twice = false; // The resizing algorithm is chosen according to the oversampling factor. if (__oversampling == 0) - { - __make_twice = true; - __oversampling = 1; - } + { + __make_twice = true; + __oversampling = 1; + } std::vector<_IIter> __os_starts(2 * __oversampling * __num_parts + 1); @@ -119,27 +119,28 @@ namespace __gnu_parallel size_t __range_length = 1; size_t __count_to_two = 0; while (__it != __end) - { - __cur = __next; - for (; __cur < __os_starts.size() and __it != __end; ++__cur) - { - for (__dist_limit += __range_length; - __dist < __dist_limit and __it != __end; ++__dist) - { - __f(__it); - ++__it; - } - __os_starts[__cur] = __it; - } - - // Must compare for end and not __cur < __os_starts.size() , because - // __cur could be == __os_starts.size() as well - if (__it == __end) - break; - - __shrink_and_double(__os_starts, __count_to_two, __range_length, __make_twice); - __next = __os_starts.size() / 2 + 1; - } + { + __cur = __next; + for (; __cur < __os_starts.size() and __it != __end; ++__cur) + { + for (__dist_limit += __range_length; + __dist < __dist_limit and __it != __end; ++__dist) + { + __f(__it); + ++__it; + } + __os_starts[__cur] = __it; + } + + // Must compare for end and not __cur < __os_starts.size() , because + // __cur could be == __os_starts.size() as well + if (__it == __end) + break; + + __shrink_and_double(__os_starts, __count_to_two, __range_length, + __make_twice); + __next = __os_starts.size() / 2 + 1; + } // Calculation of the parts (one must be extracted from __current // because the partition beginning at __end, consists only of @@ -152,19 +153,20 @@ namespace __gnu_parallel // Smallest partitions. for (int __i = 1; __i < (__num_parts + 1 - __size_greater); ++__i) - { - __lengths[__i - 1] = __size_part * __range_length; - __index += __size_part; - __starts[__i] = __os_starts[__index]; - } + { + __lengths[__i - 1] = __size_part * __range_length; + __index += __size_part; + __starts[__i] = __os_starts[__index]; + } // Biggest partitions. - for (int __i = __num_parts + 1 - __size_greater; __i <= __num_parts; ++__i) - { - __lengths[__i - 1] = (__size_part+1) * __range_length; - __index += (__size_part+1); - __starts[__i] = __os_starts[__index]; - } + for (int __i = __num_parts + 1 - __size_greater; __i <= __num_parts; + ++__i) + { + __lengths[__i - 1] = (__size_part+1) * __range_length; + __index += (__size_part+1); + __starts[__i] = __os_starts[__index]; + } // Correction of the end size (the end iteration has not finished). __lengths[__num_parts - 1] -= (__dist_limit - __dist); diff --git a/libstdc++-v3/include/parallel/losertree.h b/libstdc++-v3/include/parallel/losertree.h index 33a4070e9a8..239aac8c057 100644 --- a/libstdc++-v3/include/parallel/losertree.h +++ b/libstdc++-v3/include/parallel/losertree.h @@ -106,7 +106,8 @@ public: _M_offset = _M_k; // Avoid default-constructing _M_losers[]._M_key - _M_losers = static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser))); + _M_losers + = static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser))); for (unsigned int __i = _M_ik - 1; __i < _M_k; ++__i) _M_losers[__i + _M_k]._M_sup = true; @@ -187,7 +188,7 @@ public: unsigned int __right = __init_winner (2 * __root + 1); if (_M_losers[__right]._M_sup || (!_M_losers[__left]._M_sup - && !_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key))) + && !_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key))) { // Left one is less or equal. _M_losers[__root] = _M_losers[__right]; @@ -223,7 +224,8 @@ public: for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2) { // The smaller one gets promoted, ties are broken by _M_source. - if ((_M_sup && (!_M_losers[__pos]._M_sup || _M_losers[__pos]._M_source < _M_source)) + if ((_M_sup && (!_M_losers[__pos]._M_sup + || _M_losers[__pos]._M_source < _M_source)) || (!_M_sup && !_M_losers[__pos]._M_sup && ((_M_comp(_M_losers[__pos]._M_key, _M_key)) || (!_M_comp(_M_key, _M_losers[__pos]._M_key) @@ -280,9 +282,9 @@ public: { unsigned int __left = __init_winner (2 * __root); unsigned int __right = __init_winner (2 * __root + 1); - if (_M_losers[__right]._M_sup || - (!_M_losers[__left]._M_sup - && !_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key))) + if (_M_losers[__right]._M_sup + || (!_M_losers[__left]._M_sup + && !_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key))) { // Left one is less or equal. _M_losers[__root] = _M_losers[__right]; @@ -320,7 +322,8 @@ public: for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2) { // The smaller one gets promoted. - if (_M_sup || (!_M_losers[__pos]._M_sup && _M_comp(_M_losers[__pos]._M_key, _M_key))) + if (_M_sup || (!_M_losers[__pos]._M_sup + && _M_comp(_M_losers[__pos]._M_key, _M_key))) { // The other one is smaller. std::swap(_M_losers[__pos]._M_sup, _M_sup); @@ -414,8 +417,9 @@ public: unsigned int __left = __init_winner (2 * __root); unsigned int __right = __init_winner (2 * __root + 1); if (_M_losers[__right]._M_sup - || (!_M_losers[__left]._M_sup && !_M_comp(*_M_losers[__right]._M_keyp, - *_M_losers[__left]._M_keyp))) + || (!_M_losers[__left]._M_sup + && !_M_comp(*_M_losers[__right]._M_keyp, + *_M_losers[__left]._M_keyp))) { // Left one is less or equal. _M_losers[__root] = _M_losers[__right]; @@ -445,7 +449,8 @@ public: for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2) { // The smaller one gets promoted, ties are broken by _M_source. - if ((_M_sup && (!_M_losers[__pos]._M_sup || _M_losers[__pos]._M_source < _M_source)) || + if ((_M_sup && (!_M_losers[__pos]._M_sup || + _M_losers[__pos]._M_source < _M_source)) || (!_M_sup && !_M_losers[__pos]._M_sup && ((_M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)) || (!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp) @@ -495,7 +500,8 @@ public: unsigned int __right = __init_winner (2 * __root + 1); if (_M_losers[__right]._M_sup || (!_M_losers[__left]._M_sup - && !_M_comp(*_M_losers[__right]._M_keyp, *_M_losers[__left]._M_keyp))) + && !_M_comp(*_M_losers[__right]._M_keyp, + *_M_losers[__left]._M_keyp))) { // Left one is less or equal. _M_losers[__root] = _M_losers[__right]; @@ -525,7 +531,8 @@ public: for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2) { // The smaller one gets promoted. - if (_M_sup || (!_M_losers[__pos]._M_sup && _M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp))) + if (_M_sup || (!_M_losers[__pos]._M_sup + && _M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp))) { // The other one is smaller. std::swap(_M_losers[__pos]._M_sup, _M_sup); @@ -576,7 +583,8 @@ public: _M_k = 1 << (__log2(_M_ik - 1) + 1); _M_offset = _M_k; // Avoid default-constructing _M_losers[]._M_key - _M_losers = static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser))); + _M_losers + = static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser))); for (unsigned int __i = _M_k + _M_ik - 1; __i < (2 * _M_k); ++__i) { @@ -677,7 +685,8 @@ public: { // The smaller one gets promoted, ties are broken by _M_source. if (_M_comp(_M_losers[__pos]._M_key, _M_key) - || (!_M_comp(_M_key, _M_losers[__pos]._M_key) && _M_losers[__pos]._M_source < _M_source)) + || (!_M_comp(_M_key, _M_losers[__pos]._M_key) + && _M_losers[__pos]._M_source < _M_source)) { // The other one is smaller. std::swap(_M_losers[__pos]._M_source, _M_source); @@ -914,7 +923,8 @@ public: { // The smaller one gets promoted, ties are broken by _M_source. if (_M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp) - || (!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp) && _M_losers[__pos]._M_source < _M_source)) + || (!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp) + && _M_losers[__pos]._M_source < _M_source)) { // The other one is smaller. std::swap(_M_losers[__pos]._M_source, _M_source); diff --git a/libstdc++-v3/include/parallel/merge.h b/libstdc++-v3/include/parallel/merge.h index 7b61ca692e8..b2d8996ae5a 100644 --- a/libstdc++-v3/include/parallel/merge.h +++ b/libstdc++-v3/include/parallel/merge.h @@ -51,36 +51,36 @@ namespace __gnu_parallel * @param __comp Comparator. * @return Output end iterator. */ template<typename _RAIter1, typename _RAIter2, - typename _OutputIterator, typename _DifferenceTp, - typename _Compare> + typename _OutputIterator, typename _DifferenceTp, + typename _Compare> _OutputIterator __merge_advance_usual(_RAIter1& __begin1, - _RAIter1 __end1, - _RAIter2& __begin2, - _RAIter2 __end2, _OutputIterator __target, - _DifferenceTp __max_length, _Compare __comp) + _RAIter1 __end1, + _RAIter2& __begin2, + _RAIter2 __end2, _OutputIterator __target, + _DifferenceTp __max_length, _Compare __comp) { typedef _DifferenceTp _DifferenceType; while (__begin1 != __end1 && __begin2 != __end2 && __max_length > 0) - { - // array1[__i1] < array0[i0] - if (__comp(*__begin2, *__begin1)) - *__target++ = *__begin2++; - else - *__target++ = *__begin1++; - --__max_length; - } + { + // array1[__i1] < array0[i0] + if (__comp(*__begin2, *__begin1)) + *__target++ = *__begin2++; + else + *__target++ = *__begin1++; + --__max_length; + } if (__begin1 != __end1) - { - __target = std::copy(__begin1, __begin1 + __max_length, __target); - __begin1 += __max_length; - } + { + __target = std::copy(__begin1, __begin1 + __max_length, __target); + __begin1 += __max_length; + } else - { - __target = std::copy(__begin2, __begin2 + __max_length, __target); - __begin2 += __max_length; - } + { + __target = std::copy(__begin2, __begin2 + __max_length, __target); + __begin2 += __max_length; + } return __target; } @@ -100,56 +100,56 @@ namespace __gnu_parallel * @param __comp Comparator. * @return Output end iterator. */ template<typename _RAIter1, typename _RAIter2, - typename _OutputIterator, typename _DifferenceTp, - typename _Compare> + typename _OutputIterator, typename _DifferenceTp, + typename _Compare> _OutputIterator __merge_advance_movc(_RAIter1& __begin1, - _RAIter1 __end1, - _RAIter2& __begin2, - _RAIter2 __end2, - _OutputIterator __target, - _DifferenceTp __max_length, _Compare __comp) + _RAIter1 __end1, + _RAIter2& __begin2, + _RAIter2 __end2, + _OutputIterator __target, + _DifferenceTp __max_length, _Compare __comp) { typedef _DifferenceTp _DifferenceType; typedef typename std::iterator_traits<_RAIter1>::value_type - value_type1; + value_type1; typedef typename std::iterator_traits<_RAIter2>::value_type - value_type2; + value_type2; #if _GLIBCXX_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(__max_length >= 0); #endif while (__begin1 != __end1 && __begin2 != __end2 && __max_length > 0) - { - _RAIter1 __next1 = __begin1 + 1; - _RAIter2 __next2 = __begin2 + 1; - value_type1 __element1 = *__begin1; - value_type2 __element2 = *__begin2; + { + _RAIter1 __next1 = __begin1 + 1; + _RAIter2 __next2 = __begin2 + 1; + value_type1 __element1 = *__begin1; + value_type2 __element2 = *__begin2; - if (__comp(__element2, __element1)) - { - __element1 = __element2; - __begin2 = __next2; - } - else - __begin1 = __next1; + if (__comp(__element2, __element1)) + { + __element1 = __element2; + __begin2 = __next2; + } + else + __begin1 = __next1; - *__target = __element1; + *__target = __element1; - ++__target; - --__max_length; - } + ++__target; + --__max_length; + } if (__begin1 != __end1) - { - __target = std::copy(__begin1, __begin1 + __max_length, __target); - __begin1 += __max_length; - } + { + __target = std::copy(__begin1, __begin1 + __max_length, __target); + __begin1 += __max_length; + } else - { - __target = std::copy(__begin2, __begin2 + __max_length, __target); - __begin2 += __max_length; - } + { + __target = std::copy(__begin2, __begin2 + __max_length, __target); + __begin2 += __max_length; + } return __target; } @@ -168,18 +168,18 @@ namespace __gnu_parallel * @param __comp Comparator. * @return Output end iterator. */ template<typename _RAIter1, typename _RAIter2, - typename _OutputIterator, typename _DifferenceTp, - typename _Compare> + typename _OutputIterator, typename _DifferenceTp, + typename _Compare> inline _OutputIterator __merge_advance(_RAIter1& __begin1, _RAIter1 __end1, - _RAIter2& __begin2, _RAIter2 __end2, - _OutputIterator __target, _DifferenceTp __max_length, - _Compare __comp) + _RAIter2& __begin2, _RAIter2 __end2, + _OutputIterator __target, _DifferenceTp __max_length, + _Compare __comp) { _GLIBCXX_CALL(__max_length) return __merge_advance_movc(__begin1, __end1, __begin2, __end2, __target, - __max_length, __comp); + __max_length, __comp); } /** @brief Merge routine fallback to sequential in case the @@ -193,19 +193,19 @@ namespace __gnu_parallel * @param __comp Comparator. * @return Output end iterator. */ template<typename _RAIter1, typename _RAIter2, - typename _RAIter3, typename _Compare> + typename _RAIter3, typename _Compare> inline _RAIter3 __parallel_merge_advance(_RAIter1& __begin1, - _RAIter1 __end1, - _RAIter2& __begin2, - // different iterators, parallel implementation - // not available - _RAIter2 __end2, - _RAIter3 __target, typename - std::iterator_traits<_RAIter1>:: - difference_type __max_length, _Compare __comp) + _RAIter1 __end1, + _RAIter2& __begin2, + // different iterators, parallel implementation + // not available + _RAIter2 __end2, + _RAIter3 __target, typename + std::iterator_traits<_RAIter1>:: + difference_type __max_length, _Compare __comp) { return __merge_advance(__begin1, __end1, __begin2, __end2, __target, - __max_length, __comp); } + __max_length, __comp); } /** @brief Parallel merge routine being able to merge only the @__c * __max_length smallest elements. @@ -223,28 +223,28 @@ namespace __gnu_parallel * @return Output end iterator. */ template<typename _RAIter1, typename _RAIter3, - typename _Compare> + typename _Compare> inline _RAIter3 __parallel_merge_advance(_RAIter1& __begin1, - _RAIter1 __end1, - _RAIter1& __begin2, - _RAIter1 __end2, - _RAIter3 __target, typename - std::iterator_traits<_RAIter1>:: - difference_type __max_length, _Compare __comp) + _RAIter1 __end1, + _RAIter1& __begin2, + _RAIter1 __end2, + _RAIter3 __target, typename + std::iterator_traits<_RAIter1>:: + difference_type __max_length, _Compare __comp) { typedef typename std::iterator_traits<_RAIter1>::value_type _ValueType; typedef typename std::iterator_traits<_RAIter1>:: - difference_type _DifferenceType1 /* == difference_type2 */; + difference_type _DifferenceType1 /* == difference_type2 */; typedef typename std::iterator_traits<_RAIter3>:: - difference_type _DifferenceType3; + difference_type _DifferenceType3; typedef typename std::pair<_RAIter1, _RAIter1> _IteratorPair; _IteratorPair - seqs[2] = { std::make_pair(__begin1, __end1), - std::make_pair(__begin2, __end2) }; + seqs[2] = { std::make_pair(__begin1, __end1), + std::make_pair(__begin2, __end2) }; _RAIter3 __target_end = parallel_multiway_merge < /* __stable = */ true, /* __sentinels = */ false>( @@ -256,6 +256,6 @@ namespace __gnu_parallel return __target_end; } -} //namespace __gnu_parallel +} //namespace __gnu_parallel #endif /* _GLIBCXX_PARALLEL_MERGE_H */ diff --git a/libstdc++-v3/include/parallel/multiseq_selection.h b/libstdc++-v3/include/parallel/multiseq_selection.h index 148b4ab65e4..539695fc766 100644 --- a/libstdc++-v3/include/parallel/multiseq_selection.h +++ b/libstdc++-v3/include/parallel/multiseq_selection.h @@ -53,7 +53,8 @@ namespace __gnu_parallel /** @brief Compare __a pair of types lexicographically, ascending. */ template<typename _T1, typename _T2, typename _Compare> class _Lexicographic - : public std::binary_function<std::pair<_T1, _T2>, std::pair<_T1, _T2>, bool> + : public std::binary_function< + std::pair<_T1, _T2>, std::pair<_T1, _T2>, bool> { private: _Compare& _M_comp; @@ -63,16 +64,16 @@ namespace __gnu_parallel bool operator()(const std::pair<_T1, _T2>& __p1, - const std::pair<_T1, _T2>& __p2) const + const std::pair<_T1, _T2>& __p2) const { - if (_M_comp(__p1.first, __p2.first)) - return true; + if (_M_comp(__p1.first, __p2.first)) + return true; - if (_M_comp(__p2.first, __p1.first)) - return false; + if (_M_comp(__p2.first, __p1.first)) + return false; - // Firsts are equal. - return __p1.second < __p2.second; + // Firsts are equal. + return __p1.second < __p2.second; } }; @@ -88,16 +89,16 @@ namespace __gnu_parallel bool operator()(const std::pair<_T1, _T2>& __p1, - const std::pair<_T1, _T2>& __p2) const + const std::pair<_T1, _T2>& __p2) const { - if (_M_comp(__p2.first, __p1.first)) - return true; + if (_M_comp(__p2.first, __p1.first)) + return true; - if (_M_comp(__p1.first, __p2.first)) - return false; + if (_M_comp(__p1.first, __p2.first)) + return false; - // Firsts are equal. - return __p2.second < __p1.second; + // Firsts are equal. + return __p2.second < __p1.second; } }; @@ -133,7 +134,7 @@ namespace __gnu_parallel typedef typename std::iterator_traits<_RanSeqs>::value_type::first_type _It; typedef typename std::iterator_traits<_It>::difference_type - _DifferenceType; + _DifferenceType; typedef typename std::iterator_traits<_It>::value_type _ValueType; _Lexicographic<_ValueType, int, _Compare> __lcomp(__comp); @@ -146,9 +147,11 @@ namespace __gnu_parallel for (int __i = 0; __i < __m; __i++) { - __N += std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second); + __N += std::distance(__begin_seqs[__i].first, + __begin_seqs[__i].second); _GLIBCXX_PARALLEL_ASSERT( - std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second) > 0); + std::distance(__begin_seqs[__i].first, + __begin_seqs[__i].second) > 0); } if (__rank == __N) @@ -172,10 +175,11 @@ namespace __gnu_parallel __ns[0] = std::distance(__begin_seqs[0].first, __begin_seqs[0].second); __nmax = __ns[0]; for (int __i = 0; __i < __m; __i++) - { - __ns[__i] = std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second); - __nmax = std::max(__nmax, __ns[__i]); - } + { + __ns[__i] = std::distance(__begin_seqs[__i].first, + __begin_seqs[__i].second); + __nmax = std::max(__nmax, __ns[__i]); + } __r = __log2(__nmax) + 1; @@ -187,10 +191,10 @@ namespace __gnu_parallel __N = __l * __m; for (int __i = 0; __i < __m; __i++) - { - __a[__i] = 0; - __b[__i] = __l; - } + { + __a[__i] = 0; + __b[__i] = __l; + } __n = __l / 2; // Invariants: @@ -202,124 +206,128 @@ namespace __gnu_parallel std::vector<std::pair<_ValueType, int> > __sample; for (int __i = 0; __i < __m; __i++) - if (__n < __ns[__i]) //__sequence long enough - __sample.push_back(std::make_pair(__S(__i)[__n], __i)); + if (__n < __ns[__i]) //__sequence long enough + __sample.push_back(std::make_pair(__S(__i)[__n], __i)); __gnu_sequential::sort(__sample.begin(), __sample.end(), __lcomp); - for (int __i = 0; __i < __m; __i++) //conceptual infinity - if (__n >= __ns[__i]) //__sequence too short, conceptual infinity - __sample.push_back(std::make_pair(__S(__i)[0] /*__dummy element*/, __i)); + for (int __i = 0; __i < __m; __i++) //conceptual infinity + if (__n >= __ns[__i]) //__sequence too short, conceptual infinity + __sample.push_back( + std::make_pair(__S(__i)[0] /*__dummy element*/, __i)); _DifferenceType localrank = __rank * __m / __N ; int __j; - for (__j = 0; __j < localrank && ((__n + 1) <= __ns[__sample[__j].second]); ++__j) - __a[__sample[__j].second] += __n + 1; + for (__j = 0; + __j < localrank && ((__n + 1) <= __ns[__sample[__j].second]); ++__j) + __a[__sample[__j].second] += __n + 1; for (; __j < __m; __j++) - __b[__sample[__j].second] -= __n + 1; + __b[__sample[__j].second] -= __n + 1; // Further refinement. while (__n > 0) - { - __n /= 2; - - int __lmax_seq = -1; // to avoid warning - const _ValueType* __lmax = NULL; // impossible to avoid the warning? - for (int __i = 0; __i < __m; __i++) - { - if (__a[__i] > 0) - { - if (!__lmax) - { - __lmax = &(__S(__i)[__a[__i] - 1]); - __lmax_seq = __i; - } - else - { - // Max, favor rear sequences. - if (!__comp(__S(__i)[__a[__i] - 1], *__lmax)) - { - __lmax = &(__S(__i)[__a[__i] - 1]); - __lmax_seq = __i; - } - } - } - } - - int __i; - for (__i = 0; __i < __m; __i++) - { - _DifferenceType __middle = (__b[__i] + __a[__i]) / 2; - if (__lmax && __middle < __ns[__i] && - __lcomp(std::make_pair(__S(__i)[__middle], __i), - std::make_pair(*__lmax, __lmax_seq))) - __a[__i] = std::min(__a[__i] + __n + 1, __ns[__i]); - else - __b[__i] -= __n + 1; - } - - _DifferenceType __leftsize = 0, __total = 0; - for (int __i = 0; __i < __m; __i++) - { - __leftsize += __a[__i] / (__n + 1); - __total += __l / (__n + 1); - } - - _DifferenceType __skew = static_cast<_DifferenceType> - (static_cast<uint64>(__total) * __rank / __N - __leftsize); - - if (__skew > 0) - { - // Move to the left, find smallest. - std::priority_queue<std::pair<_ValueType, int>, - std::vector<std::pair<_ValueType, int> >, - _LexicographicReverse<_ValueType, int, _Compare> > - __pq(__lrcomp); - - for (int __i = 0; __i < __m; __i++) - if (__b[__i] < __ns[__i]) - __pq.push(std::make_pair(__S(__i)[__b[__i]], __i)); - - for (; __skew != 0 && !__pq.empty(); --__skew) - { - int source = __pq.top().second; - __pq.pop(); - - __a[source] = std::min(__a[source] + __n + 1, __ns[source]); - __b[source] += __n + 1; - - if (__b[source] < __ns[source]) - __pq.push(std::make_pair(__S(source)[__b[source]], source)); - } - } - else if (__skew < 0) - { - // Move to the right, find greatest. - std::priority_queue<std::pair<_ValueType, int>, - std::vector<std::pair<_ValueType, int> >, - _Lexicographic<_ValueType, int, _Compare> > __pq(__lcomp); - - for (int __i = 0; __i < __m; __i++) - if (__a[__i] > 0) - __pq.push(std::make_pair(__S(__i)[__a[__i] - 1], __i)); - - for (; __skew != 0; ++__skew) - { - int source = __pq.top().second; - __pq.pop(); - - __a[source] -= __n + 1; - __b[source] -= __n + 1; - - if (__a[source] > 0) - __pq.push(std::make_pair(__S(source)[__a[source] - 1], source)); - } - } - } + { + __n /= 2; + + int __lmax_seq = -1; // to avoid warning + const _ValueType* __lmax = NULL; // impossible to avoid the warning? + for (int __i = 0; __i < __m; __i++) + { + if (__a[__i] > 0) + { + if (!__lmax) + { + __lmax = &(__S(__i)[__a[__i] - 1]); + __lmax_seq = __i; + } + else + { + // Max, favor rear sequences. + if (!__comp(__S(__i)[__a[__i] - 1], *__lmax)) + { + __lmax = &(__S(__i)[__a[__i] - 1]); + __lmax_seq = __i; + } + } + } + } + + int __i; + for (__i = 0; __i < __m; __i++) + { + _DifferenceType __middle = (__b[__i] + __a[__i]) / 2; + if (__lmax && __middle < __ns[__i] && + __lcomp(std::make_pair(__S(__i)[__middle], __i), + std::make_pair(*__lmax, __lmax_seq))) + __a[__i] = std::min(__a[__i] + __n + 1, __ns[__i]); + else + __b[__i] -= __n + 1; + } + + _DifferenceType __leftsize = 0, __total = 0; + for (int __i = 0; __i < __m; __i++) + { + __leftsize += __a[__i] / (__n + 1); + __total += __l / (__n + 1); + } + + _DifferenceType __skew = static_cast<_DifferenceType> + (static_cast<uint64>(__total) * __rank / __N - __leftsize); + + if (__skew > 0) + { + // Move to the left, find smallest. + std::priority_queue<std::pair<_ValueType, int>, + std::vector<std::pair<_ValueType, int> >, + _LexicographicReverse<_ValueType, int, _Compare> > + __pq(__lrcomp); + + for (int __i = 0; __i < __m; __i++) + if (__b[__i] < __ns[__i]) + __pq.push(std::make_pair(__S(__i)[__b[__i]], __i)); + + for (; __skew != 0 && !__pq.empty(); --__skew) + { + int source = __pq.top().second; + __pq.pop(); + + __a[source] = std::min(__a[source] + __n + 1, __ns[source]); + __b[source] += __n + 1; + + if (__b[source] < __ns[source]) + __pq.push( + std::make_pair(__S(source)[__b[source]], source)); + } + } + else if (__skew < 0) + { + // Move to the right, find greatest. + std::priority_queue<std::pair<_ValueType, int>, + std::vector<std::pair<_ValueType, int> >, + _Lexicographic<_ValueType, int, _Compare> > __pq(__lcomp); + + for (int __i = 0; __i < __m; __i++) + if (__a[__i] > 0) + __pq.push(std::make_pair(__S(__i)[__a[__i] - 1], __i)); + + for (; __skew != 0; ++__skew) + { + int source = __pq.top().second; + __pq.pop(); + + __a[source] -= __n + 1; + __b[source] -= __n + 1; + + if (__a[source] > 0) + __pq.push( + std::make_pair(__S(source)[__a[source] - 1], source)); + } + } + } // Postconditions: - // __a[__i] == __b[__i] in most cases, except when __a[__i] has been clamped - // because of having reached the boundary + // __a[__i] == __b[__i] in most cases, except when __a[__i] has been + // clamped because of having reached the boundary // Now return the result, calculate the offset. @@ -329,34 +337,34 @@ namespace __gnu_parallel _ValueType* __maxleft = NULL; _ValueType* __minright = NULL; for (int __i = 0; __i < __m; __i++) - { - if (__a[__i] > 0) - { - if (!__maxleft) - __maxleft = &(__S(__i)[__a[__i] - 1]); - else - { - // Max, favor rear sequences. - if (!__comp(__S(__i)[__a[__i] - 1], *__maxleft)) - __maxleft = &(__S(__i)[__a[__i] - 1]); - } - } - if (__b[__i] < __ns[__i]) - { - if (!__minright) - __minright = &(__S(__i)[__b[__i]]); - else - { - // Min, favor fore sequences. - if (__comp(__S(__i)[__b[__i]], *__minright)) - __minright = &(__S(__i)[__b[__i]]); - } - } - } + { + if (__a[__i] > 0) + { + if (!__maxleft) + __maxleft = &(__S(__i)[__a[__i] - 1]); + else + { + // Max, favor rear sequences. + if (!__comp(__S(__i)[__a[__i] - 1], *__maxleft)) + __maxleft = &(__S(__i)[__a[__i] - 1]); + } + } + if (__b[__i] < __ns[__i]) + { + if (!__minright) + __minright = &(__S(__i)[__b[__i]]); + else + { + // Min, favor fore sequences. + if (__comp(__S(__i)[__b[__i]], *__minright)) + __minright = &(__S(__i)[__b[__i]]); + } + } + } int __seq = 0; for (int __i = 0; __i < __m; __i++) - __begin_offsets[__i] = __S(__i) + __a[__i]; + __begin_offsets[__i] = __S(__i) + __a[__i]; delete[] __ns; delete[] __a; @@ -379,17 +387,18 @@ namespace __gnu_parallel * @param __comp The ordering functor, defaults to std::less. */ template<typename _Tp, typename _RanSeqs, typename _RankType, - typename _Compare> + typename _Compare> _Tp - multiseq_selection(_RanSeqs __begin_seqs, _RanSeqs __end_seqs, _RankType __rank, - _RankType& __offset, _Compare __comp = std::less<_Tp>()) + multiseq_selection(_RanSeqs __begin_seqs, _RanSeqs __end_seqs, + _RankType __rank, + _RankType& __offset, _Compare __comp = std::less<_Tp>()) { _GLIBCXX_CALL(__end_seqs - __begin_seqs) typedef typename std::iterator_traits<_RanSeqs>::value_type::first_type - _It; + _It; typedef typename std::iterator_traits<_It>::difference_type - _DifferenceType; + _DifferenceType; _Lexicographic<_Tp, int, _Compare> __lcomp(__comp); _LexicographicReverse<_Tp, int, _Compare> __lrcomp(__comp); @@ -401,13 +410,14 @@ namespace __gnu_parallel _DifferenceType __nmax, __n, __r; for (int __i = 0; __i < __m; __i++) - __N += std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second); + __N += std::distance(__begin_seqs[__i].first, + __begin_seqs[__i].second); if (__m == 0 || __N == 0 || __rank < 0 || __rank >= __N) - { - // _Result undefined when there is no data or __rank is outside bounds. - throw std::exception(); - } + { + // result undefined if there is no data or __rank is outside bounds + throw std::exception(); + } _DifferenceType* __ns = new _DifferenceType[__m]; @@ -418,10 +428,11 @@ namespace __gnu_parallel __ns[0] = std::distance(__begin_seqs[0].first, __begin_seqs[0].second); __nmax = __ns[0]; for (int __i = 0; __i < __m; ++__i) - { - __ns[__i] = std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second); - __nmax = std::max(__nmax, __ns[__i]); - } + { + __ns[__i] = std::distance(__begin_seqs[__i].first, + __begin_seqs[__i].second); + __nmax = std::max(__nmax, __ns[__i]); + } __r = __log2(__nmax) + 1; @@ -433,10 +444,10 @@ namespace __gnu_parallel __N = __l * __m; for (int __i = 0; __i < __m; ++__i) - { - __a[__i] = 0; - __b[__i] = __l; - } + { + __a[__i] = 0; + __b[__i] = __l; + } __n = __l / 2; // Invariants: @@ -448,115 +459,120 @@ namespace __gnu_parallel std::vector<std::pair<_Tp, int> > __sample; for (int __i = 0; __i < __m; __i++) - if (__n < __ns[__i]) - __sample.push_back(std::make_pair(__S(__i)[__n], __i)); + if (__n < __ns[__i]) + __sample.push_back(std::make_pair(__S(__i)[__n], __i)); __gnu_sequential::sort(__sample.begin(), __sample.end(), - __lcomp, sequential_tag()); + __lcomp, sequential_tag()); // Conceptual infinity. for (int __i = 0; __i < __m; __i++) - if (__n >= __ns[__i]) - __sample.push_back(std::make_pair(__S(__i)[0] /*__dummy element*/, __i)); + if (__n >= __ns[__i]) + __sample.push_back( + std::make_pair(__S(__i)[0] /*__dummy element*/, __i)); _DifferenceType localrank = __rank * __m / __N ; int __j; - for (__j = 0; __j < localrank && ((__n + 1) <= __ns[__sample[__j].second]); ++__j) - __a[__sample[__j].second] += __n + 1; + for (__j = 0; + __j < localrank && ((__n + 1) <= __ns[__sample[__j].second]); ++__j) + __a[__sample[__j].second] += __n + 1; for (; __j < __m; ++__j) - __b[__sample[__j].second] -= __n + 1; + __b[__sample[__j].second] -= __n + 1; // Further refinement. while (__n > 0) - { - __n /= 2; - - const _Tp* __lmax = NULL; - for (int __i = 0; __i < __m; ++__i) - { - if (__a[__i] > 0) - { - if (!__lmax) - __lmax = &(__S(__i)[__a[__i] - 1]); - else - { - if (__comp(*__lmax, __S(__i)[__a[__i] - 1])) //max - __lmax = &(__S(__i)[__a[__i] - 1]); - } - } - } - - int __i; - for (__i = 0; __i < __m; __i++) - { - _DifferenceType __middle = (__b[__i] + __a[__i]) / 2; - if (__lmax && __middle < __ns[__i] && __comp(__S(__i)[__middle], *__lmax)) - __a[__i] = std::min(__a[__i] + __n + 1, __ns[__i]); - else - __b[__i] -= __n + 1; - } - - _DifferenceType __leftsize = 0, __total = 0; - for (int __i = 0; __i < __m; ++__i) - { - __leftsize += __a[__i] / (__n + 1); - __total += __l / (__n + 1); - } - - _DifferenceType __skew = ((unsigned long long)__total * __rank / __N - - __leftsize); - - if (__skew > 0) - { - // Move to the left, find smallest. - std::priority_queue<std::pair<_Tp, int>, - std::vector<std::pair<_Tp, int> >, - _LexicographicReverse<_Tp, int, _Compare> > __pq(__lrcomp); - - for (int __i = 0; __i < __m; ++__i) - if (__b[__i] < __ns[__i]) - __pq.push(std::make_pair(__S(__i)[__b[__i]], __i)); - - for (; __skew != 0 && !__pq.empty(); --__skew) - { - int source = __pq.top().second; - __pq.pop(); - - __a[source] = std::min(__a[source] + __n + 1, __ns[source]); - __b[source] += __n + 1; - - if (__b[source] < __ns[source]) - __pq.push(std::make_pair(__S(source)[__b[source]], source)); - } - } - else if (__skew < 0) - { - // Move to the right, find greatest. - std::priority_queue<std::pair<_Tp, int>, - std::vector<std::pair<_Tp, int> >, - _Lexicographic<_Tp, int, _Compare> > __pq(__lcomp); - - for (int __i = 0; __i < __m; ++__i) - if (__a[__i] > 0) - __pq.push(std::make_pair(__S(__i)[__a[__i] - 1], __i)); - - for (; __skew != 0; ++__skew) - { - int source = __pq.top().second; - __pq.pop(); - - __a[source] -= __n + 1; - __b[source] -= __n + 1; - - if (__a[source] > 0) - __pq.push(std::make_pair(__S(source)[__a[source] - 1], source)); - } - } - } + { + __n /= 2; + + const _Tp* __lmax = NULL; + for (int __i = 0; __i < __m; ++__i) + { + if (__a[__i] > 0) + { + if (!__lmax) + __lmax = &(__S(__i)[__a[__i] - 1]); + else + { + if (__comp(*__lmax, __S(__i)[__a[__i] - 1])) //max + __lmax = &(__S(__i)[__a[__i] - 1]); + } + } + } + + int __i; + for (__i = 0; __i < __m; __i++) + { + _DifferenceType __middle = (__b[__i] + __a[__i]) / 2; + if (__lmax && __middle < __ns[__i] + && __comp(__S(__i)[__middle], *__lmax)) + __a[__i] = std::min(__a[__i] + __n + 1, __ns[__i]); + else + __b[__i] -= __n + 1; + } + + _DifferenceType __leftsize = 0, __total = 0; + for (int __i = 0; __i < __m; ++__i) + { + __leftsize += __a[__i] / (__n + 1); + __total += __l / (__n + 1); + } + + _DifferenceType __skew = ((unsigned long long)__total * __rank / __N + - __leftsize); + + if (__skew > 0) + { + // Move to the left, find smallest. + std::priority_queue<std::pair<_Tp, int>, + std::vector<std::pair<_Tp, int> >, + _LexicographicReverse<_Tp, int, _Compare> > __pq(__lrcomp); + + for (int __i = 0; __i < __m; ++__i) + if (__b[__i] < __ns[__i]) + __pq.push(std::make_pair(__S(__i)[__b[__i]], __i)); + + for (; __skew != 0 && !__pq.empty(); --__skew) + { + int source = __pq.top().second; + __pq.pop(); + + __a[source] = std::min(__a[source] + __n + 1, __ns[source]); + __b[source] += __n + 1; + + if (__b[source] < __ns[source]) + __pq.push( + std::make_pair(__S(source)[__b[source]], source)); + } + } + else if (__skew < 0) + { + // Move to the right, find greatest. + std::priority_queue<std::pair<_Tp, int>, + std::vector<std::pair<_Tp, int> >, + _Lexicographic<_Tp, int, _Compare> > __pq(__lcomp); + + for (int __i = 0; __i < __m; ++__i) + if (__a[__i] > 0) + __pq.push(std::make_pair(__S(__i)[__a[__i] - 1], __i)); + + for (; __skew != 0; ++__skew) + { + int source = __pq.top().second; + __pq.pop(); + + __a[source] -= __n + 1; + __b[source] -= __n + 1; + + if (__a[source] > 0) + __pq.push( + std::make_pair(__S(source)[__a[source] - 1], source)); + } + } + } // Postconditions: - // __a[__i] == __b[__i] in most cases, except when __a[__i] has been clamped - // because of having reached the boundary + // __a[__i] == __b[__i] in most cases, except when __a[__i] has been + // clamped because of having reached the boundary // Now return the result, calculate the offset. @@ -568,57 +584,58 @@ namespace __gnu_parallel // Impossible to avoid the warning? _Tp __maxleft, __minright; for (int __i = 0; __i < __m; ++__i) - { - if (__a[__i] > 0) - { - if (!__maxleftset) - { - __maxleft = __S(__i)[__a[__i] - 1]; - __maxleftset = true; - } - else - { - // Max. - if (__comp(__maxleft, __S(__i)[__a[__i] - 1])) - __maxleft = __S(__i)[__a[__i] - 1]; - } - } - if (__b[__i] < __ns[__i]) - { - if (!__minrightset) - { - __minright = __S(__i)[__b[__i]]; - __minrightset = true; - } - else - { - // Min. - if (__comp(__S(__i)[__b[__i]], __minright)) - __minright = __S(__i)[__b[__i]]; - } - } + { + if (__a[__i] > 0) + { + if (!__maxleftset) + { + __maxleft = __S(__i)[__a[__i] - 1]; + __maxleftset = true; + } + else + { + // Max. + if (__comp(__maxleft, __S(__i)[__a[__i] - 1])) + __maxleft = __S(__i)[__a[__i] - 1]; + } + } + if (__b[__i] < __ns[__i]) + { + if (!__minrightset) + { + __minright = __S(__i)[__b[__i]]; + __minrightset = true; + } + else + { + // Min. + if (__comp(__S(__i)[__b[__i]], __minright)) + __minright = __S(__i)[__b[__i]]; + } + } } // Minright is the splitter, in any case. if (!__maxleftset || __comp(__minright, __maxleft)) - { - // Good luck, everything is split unambiguously. - __offset = 0; - } + { + // Good luck, everything is split unambiguously. + __offset = 0; + } else - { - // We have to calculate an offset. - __offset = 0; - - for (int __i = 0; __i < __m; ++__i) - { - _DifferenceType lb = std::lower_bound(__S(__i), __S(__i) + __ns[__i], - __minright, - __comp) - __S(__i); - __offset += __a[__i] - lb; - } - } + { + // We have to calculate an offset. + __offset = 0; + + for (int __i = 0; __i < __m; ++__i) + { + _DifferenceType lb + = std::lower_bound(__S(__i), __S(__i) + __ns[__i], + __minright, + __comp) - __S(__i); + __offset += __a[__i] - lb; + } + } delete[] __ns; delete[] __a; diff --git a/libstdc++-v3/include/parallel/multiway_merge.h b/libstdc++-v3/include/parallel/multiway_merge.h index 808caf20999..b5540e71426 100644 --- a/libstdc++-v3/include/parallel/multiway_merge.h +++ b/libstdc++-v3/include/parallel/multiway_merge.h @@ -144,11 +144,11 @@ template<typename _RAIter, typename _Compare> operator<(_GuardedIterator<_RAIter, _Compare>& __bi1, _GuardedIterator<_RAIter, _Compare>& __bi2) { - if (__bi1._M_current == __bi1._M_end) //__bi1 is sup - return __bi2._M_current == __bi2._M_end; //__bi2 is not sup - if (__bi2._M_current == __bi2._M_end) //__bi2 is sup + if (__bi1._M_current == __bi1._M_end) //__bi1 is sup + return __bi2._M_current == __bi2._M_end; //__bi2 is not sup + if (__bi2._M_current == __bi2._M_end) //__bi2 is sup return true; - return (__bi1.__comp)(*__bi1, *__bi2); //normal compare + return (__bi1.__comp)(*__bi1, *__bi2); //normal compare } /** @brief Compare two elements referenced by guarded iterators. @@ -160,11 +160,11 @@ template<typename _RAIter, typename _Compare> operator<=(_GuardedIterator<_RAIter, _Compare>& __bi1, _GuardedIterator<_RAIter, _Compare>& __bi2) { - if (__bi2._M_current == __bi2._M_end) //__bi1 is sup - return __bi1._M_current != __bi1._M_end; //__bi2 is not sup - if (__bi1._M_current == __bi1._M_end) //__bi2 is sup + if (__bi2._M_current == __bi2._M_end) //__bi1 is sup + return __bi1._M_current != __bi1._M_end; //__bi2 is not sup + if (__bi1._M_current == __bi1._M_end) //__bi2 is sup return false; - return !(__bi1.__comp)(*__bi2, *__bi1); //normal compare + return !(__bi1.__comp)(*__bi2, *__bi1); //normal compare } template<typename _RAIter, typename _Compare> @@ -282,10 +282,10 @@ template<typename _RAIter, typename _Compare> * @return End iterator of output sequence. */ template<template<typename RAI, typename C> class iterator, - typename _RAIterIterator, - typename _RAIter3, - typename _DifferenceTp, - typename _Compare> + typename _RAIterIterator, + typename _RAIter3, + typename _DifferenceTp, + typename _Compare> _RAIter3 multiway_merge_3_variant( _RAIterIterator __seqs_begin, @@ -402,10 +402,10 @@ template<template<typename RAI, typename C> class iterator, * @return End iterator of output sequence. */ template<template<typename RAI, typename C> class iterator, - typename _RAIterIterator, - typename _RAIter3, - typename _DifferenceTp, - typename _Compare> + typename _RAIterIterator, + typename _RAIter3, + typename _DifferenceTp, + typename _Compare> _RAIter3 multiway_merge_4_variant(_RAIterIterator __seqs_begin, _RAIterIterator __seqs_end, @@ -427,10 +427,10 @@ template<template<typename RAI, typename C> class iterator, __seq2(__seqs_begin[2].first, __seqs_begin[2].second, __comp), __seq3(__seqs_begin[3].first, __seqs_begin[3].second, __comp); -#define _GLIBCXX_PARALLEL_DECISION(__a,__b,__c,d) { \ - if (__seq ## d < __seq ## __a) goto __s ## d ## __a ## __b ## __c; \ - if (__seq ## d < __seq ## __b) goto __s ## __a ## d ## __b ## __c; \ - if (__seq ## d < __seq ## __c) goto __s ## __a ## __b ## d ## __c; \ +#define _GLIBCXX_PARALLEL_DECISION(__a,__b,__c,d) { \ + if (__seq ## d < __seq ## __a) goto __s ## d ## __a ## __b ## __c; \ + if (__seq ## d < __seq ## __b) goto __s ## __a ## d ## __b ## __c; \ + if (__seq ## d < __seq ## __c) goto __s ## __a ## __b ## d ## __c; \ goto __s ## __a ## __b ## __c ## d; } if (__seq0 <= __seq1) @@ -456,16 +456,16 @@ template<template<typename RAI, typename C> class iterator, _GLIBCXX_PARALLEL_DECISION(2,1,0,3) } -#define _GLIBCXX_PARALLEL_MERGE_4_CASE(__a,__b,__c,d,c0,c1,c2) \ - __s ## __a ## __b ## __c ## d: \ - if (__length == 0) goto finish; \ - *__target = *__seq ## __a; \ - ++__target; \ - --__length; \ - ++__seq ## __a; \ - if (__seq ## __a c0 __seq ## __b) goto __s ## __a ## __b ## __c ## d; \ - if (__seq ## __a c1 __seq ## __c) goto __s ## __b ## __a ## __c ## d; \ - if (__seq ## __a c2 __seq ## d) goto __s ## __b ## __c ## __a ## d; \ +#define _GLIBCXX_PARALLEL_MERGE_4_CASE(__a,__b,__c,d,c0,c1,c2) \ + __s ## __a ## __b ## __c ## d: \ + if (__length == 0) goto finish; \ + *__target = *__seq ## __a; \ + ++__target; \ + --__length; \ + ++__seq ## __a; \ + if (__seq ## __a c0 __seq ## __b) goto __s ## __a ## __b ## __c ## d; \ + if (__seq ## __a c1 __seq ## __c) goto __s ## __b ## __a ## __c ## d; \ + if (__seq ## __a c2 __seq ## d) goto __s ## __b ## __c ## __a ## d; \ goto __s ## __b ## __c ## d ## __a; _GLIBCXX_PARALLEL_MERGE_4_CASE(0, 1, 2, 3, <=, <=, <=); @@ -526,10 +526,10 @@ template<template<typename RAI, typename C> class iterator, * @return End iterator of output sequence. */ template<typename LT, - typename _RAIterIterator, - typename _RAIter3, - typename _DifferenceTp, - typename _Compare> + typename _RAIterIterator, + typename _RAIter3, + typename _DifferenceTp, + typename _Compare> _RAIter3 multiway_merge_loser_tree(_RAIterIterator __seqs_begin, _RAIterIterator __seqs_end, @@ -638,7 +638,8 @@ template<typename LT, for (int __t = 0; __t < __k; ++__t) { #if _GLIBCXX_ASSERTIONS - _GLIBCXX_PARALLEL_ASSERT(__seqs_begin[__t].first != __seqs_begin[__t].second); + _GLIBCXX_PARALLEL_ASSERT(__seqs_begin[__t].first + != __seqs_begin[__t].second); #endif __lt.__insert_start(*__seqs_begin[__t].first, __t, false); } @@ -914,7 +915,8 @@ struct __multiway_merge_k_variant_sentinel_switch _LoserTreeTraits<_ValueType>::_M_use_pointer , LoserTreePointerUnguarded<__stable, _ValueType, _Compare> , _LoserTreeUnguarded<__stable, _ValueType, _Compare> - >::__type>(__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp); + >::__type>( + __seqs_begin, __seqs_end, __target, __sentinel, __length, __comp); } }; @@ -997,7 +999,8 @@ template< #if _GLIBCXX_ASSERTIONS for (_RAIterIterator __s = __seqs_begin; __s != __seqs_end; ++__s) { - _GLIBCXX_PARALLEL_ASSERT(__is_sorted((*__s).first, (*__s).second, __comp)); + _GLIBCXX_PARALLEL_ASSERT( + __is_sorted((*__s).first, (*__s).second, __comp)); } #endif @@ -1053,11 +1056,13 @@ template< , _RAIterIterator , _RAIter3 , _DifferenceTp - , _Compare>()(__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp); + , _Compare>()(__seqs_begin, __seqs_end, __target, __sentinel, + __length, __comp); break; } #if _GLIBCXX_ASSERTIONS - _GLIBCXX_PARALLEL_ASSERT(__is_sorted(__target, __target + __length, __comp)); + _GLIBCXX_PARALLEL_ASSERT( + __is_sorted(__target, __target + __length, __comp)); #endif return __return_target; @@ -1163,7 +1168,8 @@ void multiway_merge_sampling_splitting( - __seqs_begin[__seq].first; else // Absolute end. - __pieces[__slab][__seq].second = _GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__seq]); + __pieces[__slab][__seq].second + = _GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__seq]); } ::operator delete(__samples); } @@ -1379,7 +1385,8 @@ template< } // parallel #if _GLIBCXX_ASSERTIONS - _GLIBCXX_PARALLEL_ASSERT(__is_sorted(__target, __target + __length, __comp)); + _GLIBCXX_PARALLEL_ASSERT( + __is_sorted(__target, __target + __length, __comp)); #endif __k = 0; @@ -1490,7 +1497,8 @@ multiway_merge(_RAIterPairIterator __seqs_begin // Execute multiway merge *sequentially*. return __sequential_multiway_merge </* __stable = */ false, /* __sentinels = */ false> - (__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp); + (__seqs_begin, __seqs_end, __target, + *(__seqs_begin->second), __length, __comp); } // public interface @@ -1528,11 +1536,13 @@ multiway_merge(_RAIterPairIterator __seqs_begin multiway_merge_exact_splitting</* __stable = */ false, typename std::iterator_traits<_RAIterPairIterator> ::value_type*, _Compare, _DifferenceTp>, - static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads()); + static_cast<_DifferenceType>(__length), __comp, + __tag.__get_num_threads()); else return __sequential_multiway_merge </* __stable = */ false, /* __sentinels = */ false>( - __seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp); + __seqs_begin, __seqs_end, __target, *(__seqs_begin->second), + __length, __comp); } // public interface @@ -1571,7 +1581,8 @@ multiway_merge(_RAIterPairIterator __seqs_begin multiway_merge_exact_splitting</* __stable = */ false, typename std::iterator_traits<_RAIterPairIterator> ::value_type*, _Compare, _DifferenceTp>, - static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads()); + static_cast<_DifferenceType>(__length), __comp, + __tag.__get_num_threads()); else return __sequential_multiway_merge </* __stable = */ false, /* __sentinels = */ false>( @@ -1637,7 +1648,8 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin // Execute multiway merge *sequentially*. return __sequential_multiway_merge </* __stable = */ true, /* __sentinels = */ false> - (__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp); + (__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, + __comp); } // public interface @@ -1676,7 +1688,8 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin multiway_merge_exact_splitting</* __stable = */ true, typename std::iterator_traits<_RAIterPairIterator> ::value_type*, _Compare, _DifferenceTp>, - static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads()); + static_cast<_DifferenceType>(__length), __comp, + __tag.__get_num_threads()); else return __sequential_multiway_merge</* __stable = */ true, /* __sentinels = */ false>( @@ -1720,7 +1733,8 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin multiway_merge_sampling_splitting</* __stable = */ true, typename std::iterator_traits<_RAIterPairIterator> ::value_type*, _Compare, _DifferenceTp>, - static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads()); + static_cast<_DifferenceType>(__length), __comp, + __tag.__get_num_threads()); else return __sequential_multiway_merge </* __stable = */ true, /* __sentinels = */ false>( @@ -1742,8 +1756,9 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin , _DifferenceTp __length, _Compare __comp , parallel_tag __tag = parallel_tag(0)) { - return stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length, __comp, - exact_tag(__tag.__get_num_threads())); + return stable_multiway_merge( + __seqs_begin, __seqs_end, __target, __length, __comp, + exact_tag(__tag.__get_num_threads())); } // public interface @@ -1759,8 +1774,9 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin , _DifferenceTp __length, _Compare __comp , default_parallel_tag __tag) { - return stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length, __comp, - exact_tag(__tag.__get_num_threads())); + return stable_multiway_merge( + __seqs_begin, __seqs_end, __target, __length, __comp, + exact_tag(__tag.__get_num_threads())); } /** @@ -1902,7 +1918,8 @@ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin multiway_merge_exact_splitting</* __stable = */ false, typename std::iterator_traits<_RAIterPairIterator> ::value_type*, _Compare, _DifferenceTp>, - static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads()); + static_cast<_DifferenceType>(__length), __comp, + __tag.__get_num_threads()); else return __sequential_multiway_merge </* __stable = */ false, /* __sentinels = */ true>( @@ -1945,7 +1962,8 @@ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin multiway_merge_sampling_splitting</* __stable = */ false, typename std::iterator_traits<_RAIterPairIterator> ::value_type*, _Compare, _DifferenceTp>, - static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads()); + static_cast<_DifferenceType>(__length), __comp, + __tag.__get_num_threads()); else return __sequential_multiway_merge </* __stable = */false, /* __sentinels = */ true>( @@ -1966,8 +1984,9 @@ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin , _DifferenceTp __length, _Compare __comp , parallel_tag __tag = parallel_tag(0)) { - return multiway_merge_sentinels(__seqs_begin, __seqs_end, __target, __length, __comp, - exact_tag(__tag.__get_num_threads())); + return multiway_merge_sentinels( + __seqs_begin, __seqs_end, __target, __length, __comp, + exact_tag(__tag.__get_num_threads())); } // public interface @@ -1983,8 +2002,9 @@ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin , _DifferenceTp __length, _Compare __comp , default_parallel_tag __tag) { - return multiway_merge_sentinels(__seqs_begin, __seqs_end, __target, __length, __comp, - exact_tag(__tag.__get_num_threads())); + return multiway_merge_sentinels( + __seqs_begin, __seqs_end, __target, __length, __comp, + exact_tag(__tag.__get_num_threads())); } // stable_multiway_merge_sentinels @@ -2011,7 +2031,8 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin // Execute multiway merge *sequentially*. return __sequential_multiway_merge </* __stable = */ true, /* __sentinels = */ true> - (__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp); + (__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, + __comp); } // public interface @@ -2050,11 +2071,13 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin multiway_merge_exact_splitting</* __stable = */ true, typename std::iterator_traits<_RAIterPairIterator> ::value_type*, _Compare, _DifferenceTp>, - static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads()); + static_cast<_DifferenceType>(__length), __comp, + __tag.__get_num_threads()); else return __sequential_multiway_merge </* __stable = */ true, /* __sentinels = */ true>( - __seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp); + __seqs_begin, __seqs_end, __target, *(__seqs_begin->second), + __length, __comp); } // public interface @@ -2093,7 +2116,8 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin multiway_merge_sampling_splitting</* __stable = */ true, typename std::iterator_traits<_RAIterPairIterator> ::value_type*, _Compare, _DifferenceTp>, - static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads()); + static_cast<_DifferenceType>(__length), __comp, + __tag.__get_num_threads()); else return __sequential_multiway_merge </* __stable = */ true, /* __sentinels = */ true>( @@ -2114,8 +2138,9 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin , _DifferenceTp __length, _Compare __comp , parallel_tag __tag = parallel_tag(0)) { - return stable_multiway_merge_sentinels(__seqs_begin, __seqs_end, __target, __length, __comp, - exact_tag(__tag.__get_num_threads())); + return stable_multiway_merge_sentinels( + __seqs_begin, __seqs_end, __target, __length, __comp, + exact_tag(__tag.__get_num_threads())); } // public interface @@ -2131,8 +2156,9 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin , _DifferenceTp __length, _Compare __comp , default_parallel_tag __tag) { - return stable_multiway_merge_sentinels(__seqs_begin, __seqs_end, __target, __length, __comp, - exact_tag(__tag.__get_num_threads())); + return stable_multiway_merge_sentinels( + __seqs_begin, __seqs_end, __target, __length, __comp, + exact_tag(__tag.__get_num_threads())); } }; // namespace __gnu_parallel diff --git a/libstdc++-v3/include/parallel/multiway_mergesort.h b/libstdc++-v3/include/parallel/multiway_mergesort.h index 546b476da8f..9f61ce305a2 100644 --- a/libstdc++-v3/include/parallel/multiway_mergesort.h +++ b/libstdc++-v3/include/parallel/multiway_mergesort.h @@ -111,7 +111,7 @@ template<typename _RAIter, typename _DifferenceTp> for (_DifferenceType __i = 0; __i < __num_samples; ++__i) ::new(&(__sd->_M_samples[__iam * __num_samples + __i])) - _ValueType(__sd->_M_source[__sd->_M_starts[__iam] + __es[__i + 1]]); + _ValueType(__sd->_M_source[__sd->_M_starts[__iam] + __es[__i + 1]]); delete[] __es; } @@ -144,25 +144,28 @@ template<typename _RAIter, typename _Compare, seqs(__sd->_M_num_threads); for (_ThreadIndex __s = 0; __s < __sd->_M_num_threads; __s++) seqs[__s] = std::make_pair(__sd->_M_temporary[__s], - __sd->_M_temporary[__s] - + (__sd->_M_starts[__s + 1] - __sd->_M_starts[__s])); + __sd->_M_temporary[__s] + + (__sd->_M_starts[__s + 1] + - __sd->_M_starts[__s])); std::vector<_SortingPlacesIterator> _M_offsets(__sd->_M_num_threads); // if not last thread if (__iam < __sd->_M_num_threads - 1) multiseq_partition(seqs.begin(), seqs.end(), - __sd->_M_starts[__iam + 1], _M_offsets.begin(), __comp); + __sd->_M_starts[__iam + 1], _M_offsets.begin(), + __comp); for (int __seq = 0; __seq < __sd->_M_num_threads; __seq++) { // for each sequence if (__iam < (__sd->_M_num_threads - 1)) - __sd->_M_pieces[__iam][__seq]._M_end = _M_offsets[__seq] - seqs[__seq].first; + __sd->_M_pieces[__iam][__seq]._M_end + = _M_offsets[__seq] - seqs[__seq].first; else // very end of this sequence __sd->_M_pieces[__iam][__seq]._M_end = - __sd->_M_starts[__seq + 1] - __sd->_M_starts[__seq]; + __sd->_M_starts[__seq + 1] - __sd->_M_starts[__seq]; } # pragma omp barrier @@ -171,7 +174,8 @@ template<typename _RAIter, typename _Compare, { // For each sequence. if (__iam > 0) - __sd->_M_pieces[__iam][__seq]._M_begin = __sd->_M_pieces[__iam - 1][__seq]._M_end; + __sd->_M_pieces[__iam][__seq]._M_begin = + __sd->_M_pieces[__iam - 1][__seq]._M_end; else // Absolute beginning. __sd->_M_pieces[__iam][__seq]._M_begin = 0; @@ -204,7 +208,8 @@ template<typename _RAIter, typename _Compare, # pragma omp single __gnu_sequential::sort(__sd->_M_samples, - __sd->_M_samples + (__num_samples * __sd->_M_num_threads), + __sd->_M_samples + + (__num_samples * __sd->_M_num_threads), __comp); # pragma omp barrier @@ -224,17 +229,19 @@ template<typename _RAIter, typename _Compare, // Absolute beginning. __sd->_M_pieces[__iam][__s]._M_begin = 0; - if ((__num_samples * (__iam + 1)) < (__num_samples * __sd->_M_num_threads)) + if ((__num_samples * (__iam + 1)) < + (__num_samples * __sd->_M_num_threads)) __sd->_M_pieces[__iam][__s]._M_end = std::lower_bound(__sd->_M_temporary[__s], __sd->_M_temporary[__s] - + (__sd->_M_starts[__s + 1] - __sd->_M_starts[__s]), + + (__sd->_M_starts[__s + 1] - __sd->_M_starts[__s]), __sd->_M_samples[__num_samples * (__iam + 1)], __comp) - __sd->_M_temporary[__s]; else // Absolute end. - __sd->_M_pieces[__iam][__s]._M_end = __sd->_M_starts[__s + 1] - __sd->_M_starts[__s]; + __sd->_M_pieces[__iam][__s]._M_end = __sd->_M_starts[__s + 1] + - __sd->_M_starts[__s]; } } }; @@ -283,8 +290,8 @@ template<typename Seq_RAIter, typename _RAIter, _Compare& __comp, DiffType __length_am) const { - stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length_am, __comp, - sequential_tag()); + stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length_am, + __comp, sequential_tag()); } }; @@ -322,7 +329,8 @@ template<bool __stable, bool __exact, typename _RAIter, _ThreadIndex __iam = omp_get_thread_num(); // Length of this thread's chunk, before merging. - _DifferenceType __length_local = __sd->_M_starts[__iam + 1] - __sd->_M_starts[__iam]; + _DifferenceType __length_local + = __sd->_M_starts[__iam + 1] - __sd->_M_starts[__iam]; // Sort in temporary storage, leave space for sentinel. @@ -333,12 +341,15 @@ template<bool __stable, bool __exact, typename _RAIter, ::operator new(sizeof(_ValueType) * (__length_local + 1))); // Copy there. - std::uninitialized_copy(__sd->_M_source + __sd->_M_starts[__iam], - __sd->_M_source + __sd->_M_starts[__iam] + __length_local, - __sd->_M_temporary[__iam]); + std::uninitialized_copy( + __sd->_M_source + __sd->_M_starts[__iam], + __sd->_M_source + __sd->_M_starts[__iam] + __length_local, + __sd->_M_temporary[__iam]); __possibly_stable_sort<__stable, _SortingPlacesIterator, _Compare>() - (__sd->_M_temporary[__iam], __sd->_M_temporary[__iam] + __length_local, __comp); + (__sd->_M_temporary[__iam], + __sd->_M_temporary[__iam] + __length_local, + __comp); // Invariant: locally sorted subsequence in sd->_M_temporary[__iam], // __sd->_M_temporary[__iam] + __length_local. @@ -355,7 +366,8 @@ template<bool __stable, bool __exact, typename _RAIter, _DifferenceType __offset = 0, __length_am = 0; for (_ThreadIndex __s = 0; __s < __sd->_M_num_threads; __s++) { - __length_am += __sd->_M_pieces[__iam][__s]._M_end - __sd->_M_pieces[__iam][__s]._M_begin; + __length_am += __sd->_M_pieces[__iam][__s]._M_end + - __sd->_M_pieces[__iam][__s]._M_begin; __offset += __sd->_M_pieces[__iam][__s]._M_begin; } @@ -367,8 +379,9 @@ template<bool __stable, bool __exact, typename _RAIter, for (int __s = 0; __s < __sd->_M_num_threads; ++__s) { seqs[__s] = - std::make_pair(__sd->_M_temporary[__s] + __sd->_M_pieces[__iam][__s]._M_begin, - __sd->_M_temporary[__s] + __sd->_M_pieces[__iam][__s]._M_end); + std::make_pair( + __sd->_M_temporary[__s] + __sd->_M_pieces[__iam][__s]._M_begin, + __sd->_M_temporary[__s] + __sd->_M_pieces[__iam][__s]._M_end); } __possibly_stable_multiway_merge< @@ -420,7 +433,7 @@ template<bool __stable, bool __exact, typename _RAIter, # pragma omp parallel num_threads(__num_threads) { - __num_threads = omp_get_num_threads(); //no more threads than requested + __num_threads = omp_get_num_threads(); //no more threads than requested # pragma omp single { @@ -432,7 +445,7 @@ template<bool __stable, bool __exact, typename _RAIter, if (!__exact) { _DifferenceType size = - (_Settings::get().sort_mwms_oversampling * __num_threads - 1) + (_Settings::get().sort_mwms_oversampling * __num_threads - 1) * __num_threads; __sd._M_samples = static_cast<_ValueType*>( ::operator new(size * sizeof(_ValueType))); @@ -441,10 +454,12 @@ template<bool __stable, bool __exact, typename _RAIter, __sd._M_samples = NULL; __sd._M_offsets = new _DifferenceType[__num_threads - 1]; - __sd._M_pieces = new std::vector<_Piece<_DifferenceType> >[__num_threads]; + __sd._M_pieces + = new std::vector<_Piece<_DifferenceType> >[__num_threads]; for (int __s = 0; __s < __num_threads; ++__s) __sd._M_pieces[__s].resize(__num_threads); - _M_starts = __sd._M_starts = new _DifferenceType[__num_threads + 1]; + _M_starts = __sd._M_starts + = new _DifferenceType[__num_threads + 1]; _DifferenceType __chunk_length = __n / __num_threads; _DifferenceType __split = __n % __num_threads; @@ -452,7 +467,8 @@ template<bool __stable, bool __exact, typename _RAIter, for (int __i = 0; __i < __num_threads; ++__i) { _M_starts[__i] = __pos; - __pos += (__i < __split) ? (__chunk_length + 1) : __chunk_length; + __pos += (__i < __split) + ? (__chunk_length + 1) : __chunk_length; } _M_starts[__num_threads] = __pos; } //single diff --git a/libstdc++-v3/include/parallel/numeric b/libstdc++-v3/include/parallel/numeric index e355097edd6..5d03e679c27 100644 --- a/libstdc++-v3/include/parallel/numeric +++ b/libstdc++-v3/include/parallel/numeric @@ -54,76 +54,77 @@ namespace __parallel template<typename _IIter, typename _Tp> inline _Tp accumulate(_IIter __begin, _IIter __end, _Tp __init, - __gnu_parallel::sequential_tag) + __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::accumulate(__begin, __end, __init); } template<typename _IIter, typename _Tp, typename _BinaryOperation> inline _Tp accumulate(_IIter __begin, _IIter __end, _Tp __init, - _BinaryOperation __binary_op, __gnu_parallel::sequential_tag) + _BinaryOperation __binary_op, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::accumulate(__begin, __end, __init, __binary_op); } // Sequential fallback for input iterator case. template<typename _IIter, typename _Tp, typename _IteratorTag> inline _Tp __accumulate_switch(_IIter __begin, _IIter __end, - _Tp __init, _IteratorTag) - { return accumulate(__begin, __end, __init, __gnu_parallel::sequential_tag()); } + _Tp __init, _IteratorTag) + { return accumulate(__begin, __end, __init, +__gnu_parallel::sequential_tag()); } template<typename _IIter, typename _Tp, typename _BinaryOperation, - typename _IteratorTag> + typename _IteratorTag> inline _Tp __accumulate_switch(_IIter __begin, _IIter __end, _Tp __init, - _BinaryOperation __binary_op, _IteratorTag) + _BinaryOperation __binary_op, _IteratorTag) { return accumulate(__begin, __end, __init, __binary_op, - __gnu_parallel::sequential_tag()); } + __gnu_parallel::sequential_tag()); } // Parallel algorithm for random access iterators. template<typename __RAIter, typename _Tp, - typename _BinaryOperation> + typename _BinaryOperation> _Tp __accumulate_switch(__RAIter __begin, __RAIter __end, - _Tp __init, _BinaryOperation __binary_op, - random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism_tag - = __gnu_parallel::parallel_unbalanced) + _Tp __init, _BinaryOperation __binary_op, + random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism_tag + = __gnu_parallel::parallel_unbalanced) { if (_GLIBCXX_PARALLEL_CONDITION( - static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) - >= __gnu_parallel::_Settings::get().accumulate_minimal_n - && __gnu_parallel::__is_parallel(__parallelism_tag))) - { - _Tp __res = __init; - __gnu_parallel::__accumulate_selector<__RAIter> - __my_selector; - __gnu_parallel:: - for_each_template_random_access_ed(__begin, __end, - __gnu_parallel::_Nothing(), - __my_selector, - __gnu_parallel:: - __accumulate_binop_reduct - <_BinaryOperation>(__binary_op), - __res, __res, -1); - return __res; - } + static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) + >= __gnu_parallel::_Settings::get().accumulate_minimal_n + && __gnu_parallel::__is_parallel(__parallelism_tag))) + { + _Tp __res = __init; + __gnu_parallel::__accumulate_selector<__RAIter> + __my_selector; + __gnu_parallel:: + for_each_template_random_access_ed(__begin, __end, + __gnu_parallel::_Nothing(), + __my_selector, + __gnu_parallel:: + __accumulate_binop_reduct + <_BinaryOperation>(__binary_op), + __res, __res, -1); + return __res; + } else - return accumulate(__begin, __end, __init, __binary_op, - __gnu_parallel::sequential_tag()); + return accumulate(__begin, __end, __init, __binary_op, + __gnu_parallel::sequential_tag()); } // Public interface. template<typename _IIter, typename _Tp> inline _Tp accumulate(_IIter __begin, _IIter __end, _Tp __init, - __gnu_parallel::_Parallelism __parallelism_tag) + __gnu_parallel::_Parallelism __parallelism_tag) { typedef std::iterator_traits<_IIter> _IteratorTraits; typedef typename _IteratorTraits::value_type _ValueType; typedef typename _IteratorTraits::iterator_category _IteratorCategory; return __accumulate_switch(__begin, __end, __init, - __gnu_parallel::_Plus<_Tp, _ValueType>(), - _IteratorCategory(), __parallelism_tag); + __gnu_parallel::_Plus<_Tp, _ValueType>(), + _IteratorCategory(), __parallelism_tag); } template<typename _IIter, typename _Tp> @@ -135,31 +136,31 @@ namespace __parallel typedef typename _IteratorTraits::iterator_category _IteratorCategory; return __accumulate_switch(__begin, __end, __init, - __gnu_parallel::_Plus<_Tp, _ValueType>(), - _IteratorCategory()); + __gnu_parallel::_Plus<_Tp, _ValueType>(), + _IteratorCategory()); } template<typename _IIter, typename _Tp, typename _BinaryOperation> inline _Tp accumulate(_IIter __begin, _IIter __end, _Tp __init, - _BinaryOperation __binary_op, - __gnu_parallel::_Parallelism __parallelism_tag) + _BinaryOperation __binary_op, + __gnu_parallel::_Parallelism __parallelism_tag) { typedef iterator_traits<_IIter> _IteratorTraits; typedef typename _IteratorTraits::iterator_category _IteratorCategory; return __accumulate_switch(__begin, __end, __init, __binary_op, - _IteratorCategory(), __parallelism_tag); + _IteratorCategory(), __parallelism_tag); } template<typename _IIter, typename _Tp, typename _BinaryOperation> inline _Tp accumulate(_IIter __begin, _IIter __end, _Tp __init, - _BinaryOperation __binary_op) + _BinaryOperation __binary_op) { typedef iterator_traits<_IIter> _IteratorTraits; typedef typename _IteratorTraits::iterator_category _IteratorCategory; return __accumulate_switch(__begin, __end, __init, __binary_op, - _IteratorCategory()); + _IteratorCategory()); } @@ -167,75 +168,76 @@ namespace __parallel template<typename _IIter1, typename _IIter2, typename _Tp> inline _Tp inner_product(_IIter1 __first1, _IIter1 __last1, - _IIter2 __first2, _Tp __init, - __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::inner_product(__first1, __last1, __first2, __init); } + _IIter2 __first2, _Tp __init, + __gnu_parallel::sequential_tag) + { return _GLIBCXX_STD_P::inner_product( + __first1, __last1, __first2, __init); } template<typename _IIter1, typename _IIter2, typename _Tp, - typename BinaryFunction1, typename BinaryFunction2> + typename BinaryFunction1, typename BinaryFunction2> inline _Tp inner_product(_IIter1 __first1, _IIter1 __last1, - _IIter2 __first2, _Tp __init, BinaryFunction1 __binary_op1, - BinaryFunction2 __binary_op2, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::inner_product(__first1, __last1, __first2, __init, - __binary_op1, __binary_op2); } + _IIter2 __first2, _Tp __init, BinaryFunction1 __binary_op1, + BinaryFunction2 __binary_op2, __gnu_parallel::sequential_tag) + { return _GLIBCXX_STD_P::inner_product(__first1, __last1, __first2, __init, + __binary_op1, __binary_op2); } // Parallel algorithm for random access iterators. template<typename _RAIter1, typename _RAIter2, - typename _Tp, typename BinaryFunction1, typename BinaryFunction2> + typename _Tp, typename BinaryFunction1, typename BinaryFunction2> _Tp __inner_product_switch(_RAIter1 __first1, - _RAIter1 __last1, - _RAIter2 __first2, _Tp __init, - BinaryFunction1 __binary_op1, - BinaryFunction2 __binary_op2, - random_access_iterator_tag, - random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism_tag - = __gnu_parallel::parallel_unbalanced) + _RAIter1 __last1, + _RAIter2 __first2, _Tp __init, + BinaryFunction1 __binary_op1, + BinaryFunction2 __binary_op2, + random_access_iterator_tag, + random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism_tag + = __gnu_parallel::parallel_unbalanced) { if (_GLIBCXX_PARALLEL_CONDITION((__last1 - __first1) - >= __gnu_parallel::_Settings::get(). - accumulate_minimal_n - && __gnu_parallel:: - __is_parallel(__parallelism_tag))) - { - _Tp __res = __init; - __gnu_parallel:: - __inner_product_selector<_RAIter1, - _RAIter2, _Tp> __my_selector(__first1, __first2); - __gnu_parallel:: - for_each_template_random_access_ed(__first1, __last1, __binary_op2, - __my_selector, __binary_op1, - __res, __res, -1); - return __res; - } + >= __gnu_parallel::_Settings::get(). + accumulate_minimal_n + && __gnu_parallel:: + __is_parallel(__parallelism_tag))) + { + _Tp __res = __init; + __gnu_parallel:: + __inner_product_selector<_RAIter1, + _RAIter2, _Tp> __my_selector(__first1, __first2); + __gnu_parallel:: + for_each_template_random_access_ed(__first1, __last1, __binary_op2, + __my_selector, __binary_op1, + __res, __res, -1); + return __res; + } else - return inner_product(__first1, __last1, __first2, __init, - __gnu_parallel::sequential_tag()); + return inner_product(__first1, __last1, __first2, __init, + __gnu_parallel::sequential_tag()); } // No parallelism for input iterators. template<typename _IIter1, typename _IIter2, typename _Tp, - typename BinaryFunction1, typename BinaryFunction2, - typename _IteratorTag1, typename _IteratorTag2> + typename BinaryFunction1, typename BinaryFunction2, + typename _IteratorTag1, typename _IteratorTag2> inline _Tp __inner_product_switch(_IIter1 __first1, _IIter1 __last1, - _IIter2 __first2, _Tp __init, - BinaryFunction1 __binary_op1, - BinaryFunction2 __binary_op2, - _IteratorTag1, _IteratorTag2) + _IIter2 __first2, _Tp __init, + BinaryFunction1 __binary_op1, + BinaryFunction2 __binary_op2, + _IteratorTag1, _IteratorTag2) { return inner_product(__first1, __last1, __first2, __init, - __binary_op1, __binary_op2, - __gnu_parallel::sequential_tag()); } + __binary_op1, __binary_op2, + __gnu_parallel::sequential_tag()); } template<typename _IIter1, typename _IIter2, typename _Tp, - typename BinaryFunction1, typename BinaryFunction2> + typename BinaryFunction1, typename BinaryFunction2> inline _Tp inner_product(_IIter1 __first1, _IIter1 __last1, - _IIter2 __first2, _Tp __init, BinaryFunction1 __binary_op1, - BinaryFunction2 __binary_op2, - __gnu_parallel::_Parallelism __parallelism_tag) + _IIter2 __first2, _Tp __init, BinaryFunction1 __binary_op1, + BinaryFunction2 __binary_op2, + __gnu_parallel::_Parallelism __parallelism_tag) { typedef iterator_traits<_IIter1> _TraitsType1; typedef typename _TraitsType1::iterator_category _IteratorCategory1; @@ -243,17 +245,18 @@ namespace __parallel typedef iterator_traits<_IIter2> _TraitsType2; typedef typename _TraitsType2::iterator_category _IteratorCategory2; - return __inner_product_switch(__first1, __last1, __first2, __init, __binary_op1, - __binary_op2, _IteratorCategory1(), - _IteratorCategory2(), __parallelism_tag); + return __inner_product_switch( + __first1, __last1, __first2, __init, __binary_op1, + __binary_op2, _IteratorCategory1(), _IteratorCategory2(), + __parallelism_tag); } template<typename _IIter1, typename _IIter2, typename _Tp, - typename BinaryFunction1, typename BinaryFunction2> + typename BinaryFunction1, typename BinaryFunction2> inline _Tp inner_product(_IIter1 __first1, _IIter1 __last1, - _IIter2 __first2, _Tp __init, BinaryFunction1 __binary_op1, - BinaryFunction2 __binary_op2) + _IIter2 __first2, _Tp __init, BinaryFunction1 __binary_op1, + BinaryFunction2 __binary_op2) { typedef iterator_traits<_IIter1> _TraitsType1; typedef typename _TraitsType1::iterator_category _IteratorCategory1; @@ -261,16 +264,16 @@ namespace __parallel typedef iterator_traits<_IIter2> _TraitsType2; typedef typename _TraitsType2::iterator_category _IteratorCategory2; - return __inner_product_switch(__first1, __last1, __first2, __init, __binary_op1, - __binary_op2, _IteratorCategory1(), - _IteratorCategory2()); + return __inner_product_switch( + __first1, __last1, __first2, __init, __binary_op1, __binary_op2, + _IteratorCategory1(), _IteratorCategory2()); } template<typename _IIter1, typename _IIter2, typename _Tp> inline _Tp inner_product(_IIter1 __first1, _IIter1 __last1, - _IIter2 __first2, _Tp __init, - __gnu_parallel::_Parallelism __parallelism_tag) + _IIter2 __first2, _Tp __init, + __gnu_parallel::_Parallelism __parallelism_tag) { typedef iterator_traits<_IIter1> traits_type1; typedef typename traits_type1::value_type value_type1; @@ -278,19 +281,19 @@ namespace __parallel typedef typename traits_type2::value_type value_type2; typedef typename - __gnu_parallel::_Multiplies<value_type1, value_type2>::__result + __gnu_parallel::_Multiplies<value_type1, value_type2>::__result _MultipliesResultType; return inner_product(__first1, __last1, __first2, __init, __gnu_parallel::_Plus<_Tp, _MultipliesResultType>(), __gnu_parallel:: - _Multiplies<value_type1, value_type2>(), + _Multiplies<value_type1, value_type2>(), __parallelism_tag); } template<typename _IIter1, typename _IIter2, typename _Tp> inline _Tp inner_product(_IIter1 __first1, _IIter1 __last1, - _IIter2 __first2, _Tp __init) + _IIter2 __first2, _Tp __init) { typedef iterator_traits<_IIter1> traits_type1; typedef typename traits_type1::value_type value_type1; @@ -298,55 +301,55 @@ namespace __parallel typedef typename traits_type2::value_type value_type2; typedef typename - __gnu_parallel::_Multiplies<value_type1, value_type2>::__result + __gnu_parallel::_Multiplies<value_type1, value_type2>::__result _MultipliesResultType; return inner_product(__first1, __last1, __first2, __init, __gnu_parallel::_Plus<_Tp, _MultipliesResultType>(), __gnu_parallel:: - _Multiplies<value_type1, value_type2>()); + _Multiplies<value_type1, value_type2>()); } // Sequential fallback. template<typename _IIter, typename _OutputIterator> inline _OutputIterator partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, - __gnu_parallel::sequential_tag) + __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::partial_sum(__begin, __end, __result); } // Sequential fallback. template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation> + typename _BinaryOperation> inline _OutputIterator partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, - _BinaryOperation __bin_op, __gnu_parallel::sequential_tag) + _BinaryOperation __bin_op, __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::partial_sum(__begin, __end, __result, __bin_op); } // Sequential fallback for input iterator case. template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation, typename _IteratorTag1, - typename _IteratorTag2> + typename _BinaryOperation, typename _IteratorTag1, + typename _IteratorTag2> inline _OutputIterator __partial_sum_switch(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - _IteratorTag1, _IteratorTag2) + _OutputIterator __result, _BinaryOperation __bin_op, + _IteratorTag1, _IteratorTag2) { return _GLIBCXX_STD_P::partial_sum(__begin, __end, __result, __bin_op); } // Parallel algorithm for random access iterators. template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation> + typename _BinaryOperation> _OutputIterator __partial_sum_switch(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - random_access_iterator_tag, random_access_iterator_tag) + _OutputIterator __result, _BinaryOperation __bin_op, + random_access_iterator_tag, random_access_iterator_tag) { if (_GLIBCXX_PARALLEL_CONDITION( - static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) - >= __gnu_parallel::_Settings::get().partial_sum_minimal_n)) - return __gnu_parallel::__parallel_partial_sum(__begin, __end, - __result, __bin_op); + static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) + >= __gnu_parallel::_Settings::get().partial_sum_minimal_n)) + return __gnu_parallel::__parallel_partial_sum(__begin, __end, + __result, __bin_op); else - return partial_sum(__begin, __end, __result, __bin_op, - __gnu_parallel::sequential_tag()); + return partial_sum(__begin, __end, __result, __bin_op, + __gnu_parallel::sequential_tag()); } // Public interface. @@ -360,10 +363,10 @@ namespace __parallel // Public interface template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation> + typename _BinaryOperation> inline _OutputIterator partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, - _BinaryOperation __binary_op) + _BinaryOperation __binary_op) { typedef iterator_traits<_IIter> traitsi_type; typedef typename traitsi_type::iterator_category _IIteratorCategory; @@ -372,100 +375,104 @@ namespace __parallel typedef typename _OTraitsType::iterator_category _OIterCategory; return __partial_sum_switch(__begin, __end, __result, __binary_op, - _IIteratorCategory(), _OIterCategory()); + _IIteratorCategory(), _OIterCategory()); } // Sequential fallback. template<typename _IIter, typename _OutputIterator> inline _OutputIterator - adjacent_difference(_IIter __begin, _IIter __end, - _OutputIterator __result, __gnu_parallel::sequential_tag) + adjacent_difference(_IIter __begin, _IIter __end, _OutputIterator __result, + __gnu_parallel::sequential_tag) { return _GLIBCXX_STD_P::adjacent_difference(__begin, __end, __result); } // Sequential fallback. template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation> + typename _BinaryOperation> inline _OutputIterator adjacent_difference(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::adjacent_difference(__begin, __end, __result, __bin_op); } + _OutputIterator __result, _BinaryOperation __bin_op, + __gnu_parallel::sequential_tag) + { return _GLIBCXX_STD_P::adjacent_difference( + __begin, __end, __result, __bin_op); } // Sequential fallback for input iterator case. template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation, typename _IteratorTag1, - typename _IteratorTag2> + typename _BinaryOperation, typename _IteratorTag1, + typename _IteratorTag2> inline _OutputIterator - __adjacent_difference_switch(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - _IteratorTag1, _IteratorTag2) - { return adjacent_difference(__begin, __end, __result, __bin_op, - __gnu_parallel::sequential_tag()); } + __adjacent_difference_switch( + _IIter __begin, _IIter __end, _OutputIterator __result, + _BinaryOperation __bin_op, _IteratorTag1, _IteratorTag2) + { return adjacent_difference(__begin, __end, __result, __bin_op, + __gnu_parallel::sequential_tag()); } // Parallel algorithm for random access iterators. template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation> + typename _BinaryOperation> _OutputIterator - __adjacent_difference_switch(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - random_access_iterator_tag, - random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism_tag - = __gnu_parallel::parallel_balanced) + __adjacent_difference_switch( + _IIter __begin, _IIter __end, _OutputIterator __result, + _BinaryOperation __bin_op, + random_access_iterator_tag, random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism_tag + = __gnu_parallel::parallel_balanced) { if (_GLIBCXX_PARALLEL_CONDITION( - static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) - >= __gnu_parallel::_Settings::get().adjacent_difference_minimal_n - && __gnu_parallel::__is_parallel(__parallelism_tag))) - { - bool __dummy = true; - typedef __gnu_parallel::_IteratorPair<_IIter, _OutputIterator, - random_access_iterator_tag> _ItTrip; - *__result = *__begin; - _ItTrip begin_pair(__begin + 1, __result + 1), - end_pair(__end, __result + (__end - __begin)); - __gnu_parallel::__adjacent_difference_selector<_ItTrip> __functionality; - __gnu_parallel:: - for_each_template_random_access_ed(begin_pair, end_pair, __bin_op, - __functionality, - __gnu_parallel::_DummyReduct(), - __dummy, __dummy, -1); - return __functionality.finish_iterator; - } + static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) + >= __gnu_parallel::_Settings::get().adjacent_difference_minimal_n + && __gnu_parallel::__is_parallel(__parallelism_tag))) + { + bool __dummy = true; + typedef __gnu_parallel::_IteratorPair<_IIter, _OutputIterator, + random_access_iterator_tag> _ItTrip; + *__result = *__begin; + _ItTrip begin_pair(__begin + 1, __result + 1), + end_pair(__end, __result + (__end - __begin)); + __gnu_parallel::__adjacent_difference_selector<_ItTrip> + __functionality; + __gnu_parallel:: + for_each_template_random_access_ed(begin_pair, end_pair, __bin_op, + __functionality, + __gnu_parallel::_DummyReduct(), + __dummy, __dummy, -1); + return __functionality.finish_iterator; + } else - return adjacent_difference(__begin, __end, __result, __bin_op, - __gnu_parallel::sequential_tag()); + return adjacent_difference(__begin, __end, __result, __bin_op, + __gnu_parallel::sequential_tag()); } // Public interface. template<typename _IIter, typename _OutputIterator> inline _OutputIterator adjacent_difference(_IIter __begin, _IIter __end, - _OutputIterator __result, - __gnu_parallel::_Parallelism __parallelism_tag) + _OutputIterator __result, + __gnu_parallel::_Parallelism __parallelism_tag) { typedef iterator_traits<_IIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; - return adjacent_difference(__begin, __end, __result, std::minus<_ValueType>(), - __parallelism_tag); + return adjacent_difference( + __begin, __end, __result, std::minus<_ValueType>(), + __parallelism_tag); } template<typename _IIter, typename _OutputIterator> inline _OutputIterator adjacent_difference(_IIter __begin, _IIter __end, - _OutputIterator __result) + _OutputIterator __result) { typedef iterator_traits<_IIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; - return adjacent_difference(__begin, __end, __result, std::minus<_ValueType>()); + return adjacent_difference(__begin, __end, __result, + std::minus<_ValueType>()); } template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation> + typename _BinaryOperation> inline _OutputIterator adjacent_difference(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __binary_op, - __gnu_parallel::_Parallelism __parallelism_tag) + _OutputIterator __result, _BinaryOperation __binary_op, + __gnu_parallel::_Parallelism __parallelism_tag) { typedef iterator_traits<_IIter> traitsi_type; typedef typename traitsi_type::iterator_category _IIteratorCategory; @@ -473,16 +480,16 @@ namespace __parallel typedef iterator_traits<_OutputIterator> _OTraitsType; typedef typename _OTraitsType::iterator_category _OIterCategory; - return __adjacent_difference_switch(__begin, __end, __result, __binary_op, - _IIteratorCategory(), - _OIterCategory(), __parallelism_tag); + return __adjacent_difference_switch( + __begin, __end, __result, __binary_op, + _IIteratorCategory(), _OIterCategory(), __parallelism_tag); } template<typename _IIter, typename _OutputIterator, - typename _BinaryOperation> + typename _BinaryOperation> inline _OutputIterator adjacent_difference(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __binary_op) + _OutputIterator __result, _BinaryOperation __binary_op) { typedef iterator_traits<_IIter> traitsi_type; typedef typename traitsi_type::iterator_category _IIteratorCategory; @@ -490,9 +497,9 @@ namespace __parallel typedef iterator_traits<_OutputIterator> _OTraitsType; typedef typename _OTraitsType::iterator_category _OIterCategory; - return __adjacent_difference_switch(__begin, __end, __result, __binary_op, - _IIteratorCategory(), - _OIterCategory()); + return __adjacent_difference_switch( + __begin, __end, __result, __binary_op, + _IIteratorCategory(), _OIterCategory()); } } // end namespace } // end namespace diff --git a/libstdc++-v3/include/parallel/numericfwd.h b/libstdc++-v3/include/parallel/numericfwd.h index 754d5ba0d9e..e8d887be05c 100644 --- a/libstdc++-v3/include/parallel/numericfwd.h +++ b/libstdc++-v3/include/parallel/numericfwd.h @@ -61,24 +61,24 @@ namespace __parallel template<typename _IIter, typename _Tp, typename _BinaryOper> _Tp accumulate(_IIter, _IIter, _Tp, _BinaryOper, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter, typename _Tp, typename _BinaryOper> _Tp accumulate(_IIter, _IIter, _Tp, _BinaryOper, - __gnu_parallel::_Parallelism); + __gnu_parallel::_Parallelism); template<typename _IIter, typename _Tp, typename _BinaryOper, - typename _Tag> + typename _Tag> _Tp __accumulate_switch(_IIter, _IIter, _Tp, _BinaryOper, _Tag); template<typename _RAIter, typename _Tp, typename _BinaryOper> _Tp __accumulate_switch(_RAIter, _RAIter, _Tp, _BinaryOper, - random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_unbalanced); + random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_unbalanced); template<typename _IIter, typename _OIter> _OIter @@ -91,36 +91,36 @@ namespace __parallel template<typename _IIter, typename _OIter> _OIter adjacent_difference(_IIter, _IIter, _OIter, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter, typename _OIter, typename _BinaryOper> _OIter adjacent_difference(_IIter, _IIter, _OIter, _BinaryOper, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter, typename _OIter> _OIter adjacent_difference(_IIter, _IIter, _OIter, - __gnu_parallel::_Parallelism); + __gnu_parallel::_Parallelism); template<typename _IIter, typename _OIter, typename _BinaryOper> _OIter adjacent_difference(_IIter, _IIter, _OIter, _BinaryOper, - __gnu_parallel::_Parallelism); + __gnu_parallel::_Parallelism); template<typename _IIter, typename _OIter, typename _BinaryOper, - typename _Tag1, typename _Tag2> + typename _Tag1, typename _Tag2> _OIter __adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper, - _Tag1, _Tag2); + _Tag1, _Tag2); template<typename _IIter, typename _OIter, typename _BinaryOper> _OIter __adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper, - random_access_iterator_tag, - random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism - = __gnu_parallel::parallel_unbalanced); + random_access_iterator_tag, + random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism + = __gnu_parallel::parallel_unbalanced); template<typename _IIter1, typename _IIter2, typename _Tp> _Tp @@ -129,46 +129,46 @@ namespace __parallel template<typename _IIter1, typename _IIter2, typename _Tp> _Tp inner_product(_IIter1, _IIter1, _IIter2, _Tp, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _Tp> _Tp inner_product(_IIter1, _IIter1, _IIter2, _Tp, - __gnu_parallel::_Parallelism); + __gnu_parallel::_Parallelism); template<typename _IIter1, typename _IIter2, typename _Tp, - typename _BinaryFunction1, typename _BinaryFunction2> + typename _BinaryFunction1, typename _BinaryFunction2> _Tp inner_product(_IIter1, _IIter1, _IIter2, _Tp, - _BinaryFunction1, _BinaryFunction2); + _BinaryFunction1, _BinaryFunction2); template<typename _IIter1, typename _IIter2, typename _Tp, - typename _BinaryFunction1, typename _BinaryFunction2> + typename _BinaryFunction1, typename _BinaryFunction2> _Tp inner_product(_IIter1, _IIter1, _IIter2, _Tp, _BinaryFunction1, - _BinaryFunction2, __gnu_parallel::sequential_tag); + _BinaryFunction2, __gnu_parallel::sequential_tag); template<typename _IIter1, typename _IIter2, typename _Tp, - typename BinaryFunction1, typename BinaryFunction2> + typename BinaryFunction1, typename BinaryFunction2> _Tp inner_product(_IIter1, _IIter1, _IIter2, _Tp, BinaryFunction1, - BinaryFunction2, __gnu_parallel::_Parallelism); + BinaryFunction2, __gnu_parallel::_Parallelism); template<typename _RAIter1, typename _RAIter2, typename _Tp, - typename BinaryFunction1, typename BinaryFunction2> + typename BinaryFunction1, typename BinaryFunction2> _Tp __inner_product_switch(_RAIter1, _RAIter1, _RAIter2, _Tp, BinaryFunction1, - BinaryFunction2, random_access_iterator_tag, - random_access_iterator_tag, - __gnu_parallel::_Parallelism - = __gnu_parallel::parallel_unbalanced); + BinaryFunction2, random_access_iterator_tag, + random_access_iterator_tag, + __gnu_parallel::_Parallelism + = __gnu_parallel::parallel_unbalanced); template<typename _IIter1, typename _IIter2, typename _Tp, - typename _BinaryFunction1, typename _BinaryFunction2, - typename _Tag1, typename _Tag2> + typename _BinaryFunction1, typename _BinaryFunction2, + typename _Tag1, typename _Tag2> _Tp __inner_product_switch(_IIter1, _IIter1, _IIter2, _Tp, _BinaryFunction1, - _BinaryFunction2, _Tag1, _Tag2); + _BinaryFunction2, _Tag1, _Tag2); template<typename _IIter, typename _OIter> @@ -178,7 +178,7 @@ namespace __parallel template<typename _IIter, typename _OIter, typename _BinaryOper> _OIter partial_sum(_IIter, _IIter, _OIter, _BinaryOper, - __gnu_parallel::sequential_tag); + __gnu_parallel::sequential_tag); template<typename _IIter, typename _OIter> _OIter @@ -189,14 +189,14 @@ namespace __parallel partial_sum(_IIter, _IIter, _OIter, _BinaryOper); template<typename _IIter, typename _OIter, typename _BinaryOper, - typename _Tag1, typename _Tag2> + typename _Tag1, typename _Tag2> _OIter __partial_sum_switch(_IIter, _IIter, _OIter, _BinaryOper, _Tag1, _Tag2); template<typename _IIter, typename _OIter, typename _BinaryOper> _OIter __partial_sum_switch(_IIter, _IIter, _OIter, _BinaryOper, - random_access_iterator_tag, random_access_iterator_tag); + random_access_iterator_tag, random_access_iterator_tag); } // end namespace } // end namespace diff --git a/libstdc++-v3/include/parallel/omp_loop.h b/libstdc++-v3/include/parallel/omp_loop.h index 5f5df679524..7147961df98 100644 --- a/libstdc++-v3/include/parallel/omp_loop.h +++ b/libstdc++-v3/include/parallel/omp_loop.h @@ -59,18 +59,15 @@ namespace __gnu_parallel * @return User-supplied functor (that may contain a part of the result). */ template<typename _RAIter, - typename _Op, - typename _Fu, - typename _Red, - typename _Result> + typename _Op, + typename _Fu, + typename _Red, + typename _Result> _Op - for_each_template_random_access_omp_loop(_RAIter __begin, - _RAIter __end, - _Op __o, _Fu& __f, _Red __r, _Result __base, - _Result& __output, - typename std::iterator_traits - <_RAIter>:: - difference_type __bound) + for_each_template_random_access_omp_loop( + _RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r, + _Result __base, _Result& __output, + typename std::iterator_traits<_RAIter>::difference_type __bound) { typedef typename std::iterator_traits<_RAIter>::difference_type @@ -95,7 +92,7 @@ template<typename _RAIter, _ThreadIndex __iam = omp_get_thread_num(); -# pragma omp for schedule(dynamic, _Settings::get().workstealing_chunk_size) +#pragma omp for schedule(dynamic, _Settings::get().workstealing_chunk_size) for (_DifferenceType __pos = 0; __pos < __length; ++__pos) __thread_results[__iam] = __r(__thread_results[__iam], __f(__o, __begin+__pos)); diff --git a/libstdc++-v3/include/parallel/omp_loop_static.h b/libstdc++-v3/include/parallel/omp_loop_static.h index 5244d11494a..cc3443ba1a9 100644 --- a/libstdc++-v3/include/parallel/omp_loop_static.h +++ b/libstdc++-v3/include/parallel/omp_loop_static.h @@ -59,18 +59,15 @@ namespace __gnu_parallel * @return User-supplied functor (that may contain a part of the result). */ template<typename _RAIter, - typename _Op, - typename _Fu, - typename _Red, - typename _Result> + typename _Op, + typename _Fu, + typename _Red, + typename _Result> _Op - for_each_template_random_access_omp_loop_static(_RAIter __begin, - _RAIter __end, - _Op __o, _Fu& __f, _Red __r, - _Result __base, _Result& __output, - typename std::iterator_traits - <_RAIter>:: - difference_type __bound) + for_each_template_random_access_omp_loop_static( + _RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r, + _Result __base, _Result& __output, + typename std::iterator_traits<_RAIter>::difference_type __bound) { typedef typename std::iterator_traits<_RAIter>::difference_type @@ -95,9 +92,10 @@ template<typename _RAIter, _ThreadIndex __iam = omp_get_thread_num(); -# pragma omp for schedule(static, _Settings::get().workstealing_chunk_size) +#pragma omp for schedule(static, _Settings::get().workstealing_chunk_size) for (_DifferenceType __pos = 0; __pos < __length; ++__pos) - __thread_results[__iam] = __r(__thread_results[__iam], __f(__o, __begin+__pos)); + __thread_results[__iam] = __r(__thread_results[__iam], + __f(__o, __begin+__pos)); } //parallel for (_ThreadIndex __i = 0; __i < __num_threads; ++__i) diff --git a/libstdc++-v3/include/parallel/par_loop.h b/libstdc++-v3/include/parallel/par_loop.h index 68dee423eda..0a71831342e 100644 --- a/libstdc++-v3/include/parallel/par_loop.h +++ b/libstdc++-v3/include/parallel/par_loop.h @@ -60,18 +60,15 @@ namespace __gnu_parallel * @return User-supplied functor (that may contain a part of the result). */ template<typename _RAIter, - typename _Op, - typename _Fu, - typename _Red, - typename _Result> + typename _Op, + typename _Fu, + typename _Red, + typename _Result> _Op - for_each_template_random_access_ed(_RAIter __begin, - _RAIter __end, - _Op __o, _Fu& __f, _Red __r, _Result __base, - _Result& __output, - typename std::iterator_traits - <_RAIter>:: - difference_type __bound) + for_each_template_random_access_ed( + _RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r, + _Result __base, _Result& __output, + typename std::iterator_traits<_RAIter>::difference_type __bound) { typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::difference_type _DifferenceType; @@ -87,15 +84,17 @@ template<typename _RAIter, # pragma omp single { __num_threads = omp_get_num_threads(); - __thread_results = static_cast<_Result*>( - ::operator new(__num_threads * sizeof(_Result))); + __thread_results = + static_cast<_Result*>( + ::operator new(__num_threads * sizeof(_Result))); __constructed = new bool[__num_threads]; } _ThreadIndex __iam = omp_get_thread_num(); // Neutral element. - _Result* __reduct = static_cast<_Result*>(::operator new(sizeof(_Result))); + _Result* __reduct = + static_cast<_Result*>(::operator new(sizeof(_Result))); _DifferenceType __start = equally_split_point(__length, __num_threads, __iam), diff --git a/libstdc++-v3/include/parallel/partial_sum.h b/libstdc++-v3/include/parallel/partial_sum.h index da04270b6e2..b121e1ff8c7 100644 --- a/libstdc++-v3/include/parallel/partial_sum.h +++ b/libstdc++-v3/include/parallel/partial_sum.h @@ -52,13 +52,13 @@ namespace __gnu_parallel * element is unknown in general. * @return End iterator of output sequence. */ template<typename _IIter, - typename _OutputIterator, - typename _BinaryOperation> + typename _OutputIterator, + typename _BinaryOperation> _OutputIterator - __parallel_partial_sum_basecase(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - typename std::iterator_traits - <_IIter>::value_type __value) + __parallel_partial_sum_basecase( + _IIter __begin, _IIter __end, _OutputIterator __result, + _BinaryOperation __bin_op, + typename std::iterator_traits <_IIter>::value_type __value) { if (__begin == __end) return __result; @@ -84,13 +84,13 @@ template<typename _IIter, * @return End iterator of output sequence. */ template<typename _IIter, - typename _OutputIterator, - typename _BinaryOperation> + typename _OutputIterator, + typename _BinaryOperation> _OutputIterator - __parallel_partial_sum_linear(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - typename std::iterator_traits - <_IIter>::difference_type __n) + __parallel_partial_sum_linear( + _IIter __begin, _IIter __end, _OutputIterator __result, + _BinaryOperation __bin_op, + typename std::iterator_traits<_IIter>::difference_type __n) { typedef std::iterator_traits<_IIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; @@ -128,8 +128,8 @@ template<typename _IIter, { _DifferenceType __chunk_length = ((double)__n - / ((double)__num_threads + __s.partial_sum_dilation)), - __borderstart = __n - __num_threads * __chunk_length; + / ((double)__num_threads + __s.partial_sum_dilation)), + __borderstart = __n - __num_threads * __chunk_length; __borders[0] = 0; for (int __i = 1; __i < (__num_threads + 1); ++__i) { @@ -140,7 +140,7 @@ template<typename _IIter, } __sums = static_cast<_ValueType*>(::operator new(sizeof(_ValueType) - * __num_threads)); + * __num_threads)); _OutputIterator __target_end; } //single @@ -148,33 +148,35 @@ template<typename _IIter, if (__iam == 0) { *__result = *__begin; - __parallel_partial_sum_basecase(__begin + 1, __begin + __borders[1], - __result + 1, __bin_op, *__begin); + __parallel_partial_sum_basecase( + __begin + 1, __begin + __borders[1], __result + 1, + __bin_op, *__begin); ::new(&(__sums[__iam])) _ValueType(*(__result + __borders[1] - 1)); } else { ::new(&(__sums[__iam])) - _ValueType(std::accumulate(__begin + __borders[__iam] + 1, - __begin + __borders[__iam + 1], - *(__begin + __borders[__iam]), - __bin_op, - __gnu_parallel::sequential_tag())); + _ValueType(std::accumulate(__begin + __borders[__iam] + 1, + __begin + __borders[__iam + 1], + *(__begin + __borders[__iam]), + __bin_op, + __gnu_parallel::sequential_tag())); } # pragma omp barrier # pragma omp single - __parallel_partial_sum_basecase( - __sums + 1, __sums + __num_threads, __sums + 1, __bin_op, __sums[0]); + __parallel_partial_sum_basecase(__sums + 1, __sums + __num_threads, + __sums + 1, __bin_op, __sums[0]); # pragma omp barrier // Still same team. - __parallel_partial_sum_basecase(__begin + __borders[__iam + 1], - __begin + __borders[__iam + 2], - __result + __borders[__iam + 1], __bin_op, - __sums[__iam]); + __parallel_partial_sum_basecase( + __begin + __borders[__iam + 1], + __begin + __borders[__iam + 2], + __result + __borders[__iam + 1], + __bin_op, __sums[__iam]); } //parallel ::operator delete(__sums); @@ -190,8 +192,8 @@ template<typename _IIter, * @param __bin_op Associative binary function. * @return End iterator of output sequence. */ template<typename _IIter, - typename _OutputIterator, - typename _BinaryOperation> + typename _OutputIterator, + typename _BinaryOperation> _OutputIterator __parallel_partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op) @@ -208,7 +210,8 @@ template<typename _IIter, { case LINEAR: // Need an initial offset. - return __parallel_partial_sum_linear(__begin, __end, __result, __bin_op, __n); + return __parallel_partial_sum_linear( + __begin, __end, __result, __bin_op, __n); default: // Partial_sum algorithm not implemented. _GLIBCXX_PARALLEL_ASSERT(0); diff --git a/libstdc++-v3/include/parallel/partition.h b/libstdc++-v3/include/parallel/partition.h index 399ad418d31..f50e83bbfd3 100644 --- a/libstdc++-v3/include/parallel/partition.h +++ b/libstdc++-v3/include/parallel/partition.h @@ -88,9 +88,10 @@ template<typename _RAIter, typename _Predicate> __reserved_right = new bool[__num_threads]; if (__s.partition_chunk_share > 0.0) - __chunk_size = std::max<_DifferenceType>(__s.partition_chunk_size, - (double)__n * __s.partition_chunk_share - / (double)__num_threads); + __chunk_size = std::max<_DifferenceType>( + __s.partition_chunk_size, + (double)__n * __s.partition_chunk_share / + (double)__num_threads); else __chunk_size = __s.partition_chunk_size; } @@ -99,7 +100,8 @@ template<typename _RAIter, typename _Predicate> { # pragma omp single { - _DifferenceType __num_chunks = (__right - __left + 1) / __chunk_size; + _DifferenceType __num_chunks + = (__right - __left + 1) / __chunk_size; for (int __r = 0; __r < __num_threads; ++__r) { @@ -198,7 +200,8 @@ template<typename _RAIter, typename _Predicate> && __thread_left_border >= __leftnew) { // Chunk already in place, reserve spot. - __reserved_left[(__left - (__thread_left_border + 1)) / __chunk_size] + __reserved_left + [(__left - (__thread_left_border + 1)) / __chunk_size] = true; } @@ -208,7 +211,7 @@ template<typename _RAIter, typename _Predicate> { // Chunk already in place, reserve spot. __reserved_right[((__thread_right_border - 1) - __right) - / __chunk_size] = true; + / __chunk_size] = true; } # pragma omp barrier @@ -233,9 +236,9 @@ template<typename _RAIter, typename _Predicate> #endif std::swap_ranges(__begin + __thread_left_border - - (__chunk_size - 1), - __begin + __thread_left_border + 1, - __begin + __swapstart); + - (__chunk_size - 1), + __begin + __thread_left_border + 1, + __begin + __swapstart); } if (thread_right >= __thread_right_border @@ -257,9 +260,10 @@ template<typename _RAIter, typename _Predicate> _GLIBCXX_PARALLEL_ASSERT(__swapstart != -1); #endif - std::swap_ranges(__begin + __thread_right_border, - __begin + __thread_right_border + __chunk_size, - __begin + __swapstart); + std::swap_ranges( + __begin + __thread_right_border, + __begin + __thread_right_border + __chunk_size, + __begin + __swapstart); } #if _GLIBCXX_ASSERTIONS # pragma omp barrier @@ -328,7 +332,7 @@ template<typename _RAIter, typename _Predicate> template<typename _RAIter, typename _Compare> void parallel_nth_element(_RAIter __begin, _RAIter __nth, - _RAIter __end, _Compare __comp) + _RAIter __end, _Compare __comp) { typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; @@ -355,18 +359,19 @@ template<typename _RAIter, typename _Compare> __pivot_pos = __end - 1; // XXX _Compare must have first__ValueType, second__ValueType, - // _ResultType + // _ResultType // _Compare == __gnu_parallel::_Lexicographic<S, int, - // __gnu_parallel::_Less<S, S> > + // __gnu_parallel::_Less<S, S> > // __pivot_pos == std::pair<S, int>* // XXX binder2nd only for _RAIters?? __gnu_parallel::binder2nd<_Compare, _ValueType, _ValueType, bool> - __pred(__comp, *__pivot_pos); + __pred(__comp, *__pivot_pos); // Divide, leave pivot unchanged in last place. _RAIter __split_pos1, __split_pos2; - __split_pos1 = __begin + __parallel_partition(__begin, __end - 1, __pred, - __get_max_threads()); + __split_pos1 = __begin + + __parallel_partition(__begin, __end - 1, __pred, + __get_max_threads()); // Left side: < __pivot_pos; __right side: >= __pivot_pos @@ -377,18 +382,18 @@ template<typename _RAIter, typename _Compare> // In case all elements are equal, __split_pos1 == 0 if ((__split_pos1 + 1 - __begin) < (__n >> 7) - || (__end - __split_pos1) < (__n >> 7)) + || (__end - __split_pos1) < (__n >> 7)) { // Very unequal split, one part smaller than one 128th // elements not strictly larger than the pivot. __gnu_parallel::__unary_negate<__gnu_parallel:: - __binder1st<_Compare, _ValueType, _ValueType, bool>, _ValueType> - __pred(__gnu_parallel::__binder1st<_Compare, _ValueType, - _ValueType, bool>(__comp, *__pivot_pos)); + __binder1st<_Compare, _ValueType, _ValueType, bool>, _ValueType> + __pred(__gnu_parallel::__binder1st<_Compare, _ValueType, + _ValueType, bool>(__comp, *__pivot_pos)); // Find other end of pivot-equal range. __split_pos2 = __gnu_sequential::partition(__split_pos1 + 1, - __end, __pred); + __end, __pred); } else // Only skip the pivot. @@ -415,8 +420,8 @@ template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare> void parallel_partial_sort(_RAIter __begin, - _RAIter __middle, - _RAIter __end, _Compare __comp) + _RAIter __middle, + _RAIter __end, _Compare __comp) { parallel_nth_element(__begin, __middle, __end, __comp); std::sort(__begin, __middle, __comp); diff --git a/libstdc++-v3/include/parallel/queue.h b/libstdc++-v3/include/parallel/queue.h index 587fa5312e2..348bb1ac900 100644 --- a/libstdc++-v3/include/parallel/queue.h +++ b/libstdc++-v3/include/parallel/queue.h @@ -59,7 +59,7 @@ namespace __gnu_parallel _SequenceIndex _M_max_size; /** @brief Cyclic __begin and __end pointers contained in one - atomically changeable value. */ + atomically changeable value. */ _GLIBCXX_VOLATILE _CASable _M_borders; public: @@ -67,9 +67,9 @@ namespace __gnu_parallel * @param _M_max_size Maximal number of elements to be contained. */ _RestrictedBoundedConcurrentQueue(_SequenceIndex _M_max_size) { - this->_M_max_size = _M_max_size; - _M_base = new _Tp[_M_max_size]; - _M_borders = __encode2(0, 0); + this->_M_max_size = _M_max_size; + _M_base = new _Tp[_M_max_size]; + _M_borders = __encode2(0, 0); #pragma omp flush } @@ -82,16 +82,16 @@ namespace __gnu_parallel void push_front(const _Tp& __t) { - _CASable __former_borders = _M_borders; - int __former_front, __former_back; - decode2(__former_borders, __former_front, __former_back); - *(_M_base + __former_front % _M_max_size) = __t; + _CASable __former_borders = _M_borders; + int __former_front, __former_back; + decode2(__former_borders, __former_front, __former_back); + *(_M_base + __former_front % _M_max_size) = __t; #if _GLIBCXX_ASSERTIONS - // Otherwise: front - back > _M_max_size eventually. - _GLIBCXX_PARALLEL_ASSERT(((__former_front + 1) - __former_back) - <= _M_max_size); + // Otherwise: front - back > _M_max_size eventually. + _GLIBCXX_PARALLEL_ASSERT(((__former_front + 1) - __former_back) + <= _M_max_size); #endif - __fetch_and_add(&_M_borders, __encode2(1, 0)); + __fetch_and_add(&_M_borders, __encode2(1, 0)); } /** @brief Pops one element from the queue at the front end. @@ -99,50 +99,56 @@ namespace __gnu_parallel bool pop_front(_Tp& __t) { - int __former_front, __former_back; + int __former_front, __former_back; #pragma omp flush - decode2(_M_borders, __former_front, __former_back); - while (__former_front > __former_back) - { - // Chance. - _CASable __former_borders = __encode2(__former_front, __former_back); - _CASable __new_borders = __encode2(__former_front - 1, __former_back); - if (__compare_and_swap(&_M_borders, __former_borders, __new_borders)) - { - __t = *(_M_base + (__former_front - 1) % _M_max_size); - return true; - } + decode2(_M_borders, __former_front, __former_back); + while (__former_front > __former_back) + { + // Chance. + _CASable + __former_borders = __encode2(__former_front, __former_back); + _CASable + __new_borders = __encode2(__former_front - 1, __former_back); + if (__compare_and_swap( + &_M_borders, __former_borders, __new_borders)) + { + __t = *(_M_base + (__former_front - 1) % _M_max_size); + return true; + } #pragma omp flush - decode2(_M_borders, __former_front, __former_back); - } - return false; + decode2(_M_borders, __former_front, __former_back); + } + return false; } /** @brief Pops one element from the queue at the front end. * Must not be called concurrently with pop_front(). */ bool - pop_back(_Tp& __t) //queue behavior + pop_back(_Tp& __t) //queue behavior { - int __former_front, __former_back; + int __former_front, __former_back; #pragma omp flush - decode2(_M_borders, __former_front, __former_back); - while (__former_front > __former_back) - { - // Chance. - _CASable __former_borders = __encode2(__former_front, __former_back); - _CASable __new_borders = __encode2(__former_front, __former_back + 1); - if (__compare_and_swap(&_M_borders, __former_borders, __new_borders)) - { - __t = *(_M_base + __former_back % _M_max_size); - return true; - } + decode2(_M_borders, __former_front, __former_back); + while (__former_front > __former_back) + { + // Chance. + _CASable + __former_borders = __encode2(__former_front, __former_back); + _CASable + __new_borders = __encode2(__former_front, __former_back + 1); + if (__compare_and_swap( + &_M_borders, __former_borders, __new_borders)) + { + __t = *(_M_base + __former_back % _M_max_size); + return true; + } #pragma omp flush - decode2(_M_borders, __former_front, __former_back); - } - return false; + decode2(_M_borders, __former_front, __former_back); + } + return false; } }; -} //namespace __gnu_parallel +} //namespace __gnu_parallel #undef _GLIBCXX_VOLATILE diff --git a/libstdc++-v3/include/parallel/quicksort.h b/libstdc++-v3/include/parallel/quicksort.h index 60f4b23bcd8..1ed46b4a77f 100644 --- a/libstdc++-v3/include/parallel/quicksort.h +++ b/libstdc++-v3/include/parallel/quicksort.h @@ -49,12 +49,12 @@ namespace __gnu_parallel template<typename _RAIter, typename _Compare> typename std::iterator_traits<_RAIter>::difference_type __parallel_sort_qs_divide(_RAIter __begin, - _RAIter __end, - _Compare __comp, typename std::iterator_traits - <_RAIter>::difference_type __pivot_rank, - typename std::iterator_traits - <_RAIter>::difference_type - __num_samples, _ThreadIndex __num_threads) + _RAIter __end, + _Compare __comp, typename std::iterator_traits + <_RAIter>::difference_type __pivot_rank, + typename std::iterator_traits + <_RAIter>::difference_type + __num_samples, _ThreadIndex __num_threads) { typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; @@ -65,15 +65,15 @@ namespace __gnu_parallel // Allocate uninitialized, to avoid default constructor. _ValueType* __samples = - static_cast<_ValueType*>(::operator new(__num_samples - * sizeof(_ValueType))); + static_cast<_ValueType*>(::operator new(__num_samples + * sizeof(_ValueType))); for (_DifferenceType __s = 0; __s < __num_samples; ++__s) - { - const unsigned long long __index = static_cast<unsigned long long>(__s) - * __n / __num_samples; - ::new(&(__samples[__s])) _ValueType(__begin[__index]); - } + { + const unsigned long long __index + = static_cast<unsigned long long>(__s) * __n / __num_samples; + ::new(&(__samples[__s])) _ValueType(__begin[__index]); + } __gnu_sequential::sort(__samples, __samples + __num_samples, __comp); @@ -99,47 +99,47 @@ namespace __gnu_parallel template<typename _RAIter, typename _Compare> void __parallel_sort_qs_conquer(_RAIter __begin, - _RAIter __end, - _Compare __comp, - _ThreadIndex __num_threads) + _RAIter __end, + _Compare __comp, + _ThreadIndex __num_threads) { typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; typedef typename _TraitsType::difference_type _DifferenceType; if (__num_threads <= 1) - { - __gnu_sequential::sort(__begin, __end, __comp); - return; - } + { + __gnu_sequential::sort(__begin, __end, __comp); + return; + } _DifferenceType __n = __end - __begin, __pivot_rank; if (__n <= 1) - return; + return; _ThreadIndex __num_threads_left; if ((__num_threads % 2) == 1) - __num_threads_left = __num_threads / 2 + 1; + __num_threads_left = __num_threads / 2 + 1; else - __num_threads_left = __num_threads / 2; + __num_threads_left = __num_threads / 2; __pivot_rank = __n * __num_threads_left / __num_threads; _DifferenceType __split = - __parallel_sort_qs_divide(__begin, __end, __comp, __pivot_rank, - _Settings::get().sort_qs_num_samples_preset, - __num_threads); + __parallel_sort_qs_divide(__begin, __end, __comp, __pivot_rank, + _Settings::get().sort_qs_num_samples_preset, + __num_threads); #pragma omp parallel sections num_threads(2) { #pragma omp section - __parallel_sort_qs_conquer(__begin, __begin + __split, - __comp, __num_threads_left); + __parallel_sort_qs_conquer(__begin, __begin + __split, + __comp, __num_threads_left); #pragma omp section - __parallel_sort_qs_conquer(__begin + __split, __end, - __comp, __num_threads - __num_threads_left); + __parallel_sort_qs_conquer(__begin + __split, __end, + __comp, __num_threads - __num_threads_left); } } @@ -155,9 +155,9 @@ namespace __gnu_parallel template<typename _RAIter, typename _Compare> void __parallel_sort_qs(_RAIter __begin, - _RAIter __end, - _Compare __comp, - _ThreadIndex __num_threads) + _RAIter __end, + _Compare __comp, + _ThreadIndex __num_threads) { _GLIBCXX_CALL(__n) @@ -171,7 +171,8 @@ namespace __gnu_parallel if (__num_threads > __n) __num_threads = static_cast<_ThreadIndex>(__n); - __parallel_sort_qs_conquer(__begin, __begin + __n, __comp, __num_threads); + __parallel_sort_qs_conquer( + __begin, __begin + __n, __comp, __num_threads); } } //namespace __gnu_parallel diff --git a/libstdc++-v3/include/parallel/random_number.h b/libstdc++-v3/include/parallel/random_number.h index 12f646b2eb2..6447087ebbb 100644 --- a/libstdc++-v3/include/parallel/random_number.h +++ b/libstdc++-v3/include/parallel/random_number.h @@ -41,14 +41,14 @@ namespace __gnu_parallel class _RandomNumber { private: - std::tr1::mt19937 _M_mt; - uint64 _M_supremum; - uint64 _M_rand_sup; - double _M_supremum_reciprocal; - double _M_rand_sup_reciprocal; + std::tr1::mt19937 _M_mt; + uint64 _M_supremum; + uint64 _M_rand_sup; + double _M_supremum_reciprocal; + double _M_rand_sup_reciprocal; // Assumed to be twice as long as the usual random number. - uint64 __cache; + uint64 __cache; // Bit results. int __bits_left; @@ -56,17 +56,17 @@ namespace __gnu_parallel static uint32 __scale_down(uint64 __x, #if _GLIBCXX_SCALE_DOWN_FPU - uint64 /*_M_supremum*/, double _M_supremum_reciprocal) + uint64 /*_M_supremum*/, double _M_supremum_reciprocal) #else uint64 _M_supremum, double /*_M_supremum_reciprocal*/) #endif - { + { #if _GLIBCXX_SCALE_DOWN_FPU - return uint32(__x * _M_supremum_reciprocal); + return uint32(__x * _M_supremum_reciprocal); #else - return static_cast<uint32>(__x % _M_supremum); + return static_cast<uint32>(__x % _M_supremum); #endif - } + } public: /** @brief Default constructor. Seed with 0. */ @@ -94,12 +94,12 @@ namespace __gnu_parallel { return __scale_down(_M_mt(), _M_supremum, _M_supremum_reciprocal); } /** @brief Generate unsigned random 32-bit integer in the - interval @__c [0,local_supremum). */ + interval @__c [0,local_supremum). */ uint32 operator()(uint64 local_supremum) { return __scale_down(_M_mt(), local_supremum, - double(local_supremum * _M_rand_sup_reciprocal)); + double(local_supremum * _M_rand_sup_reciprocal)); } /** @brief Generate a number of random bits, run-time parameter. @@ -111,10 +111,10 @@ namespace __gnu_parallel __cache = __cache >> __bits; __bits_left -= __bits; if (__bits_left < 32) - { - __cache |= ((uint64(_M_mt())) << __bits_left); - __bits_left += 32; - } + { + __cache |= ((uint64(_M_mt())) << __bits_left); + __bits_left += 32; + } return __res; } }; diff --git a/libstdc++-v3/include/parallel/random_shuffle.h b/libstdc++-v3/include/parallel/random_shuffle.h index faab8d80f27..49d0d8557b7 100644 --- a/libstdc++-v3/include/parallel/random_shuffle.h +++ b/libstdc++-v3/include/parallel/random_shuffle.h @@ -70,7 +70,7 @@ template<typename _RAIter> _DifferenceType* _M_starts; /** @brief Number of the thread that will further process the - corresponding bin. */ + corresponding bin. */ _ThreadIndex* _M_bin_proc; /** @brief Number of bins to distribute to. */ @@ -131,7 +131,8 @@ template<typename _RAIter, typename RandomNumberGenerator> _DRandomShufflingGlobalData<_RAIter>* _M_sd = d->_M_sd; // Indexing: _M_dist[bin][processor] - _DifferenceType __length = _M_sd->_M_starts[__iam + 1] - _M_sd->_M_starts[__iam]; + _DifferenceType __length = _M_sd->_M_starts[__iam + 1] - + _M_sd->_M_starts[__iam]; _BinIndex* __oracles = new _BinIndex[__length]; _DifferenceType* _M_dist = new _DifferenceType[_M_sd->_M_num_bins + 1]; _BinIndex* _M_bin_proc = new _BinIndex[_M_sd->_M_num_bins]; @@ -161,12 +162,13 @@ template<typename _RAIter, typename RandomNumberGenerator> # pragma omp single { - // Sum up bins, _M_sd->_M_dist[__s + 1][d->_M_num_threads] now contains the - // total number of items in bin __s + // Sum up bins, _M_sd->_M_dist[__s + 1][d->_M_num_threads] now contains + // the total number of items in bin __s for (_BinIndex __s = 0; __s < _M_sd->_M_num_bins; ++__s) - __gnu_sequential::partial_sum(_M_sd->_M_dist[__s + 1], - _M_sd->_M_dist[__s + 1] + d->_M_num_threads + 1, - _M_sd->_M_dist[__s + 1]); + __gnu_sequential::partial_sum( + _M_sd->_M_dist[__s + 1], + _M_sd->_M_dist[__s + 1] + d->_M_num_threads + 1, + _M_sd->_M_dist[__s + 1]); } # pragma omp barrier @@ -179,9 +181,9 @@ template<typename _RAIter, typename RandomNumberGenerator> for (_BinIndex __s = d->_M_bins_begin; __s < d->__bins_end; ++__s) { - for (int __t = 0; __t < d->_M_num_threads + 1; ++__t) - _M_sd->_M_dist[__s + 1][__t] += __offset; - __offset = _M_sd->_M_dist[__s + 1][d->_M_num_threads]; + for (int __t = 0; __t < d->_M_num_threads + 1; ++__t) + _M_sd->_M_dist[__s + 1][__t] += __offset; + __offset = _M_sd->_M_dist[__s + 1][d->_M_num_threads]; } _M_sd->_M_temporaries[__iam] = static_cast<_ValueType*>( @@ -208,7 +210,7 @@ template<typename _RAIter, typename RandomNumberGenerator> // Last column [d->_M_num_threads] stays unchanged. ::new(&(_M_temporaries[target_p][_M_dist[target_bin + 1]++])) - _ValueType(*(_M_source + __i + __start)); + _ValueType(*(_M_source + __i + __start)); } delete[] __oracles; @@ -223,12 +225,15 @@ template<typename _RAIter, typename RandomNumberGenerator> { _ValueType* __begin = _M_sd->_M_temporaries[__iam] + - ((__b == d->_M_bins_begin) ? 0 : _M_sd->_M_dist[__b][d->_M_num_threads]), + ((__b == d->_M_bins_begin) + ? 0 : _M_sd->_M_dist[__b][d->_M_num_threads]), * __end = - _M_sd->_M_temporaries[__iam] + _M_sd->_M_dist[__b + 1][d->_M_num_threads]; + _M_sd->_M_temporaries[__iam] + + _M_sd->_M_dist[__b + 1][d->_M_num_threads]; __sequential_random_shuffle(__begin, __end, __rng); std::copy(__begin, __end, _M_sd->_M_source + __global_offset + - ((__b == d->_M_bins_begin) ? 0 : _M_sd->_M_dist[__b][d->_M_num_threads])); + ((__b == d->_M_bins_begin) + ? 0 : _M_sd->_M_dist[__b][d->_M_num_threads])); } ::operator delete(_M_sd->_M_temporaries[__iam]); @@ -256,11 +261,11 @@ template<typename _Tp> template<typename _RAIter, typename RandomNumberGenerator> void __parallel_random_shuffle_drs(_RAIter __begin, - _RAIter __end, - typename std::iterator_traits - <_RAIter>::difference_type __n, - _ThreadIndex __num_threads, - RandomNumberGenerator& __rng) + _RAIter __end, + typename std::iterator_traits + <_RAIter>::difference_type __n, + _ThreadIndex __num_threads, + RandomNumberGenerator& __rng) { typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; @@ -343,7 +348,8 @@ template<typename _RAIter, typename RandomNumberGenerator> _M_sd._M_dist[0][0] = 0; _M_sd._M_dist[__b][0] = 0; } - _M_starts = _M_sd._M_starts = new _DifferenceType[__num_threads + 1]; + _M_starts = _M_sd._M_starts + = new _DifferenceType[__num_threads + 1]; int bin_cursor = 0; _M_sd._M_num_bins = _M_num_bins; _M_sd._M_num_bits = __log2(_M_num_bins); @@ -355,7 +361,8 @@ template<typename _RAIter, typename RandomNumberGenerator> for (_ThreadIndex __i = 0; __i < __num_threads; ++__i) { _M_starts[__i] = __start; - __start += (__i < __split) ? (__chunk_length + 1) : __chunk_length; + __start += (__i < __split) + ? (__chunk_length + 1) : __chunk_length; int __j = __pus[__i]._M_bins_begin = bin_cursor; // Range of bins for this processor. @@ -469,14 +476,16 @@ template<typename _RAIter, typename RandomNumberGenerator> } // Sum up bins. - __gnu_sequential::partial_sum(__dist0, __dist0 + _M_num_bins + 1, __dist0); + __gnu_sequential:: + partial_sum(__dist0, __dist0 + _M_num_bins + 1, __dist0); for (int __b = 0; __b < _M_num_bins + 1; ++__b) __dist1[__b] = __dist0[__b]; // Distribute according to oracles. for (_DifferenceType __i = 0; __i < __n; ++__i) - ::new(&(__target[(__dist0[__oracles[__i]])++])) _ValueType(*(__begin + __i)); + ::new(&(__target[(__dist0[__oracles[__i]])++])) + _ValueType(*(__begin + __i)); for (int __b = 0; __b < _M_num_bins; ++__b) { @@ -511,7 +520,8 @@ template<typename _RAIter, typename RandomNumberGenerator> typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::difference_type _DifferenceType; _DifferenceType __n = __end - __begin; - __parallel_random_shuffle_drs(__begin, __end, __n, __get_max_threads(), __rng) ; + __parallel_random_shuffle_drs( + __begin, __end, __n, __get_max_threads(), __rng) ; } } diff --git a/libstdc++-v3/include/parallel/search.h b/libstdc++-v3/include/parallel/search.h index b0a9f6918bf..a253126d90a 100644 --- a/libstdc++-v3/include/parallel/search.h +++ b/libstdc++-v3/include/parallel/search.h @@ -76,8 +76,8 @@ template<typename _RAIter, typename _DifferenceTp> * @param __pred Find predicate. * @return Place of finding in first sequences. */ template<typename __RAIter1, - typename __RAIter2, - typename _Pred> + typename __RAIter2, + typename _Pred> __RAIter1 __search_template(__RAIter1 __begin1, __RAIter1 __end1, __RAIter2 __begin2, __RAIter2 __end2, @@ -126,7 +126,8 @@ template<typename __RAIter1, _ThreadIndex __iam = omp_get_thread_num(); - _DifferenceType __start = __splitters[__iam], __stop = __splitters[__iam + 1]; + _DifferenceType __start = __splitters[__iam], + __stop = __splitters[__iam + 1]; _DifferenceType __pos_in_pattern = 0; bool __found_pattern = false; @@ -156,7 +157,8 @@ template<typename __RAIter1, // Make safe jump. __start += (__pos_in_pattern - __advances[__pos_in_pattern]); __pos_in_pattern = - (__advances[__pos_in_pattern] < 0) ? 0 : __advances[__pos_in_pattern]; + (__advances[__pos_in_pattern] < 0) ? + 0 : __advances[__pos_in_pattern]; } } //parallel diff --git a/libstdc++-v3/include/parallel/set_operations.h b/libstdc++-v3/include/parallel/set_operations.h index 4bbbf089363..ac669c55d5d 100644 --- a/libstdc++-v3/include/parallel/set_operations.h +++ b/libstdc++-v3/include/parallel/set_operations.h @@ -63,8 +63,8 @@ template<typename _IIter, typename _OutputIterator> } template<typename _IIter, - typename _OutputIterator, - typename _Compare> + typename _OutputIterator, + typename _Compare> struct symmetric_difference_func { typedef std::iterator_traits<_IIter> _TraitsType; @@ -77,8 +77,8 @@ template<typename _IIter, _OutputIterator _M_invoke(_IIter __a, _IIter __b, - _IIter __c, _IIter d, - _OutputIterator __r) const + _IIter __c, _IIter d, + _OutputIterator __r) const { while (__a != __b && __c != d) { @@ -105,7 +105,7 @@ template<typename _IIter, _DifferenceType __count(_IIter __a, _IIter __b, - _IIter __c, _IIter d) const + _IIter __c, _IIter d) const { _DifferenceType __counter = 0; @@ -142,8 +142,8 @@ template<typename _IIter, template<typename _IIter, - typename _OutputIterator, - typename _Compare> + typename _OutputIterator, + typename _Compare> struct __difference_func { typedef std::iterator_traits<_IIter> _TraitsType; @@ -179,7 +179,7 @@ template<typename _IIter, _DifferenceType __count(_IIter __a, _IIter __b, - _IIter __c, _IIter d) const + _IIter __c, _IIter d) const { _DifferenceType __counter = 0; @@ -210,8 +210,8 @@ template<typename _IIter, template<typename _IIter, - typename _OutputIterator, - typename _Compare> + typename _OutputIterator, + typename _Compare> struct __intersection_func { typedef std::iterator_traits<_IIter> _TraitsType; @@ -246,7 +246,7 @@ template<typename _IIter, _DifferenceType __count(_IIter __a, _IIter __b, - _IIter __c, _IIter d) const + _IIter __c, _IIter d) const { _DifferenceType __counter = 0; @@ -315,7 +315,7 @@ template<class _IIter, class _OutputIterator, class _Compare> _DifferenceType __count(_IIter __a, _IIter __b, - _IIter __c, _IIter d) const + _IIter __c, _IIter d) const { _DifferenceType __counter = 0; @@ -348,8 +348,8 @@ template<class _IIter, class _OutputIterator, class _Compare> }; template<typename _IIter, - typename _OutputIterator, - typename Operation> + typename _OutputIterator, + typename Operation> _OutputIterator __parallel_set_operation(_IIter __begin1, _IIter __end1, _IIter __begin2, _IIter __end2, @@ -370,7 +370,7 @@ template<typename _IIter, const _DifferenceType size = (__end1 - __begin1) + (__end2 - __begin2); const _IteratorPair __sequence[ 2 ] = - { std::make_pair(__begin1, __end1), std::make_pair(__begin2, __end2) } ; + { std::make_pair(__begin1, __end1), std::make_pair(__begin2, __end2) }; _OutputIterator return_value = __result; _DifferenceType *__borders; _IteratorPair *__block_begins; @@ -400,7 +400,8 @@ template<typename _IIter, _IIter __offset[2]; const _DifferenceType __rank = __borders[__iam + 1]; - multiseq_partition(__sequence, __sequence + 2, __rank, __offset, __op._M_comp); + multiseq_partition(__sequence, __sequence + 2, + __rank, __offset, __op._M_comp); // allowed to read? // together @@ -427,15 +428,16 @@ template<typename _IIter, if (__iam == 0) { // The first thread can copy already. - __lengths[ __iam ] = __op._M_invoke(__block_begin.first, block_end.first, - __block_begin.second, block_end.second, - __result) + __lengths[ __iam ] = + __op._M_invoke(__block_begin.first, block_end.first, + __block_begin.second, block_end.second, __result) - __result; } else { - __lengths[ __iam ] = __op.__count(__block_begin.first, block_end.first, - __block_begin.second, block_end.second); + __lengths[ __iam ] = + __op.__count(__block_begin.first, block_end.first, + __block_begin.second, block_end.second); } // Make sure everyone wrote their lengths. @@ -453,7 +455,7 @@ template<typename _IIter, // Return the result iterator of the last block. return_value = __op._M_invoke( - __block_begin.first, __end1, __block_begin.second, __end2, __r); + __block_begin.first, __end1, __block_begin.second, __end2, __r); } else @@ -471,52 +473,56 @@ template<typename _IIter, template<typename _IIter, - typename _OutputIterator, - typename _Compare> + typename _OutputIterator, + typename _Compare> inline _OutputIterator __parallel_set_union(_IIter __begin1, _IIter __end1, _IIter __begin2, _IIter __end2, _OutputIterator __result, _Compare _M_comp) { - return __parallel_set_operation(__begin1, __end1, __begin2, __end2, __result, - __union_func< _IIter, _OutputIterator, _Compare>(_M_comp)); + return __parallel_set_operation(__begin1, __end1, __begin2, __end2, + __result, __union_func< _IIter, _OutputIterator, _Compare>(_M_comp)); } template<typename _IIter, - typename _OutputIterator, - typename _Compare> + typename _OutputIterator, + typename _Compare> inline _OutputIterator __parallel_set_intersection(_IIter __begin1, _IIter __end1, - _IIter __begin2, _IIter __end2, - _OutputIterator __result, _Compare _M_comp) + _IIter __begin2, _IIter __end2, + _OutputIterator __result, _Compare _M_comp) { - return __parallel_set_operation(__begin1, __end1, __begin2, __end2, __result, - __intersection_func<_IIter, _OutputIterator, _Compare>(_M_comp)); + return __parallel_set_operation( + __begin1, __end1, __begin2, __end2, __result, + __intersection_func<_IIter, _OutputIterator, _Compare>(_M_comp)); } template<typename _IIter, - typename _OutputIterator, - typename _Compare> + typename _OutputIterator, + typename _Compare> inline _OutputIterator __parallel_set_difference(_IIter __begin1, _IIter __end1, - _IIter __begin2, _IIter __end2, - _OutputIterator __result, _Compare _M_comp) + _IIter __begin2, _IIter __end2, + _OutputIterator __result, _Compare _M_comp) { - return __parallel_set_operation(__begin1, __end1, __begin2, __end2, __result, - __difference_func<_IIter, _OutputIterator, _Compare>(_M_comp)); + return __parallel_set_operation( + __begin1, __end1, __begin2, __end2, __result, + __difference_func<_IIter, _OutputIterator, _Compare>(_M_comp)); } template<typename _IIter, - typename _OutputIterator, - typename _Compare> + typename _OutputIterator, + typename _Compare> inline _OutputIterator __parallel_set_symmetric_difference(_IIter __begin1, _IIter __end1, - _IIter __begin2, _IIter __end2, - _OutputIterator __result, _Compare _M_comp) + _IIter __begin2, _IIter __end2, + _OutputIterator __result, + _Compare _M_comp) { - return __parallel_set_operation(__begin1, __end1, __begin2, __end2, __result, - symmetric_difference_func<_IIter, _OutputIterator, _Compare> - (_M_comp)); + return __parallel_set_operation( + __begin1, __end1, __begin2, __end2, __result, + symmetric_difference_func<_IIter, _OutputIterator, _Compare> + (_M_comp)); } } diff --git a/libstdc++-v3/include/parallel/settings.h b/libstdc++-v3/include/parallel/settings.h index e68a0c4da9a..e83ecc50ea5 100644 --- a/libstdc++-v3/include/parallel/settings.h +++ b/libstdc++-v3/include/parallel/settings.h @@ -92,7 +92,12 @@ * __gnu_parallel::_Settings::algorithm_strategy. Usually a decision * based on the input size. */ -#define _GLIBCXX_PARALLEL_CONDITION(__c) (__gnu_parallel::_Settings::get().algorithm_strategy != __gnu_parallel::force_sequential && ((__gnu_parallel::__get_max_threads() > 1 && (__c)) || __gnu_parallel::_Settings::get().algorithm_strategy == __gnu_parallel::force_parallel)) +#define _GLIBCXX_PARALLEL_CONDITION(__c) \ + (__gnu_parallel::_Settings::get().algorithm_strategy \ + != __gnu_parallel::force_sequential \ + && ((__gnu_parallel::__get_max_threads() > 1 && (__c)) \ + || __gnu_parallel::_Settings::get().algorithm_strategy \ + == __gnu_parallel::force_parallel)) /* inline bool @@ -103,9 +108,9 @@ parallel_condition(bool __c) if (__s.algorithm_strategy != force_seqential) { if (__s.algorithm_strategy == force_parallel) - ret = true; + ret = true; else - ret = __get_max_threads() > 1 && __c; + ret = __get_max_threads() > 1 && __c; } return ret; } @@ -113,156 +118,156 @@ parallel_condition(bool __c) namespace __gnu_parallel { - /// class _Settings - /// Run-time settings for the parallel mode, including all tunable parameters. + /// class _Settings + /// Run-time settings for the parallel mode including all tunable parameters. struct _Settings { - _AlgorithmStrategy algorithm_strategy; + _AlgorithmStrategy algorithm_strategy; - _SortAlgorithm sort_algorithm; - _PartialSumAlgorithm partial_sum_algorithm; - _MultiwayMergeAlgorithm multiway_merge_algorithm; - _FindAlgorithm find_algorithm; + _SortAlgorithm sort_algorithm; + _PartialSumAlgorithm partial_sum_algorithm; + _MultiwayMergeAlgorithm multiway_merge_algorithm; + _FindAlgorithm find_algorithm; - _SplittingAlgorithm sort_splitting; - _SplittingAlgorithm merge_splitting; - _SplittingAlgorithm multiway_merge_splitting; + _SplittingAlgorithm sort_splitting; + _SplittingAlgorithm merge_splitting; + _SplittingAlgorithm multiway_merge_splitting; // Per-algorithm settings. /// Minimal input size for accumulate. - _SequenceIndex accumulate_minimal_n; + _SequenceIndex accumulate_minimal_n; /// Minimal input size for adjacent_difference. - unsigned int adjacent_difference_minimal_n; + unsigned int adjacent_difference_minimal_n; /// Minimal input size for count and count_if. - _SequenceIndex count_minimal_n; + _SequenceIndex count_minimal_n; /// Minimal input size for fill. - _SequenceIndex fill_minimal_n; + _SequenceIndex fill_minimal_n; /// Block size increase factor for find. - double find_increasing_factor; + double find_increasing_factor; /// Initial block size for find. - _SequenceIndex find_initial_block_size; + _SequenceIndex find_initial_block_size; /// Maximal block size for find. - _SequenceIndex find_maximum_block_size; + _SequenceIndex find_maximum_block_size; /// Start with looking for this many elements sequentially, for find. - _SequenceIndex find_sequential_search_size; + _SequenceIndex find_sequential_search_size; /// Minimal input size for for_each. - _SequenceIndex for_each_minimal_n; + _SequenceIndex for_each_minimal_n; /// Minimal input size for generate. - _SequenceIndex generate_minimal_n; + _SequenceIndex generate_minimal_n; /// Minimal input size for max_element. - _SequenceIndex max_element_minimal_n; + _SequenceIndex max_element_minimal_n; /// Minimal input size for merge. - _SequenceIndex merge_minimal_n; + _SequenceIndex merge_minimal_n; /// Oversampling factor for merge. - unsigned int merge_oversampling; + unsigned int merge_oversampling; /// Minimal input size for min_element. - _SequenceIndex min_element_minimal_n; + _SequenceIndex min_element_minimal_n; /// Minimal input size for multiway_merge. - _SequenceIndex multiway_merge_minimal_n; + _SequenceIndex multiway_merge_minimal_n; /// Oversampling factor for multiway_merge. - int multiway_merge_minimal_k; + int multiway_merge_minimal_k; /// Oversampling factor for multiway_merge. - unsigned int multiway_merge_oversampling; + unsigned int multiway_merge_oversampling; /// Minimal input size for nth_element. - _SequenceIndex nth_element_minimal_n; + _SequenceIndex nth_element_minimal_n; /// Chunk size for partition. - _SequenceIndex partition_chunk_size; + _SequenceIndex partition_chunk_size; /// Chunk size for partition, relative to input size. If > 0.0, /// this value overrides partition_chunk_size. - double partition_chunk_share; + double partition_chunk_share; /// Minimal input size for partition. - _SequenceIndex partition_minimal_n; + _SequenceIndex partition_minimal_n; /// Minimal input size for partial_sort. - _SequenceIndex partial_sort_minimal_n; + _SequenceIndex partial_sort_minimal_n; /// Ratio for partial_sum. Assume "sum and write result" to be /// this factor slower than just "sum". - float partial_sum_dilation; + float partial_sum_dilation; /// Minimal input size for partial_sum. - unsigned int partial_sum_minimal_n; + unsigned int partial_sum_minimal_n; /// Minimal input size for random_shuffle. - unsigned int random_shuffle_minimal_n; + unsigned int random_shuffle_minimal_n; /// Minimal input size for replace and replace_if. - _SequenceIndex replace_minimal_n; + _SequenceIndex replace_minimal_n; /// Minimal input size for set_difference. - _SequenceIndex set_difference_minimal_n; + _SequenceIndex set_difference_minimal_n; /// Minimal input size for set_intersection. - _SequenceIndex set_intersection_minimal_n; + _SequenceIndex set_intersection_minimal_n; /// Minimal input size for set_symmetric_difference. - _SequenceIndex set_symmetric_difference_minimal_n; + _SequenceIndex set_symmetric_difference_minimal_n; /// Minimal input size for set_union. - _SequenceIndex set_union_minimal_n; + _SequenceIndex set_union_minimal_n; /// Minimal input size for parallel sorting. - _SequenceIndex sort_minimal_n; + _SequenceIndex sort_minimal_n; /// Oversampling factor for parallel std::sort (MWMS). - unsigned int sort_mwms_oversampling; + unsigned int sort_mwms_oversampling; /// Such many samples to take to find a good pivot (quicksort). - unsigned int sort_qs_num_samples_preset; + unsigned int sort_qs_num_samples_preset; /// Maximal subsequence __length to switch to unbalanced __base case. /// Applies to std::sort with dynamically load-balanced quicksort. - _SequenceIndex sort_qsb_base_case_maximal_n; + _SequenceIndex sort_qsb_base_case_maximal_n; /// Minimal input size for parallel std::transform. - _SequenceIndex transform_minimal_n; + _SequenceIndex transform_minimal_n; /// Minimal input size for unique_copy. - _SequenceIndex unique_copy_minimal_n; + _SequenceIndex unique_copy_minimal_n; - _SequenceIndex workstealing_chunk_size; + _SequenceIndex workstealing_chunk_size; // Hardware dependent tuning parameters. /// size of the L1 cache in bytes (underestimation). - unsigned long long L1_cache_size; + unsigned long long L1_cache_size; /// size of the L2 cache in bytes (underestimation). - unsigned long long L2_cache_size; + unsigned long long L2_cache_size; /// size of the Translation Lookaside Buffer (underestimation). - unsigned int TLB_size; + unsigned int TLB_size; /// Overestimation of cache line size. Used to avoid false /// sharing, i.e. elements of different threads are at least this /// amount apart. - unsigned int cache_line_size; + unsigned int cache_line_size; // Statistics. /// The number of stolen ranges in load-balanced quicksort. - _SequenceIndex qsb_steals; + _SequenceIndex qsb_steals; /// Get the global settings. _GLIBCXX_CONST static const _Settings& @@ -273,7 +278,56 @@ namespace __gnu_parallel set(_Settings&) throw(); explicit - _Settings() : algorithm_strategy(heuristic), sort_algorithm(MWMS), partial_sum_algorithm(LINEAR), multiway_merge_algorithm(LOSER_TREE), find_algorithm(CONSTANT_SIZE_BLOCKS), sort_splitting(EXACT), merge_splitting(EXACT), multiway_merge_splitting(EXACT), accumulate_minimal_n(1000), adjacent_difference_minimal_n(1000), count_minimal_n(1000), fill_minimal_n(1000), find_increasing_factor(2.0), find_initial_block_size(256), find_maximum_block_size(8192), find_sequential_search_size(256), for_each_minimal_n(1000), generate_minimal_n(1000), max_element_minimal_n(1000), merge_minimal_n(1000), merge_oversampling(10), min_element_minimal_n(1000), multiway_merge_minimal_n(1000), multiway_merge_minimal_k(2), multiway_merge_oversampling(10), nth_element_minimal_n(1000), partition_chunk_size(1000), partition_chunk_share(0.0), partition_minimal_n(1000), partial_sort_minimal_n(1000), partial_sum_dilation(1.0f), partial_sum_minimal_n(1000), random_shuffle_minimal_n(1000), replace_minimal_n(1000), set_difference_minimal_n(1000), set_intersection_minimal_n(1000), set_symmetric_difference_minimal_n(1000), set_union_minimal_n(1000), sort_minimal_n(1000), sort_mwms_oversampling(10), sort_qs_num_samples_preset(100), sort_qsb_base_case_maximal_n(100), transform_minimal_n(1000), unique_copy_minimal_n(10000), workstealing_chunk_size(100), L1_cache_size(16 << 10), L2_cache_size(256 << 10), TLB_size(128), cache_line_size(64), qsb_steals(0) + _Settings() : + algorithm_strategy(heuristic), + sort_algorithm(MWMS), + partial_sum_algorithm(LINEAR), + multiway_merge_algorithm(LOSER_TREE), + find_algorithm(CONSTANT_SIZE_BLOCKS), + sort_splitting(EXACT), + merge_splitting(EXACT), + multiway_merge_splitting(EXACT), + accumulate_minimal_n(1000), + adjacent_difference_minimal_n(1000), + count_minimal_n(1000), + fill_minimal_n(1000), + find_increasing_factor(2.0), + find_initial_block_size(256), + find_maximum_block_size(8192), + find_sequential_search_size(256), + for_each_minimal_n(1000), + generate_minimal_n(1000), + max_element_minimal_n(1000), + merge_minimal_n(1000), + merge_oversampling(10), + min_element_minimal_n(1000), + multiway_merge_minimal_n(1000), + multiway_merge_minimal_k(2), multiway_merge_oversampling(10), + nth_element_minimal_n(1000), + partition_chunk_size(1000), + partition_chunk_share(0.0), + partition_minimal_n(1000), + partial_sort_minimal_n(1000), + partial_sum_dilation(1.0f), + partial_sum_minimal_n(1000), + random_shuffle_minimal_n(1000), + replace_minimal_n(1000), + set_difference_minimal_n(1000), + set_intersection_minimal_n(1000), + set_symmetric_difference_minimal_n(1000), + set_union_minimal_n(1000), + sort_minimal_n(1000), + sort_mwms_oversampling(10), + sort_qs_num_samples_preset(100), + sort_qsb_base_case_maximal_n(100), + transform_minimal_n(1000), + unique_copy_minimal_n(10000), + workstealing_chunk_size(100), + L1_cache_size(16 << 10), + L2_cache_size(256 << 10), + TLB_size(128), + cache_line_size(64), + qsb_steals(0) { } }; } diff --git a/libstdc++-v3/include/parallel/sort.h b/libstdc++-v3/include/parallel/sort.h index 259b1982322..03b19210a82 100644 --- a/libstdc++-v3/include/parallel/sort.h +++ b/libstdc++-v3/include/parallel/sort.h @@ -54,13 +54,13 @@ namespace __gnu_parallel { - //prototype + //prototype template<bool __stable, typename _RAIter, typename _Compare, typename _Parallelism> void parallel_sort(_RAIter __begin, _RAIter __end, _Compare __comp, _Parallelism __parallelism); - + /** * @brief Choose multiway mergesort, splitting variant at run-time, * for parallel sorting. @@ -138,7 +138,8 @@ namespace __gnu_parallel _GLIBCXX_PARALLEL_ASSERT(__stable == false); - __parallel_sort_qs(__begin, __end, __comp, __parallelism.__get_num_threads()); + __parallel_sort_qs(__begin, __end, __comp, + __parallelism.__get_num_threads()); } /** @@ -158,7 +159,8 @@ namespace __gnu_parallel _GLIBCXX_PARALLEL_ASSERT(__stable == false); - __parallel_sort_qsb(__begin, __end, __comp, __parallelism.__get_num_threads()); + __parallel_sort_qsb(__begin, __end, __comp, + __parallelism.__get_num_threads()); } @@ -215,11 +217,13 @@ namespace __gnu_parallel #endif #if _GLIBCXX_QUICKSORT else if (_Settings::get().sort_algorithm == QS) - __parallel_sort_qs(__begin, __end, __comp, __parallelism.__get_num_threads()); + __parallel_sort_qs(__begin, __end, __comp, + __parallelism.__get_num_threads()); #endif #if _GLIBCXX_BAL_QUICKSORT else if (_Settings::get().sort_algorithm == QS_BALANCED) - __parallel_sort_qsb(__begin, __end, __comp, __parallelism.__get_num_threads()); + __parallel_sort_qsb(__begin, __end, __comp, + __parallelism.__get_num_threads()); #endif else __gnu_sequential::sort(__begin, __end, __comp); diff --git a/libstdc++-v3/include/parallel/types.h b/libstdc++-v3/include/parallel/types.h index 70bfb64120a..3321f2d5bad 100644 --- a/libstdc++-v3/include/parallel/types.h +++ b/libstdc++-v3/include/parallel/types.h @@ -149,7 +149,8 @@ namespace __gnu_parallel static const int _CASable_bits = sizeof(_CASable) * 8; /// ::_CASable with the right half of bits set to 1. - static const _CASable _CASable_mask = ((_CASable(1) << (_CASable_bits / 2)) - 1); + static const _CASable _CASable_mask = + ((_CASable(1) << (_CASable_bits / 2)) - 1); } #endif /* _GLIBCXX_PARALLEL_TYPES_H */ diff --git a/libstdc++-v3/include/parallel/unique_copy.h b/libstdc++-v3/include/parallel/unique_copy.h index db2e820a708..327870e7d86 100644 --- a/libstdc++-v3/include/parallel/unique_copy.h +++ b/libstdc++-v3/include/parallel/unique_copy.h @@ -45,11 +45,11 @@ namespace __gnu_parallel * @param __binary_pred Equality predicate. * @return End iterator of result __sequence. */ template<typename _IIter, - class _OutputIterator, - class _BinaryPredicate> + class _OutputIterator, + class _BinaryPredicate> _OutputIterator __parallel_unique_copy(_IIter __first, _IIter __last, - _OutputIterator __result, _BinaryPredicate __binary_pred) + _OutputIterator __result, _BinaryPredicate __binary_pred) { _GLIBCXX_CALL(__last - __first) @@ -72,10 +72,10 @@ template<typename _IIter, { # pragma omp single { - __num_threads = omp_get_num_threads(); - __borders = new _DifferenceType[__num_threads + 2]; - equally_split(size, __num_threads + 1, __borders); - __counter = new _DifferenceType[__num_threads + 1]; + __num_threads = omp_get_num_threads(); + __borders = new _DifferenceType[__num_threads + 2]; + equally_split(size, __num_threads + 1, __borders); + __counter = new _DifferenceType[__num_threads + 1]; } _ThreadIndex __iam = omp_get_thread_num(); @@ -89,7 +89,7 @@ template<typename _IIter, if (__iam == 0) { - __begin = __borders[0] + 1; // == 1 + __begin = __borders[0] + 1; // == 1 __end = __borders[__iam + 1]; ++__i; @@ -112,8 +112,8 @@ template<typename _IIter, for (_IIter iter = __first + __begin; iter < __first + __end; ++iter) { if (!__binary_pred(*iter, *(iter - 1))) - ++__i; - } + ++__i; + } } __counter[__iam] = __i; @@ -157,8 +157,8 @@ template<typename _IIter, for (_IIter iter = __first + __begin; iter < __first + __end; ++iter) { if (!__binary_pred(*iter, *(iter-1))) - *__iter_out++ = *iter; - } + *__iter_out++ = *iter; + } } } @@ -184,7 +184,7 @@ template<typename _IIter, class _OutputIterator> typedef typename std::iterator_traits<_IIter>::value_type _ValueType; return __parallel_unique_copy(__first, __last, __result, - std::equal_to<_ValueType>()); + std::equal_to<_ValueType>()); } }//namespace __gnu_parallel diff --git a/libstdc++-v3/include/parallel/workstealing.h b/libstdc++-v3/include/parallel/workstealing.h index ad9208c4e2b..ca6eb0cc4d3 100644 --- a/libstdc++-v3/include/parallel/workstealing.h +++ b/libstdc++-v3/include/parallel/workstealing.h @@ -91,18 +91,15 @@ template<typename _DifferenceTp> * @return User-supplied functor (that may contain a part of the result). */ template<typename _RAIter, - typename _Op, - typename _Fu, - typename _Red, - typename _Result> + typename _Op, + typename _Fu, + typename _Red, + typename _Result> _Op - for_each_template_random_access_workstealing(_RAIter __begin, - _RAIter __end, - _Op __op, _Fu& __f, _Red __r, - _Result __base, _Result& __output, - typename std::iterator_traits - <_RAIter>:: - difference_type __bound) + for_each_template_random_access_workstealing( + _RAIter __begin, _RAIter __end, _Op __op, _Fu& __f, _Red __r, + _Result __base, _Result& __output, + typename std::iterator_traits<_RAIter>::difference_type __bound) { _GLIBCXX_CALL(__end - __begin) @@ -111,13 +108,15 @@ template<typename _RAIter, const _Settings& __s = _Settings::get(); - _DifferenceType __chunk_size = static_cast<_DifferenceType>(__s.workstealing_chunk_size); + _DifferenceType __chunk_size = + static_cast<_DifferenceType>(__s.workstealing_chunk_size); // How many jobs? _DifferenceType __length = (__bound < 0) ? (__end - __begin) : __bound; // To avoid false sharing in a cache line. - const int __stride = __s.cache_line_size * 10 / sizeof(_Job<_DifferenceType>) + 1; + const int __stride = + __s.cache_line_size * 10 / sizeof(_Job<_DifferenceType>) + 1; // Total number of threads currently working. _ThreadIndex __busy = 0; @@ -132,8 +131,8 @@ template<typename _RAIter, // No more threads than jobs, at least one thread. _ThreadIndex __num_threads = - __gnu_parallel::max<_ThreadIndex>(1, - __gnu_parallel::min<_DifferenceType>(__length, __get_max_threads())); + __gnu_parallel::max<_ThreadIndex>(1, + __gnu_parallel::min<_DifferenceType>(__length, __get_max_threads())); # pragma omp parallel shared(__busy) num_threads(__num_threads) { @@ -184,7 +183,7 @@ template<typename _RAIter, (__length - 1) : ((__iam + 1) * (__length / __num_threads) - 1); __my_job._M_load = __my_job._M_last - __my_job._M_first + 1; - // Init result with _M_first __value (to have a base value for reduction). + // Init result with _M_first value (to have a base value for reduction) if (__my_job._M_first <= __my_job._M_last) { // Cannot use volatile variable directly. @@ -211,13 +210,15 @@ template<typename _RAIter, // fetch-and-add call // Reserve current job block (size __chunk_size) in my queue. _DifferenceType current_job = - __fetch_and_add<_DifferenceType>(&(__my_job._M_first), __chunk_size); + __fetch_and_add<_DifferenceType>( + &(__my_job._M_first), __chunk_size); // Update _M_load, to make the three values consistent, // _M_first might have been changed in the meantime __my_job._M_load = __my_job._M_last - __my_job._M_first + 1; for (_DifferenceType job_counter = 0; - job_counter < __chunk_size && current_job <= __my_job._M_last; + job_counter < __chunk_size + && current_job <= __my_job._M_last; ++job_counter) { // Yes: process it! @@ -254,7 +255,8 @@ template<typename _RAIter, } while (__busy > 0 && ((__supposed_load <= 0) - || ((__supposed_first + __supposed_load - 1) != __supposed_last))); + || ((__supposed_first + __supposed_load - 1) + != __supposed_last))); if (__busy == 0) break; @@ -273,7 +275,8 @@ template<typename _RAIter, __stolen_first + __steal - _DifferenceType(1); __my_job._M_first = __stolen_first; - __my_job._M_last = __gnu_parallel::min(stolen_try, __supposed_last); + __my_job._M_last = + __gnu_parallel::min(stolen_try, __supposed_last); __my_job._M_load = __my_job._M_last - __my_job._M_first + 1; // Has potential work again. diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc index e08a48a6b0e..bb175150556 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc @@ -20,6 +20,7 @@ // 27.8.1.4 Overridden virtual functions // { dg-require-fileio "" } +// { dg-require-binary-io "" } #include <fstream> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc index 5d30517cbbb..67a376e67c4 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc @@ -20,6 +20,7 @@ // 27.8.1.4 Overridden virtual functions // { dg-require-fileio "" } +// { dg-require-binary-io "" } #include <fstream> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc index 23f438fc11c..47c0597cbc4 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc @@ -24,6 +24,7 @@ // 27.8.1.4 Overridden virtual functions // { dg-require-fileio "" } +// { dg-require-binary-io "" } #include <fstream> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc index 26b8bd21e4b..ffcdc2c1453 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc @@ -24,6 +24,7 @@ // 27.8.1.4 Overridden virtual functions // { dg-require-fileio "" } +// { dg-require-binary-io "" } #include <fstream> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc index 7831128ecbe..dda7c67e3bf 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc @@ -24,6 +24,7 @@ // 27.8.1.4 Overridden virtual functions // { dg-require-fileio "" } +// { dg-require-binary-io "" } #include <fstream> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc index 2f7657f8284..d401f8732d5 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc @@ -24,6 +24,7 @@ // 27.8.1.4 Overridden virtual functions // { dg-require-fileio "" } +// { dg-require-binary-io "" } #include <fstream> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc index 8bf915debed..116c404a582 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc @@ -17,6 +17,8 @@ // 27.8.1.4 Overridden virtual functions +// { dg-require-binary-io "" } + #include <fstream> #include <locale> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-2.cc index 9a6875ba300..ed74751dce5 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-2.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-2.cc @@ -26,6 +26,7 @@ // @diff@ %-*.tst %-*.txt // { dg-require-fileio "" } +// { dg-require-binary-io "" } #include <istream> #include <fstream> diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc index 6338be6746e..c7703132245 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc @@ -19,6 +19,8 @@ // causes "in_avail" to return an incorrect value. // { dg-do run { xfail arm*-*-elf arm*-*-eabi } } +// { dg-require-binary-io "" } + // 27.6.1.3 unformatted input functions // @require@ %-*.tst %-*.txt // @diff@ %-*.tst %-*.txt diff --git a/libstdc++-v3/testsuite/27_io/objects/char/10.cc b/libstdc++-v3/testsuite/27_io/objects/char/10.cc index cfa21c81750..a744e787ac6 100644 --- a/libstdc++-v3/testsuite/27_io/objects/char/10.cc +++ b/libstdc++-v3/testsuite/27_io/objects/char/10.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-require-fileio "" } +// { dg-require-binary-io "" } #include <iostream> #include <cstdio> diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp index 6e8f74b0c14..1d9af09a3a6 100644 --- a/libstdc++-v3/testsuite/lib/dg-options.exp +++ b/libstdc++-v3/testsuite/lib/dg-options.exp @@ -151,3 +151,12 @@ proc dg-require-swprintf { args } { } return } + +proc dg-require-binary-io { args } { + if { ![ check_v3_target_binary_io ] } { + upvar dg-do-what dg-do-what + set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] + return + } + return +} diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index dc67368a7d5..05a9b5db860 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -1441,3 +1441,61 @@ proc check_v3_target_swprintf { } { verbose "check_v3_target_swprintf: $et_swprintf" 2 return $et_swprintf } + +proc check_v3_target_binary_io { } { + global cxxflags + global DEFAULT_CXXFLAGS + global et_binary_io + + global tool + + if { ![info exists et_binary_io_target_name] } { + set et_binary_io_target_name "" + } + + # If the target has changed since we set the cached value, clear it. + set current_target [current_target_name] + if { $current_target != $et_binary_io_target_name } { + verbose "check_v3_target_binary_io: `$et_binary_io_target_name'" 2 + set et_binary_io_target_name $current_target + if [info exists et_binary_io] { + verbose "check_v3_target_binary_io: removing cached result" 2 + unset et_binary_io + } + } + + if [info exists et_binary_io] { + verbose "check_v3_target_binary_io: using cached result" 2 + } else { + set et_binary_io 0 + + # Set up and compile a C++0x test program that depends + # on text and binary I/O being the same. + set src binary_io[pid].cc + set exe binary_io[pid].exe + + set f [open $src "w"] + puts $f "#include <bits/c++config.h>" + puts $f "int main()" + puts $f "#if !defined(_GLIBCXX_HAVE_DOS_BASED_FILESYSTEM)" + puts $f "{ return 0; }" + puts $f "#endif" + close $f + + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + + set lines [v3_target_compile $src $exe executable ""] + set cxxflags $cxxflags_saved + file delete $src + + if [string match "" $lines] { + # No error message, compilation succeeded. + set et_binary_io 1 + } else { + verbose "check_v3_target_binary_io: compilation failed" 2 + } + } + verbose "check_v3_target_binary_io: $et_binary_io" 2 + return $et_binary_io +} |