This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
If the Small values of the fixed points involved in a division operation have common factors, it is possible to simplify the restulting expression, which will involve numerators and denominators of the corresponding Small values of the type, as those values are integer literals. The following must execute quietly: gcc -c -gnatDG ec.adb grep "30 / 30" ec.adb.dg with S; with Interfaces; use Interfaces; procedure Ec is Signal_Denominator : constant := 400; type Signal_Type is delta 1.0 / Signal_Denominator range -65_536.0 / Signal_Denominator .. 65_535.0 / Signal_Denominator; for Signal_Type'Small use 1.0 / Signal_Denominator; Delay_30 : constant := 30; type Filter_30_Input_Type is delta 1.0 / Signal_Denominator range 0.0 .. Signal_Type'Last; for Filter_30_Input_Type'Small use 1.0 / Signal_Denominator; type Filter_30_Output_Type is delta 1.0 / Signal_Denominator / Delay_30 range 0.0 .. Signal_Type'Last; for Filter_30_Output_Type'Small use 1.0 / Signal_Denominator / Delay_30; type Sum_30_Index_Type is mod Delay_30; package Sum_30_Filter is new S (Input_Type => Filter_30_Input_Type, Output_Type => Filter_30_Output_Type, Filter_Index_Type => Sum_30_Index_Type); begin null; end Ec; --- generic type Input_Type is delta <>; type Output_Type is delta <>; type Filter_Index_Type is mod <>; package S is type Filter_Type is private; function Process_Sample (This : in out Filter_Type; Sample : in Input_Type) return Output_Type; private type Sum_Filter_Array_Type is array (Filter_Index_Type) of Input_Type; type Filter_Type is record Samples : Sum_Filter_Array_Type; Index : Filter_Index_Type; Last_Output : Output_Type; end record; end S; --- package body S is function Process_Sample (This : in out Filter_Type; Sample : in Input_Type) return Output_Type is -- Initialize output as y(n-1). Output : Output_Type := This.Last_Output; type Filter_Delay_Type is delta 1.0 range 1.0 .. 65_535.0; D : constant Filter_Delay_Type := Filter_Delay_Type (Filter_Index_Type'Last - Filter_Index_Type'First) + 1.0; begin -- Compute y(n) = y(n-1) + (x(n) - x(n-D)) / D, where D = filter delay. Output := Output + (Sample - This.Samples (This.Index)) / D; return Output; end Process_Sample; end S; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-05-02 Ed Schonberg <schonberg@adacore.com> * exp_fixd.adb (Expand_Divide_Fixed_By_Fixed_Giving_Fixed): Simplify the expression for a fixed-fixed division to remove divisions by constants whenever possible, as an optimization for restricted targets.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |