AdaCore / Ada_Drivers_Library

Ada source code and complete sample GNAT projects for selected bare-board platforms supported by GNAT.
BSD 3-Clause "New" or "Revised" License
248 stars 144 forks source link

Avoid unnecessary conversions when utilising the Interfaces package on the compatible HAL types. #414

Closed kevlar700 closed 2 years ago

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

kevlar700 commented 2 years ago

Why wouldn't you want to use Interfaces functions like shift without conversions as a user of the Hal crate?

Fabien-Chouteau commented 2 years ago

The Shift_Left Shift_Right functions are available with the current code, without conversions.

kevlar700 commented 2 years ago

Where are they? I can find the assembly from within Interfaces. I shall see if they somehow magically work within my codebase. Do you have to use Hal?

Fabien-Chouteau commented 2 years ago

These functions are intrinsics, see definition in Interfaces: https://github.com/Fabien-Chouteau/bare_runtime/blob/bd95e2b7d0911d72370e2f9abcd7c11d77690a75/src/interfac.ads#L89

The UInt8, UInt16 and UInt32 type in HAL inherit them from the Intrerfaces.Unsigned_ types.

We should actually declare those functions for all the other UInt* types here.

pat-rogers commented 2 years ago

Right, the shift/rotate ops are inherited when deriving from those types declared in Interfaces,, and are not otherwise defined for user-defined modular types. We could explicitly declare the functions, as intrinsics, or we could apply the GNAT-defined pragma Provide_Shift_Operators.