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]

[Ada] Fixed-point multiplication in with no floating point


In the general case, a multiplication of two fixed-point values that yield
an integer type requires the use of floating point operations. When the types
of the operands are identical it is possible to avoid their use by introducing
a temporary of the same type, and performing a conversion to integer in a
separate step. Transformation is useful when floating-point is unavailable
on the target.

The following must compile quietly:

    gcc -c -gnatG t.adb | grep universal_real

---
pragma Restrictions (No_Floating_Point);

Package T is
   type T_Real_64_Bis is
       delta 2.0 ** (-32) range -(2.0 ** 31) .. (2.0 ** 31) - 2.0 ** (-32);
   procedure  Add_Duration_Tst (Dur     : in     T_Real_64_Bis);
end T;
---
Package body T is
   procedure Add_Duration_Tst (Dur     : in     T_Real_64_Bis) is
      c_To_us        : constant T_Real_64_Bis            := 1_000_000.0;
      c_Duration_us1  : constant Integer := Integer (Dur * C_To_Us);
   begin
      null;
   end Add_Duration_Tst;
end T;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-11-07  Ed Schonberg  <schonberg@adacore.com>

	* exp_fixd.adb (Expand_Multiply_Fixed_By_Fixed_Giving_Integer):
	If the restriction No_Floating_Point is in effect, and the
	operands have the same type, introduce a temporary to hold
	the fixed point result, to prevent the use of floating-point
	operations at run-time.

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]