comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: Using pointers with inline assembly in Ada
  2022-06-11 12:28  6% ` Simon Wright
@ 2022-06-11 12:32  0%   ` NiGHTS
  0 siblings, 0 replies; 82+ results
From: NiGHTS @ 2022-06-11 12:32 UTC (permalink / raw)


On Saturday, June 11, 2022 at 8:28:28 AM UTC-4, Simon Wright wrote:
> NiGHTS <nig...@unku.us> writes: 
> 
> > This was my first experiment which produces a memory access error. In 
> > this early version I'm just trying to write to the first element. 
> > 
> > declare 
> > type ff is array (0 .. 10) of Unsigned_32; 
> > pragma Pack(ff); 
> > Flags : aliased ff := (others => 0); 
> > Flag_Address : System.Address := Flags'Address; 
> > begin 
> > Asm ( "movl %0, %%eax" & 
> > "movl $1, (%%eax)" , 
> > Inputs => System.Address'Asm_Input ("g", Flag_Address), 
> > Clobber => "eax", 
> > Volatile => true 
> > ); 
> > Put_Line ("Output:" & Flags(0)'Img); 
> > end;
> I got an access error as well (macOS, GCC 12.1.0, 64 bits). 
> 
> Eventually, it turned out that the problem was that eax is a 32-bit 
> register. (the compiler used rdx, and the assembler told me that 
> movl %rdx, %eax wasn't allowed). 
> 
> This is my working code; Flags is volatile, because otherwise the 
> compiler doesn't realise (at -O2) that Flags (0) has been touched. 
> 
> ALso, note the Inputs line! 
> 
> ==== 
> with System.Machine_Code; use System.Machine_Code; 
> with Interfaces; use Interfaces; 
> with Ada.Text_IO; use Ada.Text_IO; 
> procedure Nights is 
> type Ff is array (0 .. 10) of Unsigned_32; 
> Flags : aliased Ff := (others => 0) with Volatile; 
> begin 
> Asm ( 
> "movq %0, %%rax" & ASCII.LF & ASCII.HT 
> & "movl $1, (%%rax)", 
> Inputs => System.Address'Asm_Input ("g", Flags (Flags'First)'Address), 
> Clobber => "rax", 
> Volatile => True
> ); 
> Put_Line ("Output:" & Flags(0)'Img);
> end Nights;
I haven't tested this yet but the solution makes sense to me. Thank you for your help!

^ permalink raw reply	[relevance 0%]

* Re: Using pointers with inline assembly in Ada
  @ 2022-06-11 12:28  6% ` Simon Wright
  2022-06-11 12:32  0%   ` NiGHTS
  0 siblings, 1 reply; 82+ results
From: Simon Wright @ 2022-06-11 12:28 UTC (permalink / raw)


NiGHTS <nights@unku.us> writes:

> This was my first experiment which produces a memory access error. In
> this early version I'm just trying to write to the first element.
>
> declare
>          type ff is array (0 .. 10) of Unsigned_32;
>          pragma Pack(ff);
>          Flags : aliased ff := (others => 0);
>          Flag_Address : System.Address := Flags'Address;
> begin
>         Asm (   "movl %0, %%eax" &
>                 "movl $1, (%%eax)" ,             
>                 Inputs   => System.Address'Asm_Input ("g", Flag_Address),
>                 Clobber  => "eax",
>                 Volatile => true
>         );
>         Put_Line ("Output:" & Flags(0)'Img);
> end;

I got an access error as well (macOS, GCC 12.1.0, 64 bits).

Eventually, it turned out that the problem was that eax is a 32-bit
register. (the compiler used rdx, and the assembler told me that
movl %rdx, %eax wasn't allowed).

This is my working code; Flags is volatile, because otherwise the
compiler doesn't realise (at -O2) that Flags (0) has been touched.

ALso, note the Inputs line!

====
with System.Machine_Code; use System.Machine_Code;
with Interfaces; use Interfaces;
with Ada.Text_IO; use Ada.Text_IO;
procedure Nights is
   type Ff is array (0 .. 10) of Unsigned_32;
   Flags : aliased Ff := (others => 0) with Volatile;
begin
   Asm (
        "movq %0, %%rax" & ASCII.LF & ASCII.HT
          & "movl $1, (%%rax)",
        Inputs   => System.Address'Asm_Input ("g", Flags (Flags'First)'Address),
        Clobber  => "rax",
        Volatile => True
       );
   Put_Line ("Output:" & Flags(0)'Img);
end Nights;

^ permalink raw reply	[relevance 6%]

* Re: GNAT for AVR - Mathematical Functions
  @ 2018-09-17 22:41  6%   ` Aurele Vitali
  0 siblings, 0 replies; 82+ results
From: Aurele Vitali @ 2018-09-17 22:41 UTC (permalink / raw)


I don't know anything about the ATmega328P, but if it uses a builtin floating point processor, you can use Ada inline floating point assembler.  Its not hard to do. Here is a simple example of the square root function: 

  with System.Machine_Code; use System.Machine_Code; 
  EOL : constant String := ASCII.LF & ASCII.HT;

  function Sqrt( x : in Long_Float ) return Long_Float is 
    Result : Long_Float := 0.0; 
  begin 
    Asm( ( "fldl  %1" & EOL &                 -- Load x in St(0) 
           "fsqrt   " & EOL &                 -- Take the Sqrt of St(0) 
           "fstpl %0" ),                      -- Store result and pop St(0) 
         Outputs => ( Long_Float'Asm_Output("=m", Result ) ), 
         Inputs  => ( Long_Float'Asm_Input ( "m",      x ) ) ); 
    return Result; 
  end Sqrt; 

You can do the same thing for trig functions...  Just cut and past and see if this example works. 

Cheers 

^ permalink raw reply	[relevance 6%]

* Re: GNAT for AVR - Mathematical Functions
    @ 2018-09-17 22:35  6% ` Aurele Vitali
  1 sibling, 0 replies; 82+ results
From: Aurele Vitali @ 2018-09-17 22:35 UTC (permalink / raw)


I don't know anything about the ATmega328P, but if it uses a builtin floating point processor, you can use Ada inline floating point assembler.  Its not hard to do. Here is a simple example of the square root function:

  with System.Machine_Code; use System.Machine_Code;

  function Sqrt( x : in Long_Float ) return Long_Float is
    Result : Long_Float := 0.0;
  begin
    Asm( ( "fldl  %1" & EOL &                 -- Load x in St(0)
           "fsqrt   " & EOL &                 -- Take the Sqrt of St(0)
           "fstpl %0" ),                      -- Store result and pop St(0)
         Outputs => ( Long_Float'Asm_Output("=m", Result ) ),
         Inputs  => ( Long_Float'Asm_Input ( "m",      x ) ) );
    return Result;
  end Sqrt;

You can do the same thing for trig functions...  Just cut and past and see if this example works. 

Cheers

^ permalink raw reply	[relevance 6%]

* Re: Using System.Machine_Code in GPL 2017 Zfp for Arm
  2017-11-13 10:08 13% Using System.Machine_Code in GPL 2017 Zfp for Arm ahlan
  2017-11-13 10:57 14% ` ahlan
  2017-11-13 11:40  8% ` Simon Wright
@ 2017-11-13 13:21  8% ` ahlan
  2 siblings, 0 replies; 82+ results
From: ahlan @ 2017-11-13 13:21 UTC (permalink / raw)


On Monday, November 13, 2017 at 11:08:56 AM UTC+1, ah...@marriott.org wrote:
> We are trying to build a zfp system for an arm M3 processor that is not on the list of supported GPL processors.
> We only want the Ada intrinsics. We do not need or want any RTS and so expected that --RTS=zfp would do the trick.
> however when we place this switch on arm-eabi-gcc from GPL 2017 we get the error message
> RTS path not valid: Missing adainclude and adalib directories.
> So things are not as simple as we thought.
> It appears that --RTS takes the name of a directory so we created one and named this on the RTS switch.
> In the directory we placed two files ada_object_path and ada_source_path that both contain the single word gnat.
> In the RTS directory we then created the empty directory adalib and another  directory gnat and placed in gnat directory the file System.ads which we copied from an RTS directory of a similar processor.
> This all seems to work.
> With this we are able to create simple programs.
> However when we want to use System.Machine_Code we get the error message that
> System.Machine_Code is not a predefined library.
> I suspect that we need to add something to our RTS directory.
> But what?
> Has anyone any experience building ARM ZFP systems and can tell us how we get add System.Machine_Code to our Zfp.
> Any help or suggestions what to do next would be greatly appreciated.
> 
> Best wishes,
> Ahlan

Dear Simon,

Thanks for your quick response.
In the meantime we discovered exactly what you have just written.

Best wishes,
MfG
Ahlan

^ permalink raw reply	[relevance 8%]

* Re: Using System.Machine_Code in GPL 2017 Zfp for Arm
  2017-11-13 10:08 13% Using System.Machine_Code in GPL 2017 Zfp for Arm ahlan
  2017-11-13 10:57 14% ` ahlan
@ 2017-11-13 11:40  8% ` Simon Wright
  2017-11-13 13:21  8% ` ahlan
  2 siblings, 0 replies; 82+ results
From: Simon Wright @ 2017-11-13 11:40 UTC (permalink / raw)


ahlan@marriott.org writes:

> We are trying to build a zfp system for an arm M3 processor that is
> not on the list of supported GPL processors.
> We only want the Ada intrinsics. We do not need or want any RTS and so
> expected that --RTS=zfp would do the trick.
> however when we place this switch on arm-eabi-gcc from GPL 2017 we get
> the error message
> RTS path not valid: Missing adainclude and adalib directories.
> So things are not as simple as we thought.
> It appears that --RTS takes the name of a directory so we created one
> and named this on the RTS switch.
> In the directory we placed two files ada_object_path and
> ada_source_path that both contain the single word gnat.

I'd expect ada_object_path to contain the word adalib, and adalib/ to
contain the .ali's and .a(s), or perhaps .o's. Don't know what happens
if you put them in gnat/ with the sources, but it seems to work for you!
(and you shouldn't need adalib/ at all - though the
compiler/gnatls/gprconfig rules for determining whether this looks
enough like an RTS are a bit arbitrary & changeable & not necessarily
consistent).

> In the RTS directory we then created the empty directory adalib and
> another directory gnat and placed in gnat directory the file
> System.ads which we copied from an RTS directory of a similar
> processor.
> This all seems to work.
> With this we are able to create simple programs.
> However when we want to use System.Machine_Code we get the error message that
> System.Machine_Code is not a predefined library.
> I suspect that we need to add something to our RTS directory.

You need s-maccod.ads (from the same place; looks pretty
machine-independent).

GNAT GPL 2017 has $prefix/arm-eabi/lib/gnat/zfp-lm3s which is an M3 system.

^ permalink raw reply	[relevance 8%]

* Re: Using System.Machine_Code in GPL 2017 Zfp for Arm
  2017-11-13 10:08 13% Using System.Machine_Code in GPL 2017 Zfp for Arm ahlan
@ 2017-11-13 10:57 14% ` ahlan
  2017-11-13 11:40  8% ` Simon Wright
  2017-11-13 13:21  8% ` ahlan
  2 siblings, 0 replies; 82+ results
From: ahlan @ 2017-11-13 10:57 UTC (permalink / raw)


On Monday, November 13, 2017 at 11:08:56 AM UTC+1, ah...@marriott.org wrote:
> We are trying to build a zfp system for an arm M3 processor that is not on the list of supported GPL processors.
> We only want the Ada intrinsics. We do not need or want any RTS and so expected that --RTS=zfp would do the trick.
> however when we place this switch on arm-eabi-gcc from GPL 2017 we get the error message
> RTS path not valid: Missing adainclude and adalib directories.
> So things are not as simple as we thought.
> It appears that --RTS takes the name of a directory so we created one and named this on the RTS switch.
> In the directory we placed two files ada_object_path and ada_source_path that both contain the single word gnat.
> In the RTS directory we then created the empty directory adalib and another  directory gnat and placed in gnat directory the file System.ads which we copied from an RTS directory of a similar processor.
> This all seems to work.
> With this we are able to create simple programs.
> However when we want to use System.Machine_Code we get the error message that
> System.Machine_Code is not a predefined library.
> I suspect that we need to add something to our RTS directory.
> But what?
> Has anyone any experience building ARM ZFP systems and can tell us how we get add System.Machine_Code to our Zfp.
> Any help or suggestions what to do next would be greatly appreciated.
> 
> Best wishes,
> Ahlan

To answer my own question:
You need to add the file s-maccod.ads
However, and this is what confused us, the filename is fixed.
If you rename the file to system-machine_code.ads it doesn't work.


^ permalink raw reply	[relevance 14%]

* Using System.Machine_Code in GPL 2017 Zfp for Arm
@ 2017-11-13 10:08 13% ahlan
  2017-11-13 10:57 14% ` ahlan
                   ` (2 more replies)
  0 siblings, 3 replies; 82+ results
From: ahlan @ 2017-11-13 10:08 UTC (permalink / raw)


We are trying to build a zfp system for an arm M3 processor that is not on the list of supported GPL processors.
We only want the Ada intrinsics. We do not need or want any RTS and so expected that --RTS=zfp would do the trick.
however when we place this switch on arm-eabi-gcc from GPL 2017 we get the error message
RTS path not valid: Missing adainclude and adalib directories.
So things are not as simple as we thought.
It appears that --RTS takes the name of a directory so we created one and named this on the RTS switch.
In the directory we placed two files ada_object_path and ada_source_path that both contain the single word gnat.
In the RTS directory we then created the empty directory adalib and another  directory gnat and placed in gnat directory the file System.ads which we copied from an RTS directory of a similar processor.
This all seems to work.
With this we are able to create simple programs.
However when we want to use System.Machine_Code we get the error message that
System.Machine_Code is not a predefined library.
I suspect that we need to add something to our RTS directory.
But what?
Has anyone any experience building ARM ZFP systems and can tell us how we get add System.Machine_Code to our Zfp.
Any help or suggestions what to do next would be greatly appreciated.

Best wishes,
Ahlan

^ permalink raw reply	[relevance 13%]

* Re: Protected Objects and Interrupt Handlers
  2016-02-25 19:49  5%       ` Simon Wright
@ 2016-03-13  8:10  0%         ` Simon Wright
  0 siblings, 0 replies; 82+ results
From: Simon Wright @ 2016-03-13  8:10 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Tero Koskinen <tero.koskinen@iki.fi> writes:
>
>> For example in the normal case, you can have all the startup code in C
>> (or in Ada, which is then exported to C)
>
> Actually, very little even needs exporting to C! I had one that I've
> given convention Asm (it's invoked by the linker script), but I'm not at
> all sure it needs it.
>
> Mind you,
>
>    procedure Program_Initialization
>    with
>      Export,
>      Convention => Asm,
>      External_Name => "program_initialization",
>      No_Return;
>    pragma Machine_Attribute (Program_Initialization, "naked");
>
>    procedure Program_Initialization is
>    begin
>       --  _estack: the first address after the top of stack space
>       System.Machine_Code.Asm ("ldr sp, =_estack", Volatile => True);
>       Complete_Program_Initialization;
>    end Program_Initialization;
>
> probably isn't going to cause much trouble anyway.

The thinking behind that little bit of asm was that the SAM3X8E has a
bootstrap loader in (a separate section of) FLASH, and a reset mode that
uses it, and you can mistakenly leave the MCU in bootstrap mode, and thi
should recover it .. but I'm now pretty sure it desn't.

Corrent work, on STM32F429I, manages an Ada startup with two assembler
instructions (dsb, isb to flush the caches after enabling the FPU).

^ permalink raw reply	[relevance 0%]

* Re: Protected Objects and Interrupt Handlers
  @ 2016-02-25 19:49  5%       ` Simon Wright
  2016-03-13  8:10  0%         ` Simon Wright
  0 siblings, 1 reply; 82+ results
From: Simon Wright @ 2016-02-25 19:49 UTC (permalink / raw)


Tero Koskinen <tero.koskinen@iki.fi> writes:

> For example in the normal case, you can have all the startup code in C
> (or in Ada, which is then exported to C)

Actually, very little even needs exporting to C! I had one that I've
given convention Asm (it's invoked by the linker script), but I'm not at
all sure it needs it.

Mind you,

   procedure Program_Initialization
   with
     Export,
     Convention => Asm,
     External_Name => "program_initialization",
     No_Return;
   pragma Machine_Attribute (Program_Initialization, "naked");

   procedure Program_Initialization is
   begin
      --  _estack: the first address after the top of stack space
      System.Machine_Code.Asm ("ldr sp, =_estack", Volatile => True);
      Complete_Program_Initialization;
   end Program_Initialization;

probably isn't going to cause much trouble anyway.

^ permalink raw reply	[relevance 5%]

* Re: ANN: gcc 4.9.1bis for Darwin
  2015-02-21 12:10  5%   ` Simon Wright
@ 2015-02-24 21:53  0%     ` Vincent
  0 siblings, 0 replies; 82+ results
From: Vincent @ 2015-02-24 21:53 UTC (permalink / raw)


Le samedi 21 février 2015 13:10:04 UTC+1, Simon Wright a écrit :
> vincent wrote:
> 
> > Thank you very much Simon.
> > Your compiler release has become my main compiler.
> 
> Same for me ...
> 
> > Just a small question : is it possible to use INTEL syntax for on-line
> > assembly, in mean among Ada source code ?
> > If not, how can I link assembly language routines with Ada code ?
> 
> For inline assembly, you need to use GNU syntax. As a simple(?) ARM
> example,
> 
>    function In_ISR return Boolean is
>       IPSR : Interfaces.Unsigned_32;
>       use type Interfaces.Unsigned_32;
>    begin
>       System.Machine_Code.Asm
>         ("mrs %0, ipsr",
>          Outputs => Interfaces.Unsigned_32'Asm_Output ("=r", IPSR),
>          Volatile => True);
>       return (IPSR and 16#ff#) /= 0;
>    end In_ISR;
> 
> Looking at some of the AdaCore STM32 code, there are two other things
> that might be helpful.
> 
> First, there is convention Asm:
> 
>    System_Vectors : constant System.Address;
>    pragma Import (Asm, System_Vectors, "__vectors");
> 
> which is fine for data objects like this, not so sure what calling
> convention might be expected from an ASM subprogram.
> 
> Second, there is pragma Machine_Attribute:
> 
>    procedure Pend_SV_Handler;
>    pragma Machine_Attribute (Pend_SV_Handler, "naked");
>    pragma Export (Asm, Pend_SV_Handler, "__gnat_pend_sv_trap");
>    --  This assembly routine needs to save and restore registers without
>    --  interference. The "naked" machine attribute communicates this to GCC.

Ok, so I have to resign myself to use GNU syntax.. :-(
I thought that GCC could use both. But maybe not GNAT.

I suppose that if I want to call a routine written in assembly,
I need to use pragma Import (Asm, MyRoutine, "myroutine").

Thank you very much,

Vincent

^ permalink raw reply	[relevance 0%]

* Re: ANN: gcc 4.9.1bis for Darwin
  @ 2015-02-21 12:10  5%   ` Simon Wright
  2015-02-24 21:53  0%     ` Vincent
  0 siblings, 1 reply; 82+ results
From: Simon Wright @ 2015-02-21 12:10 UTC (permalink / raw)


vincent.diemunsch@gmail.com writes:

> Thank you very much Simon.
> Your compiler release has become my main compiler.

Same for me ...

> Just a small question : is it possible to use INTEL syntax for on-line
> assembly, in mean among Ada source code ?
> If not, how can I link assembly language routines with Ada code ?

For inline assembly, you need to use GNU syntax. As a simple(?) ARM
example,

   function In_ISR return Boolean is
      IPSR : Interfaces.Unsigned_32;
      use type Interfaces.Unsigned_32;
   begin
      System.Machine_Code.Asm
        ("mrs %0, ipsr",
         Outputs => Interfaces.Unsigned_32'Asm_Output ("=r", IPSR),
         Volatile => True);
      return (IPSR and 16#ff#) /= 0;
   end In_ISR;

Looking at some of the AdaCore STM32 code, there are two other things
that might be helpful.

First, there is convention Asm:

   System_Vectors : constant System.Address;
   pragma Import (Asm, System_Vectors, "__vectors");

which is fine for data objects like this, not so sure what calling
convention might be expected from an ASM subprogram.

Second, there is pragma Machine_Attribute:

   procedure Pend_SV_Handler;
   pragma Machine_Attribute (Pend_SV_Handler, "naked");
   pragma Export (Asm, Pend_SV_Handler, "__gnat_pend_sv_trap");
   --  This assembly routine needs to save and restore registers without
   --  interference. The "naked" machine attribute communicates this to GCC.


^ permalink raw reply	[relevance 5%]

* Re: C versus Ada (once again :-)), was: Re: F-22 ADA Programming
  2014-11-03 21:58  5%                                         ` Shark8
  2014-11-03 22:28  0%                                           ` Dmitry A. Kazakov
@ 2014-11-04 13:42  0%                                           ` Florian Weimer
  1 sibling, 0 replies; 82+ results
From: Florian Weimer @ 2014-11-04 13:42 UTC (permalink / raw)


* Shark8:

>> If you are trying to parallelize your programs for performance
>> reasons, Ada (as standardized) is not such a nice language anymore
>> because it lacks a modern memory model (which reflects the variations
>> of existing hardware) and access to various forms of atomic
>> instructions with well-defined properties.
>>
>
> Isn't the atomic instruction thing properly recognized as platform
> dependent?

The actual implementation is platform-dependent, but the C11 memory
model abstracts over it.  You use the <stdatomic.h> functionality
which you need to implement your parallel algorithm, and the C
implementation will select something matching for the target
architecture (either an exact match, or a stronger (and slower)
variant).

> If that's the case, then should it be part of Ada, or would
> it be acceptable to have a machine-language (e.g. System.Machine_Code)
> insert for handling it in the implementation part of some package?

It's difficult to get that right because it needs a lot of knowledge
of the target architecture and its variations.  If you stick to the
C11 memory model (or C++11 variant, they are supposed to be
compatible), you only need to learn that, and the C implementation
will map it to the hardware.

> (Would such atomic instructions need to be incorporated at the
> Run-time level?)

Some systems need kernel calls for certain barriers, yes.  But Ada
code needs to issue these barriers today, so support already has to be
present.

The main challenge is to expose weaker (and therefore more efficient)
synchronization primitives.


^ permalink raw reply	[relevance 0%]

* Re: C versus Ada (once again :-)), was: Re: F-22 ADA Programming
  2014-11-03 21:58  5%                                         ` Shark8
@ 2014-11-03 22:28  0%                                           ` Dmitry A. Kazakov
  2014-11-04 13:42  0%                                           ` Florian Weimer
  1 sibling, 0 replies; 82+ results
From: Dmitry A. Kazakov @ 2014-11-03 22:28 UTC (permalink / raw)


On Mon, 03 Nov 2014 14:58:06 -0700, Shark8 wrote:

> On 03-Nov-14 05:40, Florian Weimer wrote:
>> * Simon Clubley:
>>
>>> As I keep saying in one way or another:
>>>
>>> 	Ada: nice language, lousy compiler situation.
>>
>> If you are trying to parallelize your programs for performance
>> reasons, Ada (as standardized) is not such a nice language anymore
>> because it lacks a modern memory model (which reflects the variations
>> of existing hardware) and access to various forms of atomic
>> instructions with well-defined properties.
> 
> Isn't the atomic instruction thing properly recognized as platform 
> dependent?

Instruction is a wrong term, should be "atomic primitive" instead.

> If that's the case, then should it be part of Ada, or would 
> it be acceptable to have a machine-language (e.g. System.Machine_Code) 
> insert for handling it in the implementation part of some package?

No, that would be practically useless.

Atomic primitives must be machine-independent. That is, the compiler would
select the most appropriate implementation for.

For example, consider the atomic increment primitive (of some package
Interfaces type, e.g. Unsigned_64). When there is a machine instruction the
compiler uses it, otherwise it falls back to a protected operation or OS
calls.
 
> (Would such atomic instructions need to be incorporated at the Run-time 
> level?)

Only if the implementation is based on OS calls. E.g. using Windows API
function InterlockedIncrement.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Re: C versus Ada (once again :-)), was: Re: F-22 ADA Programming
  @ 2014-11-03 21:58  5%                                         ` Shark8
  2014-11-03 22:28  0%                                           ` Dmitry A. Kazakov
  2014-11-04 13:42  0%                                           ` Florian Weimer
  0 siblings, 2 replies; 82+ results
From: Shark8 @ 2014-11-03 21:58 UTC (permalink / raw)


On 03-Nov-14 05:40, Florian Weimer wrote:
> * Simon Clubley:
>
>> As I keep saying in one way or another:
>>
>> 	Ada: nice language, lousy compiler situation.
>
> If you are trying to parallelize your programs for performance
> reasons, Ada (as standardized) is not such a nice language anymore
> because it lacks a modern memory model (which reflects the variations
> of existing hardware) and access to various forms of atomic
> instructions with well-defined properties.
>

Isn't the atomic instruction thing properly recognized as platform 
dependent? If that's the case, then should it be part of Ada, or would 
it be acceptable to have a machine-language (e.g. System.Machine_Code) 
insert for handling it in the implementation part of some package?

(Would such atomic instructions need to be incorporated at the Run-time 
level?)


^ permalink raw reply	[relevance 5%]

* Re: GLIBC_2.14  memcpy
  @ 2014-04-28 12:23  6%   ` anon
  0 siblings, 0 replies; 82+ results
From: anon @ 2014-04-28 12:23 UTC (permalink / raw)


Your Welcome!

The reduction in "file size" due to the fact that the linker is 
only adding the new "memcpy" function instead of adding the 
complete GLIBC library. Now, "GNAT Ada" uses only a small number 
of routines that are contained in the GLIBC library so it is easier 
to rewrite the routines when they are needed instead of trying to 
use the complete standard library.

Pro:  1. Smaller footprint, reduction of dead code.
      2. Easy to compile for either 32 or 64 bit mode.
      3. Easy to compile for different operating environments.

Con:  Code may not be at maximum optimization unless code is 
      written using "System.Machine_Code".


Note: For a smaller footprint, and a faster code you could
      rewrite the function "Memcpy" using System.Machine_Code 
      package. The footprint for the machine code is round 16 
      instructions while the Ada optimization code version is 
      around 21 instructions. So, unless the increase in speed
      is paramount or memory is limited the use of machine code 
      may not be worth the additional work.
      


In <8d93b0b8-4cfb-43f9-b055-ad7ecf258020@googlegroups.com>, Ian Douglas <ian@vionia.com> writes:
>On Thursday, 24 April 2014 11:56:15 UTC+2, an...@att.net  wrote:
>> A simple System.Memory_Copy package
>
>Thanks, have followed your code and confirm that it works both=A0
>locally and on the server.
>
>The other thing is that the filesize dropped from 547654 to 343340=A0
>which is better but still much more than I would like :-)
>
>I did try using GNAT.IO first instead of ADA IO but that didn't work=A0
>either.
>
>Thanks again :)
>
>cheers, Ian

^ permalink raw reply	[relevance 6%]

* Interrupt-driven Usart not working in Ada, but in C working, why?
@ 2014-03-16 20:37  5% Rego, P.
  0 siblings, 0 replies; 82+ results
From: Rego, P. @ 2014-03-16 20:37 UTC (permalink / raw)


I am trying to use interrupt-driven Usart on an Atmel AVR ATmega2560 chip. 

The problem is that when I send anything to the usart, the Ada application restarts (continuously). I simplified the codes and created a C version (or the nearer of it) of the same code (because at first I thought that it could be a hw problem or a datasheet misunderstanding of me, and AVR community would not answer me if I had posted Ada code instead of C code ...). But the C code worked (i.e., the usart echo appears, and the board is not restarted), ao now I became clueless. Maybe the AVR guys could help me? Thanks.

The simplified version of the codes are

-- main.adb
with System.Machine_Code;
with AVR.USART;
with TEST;
pragma Unreferenced (TEST);

procedure Main is
   F_CPU : constant := 16_000_000;
   USART_BAUDRATE : constant := 9600;
begin
   AVR.USART.Reg_USART1.UCSRB.RXEN := True;
   AVR.USART.Reg_USART1.UCSRB.TXEN := True;
   AVR.USART.Reg_USART1.UCSRB.RXCIE := True;
   AVR.USART.Reg_USART1.UCSRC.UCSZ0 := True;
   AVR.USART.Reg_USART1.UCSRC.UCSZ1 := True;

   AVR.USART.Reg_USART1.UBRR (0) := AVR.Byte_Type ((F_CPU / (USART_BAUDRATE * 16)) - 1);
   AVR.USART.Reg_USART1.UBRR (1) := 0;

   System.Machine_Code.Asm ("sei", Volatile => True);

   loop
      null;
   end loop;
end Main;

-- test.ads
package TEST is

   USART1RX : constant String := "__vector_36";
   
   procedure Handle_Interrupt_USART1_RX;
   pragma Machine_Attribute
     (Entity         => Handle_Interrupt_USART1_RX,
      Attribute_Name => "signal");
   pragma Export
     (Convention    => C,
      Entity        => Handle_Interrupt_USART1_RX,
      External_Name => USART1RX);

end TEST;

with AVR;
with AVR.USART;

-- test.adb
package body Test is

   procedure Handle_Interrupt_USART1_RX is
      Curr_Buffer : AVR.Byte_Type;
   begin
      Curr_Buffer := AVR.USART.Reg_USART1.UDR;
      AVR.USART.Reg_USART1.UDR := Curr_Buffer;
   end Handle_Interrupt_USART1_RX;
end Test;


Given that I have mapped the Usart registers correctly on AVR.USART package (because my JtagICE said so).

The C code is
-- simple_isr_usart.c
#include <avr/io.h>
#include <avr/interrupt.h>

#define F_CPU 16000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

int main (void){
	UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
	UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
	UBRR0H = (BAUD_PRESCALE >> 8);
	UBRR0L = BAUD_PRESCALE;
	sei();
	while (1) {}
}

ISR(USART0_RX_vect){
	char ReceivedByte;
	ReceivedByte = UDR0;
	UDR0 = ReceivedByte;
}


^ permalink raw reply	[relevance 5%]

* Slow?  Ada??
  @ 2013-07-12  1:01  4%           ` Bill Findlay
  0 siblings, 0 replies; 82+ results
From: Bill Findlay @ 2013-07-12  1:01 UTC (permalink / raw)


I was amused to read this ...

On 11/07/2013 00:21, in article krkq9u$fo9$1@loke.gir.dk, "Randy Brukardt"
<randy@rrsoftware.com> wrote:
...
> For things like Sine, the best one can do is copy an implementation from a
> cookbook -- it makes no sense to even imagine trying to create a new one.

...for reasons nothing to do with that controversy.

When debugging Whetstone Algol under my KDF9 emulator I looked at the KDF9
assembly code programming of the arctan function and was completely baffled
by it, so I asked my former colleague, Michael Jamieson to investigate.
He successfully reconstructed the mathemetics behind it, which are very
non-obvious (to put it mildly).

A couple of days ago I idly wondered how well this 50 years old algorithm
would compare with modern implementations, so I wrote a test program to race
it against GNAT GPL 2013's arctan.  I expected to find that 2013 would spank
1963's botty.  To my astonishment, the old algorithm was faster.

Digging down, I found that Ada.Numerics.Long_Elementary_Functions.arctan
does quite a bit of argument range reduction and result error checking, but
finally invokes the "fpatan" opcode of the x86_64 CPU.

The 1963 algorithm, expressed in Ada 2012 but compiled with aggressive
optimization, is only 17% slower than that single CPU opcode!

Note also that, although it was designed for a machine with 48-bit floating
point, it gets the same accuracy as the hardware method on a machine with
64-bit floating point.

Here is the code, with the observed results included as commentary:

with Ada.Numerics.Long_Elementary_Functions;
with Ada.Text_IO;
with CPU_Timing;
with System.Machine_Code;

use  Ada.Numerics.Long_Elementary_Functions;
use  Ada.Text_IO;
use  CPU_Timing;
use  System.Machine_Code;

procedure arctan_test64 is

   -- typical output:
   -- R = 100000000 evaluations
   -- checksum = 5.00000005000000E+07, loop   time per repetition = 6 ns
   -- checksum = 4.38824577044418E+07, P51V15 time per evaluation = 49 ns
   -- checksum = 4.38824577044418E+07, arctan time per evaluation = 53 ns
   -- checksum = 4.38824577044418E+07, fpatan time per evaluation = 41 ns

   -- P51V15 is the KDF9 algorithm used in Whetstone Algol, ca. 1963
   -- See http://www.findlayw.plus.com/KDF9/Arctan%20Paper.pdf

   type vector is array (0..5) of Long_Float;

   V : constant vector := (  28165298.0 / 1479104550.0,
                             28165300.0 / 1479104550.0,
                             56327872.0 / 1479104550.0,
                            113397760.0 / 1479104550.0,
                            179306496.0 / 1479104550.0,
                           1073741824.0 / 1479104550.0);

   function P51V15 (x : Long_Float) return Long_Float with Inline;

   function P51V15 (x : Long_Float)
   return Long_Float is
      A : Long_Float := 1.0;
      S : Long_Float := V(0);
      B : vector;
   begin
       B(0) := sqrt(x*x + 1.0);
       -- 4 AGM (Arithmetic-Geometric Mean) cycles give a set of values ...
       for i in 0..3 loop
          A := (A+B(i)) * 0.5;
          B(i+1) := sqrt(A*B(i));
       end loop;
       -- ... that is subjected to a convergence acceleration process:
       for i in 1..5 loop
          S := S + V(i)*B(i-1);
       end loop;
       return x / S;
   end P51V15;

   -- this is the hardware arctan function of the x86_64 Core i7 CPU
   function fpatan (X : Long_Float) return Long_Float with Inline;

   function fpatan (X : Long_Float)
   return Long_Float is
      Result  : Long_Float;
   begin
      Asm(Template  => "fld1"
                     & Character'Val(10) -- LF
                     & Character'Val(9)  -- HT
                     & "fpatan",
          Outputs   => Long_Float'Asm_Output ("=t", Result),
          Inputs    => Long_Float'Asm_Input  ("0", X));
      return Result;
   end fpatan;

   R : constant := 1e8; -- number of loop repetitions

   function ns_per_rep (c : CPU_Usage_in_Microseconds)
   return Natural is
   begin
      return Natural(c * 1e3 / R);
   end ns_per_rep;

   x : Long_Float;
   c : CPU_Timer;
   l : CPU_Usage_in_Microseconds;
   t : CPU_Usage_in_Microseconds;

begin
   Put_Line("R =" & Integer'Image(R) & " evaluations");

   -- determine the fixed overhead time
   x := 0.0;
   Reset_Timer(c);
   for i in 1..R loop
      x := x + Long_Float(i)/Long_Float(R);
   end loop;
   l := User_CPU_Time_Since(c);
   Put_Line("checksum =" & x'Img & ", "
          & "loop   time per repetition ="
          & Natural'Image(ns_per_rep(l)) & " ns");

   x := 0.0;
   Reset_Timer(c);
   for i in 1..R loop
      x := x + P51V15(Long_Float(i)/Long_Float(R));
   end loop;
   t := User_CPU_Time_Since(c) - l;
   Put_Line("checksum =" & x'Img & ", "
          & "P51V15 time per evaluation ="
          & Natural'Image(ns_per_rep(t)) & " ns");

   x := 0.0;
   Reset_Timer(c);
   for i in 1..R loop
      x := x + arctan(Long_Float(i)/Long_Float(R));
   end loop;
   t := User_CPU_Time_Since(c) - l;
   Put_Line("checksum =" & x'Img & ", "
          & "arctan time per evaluation ="
          & Natural'Image(ns_per_rep(t)) & " ns");

   x := 0.0;
   Reset_Timer(c);
   for i in 1..R loop
      x := x + fpatan(Long_Float(i)/Long_Float(R));
   end loop;
   t := User_CPU_Time_Since(c) - l;
   Put_Line("checksum =" & x'Img & ", "
          & "fpatan time per evaluation ="
          & Natural'Image(ns_per_rep(t)) & " ns");

end arctan_test64;

The difference in time between Ada.Numerics.Long_Elementary_Functions.arctan
and  the fpatan function above is due to the afore-mentioned range reduction
and checking.  The KDF9 programmers in 1963 were less punctillious about
such matters than we rightly expect Ada to be nowadays.

-- 
Bill Findlay
with blueyonder.co.uk;
use  surname & forename;



^ permalink raw reply	[relevance 4%]

* Re: Erroneous code generation from GNAT or GCC?
  @ 2013-04-30 22:22  5%                 ` Simon Wright
  0 siblings, 0 replies; 82+ results
From: Simon Wright @ 2013-04-30 22:22 UTC (permalink / raw)


"Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr> writes:

> Le Tue, 30 Apr 2013 21:06:09 +0200, Simon Wright <simon@pushface.org>
> a écrit:
>> I was wondering what you meant by using constraints "a", "b", "c", "d"
>> .. I now see [3] that these are i386 constraints for the a..d registers
>> respectively, no wonder they gave wierd results on x86_64 where they
>> mean something quite different!
>
> They do exists with 64 bits instructions too. a is eax; b is ebx, etc,
> for 32 bits mode, and a is rax, b is rbx, etc, for 64 bits mode. There
> is also ax/ah/al, ax/bh/bl, etc, as sub-parts of the above, except ax,
> bx, etc, is for 16 bits only, but ah, al, bh, bl are still a
> accessible in 32 bits mode - I don't know if it's still the case in 64
> bits mode.

Your

      System.Machine_Code.Asm
        (Template => "int $0x80",
         Outputs => Integer'Asm_Output ("=a", Result),
         Inputs =>
           (Positive'Asm_Input       ("a", Number),
            Natural'Asm_Input        ("b", Handle),
            System.Address'Asm_Input ("c", Address),
            Natural'Asm_Input        ("d", Size)),
         Volatile => True);

translated to

	movl	%ecx, %edx
	movl	%edi, %eax
	movl	%esi, %ebx
	movq	%r8, %rcx
# 14 "library.adb" 1
	int $0x80

but I think I really don't want to learn Intel assembler, lots of other
good things to do.



^ permalink raw reply	[relevance 5%]

* Erroneous code generation from GNAT or GCC?
    @ 2013-04-28 22:35  3% ` Yannick Duchêne (Hibou57)
    1 sibling, 1 reply; 82+ results
From: Yannick Duchêne (Hibou57) @ 2013-04-28 22:35 UTC (permalink / raw)


Le Sat, 27 Apr 2013 23:08:52 +0200, Yannick Duchêne (Hibou57)  
<yannick_duchene@yahoo.fr> a écrit:

> Hi all,
>
> I will make a stripped‑down version of the case, later. So far I just  
> wonder if any one already encountered a similar case: GNAT not  
> generating any code for a sub‑program. Here what it generates instead,  
> according to the assembly file:
>
>      .cfi_startproc
>      ret
>      .cfi_endproc
>
> […]
> Is this a known bug?

This topic was solved, but in the while, I'm encountering something which  
is frightening me a bit. That's not dropped code, but erroneous code  
generation.

The context: a sub‑program use machine‑code insertion. For convenience and  
avoid errors, this sub‑program is generic. Then, some sub‑program  
instantiate this generic locally, as part of their implementations.

As a remainder, here is the generic using machine‑code insertion:


     function Invoke_3
       (N  : Number_Type;
        P1 : P1_Type;
        P2 : P2_Type;
        P3 : P3_Type)
        return Result_Type
     is
        use System.Machine_Code;
        Result : Result_Type;
     begin

        Asm
          (Template => "int $0x80",
           Outputs => Result_Type'Asm_Output ("=a", Result),
           Inputs =>
             (Number_Type'Asm_Input ("a", N),
              P1_Type'Asm_Input     ("b", P1),
              P2_Type'Asm_Input     ("c", P2),
              P3_Type'Asm_Input     ("d", P3)),
           Volatile => True);

        return Result;

     end Invoke_3;


Now, here is a sample sub‑program instantiating this generic as part of  
its implementation:


     procedure Write (Item : in Character) is

        use Syscall_Numbers;
        use Syscalls;
        use Types;

        Status  : Result_Type;
        Size    : constant Size_Type := (Character'Size / 8);

        function Implementation
           is new Invoke_3
             (P1_Type     => Handle_Type,
              P2_Type     => Address_Type,
              P3_Type     => Size_Type)
              with Inline => True;

     begin
        Status := Implementation
          (N  => NR_write,
           P1 => 1,
           P2 => Item'Address,
           P3 => Size);
     end;


Note `P2`, which is the address argument, goes into ecx (see `Invoke_3`  
above).

This sub‑program will print an ASCII character to the standard output,  
using a Linux system‑call. It will later be changed a bit, to show an  
issue. This one version is working.

Note: so far, `Status` are not interpreted, I know, don't care.

Now, as sample use would be:


     Write ('[');


Note: the platform is 32 bits, so all stack operations are 32 bits  
(push/pop/add and sub on esp).

Here is the generated code for the invocation of the working version:


     movl	$91, (%esp)
     call	library__write__2


First, the character code passed as an argument is written at [esp], the  
the sub‑program in invoked, thus the character code argument is now at  
[esp+4] (32 bits platform).

Now, the generated code of the working version, which is invoked by the  
above:


     library__write__2:
     .LFB7:
        .cfi_startproc
        pushl   %ebx            #
        .cfi_def_cfa_offset 8
        .cfi_offset 3, -8
        subl    $12, %esp       #,
        .cfi_def_cfa_offset 20
        movl    20(%esp), %eax  # item, item
        movb    %al, (%esp)     # item, item
        movl    $1, %edx        #, tmp64
        movl    %esp, %ecx      #, item.19
        movl    $4, %eax        #, tmp63
        movl    %edx, %ebx      # tmp64, tmp64
        int $0x80


Remember when invoked, the argument is tat [esp+4]. The sub‑program pushes  
ebx, so the argument is now at [esp+4]. Then it substract 12 to esp, so  
the argument is now at [esp+20]. Then it reads the value at [esp+20],  
store it in eax, then write eax at [esp], in finally store esp to ecx,  
which is OK, ecx holds the address of the parameter. The system‑call is  
successfully invoked.


Now, change `Write` to that it does not get the address of it's argument,  
but get the address of a local copy of its argument (rather same as above,  
changes are marked):


     procedure Write (Item : in Character) is

        use Syscall_Numbers;
        use Syscalls;
        use Types;

        Element : Character := Item; -- <<< Copy of argument
        Status  : Result_Type;
        Size    : constant Size_Type := (Character'Size / 8);

        function Implementation
           is new Invoke_3
             (P1_Type     => Handle_Type,
              P2_Type     => Address_Type,
              P3_Type     => Size_Type)
              with Inline => True;

     begin
        Status := Implementation
          (N  => NR_write,
           P1 => 1,
           P2 => Element'Address, -- <<< Address of the copy
           P3 => Size);
     end;


This one should behave the same, isn't it? It just store of `Item` to  
local `Element` and so pass `Element'Address` to the system‑call, instead  
of `Item'Address`. Sounds right…


The code generated by GNAT for the invocation part is the same as earlier  
above:


     movl	$91, (%esp)
     call	library__write__2

Still the same, at the entry point of the sub‑program, the argument is at  
[esp+4].

Now, here the code generated for the slightly modified subprogram:


     library__write__2:
     .LFB7:
        .cfi_startproc
        pushl   %ebx            #
        .cfi_def_cfa_offset 8
        .cfi_offset 3, -8
        subl    $24, %esp       #,
        .cfi_def_cfa_offset 32
        movl    $1, %edx        #, tmp65
        leal    15(%esp), %ecx  #, element.19
        movl    $4, %eax        #, tmp64
        movl    %edx, %ebx      # tmp65, tmp65
        int $0x80


As with the previous version, it starts pushing ebx, so the argument is  
now at [esp+8]. Then it substract 24 to esp, so the argument is now at  
[esp+32]. But look at what it stores to ecx: it's the effective address  
(lea is the Intel assembly instruction Load Effective Address)  
corresponding to [esp+15]. This is the wrong address, the good address is  
17 bytes above. Above all, this address does not make any sense, it is not  
even 32 bits aligned. Obviously, the system‑call does not print what's  
expected (it print nothing, probably there is a non‑printable character at  
[esp+15]).

Also note nowhere a copy is made (remember the `Element : constant  
Character := Item;` above).

The generated code looks wrong to me: it does not get the good address, it  
not even a normal address, whatever it did of `Element` as a local copy of  
`Item`.


Sorry for being long with this post, I wanted to provide all the materials  
required to clearly expose the case.


This case makes me remind of an issue I get with GNAT 4.6, when I  
discovered GNATMake was not printing some error messages it should have  
print. I noted according to the GNAT tools sources, the message should  
have been printed, but it was not. Now I wonder if ever GNAT it‑self  
sometimes suffers from a similar bug as above.


-- 
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: Epigrams on Programming — Alan J. — P. Yale University



^ permalink raw reply	[relevance 3%]

* Re: GNAT not generating any code for sub‑program: known bug?
  2013-04-28  7:14  6%   ` Simon Wright
@ 2013-04-28 17:52  3%     ` Yannick Duchêne (Hibou57)
  0 siblings, 0 replies; 82+ results
From: Yannick Duchêne (Hibou57) @ 2013-04-28 17:52 UTC (permalink / raw)


Le Sun, 28 Apr 2013 09:14:55 +0200, Simon Wright <simon@pushface.org> a  
écrit:

> and I think that the problem is that Template actually has to use the
> inputs and outputs! So, while optimising, the compiler says
>
>    "int $0x80" doesn't use any of the inputs, so I can ignore them
>    "int $0x80" doesn't write to any of the outputs, so I can ignore them
>    Result isn't changed, so it's undefined
>    Therefore I don't need to do anything.

I thought about the same previously (not my first attempt), and retried  
what I tried before, with the same result:

     function Syscall_3
       (N  : Number_Type;
        P1 : P1_Type;
        P2 : P2_Type;
        P3 : P3_Type)
        return Result_Type
     is
        use System.Machine_Code;
        Result : Result_Type;
     begin
        Asm
          (Template =>
             "movl %1, %%eax"  & ASCII.LF &
             "movl %2, %%ebx"  & ASCII.LF &
             "movl %3, %%ecx"  & ASCII.LF &
             "movl %4, %%edx"  & ASCII.LF &
             "int $0x80"       & ASCII.LF &
             "movl %%eax, %0"  & ASCII.LF,
           Outputs => Result_Type'Asm_Output ("=g", Result),
           Inputs =>
             (Number_Type'Asm_Input ("g", N),
              P1_Type'Asm_Input     ("g", P1),
              P2_Type'Asm_Input     ("g", P2),
              P3_Type'Asm_Input     ("g", P3)),
           Clobber => "eax, ebx, ecx, edx",
           Volatile => True);

        return Result;

     end Syscall_3;

Here (except it's a generic to avoid error while copying similar things),  
the template contains all of the instructions loading registers, to be  
clear about the inputs the template uses. Then, I used a `Clobber` list  
[1][3] to explicitly notify the compiler of the registers used in the  
template and which must remains untouched, then I also added `Volatile =>  
True` [2][3] to notify the compiler it should avoid unwanted optimization.  
The result is still the same, and so, even if the generic instantiation is  
not inlined (the generic declaration is not inlined neither). That's  
enough for a a caller to be inlined for everything to be dropped, even if  
the above subprogram itself not inlined. I agree I must tell the compiler  
what it is dealing with and what not to do with it, but so far, I still  
feel that looks like a compiler bug (GCC's fault or GNAT's fault?). Will  
try something else later.


Side note: with the `type Low_High is array (Half) of  
Interfaces.Unsigned_32;` in your snippet, shouldn't you specify the array  
should be packed? Or may be that's already implied by the component type…  
will have to check the RM.


[1]: http://docs.adacore.com/gnat-unw-docs/html/gnat_ugn_38.html#SEC382
[2]: http://docs.adacore.com/gnat-unw-docs/html/gnat_ugn_38.html#SEC383
[3]: http://docs.adacore.com/gnat-unw-docs/html/gnat_rm_15.html#SEC626


-- 
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: Epigrams on Programming — Alan J. — P. Yale University



^ permalink raw reply	[relevance 3%]

* Re: GNAT not generating any code for sub‑program: known bug?
  @ 2013-04-28  7:14  6%   ` Simon Wright
  2013-04-28 17:52  3%     ` Yannick Duchêne (Hibou57)
  0 siblings, 1 reply; 82+ results
From: Simon Wright @ 2013-04-28  7:14 UTC (permalink / raw)


"Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr> writes:

> Here is:
> http://www.les-ziboux.rasama.org/download/2013-04-28-cla-gnat-bug.zip

The code is

   function Syscall
     (Number  : Positive;
      Handle  : Natural;
      Address : System.Address;
      Size    : Natural)
      return Integer
   is
      Result : Integer;
   begin
      System.Machine_Code.Asm
        (Template => "int $0x80",
         Outputs => Integer'Asm_Output ("=a", Result),
         Inputs =>
           (Positive'Asm_Input       ("a", Number),
            Natural'Asm_Input        ("b", Handle),
            System.Address'Asm_Input ("c", Address),
            Natural'Asm_Input        ("d", Size)),
         Volatile => False);
      return Result;
   end;

and I think that the problem is that Template actually has to use the
inputs and outputs! So, while optimising, the compiler says

   "int $0x80" doesn't use any of the inputs, so I can ignore them
   "int $0x80" doesn't write to any of the outputs, so I can ignore them
   Result isn't changed, so it's undefined
   Therefore I don't need to do anything.

The assembler generated by GNAT GPL 2012 is different but equally
ineffective:

.globl _library__write
_library__write:
LFB3:
        pushq   %rbp
LCFI0:
        movq    %rsp, %rbp
LCFI1:
        leave
LCFI2:
        ret
LFE3:

I think that you have to write the template to show how the parameters
are set up and returned. Here's one I wrote earlier:

   with Ada.Unchecked_Conversion;
   with System.Machine_Code;

   separate (BC.Support.High_Resolution_Time)
   function Clock return Time is

      type Half is (Low, High);
      type Low_High is array (Half) of Interfaces.Unsigned_32;

      Lower, Upper : Interfaces.Unsigned_32;

      function To_Time is new Ada.Unchecked_Conversion (Low_High, Time);

   begin

      System.Machine_Code.Asm
        ("rdtsc" & ASCII.LF & ASCII.HT &
           "movl %%eax, %0"& ASCII.LF & ASCII.HT &
           "movl %%edx, %1",
         Outputs => (Interfaces.Unsigned_32'Asm_Output ("=g", Lower),
                     Interfaces.Unsigned_32'Asm_Output ("=g", Upper)),
         Clobber => "eax, edx",
         Volatile => True);

      return To_Time ((Low => Lower, High => Upper));

   end Clock;

By the way, this doesn't actually work as intended on kit such as the
Macbook Pro (more than one core? advanced power management?), presumably
because the core's clock is slowed down or stopped. Fortunately,
Ada.Calendar.Clock's resolution is 1 microsecond, good enough for most
purposes.



^ permalink raw reply	[relevance 6%]

* Re: Help with Inline assembly
  2012-07-09  8:41  0% ` theanalogmachine
@ 2012-07-09 14:43  0%   ` theanalogmachine
  0 siblings, 0 replies; 82+ results
From: theanalogmachine @ 2012-07-09 14:43 UTC (permalink / raw)


I now have the program executing, and potentially functioning -- I won't know for sure until I test it with some sort of emulator that simulates older processors. Here is the fixed code for anyone interested (this came in handy too http://x86asm.net/articles/what-i-dislike-about-gas/)

  -----------------------
  -- Can_Execute_CPUID --
  -----------------------
    function Can_Execute_CPUID
      return Boolean
      is
      Result : Unsigned_32 := 0;
      begin
        Asm(
          --------------------------------------------------------
          " begin:                       " & Ascii.LF & Ascii.HT &
          "   pushfl                     " & Ascii.LF & Ascii.HT &
          "   popl   %%eax               " & Ascii.LF & Ascii.HT & 
          "   test   $0x00200000, %%eax  " & Ascii.LF & Ascii.HT &
          "   jz     set21               " & Ascii.LF & Ascii.HT &
          "   and    $0xffdfffff, %%eax  " & Ascii.LF & Ascii.HT &
          "   pushl  %%eax               " & Ascii.LF & Ascii.HT &
          "   popfl                      " & Ascii.LF & Ascii.HT &
          "   pushfl                     " & Ascii.LF & Ascii.HT & 
          "   popl   %%eax               " & Ascii.LF & Ascii.HT & 
          "   test   $0x00200000, %%eax  " & Ascii.LF & Ascii.HT &
          "   jz     good                " & Ascii.LF & Ascii.HT & 
          "   jmp    error               " & Ascii.LF & Ascii.HT &
          --------------------------------------------------------
          " set21:                       " & Ascii.LF & Ascii.HT & 
          "   or     $0x00200000, %%eax  " & Ascii.LF & Ascii.HT &
          "   pushl  %%eax               " & Ascii.LF & Ascii.HT &
          "   popfl                      " & Ascii.LF & Ascii.HT &
          "   pushfl                     " & Ascii.LF & Ascii.HT & 
          "   popl   %%eax               " & Ascii.LF & Ascii.HT & 
          "   test   $0x00200000, %%eax  " & Ascii.LF & Ascii.HT &
          "   jnz    good                " & Ascii.LF & Ascii.HT & 
          "   jmp    error               " & Ascii.LF & Ascii.HT &  
          --------------------------------------------------------
          " error:                       " & Ascii.LF & Ascii.HT & 
          "   movl   $0x0,        %%eax  " & Ascii.LF & Ascii.HT & 
          "   jmp    end                 " & Ascii.LF & Ascii.HT &
          --------------------------------------------------------
          " good:                        " & Ascii.LF & Ascii.HT & 
          "   movl   $0x1,        %%eax  " & Ascii.LF & Ascii.HT &
          --------------------------------------------------------
          " end:                         " & Ascii.LF & Ascii.HT , 
          --------------------------------------------------------
          Outputs  => Unsigned_32'Asm_Output("=a", Result),
          Volatile => True);
        if Result /= 1 then
          return True;
        end if;
        return False;
      end Can_Execute_CPUID;

On Monday, July 9, 2012 4:41:23 AM UTC-4, (unknown) wrote:
> Thanks for the reply, it seems your suggestion did not fix my primary problem (that a EXCEPTION_ACCESS_VIOLATION is displayed at runtime). Could you elaborate more on your suggestion?
> 
> On Sunday, July 8, 2012 11:53:05 PM UTC-4, Jim C. wrote:
> > I am running into problems translating Intel style visual C inline assembly to something gnat can understand (http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Inline-Assembler.html#Inline-Assembler). The goal of the program is to test for the existence of the CPUID command which only exists after the 386.
> > 
> > The program as it stands compiles without any errors, but it will fail at runtime with the following printed: "raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION" -- I can't tell if I am violating syntax or something more complicated is involved.
> > 
> > ///////////////////////////////////// Visual C code
> > static bool HasCPUID( void ) {
> >   __asm 
> >   {
> >       pushfd                // save eflags
> >       pop   eax
> >       test  eax, 0x00200000 // check ID bit
> >       jz    set21           // bit 21 is not set, so jump to set_21
> >       and   eax, 0xffdfffff // clear bit 21
> >       push  eax             // save new value in register
> >       popfd                 // store new value in flags
> >       pushfd
> >       pop   eax
> >       test  eax, 0x00200000 // check ID bit
> >       jz    good
> >       jmp   err             // cpuid not supported
> >     set21:
> >       or    eax, 0x00200000 // set ID bit
> >       push  eax             // store new value
> >       popfd                 // store new value in EFLAGS
> >       pushfd
> >       pop   eax
> >       test  eax, 0x00200000 // if bit 21 is on
> >       jnz   good
> >       jmp   err
> >   }
> >   err:
> >     return false;
> >   good:
> >     return true;
> > }
> > 
> > --------------------------------------- Ada code
> > with
> >   Ada.Text_IO,
> >   Interfaces,
> >   System.Machine_Code;
> > use
> >   Ada.Text_IO,
> >   Interfaces,
> >   System.Machine_Code;
> > procedure Assembly_Test
> >   is
> >   C      : Character   := Ascii.Nul;
> >   Result : Unsigned_32 := 0;
> >   begin
> >     Asm(
> >       -------------------------------------------------------
> >       "   pushf                     " & Ascii.LF & Ascii.HT &
> >       "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
> >       "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
> >       "   jz     set21              " & Ascii.LF & Ascii.HT &
> >       "   and    %%eax,  0xffdfffff " & Ascii.LF & Ascii.HT &
> >       "   push   %%eax              " & Ascii.LF & Ascii.HT &
> >       "   popf                      " & Ascii.LF & Ascii.HT &
> >       "   pushf                     " & Ascii.LF & Ascii.HT & 
> >       "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
> >       "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
> >       "   jz     good               " & Ascii.LF & Ascii.HT & 
> >       "   jmp    err                " & Ascii.LF & Ascii.HT &
> >       -------------------------------------------------------
> >       " set21:                      " & Ascii.LF & Ascii.HT & 
> >       "   or     %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
> >       "   push   %%eax              " & Ascii.LF & Ascii.HT &
> >       "   popf                      " & Ascii.LF & Ascii.HT &
> >       "   pushf                     " & Ascii.LF & Ascii.HT & 
> >       "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
> >       "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
> >       "   jnz    good               " & Ascii.LF & Ascii.HT & 
> >       "   jmp    err                " & Ascii.LF & Ascii.HT &  
> >       -------------------------------------------------------
> >       " err:                        " & Ascii.LF & Ascii.HT & 
> >       "   mov    0x0,    %%eax      " & Ascii.LF & Ascii.HT & 
> >       -------------------------------------------------------
> >       " good:                       " & Ascii.LF & Ascii.HT & 
> >       "   mov    0x1,    %%eax      " & Ascii.LF & Ascii.HT , 
> >       -------------------------------------------------------
> >       Outputs  => Unsigned_32'Asm_Output("=a", Result),
> >       Volatile => True);
> >     if Result /= 1 then
> >       Put_Line("False");
> >     end if;
> >     Put_Line("True");
> >     Get(C);
> >   end Assembly_Test;



^ permalink raw reply	[relevance 0%]

* Re: Help with Inline assembly
  2012-07-09  3:53  5% Help with Inline assembly Jim C.
  2012-07-09  6:35  0% ` anon
@ 2012-07-09  8:41  0% ` theanalogmachine
  2012-07-09 14:43  0%   ` theanalogmachine
  1 sibling, 1 reply; 82+ results
From: theanalogmachine @ 2012-07-09  8:41 UTC (permalink / raw)


Thanks for the reply, it seems your suggestion did not fix my primary problem (that a EXCEPTION_ACCESS_VIOLATION is displayed at runtime). Could you elaborate more on your suggestion?

On Sunday, July 8, 2012 11:53:05 PM UTC-4, Jim C. wrote:
> I am running into problems translating Intel style visual C inline assembly to something gnat can understand (http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Inline-Assembler.html#Inline-Assembler). The goal of the program is to test for the existence of the CPUID command which only exists after the 386.
> 
> The program as it stands compiles without any errors, but it will fail at runtime with the following printed: "raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION" -- I can't tell if I am violating syntax or something more complicated is involved.
> 
> ///////////////////////////////////// Visual C code
> static bool HasCPUID( void ) {
>   __asm 
>   {
>       pushfd                // save eflags
>       pop   eax
>       test  eax, 0x00200000 // check ID bit
>       jz    set21           // bit 21 is not set, so jump to set_21
>       and   eax, 0xffdfffff // clear bit 21
>       push  eax             // save new value in register
>       popfd                 // store new value in flags
>       pushfd
>       pop   eax
>       test  eax, 0x00200000 // check ID bit
>       jz    good
>       jmp   err             // cpuid not supported
>     set21:
>       or    eax, 0x00200000 // set ID bit
>       push  eax             // store new value
>       popfd                 // store new value in EFLAGS
>       pushfd
>       pop   eax
>       test  eax, 0x00200000 // if bit 21 is on
>       jnz   good
>       jmp   err
>   }
>   err:
>     return false;
>   good:
>     return true;
> }
> 
> --------------------------------------- Ada code
> with
>   Ada.Text_IO,
>   Interfaces,
>   System.Machine_Code;
> use
>   Ada.Text_IO,
>   Interfaces,
>   System.Machine_Code;
> procedure Assembly_Test
>   is
>   C      : Character   := Ascii.Nul;
>   Result : Unsigned_32 := 0;
>   begin
>     Asm(
>       -------------------------------------------------------
>       "   pushf                     " & Ascii.LF & Ascii.HT &
>       "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
>       "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
>       "   jz     set21              " & Ascii.LF & Ascii.HT &
>       "   and    %%eax,  0xffdfffff " & Ascii.LF & Ascii.HT &
>       "   push   %%eax              " & Ascii.LF & Ascii.HT &
>       "   popf                      " & Ascii.LF & Ascii.HT &
>       "   pushf                     " & Ascii.LF & Ascii.HT & 
>       "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
>       "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
>       "   jz     good               " & Ascii.LF & Ascii.HT & 
>       "   jmp    err                " & Ascii.LF & Ascii.HT &
>       -------------------------------------------------------
>       " set21:                      " & Ascii.LF & Ascii.HT & 
>       "   or     %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
>       "   push   %%eax              " & Ascii.LF & Ascii.HT &
>       "   popf                      " & Ascii.LF & Ascii.HT &
>       "   pushf                     " & Ascii.LF & Ascii.HT & 
>       "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
>       "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
>       "   jnz    good               " & Ascii.LF & Ascii.HT & 
>       "   jmp    err                " & Ascii.LF & Ascii.HT &  
>       -------------------------------------------------------
>       " err:                        " & Ascii.LF & Ascii.HT & 
>       "   mov    0x0,    %%eax      " & Ascii.LF & Ascii.HT & 
>       -------------------------------------------------------
>       " good:                       " & Ascii.LF & Ascii.HT & 
>       "   mov    0x1,    %%eax      " & Ascii.LF & Ascii.HT , 
>       -------------------------------------------------------
>       Outputs  => Unsigned_32'Asm_Output("=a", Result),
>       Volatile => True);
>     if Result /= 1 then
>       Put_Line("False");
>     end if;
>     Put_Line("True");
>     Get(C);
>   end Assembly_Test;



^ permalink raw reply	[relevance 0%]

* Re: Help with Inline assembly
  2012-07-09  3:53  5% Help with Inline assembly Jim C.
@ 2012-07-09  6:35  0% ` anon
  2012-07-09  8:41  0% ` theanalogmachine
  1 sibling, 0 replies; 82+ results
From: anon @ 2012-07-09  6:35 UTC (permalink / raw)


alter code to look like this:

      -------------------------------------------------------
      " err:                        " & Ascii.LF & Ascii.HT &
      "   mov    0x0,    %%eax      " & Ascii.LF & Ascii.HT &
      "   jmp    ret                " & Ascii.LF & Ascii.HT &  -- added
      -------------------------------------------------------
      " good:                       " & Ascii.LF & Ascii.HT &
      "   mov    0x1,    %%eax      " & Ascii.LF & Ascii.HT &
      -------------------------------------------------------
      " ret:"                        ",                        -- added


remove the "-- added" comment


In <85b57cc7-352e-4cee-a161-b0aaf1665305@googlegroups.com>, "Jim C." <theanalogmachine@gmail.com> writes:
>I am running into problems translating Intel style visual C inline assembly=
> to something gnat can understand (http://gcc.gnu.org/onlinedocs/gnat_ugn_u=
>nw/Inline-Assembler.html#Inline-Assembler). The goal of the program is to t=
>est for the existence of the CPUID command which only exists after the 386.
>
>The program as it stands compiles without any errors, but it will fail at r=
>untime with the following printed: "raised PROGRAM_ERROR : EXCEPTION_ACCESS=
>_VIOLATION" -- I can't tell if I am violating syntax or something more comp=
>licated is involved.
>
>///////////////////////////////////// Visual C code
>static bool HasCPUID( void ) {
>  __asm=20
>  {
>      pushfd                // save eflags
>      pop   eax
>      test  eax, 0x00200000 // check ID bit
>      jz    set21           // bit 21 is not set, so jump to set_21
>      and   eax, 0xffdfffff // clear bit 21
>      push  eax             // save new value in register
>      popfd                 // store new value in flags
>      pushfd
>      pop   eax
>      test  eax, 0x00200000 // check ID bit
>      jz    good
>      jmp   err             // cpuid not supported
>    set21:
>      or    eax, 0x00200000 // set ID bit
>      push  eax             // store new value
>      popfd                 // store new value in EFLAGS
>      pushfd
>      pop   eax
>      test  eax, 0x00200000 // if bit 21 is on
>      jnz   good
>      jmp   err
>  }
>  err:
>    return false;
>  good:
>    return true;
>}
>
>--------------------------------------- Ada code
>with
>  Ada.Text_IO,
>  Interfaces,
>  System.Machine_Code;
>use
>  Ada.Text_IO,
>  Interfaces,
>  System.Machine_Code;
>procedure Assembly_Test
>  is
>  C      : Character   :=3D Ascii.Nul;
>  Result : Unsigned_32 :=3D 0;
>  begin
>    Asm(
>      -------------------------------------------------------
>      "   pushf                     " & Ascii.LF & Ascii.HT &
>      "   pop    %%eax              " & Ascii.LF & Ascii.HT &=20
>      "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
>      "   jz     set21              " & Ascii.LF & Ascii.HT &
>      "   and    %%eax,  0xffdfffff " & Ascii.LF & Ascii.HT &
>      "   push   %%eax              " & Ascii.LF & Ascii.HT &
>      "   popf                      " & Ascii.LF & Ascii.HT &
>      "   pushf                     " & Ascii.LF & Ascii.HT &=20
>      "   pop    %%eax              " & Ascii.LF & Ascii.HT &=20
>      "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
>      "   jz     good               " & Ascii.LF & Ascii.HT &=20
>      "   jmp    err                " & Ascii.LF & Ascii.HT &
>      -------------------------------------------------------
>      " set21:                      " & Ascii.LF & Ascii.HT &=20
>      "   or     %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
>      "   push   %%eax              " & Ascii.LF & Ascii.HT &
>      "   popf                      " & Ascii.LF & Ascii.HT &
>      "   pushf                     " & Ascii.LF & Ascii.HT &=20
>      "   pop    %%eax              " & Ascii.LF & Ascii.HT &=20
>      "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
>      "   jnz    good               " & Ascii.LF & Ascii.HT &=20
>      "   jmp    err                " & Ascii.LF & Ascii.HT & =20
>      -------------------------------------------------------
>      " err:                        " & Ascii.LF & Ascii.HT &=20
>      "   mov    0x0,    %%eax      " & Ascii.LF & Ascii.HT &=20
>      -------------------------------------------------------
>      " good:                       " & Ascii.LF & Ascii.HT &=20
>      "   mov    0x1,    %%eax      " & Ascii.LF & Ascii.HT ,=20
>      -------------------------------------------------------
>      Outputs  =3D> Unsigned_32'Asm_Output("=3Da", Result),
>      Volatile =3D> True);
>    if Result /=3D 1 then
>      Put_Line("False");
>    end if;
>    Put_Line("True");
>    Get(C);
>  end Assembly_Test;




^ permalink raw reply	[relevance 0%]

* Help with Inline assembly
@ 2012-07-09  3:53  5% Jim C.
  2012-07-09  6:35  0% ` anon
  2012-07-09  8:41  0% ` theanalogmachine
  0 siblings, 2 replies; 82+ results
From: Jim C. @ 2012-07-09  3:53 UTC (permalink / raw)


I am running into problems translating Intel style visual C inline assembly to something gnat can understand (http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Inline-Assembler.html#Inline-Assembler). The goal of the program is to test for the existence of the CPUID command which only exists after the 386.

The program as it stands compiles without any errors, but it will fail at runtime with the following printed: "raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION" -- I can't tell if I am violating syntax or something more complicated is involved.

///////////////////////////////////// Visual C code
static bool HasCPUID( void ) {
  __asm 
  {
      pushfd                // save eflags
      pop   eax
      test  eax, 0x00200000 // check ID bit
      jz    set21           // bit 21 is not set, so jump to set_21
      and   eax, 0xffdfffff // clear bit 21
      push  eax             // save new value in register
      popfd                 // store new value in flags
      pushfd
      pop   eax
      test  eax, 0x00200000 // check ID bit
      jz    good
      jmp   err             // cpuid not supported
    set21:
      or    eax, 0x00200000 // set ID bit
      push  eax             // store new value
      popfd                 // store new value in EFLAGS
      pushfd
      pop   eax
      test  eax, 0x00200000 // if bit 21 is on
      jnz   good
      jmp   err
  }
  err:
    return false;
  good:
    return true;
}

--------------------------------------- Ada code
with
  Ada.Text_IO,
  Interfaces,
  System.Machine_Code;
use
  Ada.Text_IO,
  Interfaces,
  System.Machine_Code;
procedure Assembly_Test
  is
  C      : Character   := Ascii.Nul;
  Result : Unsigned_32 := 0;
  begin
    Asm(
      -------------------------------------------------------
      "   pushf                     " & Ascii.LF & Ascii.HT &
      "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
      "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
      "   jz     set21              " & Ascii.LF & Ascii.HT &
      "   and    %%eax,  0xffdfffff " & Ascii.LF & Ascii.HT &
      "   push   %%eax              " & Ascii.LF & Ascii.HT &
      "   popf                      " & Ascii.LF & Ascii.HT &
      "   pushf                     " & Ascii.LF & Ascii.HT & 
      "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
      "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
      "   jz     good               " & Ascii.LF & Ascii.HT & 
      "   jmp    err                " & Ascii.LF & Ascii.HT &
      -------------------------------------------------------
      " set21:                      " & Ascii.LF & Ascii.HT & 
      "   or     %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
      "   push   %%eax              " & Ascii.LF & Ascii.HT &
      "   popf                      " & Ascii.LF & Ascii.HT &
      "   pushf                     " & Ascii.LF & Ascii.HT & 
      "   pop    %%eax              " & Ascii.LF & Ascii.HT & 
      "   test   %%eax,  0x00200000 " & Ascii.LF & Ascii.HT &
      "   jnz    good               " & Ascii.LF & Ascii.HT & 
      "   jmp    err                " & Ascii.LF & Ascii.HT &  
      -------------------------------------------------------
      " err:                        " & Ascii.LF & Ascii.HT & 
      "   mov    0x0,    %%eax      " & Ascii.LF & Ascii.HT & 
      -------------------------------------------------------
      " good:                       " & Ascii.LF & Ascii.HT & 
      "   mov    0x1,    %%eax      " & Ascii.LF & Ascii.HT , 
      -------------------------------------------------------
      Outputs  => Unsigned_32'Asm_Output("=a", Result),
      Volatile => True);
    if Result /= 1 then
      Put_Line("False");
    end if;
    Put_Line("True");
    Get(C);
  end Assembly_Test;



^ permalink raw reply	[relevance 5%]

* Re: Importing C function with variable argument list
  @ 2012-04-13  8:04  5%           ` Markus Schöpflin
  0 siblings, 0 replies; 82+ results
From: Markus Schöpflin @ 2012-04-13  8:04 UTC (permalink / raw)


Am 13.04.2012 06:08, schrieb Tero Koskinen:

[...]

> So on amd64/x86_64 (unix) platform injecting asm code, which sets
> %rax/%eax to 0, works in most cases (= 0 vector registers used).

Yes, I did read a similar document (I think it's actually %al that is looked 
at, not the full register) which lead me to try using inline assembly like this:

---%<---
with SYSTEM.MACHINE_CODE;
with INTERFACES.C;

procedure TEST
is
    use SYSTEM.MACHINE_CODE;
    use INTERFACES.C;

    function PRINTF (FORMAT : in CHAR_ARRAY; N1 : in INT) return INT;
    pragma IMPORT (C, PRINTF, "printf");

    F1 : constant CHAR_ARRAY := TO_C("%08d" & ASCII.LF);
    DUMMY : INT;
begin
    ASM ("mov $0, %%al", CLOBBER => "al", VOLATILE => TRUE);
    DUMMY := PRINTF(F1, N1 => 123);
end TEST;
--->%---

Using -O0 when compiling results in the following assembly code:

---%<---
   401696:       b0 00                   mov    $0x0,%al
   401698:       48 8b 85 40 ff ff ff    mov    -0xc0(%rbp),%rax
   40169f:       48 89 55 c0             mov    %rdx,-0x40(%rbp)
   4016a3:       48 89 4d c8             mov    %rcx,-0x38(%rbp)
   4016a7:       48 89 45 b0             mov    %rax,-0x50(%rbp)
   4016ab:       48 8d 45 c0             lea    -0x40(%rbp),%rax
   4016af:       48 89 45 b8             mov    %rax,-0x48(%rbp)
   4016b3:       48 8b 45 b0             mov    -0x50(%rbp),%rax
   4016b7:       be 7b 00 00 00          mov    $0x7b,%esi
   4016bc:       48 89 c7                mov    %rax,%rdi
   4016bf:       e8 2c fb ff ff          callq  4011f0 <printf@plt>
   4016c4:       89 45 ec                mov    %eax,-0x14(%rbp)
--->%---

The first line is from the inline assembly, the rest is code generated by gnat 
for the call to printf and the handling of the return value. Still no luck, as 
%rax is used between the first line and the call to printf for different things.

Interestingly, compiling with -O2 gives:

---%<---
   40157c:       b0 00                   mov    $0x0,%al
   40157e:       be 7b 00 00 00          mov    $0x7b,%esi
   401583:       e8 68 fc ff ff          callq  4011f0 <printf@plt>
--->%---

Et voil�, the resulting binary really works and prints out the expected result.

> (Of course, it would be better to have some standard way to
> say this.)

As others have already said, a new calling convention for variadic C functions 
would be the way to go, I think.

Markus



^ permalink raw reply	[relevance 5%]

* Re: Any leap year issues caused by Ada yesterday?
  @ 2012-03-06 17:59  4%                       ` Simon Wright
  0 siblings, 0 replies; 82+ results
From: Simon Wright @ 2012-03-06 17:59 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Tue, 06 Mar 2012 16:46:35 +0000, Simon Wright wrote:
>
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> 
>>> Under VxWorks you can read the TSC without assembly, there is a library
>>> function for that (pentiumTscGet64).
>>>
>>>    type Timestamp is new Unsigned_64;
>>>    procedure pentiumTscGet64 (Clock : out Timestamp);
>>>    pragma Import (C, pentiumTscGet64, "pentiumTscGet64");
>>>
>>> should do the work.
>> 
>> Not sure if there was an equivalent for PPC.
>
> AFAIK, PPC has a high resolution real time counter, which is better
> designed than Intel's TSC.

Yes, the Time Base.

Ours was a 32-bit implementation, so you get to read the lower and upper
halves of the timebase separately, which would cause problems at
rollover. So read the TB using an internal Clock like this

   function Clock return Time is

      type Half is (High, Low);
      type High_Low is array (Half) of Interfaces.Unsigned_32;

      Upper, Lower, Upper_Again : Interfaces.Unsigned_32;

      function To_Time is new Ada.Unchecked_Conversion (High_Low, Time);

      use type Interfaces.Unsigned_32;

   begin

      loop
         System.Machine_Code.Asm
           ("mftbu %0" & ASCII.LF & ASCII.HT &
              "mftb %1" & ASCII.LF & ASCII.HT &
              "mftbu %2",
            Outputs =>
              (Interfaces.Unsigned_32'Asm_Output ("=r", Upper),
               Interfaces.Unsigned_32'Asm_Output ("=r", Lower),
               Interfaces.Unsigned_32'Asm_Output ("=r", Upper_Again)),
            Volatile => True);
         exit when Upper_Again = Upper;
      end loop;

      return To_Time ((High => Upper, Low => Lower));

   end Clock;

The timebase ran off the same crystal as the decrementer, so all were
internally sync'd. Internally, our synchronised time was
(Ada.Calendar.Clock (at last clock interrupt, of course) + high-res time
since last clock interrupt). We added the external sync offset on
sending a time off-board, and subtracted it on receiving one.

(I've never used VxWorks on x86).



^ permalink raw reply	[relevance 4%]

* Re: Overloading attributes
  @ 2011-11-30 11:05  4%   ` anon
  0 siblings, 0 replies; 82+ results
From: anon @ 2011-11-30 11:05 UTC (permalink / raw)


As for RM 1.1.3 "Conformity of an Implementation with the Standard"

This is just a small list of errors within the GNAT system.
Lets see GNAT violates a number of paragraphs such as:

    2  Translate and correctly execute legal programs written in Ada,
       provided that they are not so large as to exceed the capacity of
       the implementation;

   15  A conforming implementation of this International Standard shall 
       produce for the execution of a given Ada program a set of 
       interactions with the external environment whose order and timing 
       are consistent with the definitions and requirements of this 
       International Standard for the semantics of the given program.

When the GNAT compiler see a raise statement like 

         raise Program_Error ;

instead of converting the routine into something like is 

         Raise_Exception ( Program_Error'Identity,
                           Integer'Image ( Line_Number ) ) ;
or maybe 

         Raise_Exception ( Program_Error'Identity,
                           "was explicit raise by <filename> at line" 
                           & Integer'Image ( Line_Number ) ) ;

it converts it to 

         RCheck_15 ( "<filename>", Line_number ) ;

that not translate and correctly. and the routines that must be 
executed may interfer with the program timing.


    5  Supply all language-defined library units required by this
       International Standard;

   16  An implementation that conforms to this Standard shall support 
       each capability required by the core language as specified.  In 
       addition, an implementation that conforms to this Standard may 
       conform to one or more Specialized Needs Annexes (or to none).  
       Conformance to a Specialized Needs Annex means that each 
       capability required by the Annex is provided as specified.

A number of packages in GNAT do not function as stated in the Standard 
an example is System.RPC and another is Ada.Asynchronous_Task_Control.

For the "Partition Communication Subsystem", Ada uses System.RPC which 
an older communication but is still in the RM and is still useful.

Also, since GNAT compiler can process a program for multi-environments 
it is required that all language-defined library units be fully 
functional so Ada.Asynchronous_Task_Control should be fully functional 
as well.

    6  Contain no variations except those explicitly permitted by this
       International Standard, or those that are impossible or
       impractical to avoid given the implementation's execution
       environment;

GNAT is always adding extra features that may or may not be in the 
next Standard version that can causes corruptions to occur with current 
Standard. Plus, there are a number of statements designs that are not 
functional like the "representation_clause" within the "Protected Units"


   10  The execution of certain code_statements (see 13.8); which 
       code_statements cause external interactions is implementation 
       defined.


While the System.Machine_Code package may be optional, but the coding of 
"code_statements" are not optional. GNAT does not allow "code_statements" 
of any kind. Actually the GNAT compiler does contains the code for 
processing a "code_statement" but it is deactivated.



Adacore GNAT compiler and RTL is one of two Ada leading Ada systems, the 
other is IBM/APEX system.  Since GNAT can not even meet the complete 
definition that is in "RM 1.1.3" that indicates that one or the other is 
corrupted or and should not be used.


This might expain one reason the Dod drop the mandated use of Ada.


In <f10225e5-d894-4ccb-924a-6cf741781fe4@t16g2000vba.googlegroups.com>, Mark Lorenzen <mark.lorenzen@gmail.com> writes:
>On 29 Nov., 12:58, a...@att.net wrote:
>> Where in the RM does it say that the compiler and RTL is the implementation?
>> As everyone says the Ada RM is the final word! And if it is not defined in
>> the RM then the compiler and RTL are not the implementation, but are the
>> tools for the implementation.
>
>I think that chapter 1.1.3 ("Conformity of an Implementation with the
>Standard") pretty well describes the expectations for an
>implementation. To me it's pretty obvious that the standard is talking
>about the toolchain and the RTL.
>
>Regards,
>
>Mark L




^ permalink raw reply	[relevance 4%]

* Re: strange behavior while compiling code with asm()
  2011-05-26 15:10  5% strange behavior while compiling code with asm() milouz
@ 2011-05-26 16:50  0% ` Simon Wright
  0 siblings, 0 replies; 82+ results
From: Simon Wright @ 2011-05-26 16:50 UTC (permalink / raw)


milouz <a.michelizza@gmail.com> writes:

>   procedure Main is
>       Foo : Integer;
>   begin
>       Foo := 1;       -- Foo is initialized here !
>       System.Machine_Code.Asm(
>           "movl %0, %%eax",
>           Inputs => Integer'Asm_Input("m", Foo),
>           Volatile => True
>      );
>   ...
>
> Why no trying to initialize `Foo' variale during its declaration ? The
> code is exactly the same except for `Foo' :
>
>   procedure Main is
>       Foo : Integer := 1;     -- Foo is initialized here !
>   begin
>
>
> But then, compilation fails with that message : "error: memory input 0
> is not directly addressable"

Here (GCC 4.6.0) I get

   gnatmake -c -u -f milouz.adb
   gcc -c milouz.adb
   milouz.adb: In function 'Milouz':
   milouz.adb:13:23: warning: use of memory input without lvalue in asm operand 0 is deprecated [enabled by default]

but this goes away if instead of "m" I use "g". I suppose that the first
form places Foo in memory, while the second places it in a register,
which won't work with the "m" constraint
(http://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Simple-Constraints.html)



^ permalink raw reply	[relevance 0%]

* strange behavior while compiling code with asm()
@ 2011-05-26 15:10  5% milouz
  2011-05-26 16:50  0% ` Simon Wright
  0 siblings, 1 reply; 82+ results
From: milouz @ 2011-05-26 15:10 UTC (permalink / raw)


Hi all,

There's an unexpected behavior I can't understand when I compile some
Ada code with Asm() directive. In the following example, code compile
with no problem :

  ...
  procedure Main is
      Foo : Integer;
  begin
      Foo := 1;       -- Foo is initialized here !
      System.Machine_Code.Asm(
          "movl %0, %%eax",
          Inputs => Integer'Asm_Input("m", Foo),
          Volatile => True
     );
  ...

Why no trying to initialize `Foo' variale during its declaration ? The
code is exactly the same except for `Foo' :

  procedure Main is
      Foo : Integer := 1;     -- Foo is initialized here !
  begin


But then, compilation fails with that message : "error: memory input 0
is not directly addressable"

Someone have an explanation ?



^ permalink raw reply	[relevance 5%]

* Re: Advice on selling Ada to a C shop
  @ 2010-06-23 16:20  5%       ` anon
  0 siblings, 0 replies; 82+ results
From: anon @ 2010-06-23 16:20 UTC (permalink / raw)


In <hvr1j8$f1k$1@speranza.aioe.org>, "Nasser M. Abbasi" <nma@12000.org> writes:
>On 6/22/2010 11:01 AM, anon@anon.org wrote:
>
>> In<774c25c4-3270-4ffb-ad19-366a0ab16659@i31g2000yqm.googlegroups.com>, Lucretia<Lucretia9000@yahoo.co.uk>  writes:
>>> Ask them what they don't like about C and developing in C (via a
>>> questionnaire if necessary), then show them how to do it in Ada,
>>> showing the benefits.
>>>
>>> This might help get the point across.
>>>
>>> Luke.
>>
>
>>
>> That might be true until Ada 2012! With C like structure being added
>> people will say why switch.
>>
>
>any link for someone to find what does "C like structure being added" 
>mean and how can that provide something that Ada record does't provide?
>
>--Nasser

For Ada, to pull ahead of the language fight, Ada 2012 needs to 
forget the conditional C-Like structures (see below) and define a 
true portable Window and Graphic packages in the RM.  These two 
packages should allow any Ada programmer to create a program 
that controls a set of Windows with Graphics without concerns of 
the OS or the processor used.

Like in the Window packages, a set of common routines to control and 
maintain a gui window regardless of the system used, But the actually 
routines would not be just a binder but would enhance the ability of 
the operation of the window.  Like using tasks or event handlers to 
monitor and control the function of the window. Such as monitoring 
when the windows is active and needs to monitor all assigned I/O 
devices as well as make changes to the windows when requested. Or in 
another case the routines could simply sleep as long as the windows 
is invisible and only wake-up to update the windows's screen buffer 
when screen output is requested. 

As for the graphics package.  Those routines and values are mostly 
commonly define with a few exceptions though out the different OSs 
and GPU cards that could be handle in an Ada graphics interface and 
binder package. Of course, the package routines might handle a series 
of commands which could free the main Ada partition to do other 
things.

These two packages and their sub-packages should of been introduced 
to Ada's RM a back in 2000 or earlier but the powers that be 
preferred unions and "oops" and now conditional structures instead.  
None of which truly aid Ada.  These ideas are slowly causes the 
death of Ada because without graphics and windows routine Ada is 
limited in it scope of partitions that people want.  The powers 
that maintain and updates Ada are not listening to the right 
programmers.  Some here in this newsgroup would like to see Ada 
include these two packages group, because it would allow a programmer 
to create a portable gui Ada project not found even in C.  This 
would be an advantage over C or MS .net system and give Ada 
the functionality of the graphics that in found in Java but with the 
performance of a true native language.



C like Structures: 

Unions are one thing, but non Ada conditional structures are another!

AT&T create C and the first C compiler then licensed the primary 
design to IBM, NCR, Univac (unisys), DEC, etc, as well as a number 
colleges and universities but no control or RM was given for that 
design.  So, each license holder created their own version of the 
language. A "put" in one system might be define as a "putch" in 
another. Also constants like "NULL" may be define as a "0x0" in one 
system and the next system could define the value as either upper or 
lower limit of a integer while others it a user definable constant.  
Also, even a logical statement may result in a true value for one 
system while being false in another. So, to solve some of these 
and others problems conditional structures were added to C instead 
of defining and enforcing a C RM.

But all full Ada compilers are required to follow the RM and any 
alteration of the Ada system must be defined and allowed in the 
RM. Like, the System.Machine_Code package is defined as optional.  
DEC preferred to use other languages like an assembler or other 
high level languages instead of providing the System.Machine_Code 
package. While IBM and SUN version of Ada mostly followed the Ada 
RM example design. And Adacore programmers using gcc kind of 
created their own version of this package. If one looks at the 
Ada RM 13.8 section for the System.Machine_Code package one will 
see that that all three ways this package is handle are legal.


Now, with the release of GNAT 2009, Adacore started including 
"Conditional Structures".

In GNAT 2009, the "If" conditional structure was added.

   <Variable> := (if ...  then ... else ... );

Not sure if you can use add the "elsif .... then"  clause.

This is too close to C like structures for any Ada purist to approve of.
It is better and more portable to have two or more packages instead.

An example of this type of structure come from Ada.Text_IO.adb line 568:
 
  Item :=
    (if not Is_Start_Of_Encoding (Character'Val (ch), File.WC_Method)
        then Character'Val (ch)
        else Get_Upper_Half_Char_Immed (Character'Val (ch), File));


The C version would be:

  /*
   * #define CharacterVal (c)  c    // definition is not needed 
   */

  Item = (!Is_Start_Of_Encoding (ch, File.WC_Method)
          ? ch
          : Get_Upper_Half_Char_Immed (ch, File)
         );

Does this improve coding. No! It only allows a small group of C coded 
routines to be ported directly to Ada code, instead of just using the 
"Interfaces.C.*" packages and the "pragma Import" or "pragma Export" 
statements. Why should any programmer spend their time in rewriting 
the code from one language to another, if the code works.  And if the 
code does not work then simply translating the code into Ada may not 
correct the problem, but trashing the bad C code and starting from 
scratch could. So, its better to just compile and use the C code if 
it works as a small external library routine. 

Also, if you ask, most programmers do not want to spend their time in 
transferring a C or any library like the vast Fortran libraries to Ada 
just to use that routine or library in Ada. They prefer write pure 
Ada and just link to the libraries or routine written in other 
languages when needed.




^ permalink raw reply	[relevance 5%]

* Re: Code Statement
  2010-05-19  9:56  5%       ` sjw
@ 2010-05-19 10:20  0%         ` AdaMagica
  0 siblings, 0 replies; 82+ results
From: AdaMagica @ 2010-05-19 10:20 UTC (permalink / raw)


On 19 Mai, 11:56, sjw <simon.j.wri...@mac.com> wrote:
> On May 19, 7:07 am, Simon Wright <si...@pushface.org> wrote:
>
> > I'm not sure whathttp://www.adaic.com/standards/05rm/html/RM-13-8.html
> > (2) means; does it give you a licence to use any type you lke? seems
> > unlikely.
>
> Sorry, I meant (4): "The qualified_expression is expected to be of any
> type."

This is a Name Resolution Rule used for overload resolution. As far as
overloading is concernded, any type can do.

> Compare with (5): "The qualified_expression shall be of a type
> declared in package System.Machine_Code."

This is a Legality Rule and applied only after overload resolution. So
this is where code becomes illegal when other types are used.



^ permalink raw reply	[relevance 0%]

* Re: Code Statement
  2010-05-19  6:07  6%     ` Simon Wright
@ 2010-05-19  9:56  5%       ` sjw
  2010-05-19 10:20  0%         ` AdaMagica
  0 siblings, 1 reply; 82+ results
From: sjw @ 2010-05-19  9:56 UTC (permalink / raw)


On May 19, 7:07 am, Simon Wright <si...@pushface.org> wrote:

> I'm not sure what http://www.adaic.com/standards/05rm/html/RM-13-8.html
> (2) means; does it give you a licence to use any type you lke? seems
> unlikely.

Sorry, I meant (4): "The qualified_expression is expected to be of any
type."

Compare with (5): "The qualified_expression shall be of a type
declared in package System.Machine_Code."




^ permalink raw reply	[relevance 5%]

* Re: Code Statement
  2010-05-19  4:37  7%   ` anon
@ 2010-05-19  6:07  6%     ` Simon Wright
  2010-05-19  9:56  5%       ` sjw
  0 siblings, 1 reply; 82+ results
From: Simon Wright @ 2010-05-19  6:07 UTC (permalink / raw)


anon@att.net writes:

> As for the example supplied I decide use the intel "nop" for simplicity
> instead of using the codes for the attached processor.

Ah! I see what you meant by "special project".

> I prefer to use the Code Statement like the System.Machine_Code in SUN, 
> instead of using the inline-assembler of gnat\gcc. which forces the 
> following type of statements for non-native processors:
>
>     ASM ( " .byte 0x90" ) ; -- intel x86 nop
>     ASM ( " .byte 0x02" ) ; -- attach processor instruction "Load R2"
>     ...
>
> And using the code statement allows the Ada compiler to emulate a small 
> limited assembler without all of the work\time in rewriting\expanding 
> the gcc "AS" to include the new processor.
>
> So, I see no problem in using code statement except for creating or 
> expand and recompiling the "system.machine_code" package. Unless Adacore 
> has crippled gnat's code statement routines.

I'm not sure what http://www.adaic.com/standards/05rm/html/RM-13-8.html
(2) means; does it give you a licence to use any type you lke? seems
unlikely.

> Now, the RM 13.8 (2), says that the code statement is qualified_expression 
> so what the problem.  In Gnat, the ASM routines are handled by the 
> "Expand_Asm_Call" procedure ("exp_code" package) which expands the ASM 
> statement into a qualified_expression.  Also, "P_Code_Statement" ("par-ch13" 
> package) directly processes code_statements as an qualified_expression.  
> Afterwards, the "Analyze_Code_Statement" ("sem-ch13" package)  analyzes 
> should handle the code statements but this routine is where the error 
> message is generated.

I expect the compiler is written to expect System.Machine_Code.Asm_Insn
of the specific type defined in System.Machine_Code.

You could write
   Asm_Insn'(Asm (".byte 0x90"));
but it hardly seems worth the trouble. AdaCore have provided this as a 
"feature" I think -- see the GNAT RM, 
http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gnat_rm/Machine-Code-Insertions.html



^ permalink raw reply	[relevance 6%]

* Re: Code Statement
  @ 2010-05-19  4:37  7%   ` anon
  2010-05-19  6:07  6%     ` Simon Wright
  0 siblings, 1 reply; 82+ results
From: anon @ 2010-05-19  4:37 UTC (permalink / raw)


In <8242a424-5b09-4444-a3ed-7b45e159c46a@z17g2000vbd.googlegroups.com>, sjw <simon.j.wright@mac.com> writes:
>On May 18, 2:12=A0pm, johnj...@cox.net wrote:
>> Trying to use the "Code Statement" for a special project, by passing the
>> ASM proc/func. So, can Gnat process a true "Code Statement" statement?
>>
>> When I compile the following example using>gnat make temp.adb -gnatpg
>>
>> gcc -c -gnatpg temp.adb
>> temp.adb:10:07: incorrect type for code statement
>> gnatmake: "temp.adb" compilation error
>>
>> Source code:
>>
>> =A0 =A0package Machine_Code is
>>
>> =A0 =A0 =A0 =A0type Asm_Insn is new Integer; =A0-- =A0type required by ga=
>nt
>>
>> =A0 =A0 =A0 =A0x86_NOP =A0 =A0: constant Asm_Insn :=3D 16#90#;
>>
>> =A0 =A0 =A0 =A0type M_Code_0 =A0is record
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Opcode : Asm_Insn;
>> =A0 =A0 =A0 =A0end record;
>> =A0 =A0 =A0 =A0pragma Pack (M_Code_0);
>> =A0 =A0end Machine_Code;
>>
>> Source code:
>>
>> =A0 =A0with Machine_Code;
>>
>> =A0 =A0procedure temp is
>>
>> =A0 =A0 =A0 =A0procedure Test;
>>
>> =A0 =A0 =A0 =A0procedure Test is
>> =A0 =A0 =A0 =A0 =A0 use Machine_Code;
>> =A0 =A0 =A0 =A0begin
>> =A0 =A0 =A0 =A0 =A0 M_Code_0'(Opcode =3D> x86_NOP); =A0-- line 10
>> =A0 =A0 =A0 =A0end Test;
>>
>> =A0 =A0begin
>> =A0 =A0 =A0 null;
>> =A0 =A0end temp;
>
>See
>http://booch95.svn.sourceforge.net/viewvc/booch95/trunk/src/bc-support-high=
>_resolution_time-clock.adb-pentium?revision=3D1415&view=3Dmarkup
>for a working i586/x86_64 example.
>
>Best not to use -gnatpg: -gnatp says 'suppress all checks', -gnatg
>says 'GNAT implementation mode (used for compiling GNAT units)' -- I'm
>pretty sure that that mode is like -Werror.




As for the example supplied I decide use the intel "nop" for simplicity
instead of using the codes for the attached processor.

I prefer to use the Code Statement like the System.Machine_Code in SUN, 
instead of using the inline-assembler of gnat\gcc. which forces the 
following type of statements for non-native processors:

    ASM ( " .byte 0x90" ) ; -- intel x86 nop
    ASM ( " .byte 0x02" ) ; -- attach processor instruction "Load R2"
    ...

And using the code statement allows the Ada compiler to emulate a small 
limited assembler without all of the work\time in rewriting\expanding 
the gcc "AS" to include the new processor.

So, I see no problem in using code statement except for creating or 
expand and recompiling the "system.machine_code" package. Unless Adacore 
has crippled gnat's code statement routines.

Now, the RM 13.8 (2), says that the code statement is qualified_expression 
so what the problem.  In Gnat, the ASM routines are handled by the 
"Expand_Asm_Call" procedure ("exp_code" package) which expands the ASM 
statement into a qualified_expression.  Also, "P_Code_Statement" ("par-ch13" 
package) directly processes code_statements as an qualified_expression.  
Afterwards, the "Analyze_Code_Statement" ("sem-ch13" package)  analyzes 
should handle the code statements but this routine is where the error 
message is generated.

Used "-gnatpg" since machine_code is a gnat system package.



^ permalink raw reply	[relevance 7%]

* Re: Code Statement
    2010-05-18 13:22  5% ` Ludovic Brenta
@ 2010-05-18 13:29  5% ` AdaMagica
    2 siblings, 0 replies; 82+ results
From: AdaMagica @ 2010-05-18 13:29 UTC (permalink / raw)


>    package Machine_Code is
>
>        type Asm_Insn is new Integer;  --  type required by gant
>
>        x86_NOP    : constant Asm_Insn := 16#90#;
>
>        type M_Code_0  is record
>                          Opcode : Asm_Insn;
>        end record;
>        pragma Pack (M_Code_0);
>    end Machine_Code;

This is a package that you have written yourself. You must use the
package System.Machine_Code. See RM 13.8.



^ permalink raw reply	[relevance 5%]

* Re: Code Statement
  @ 2010-05-18 13:22  5% ` Ludovic Brenta
  2010-05-18 13:29  5% ` AdaMagica
    2 siblings, 0 replies; 82+ results
From: Ludovic Brenta @ 2010-05-18 13:22 UTC (permalink / raw)


johnj...@cox.net wrote on comp.lang.ada:
> Trying to use the "Code Statement" for a special project, by passing the
> ASM proc/func. So, can Gnat process a true "Code Statement" statement?
>
> When I compile the following example using>gnat make temp.adb -gnatpg
>
> gcc -c -gnatpg temp.adb
> temp.adb:10:07: incorrect type for code statement
> gnatmake: "temp.adb" compilation error
>
> Source code:
>
>    package Machine_Code is
>        type Asm_Insn is new Integer;  --  type required by gant
>        x86_NOP    : constant Asm_Insn := 16#90#;
>        type M_Code_0  is record
>                          Opcode : Asm_Insn;
>        end record;
>        pragma Pack (M_Code_0);
>    end Machine_Code;
>
> Source code:
>
>    with Machine_Code;
>    procedure temp is
>        procedure Test;
>        procedure Test is
>           use Machine_Code;
>        begin
>           M_Code_0'(Opcode => x86_NOP);  -- line 10
>        end Test;
>    begin
>       null;
>    end temp;

Line 10 is not a statement, it is a qualified expression and only
statements (and pragmas) are accepted between "begin" and "end".
Machine code insertions are very, very special; they bend the language
rules. If you want to do machine code insertions with GNAT, you must
follow the GNAT rules and use the package System.Machine_Code package
provided by the compiler, not a user-written package.

It seems you are trying to port machine code from the IBM Rational
compiler to GNAT? The only way to do that is by rewriting the machine
code in GNU assembly language. See http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Inline-Assembler.html

HTH

--
Ludovic Brenta.



^ permalink raw reply	[relevance 5%]

* Re: GPS and assembly language files
  @ 2010-03-30  8:13  5% ` Rolf
  0 siblings, 0 replies; 82+ results
From: Rolf @ 2010-03-30  8:13 UTC (permalink / raw)


On 30 Mrz., 08:35, brian <brian.cat...@gmail.com> wrote:
> I'm trying to create a standalone (run on the bare metal) program for
> a PC using GPS GPL 2009.  Obviously, I need an assembly language file
> (to setup the stack and transition the CPU to 32-bit mode), which
> would then call my Ada main entry point.  Is it possible to have GPS
> compile and build this?  I cannot figure out how to tell GPS about my
> assembly language file.
>
>  -Brian

First a caveat: the gnat runtime system relies on an operating system
for quite some functionality. e.g. file access, task scheduling, etc.
If you want to run your program on a bare voard you need a
corresponding run time system.

You have (at least) two ways to include assembler routines in your
program, you either use inline assembly (see System.Machine_Code and
the corresponding chapter in the GNAt user's guide
http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gnat_ugn_unw/Inline-Assembler.html#Inline-Assembler)
or you write your assembly code in a separate file and access it via
pragma Import.

Next look in your linker script (and the GNU ld info pages).  There
are different init sctions and you can place your code into one of the
sections via pragma Linker_Section.  This obviously only works for Ada
code (i.e. inline assembly), not for imported routines.

procedure My_Startup_Code;
pragma Linker_Section (My_Startup_Code, ".init3");

I don't use GPS and connot tell anything about it.

HTH
    Rolf



^ permalink raw reply	[relevance 5%]

* Re: Is there an Ada compiler whose Ada.Numerics.Generic_Elementary_Functions.Log(Base=>10, X=>variable) is efficient?
  2010-02-15 19:50  5%     ` sjw
@ 2010-02-16 16:50  3%       ` Colin Paul Gloster
  0 siblings, 0 replies; 82+ results
From: Colin Paul Gloster @ 2010-02-16 16:50 UTC (permalink / raw)


[-- Attachment #1: Type: TEXT/PLAIN, Size: 12325 bytes --]

On Mon, 15 Feb 2010, S. J. W. posted:

|---------------------------------------------------------------------------|
|"[..]                                                                      |
|>                                                                          |
|> You see now what's happening.  With the gnatn switch the                 |
|> compiler is smart enough to call the Log just once, rather               |
|> than 10**6 times.                                                        |
|>                                                                          |
|> If you remove the -gnatn or -gnatN switches, then it runs in             |
|>  0m0.024s again.                                                         |
|                                                                           |
|The trouble is that that benchmark does something other than Colin's!"     |
|---------------------------------------------------------------------------|

That is not the problem. The code which I posted at the beginning of
this thread was not a means in itself, but was intended for timing
performances of implementations of logarithm functions in the base of
ten in a manner representative of real code which I use. The real code
is not dedicated to calculating something approximately equal to
6.3E+08. I could have written 500 * 1_000_000 calls or 3.14 * 1000
calls or a single call. A single call might have been overwhelmed by
overhead unrelated to the logarithm function. In the case of the C++
version when using a particular compilation switch, I failed in the
task because the hardcoded arguments I provided resulted in a trivial
and dramatic optimization which would not happen in the real code.

While it is unfortunate for Ada code in general that Ada compilers
fail to mimic this optimization of G++'s, that particular optimization
would not benefit the usage of logarithms in the real code I
mentioned. Dr. Jonathan Parker is free to pursue this problem in a
subthread or with vendors.

|---------------------------------------------------------------------------|
|"This might be a more accurate translation:                                |
|                                                                           |
|with Ada.Numerics.Generic_Elementary_Functions;                            |
|with Text_IO; use Text_IO;                                                 |
|procedure Log_Bench_0 is                                                   |
|   type Real is digits 15;                                                 |
|   package Math is new Ada.Numerics.Generic_Elementary_Functions           |
|(Real);                                                                    |
|   use Math;                                                               |
|   Answer : Real := 0.0;                                                   |
|   Log_Base_10_Of_E : constant := 0.434_294_481_903_251_827_651_129;       |
|begin                                                                      |
|   for I in 1 .. 1_000_000 loop                                            |
|      declare                                                              |
|         X : Real := 0.1;                                                  |
|      begin                                                                |
|         for J in 1 .. 500 loop                                            |
|            Answer := Answer + Log_Base_10_Of_E * Log (X);                 |
|            X := X + 0.1;                                                  |
|         end loop;                                                         |
|      end;                                                                 |
|   end loop;                                                               |
|   Put (Real'Image(Answer));                                               |
|end Log_Bench_0;                                                           |
|                                                                           |
|I've tried inlining GNAT's implementation (GCC 4.5.0, x86_64-aqpple-       |
|darwin10.2.0) and even just calling up the C log10 routine using an        |
|inline. None was very impressive compared to the g++ result.               |
|                                                                           |
|Colin's time: 37s                                                          |
|Jonathan's time (-O3 -ffast-math -gnatp): 16s                              |
|Jonathan;s time (-O3 -ffast-math -gnatp -gnatN -funroll-loops): 14s        |
|Jonathan's time (same opts, but using C log10()): 11s"                     |
|---------------------------------------------------------------------------|

That ordering does not necessarily hold...

GCC4.2.4...

gnatmake -O3 -ffast-math -gnatp Log_Bench_0.adb -o  Log_Bench_0_compiled_by_GCC4.2.4_with_-ffast-math_and_-gnatp

time ./Log_Bench_0_compiled_by_GCC4.2.4_with_-ffast-math_and_-gnatp
  6.34086408606382E+08

real    0m14.328s
user    0m14.329s
sys     0m0.000s


gnatmake -O3 -ffast-math -gnatp -gnatN -funroll-loops Log_Bench_0.adb -o  Log_Bench_0_compiled_by_GCC4.2.4_with_-ffast-math_and_-gnatp_and_-gnatN_and_-funroll-loops

time ./Log_Bench_0_compiled_by_GCC4.2.4_with_-ffast-math_and_-gnatp_and_-gnatN_and_-funroll-loops
  6.34086408606382E+08

real    0m14.346s
user    0m14.341s
sys     0m0.004s


GCC4.4.3 (slower than GCC4.2.4 for this program)...

gnatmake -O3 -ffast-math  Log_Bench_0.adb -o  Log_Bench_0_compiled_by_GCC4.4.3_with_-ffast-math

  time ./Log_Bench_0_compiled_by_GCC4.4.3_with_-ffast-math
  6.34086408606382E+08

real    0m14.713s
user    0m14.689s
sys     0m0.000s


  gnatmake -O3 -ffast-math -gnatp Log_Bench_0.adb -o  Log_Bench_0_compiled_by_GCC4.4.3_with_-ffast-math_and_-gnatp

  time ./Log_Bench_0_compiled_by_GCC4.4.3_with_-ffast-math_and_-gnatp
  6.34086408606382E+08

real    0m14.691s
user    0m14.693s
sys     0m0.000s


gnatmake -O3 -ffast-math -gnatp -gnatN -funroll-loops Log_Bench_0.adb -o  Log_Bench_0_compiled_by_GCC4.4.3_with_-ffast-math_and_-gnatp_and_-gnatN_and_-funroll-loops

  time ./Log_Bench_0_compiled_by_GCC4.4.3_with_-ffast-math_and_-gnatp_and_-gnatN_and_-funroll-loops
  6.34086408606382E+08

real    0m14.690s
user    0m14.689s
sys     0m0.000s

|---------------------------------------------------------------------------|
|"so we still have 3 orders of magnitude to go to get to the g++ result:    |
|0.02s                                                                      |
|                                                                           |
|This is my final version, with the inlined GNAT implementation too:        |
|                                                                           |
|with Ada.Numerics.Generic_Elementary_Functions;                            |
|with System.Machine_Code; use System.Machine_Code;                         |
|with Text_IO; use Text_IO;                                                 |
|procedure Log_Bench is                                                     |
|   type Real is digits 15;                                                 |
|   package Math is new Ada.Numerics.Generic_Elementary_Functions           |
|(Real);                                                                    |
|   use Math;                                                               |
|   Answer : Real := 0.0;                                                   |
|   Log_Base_10_Of_E : constant := 0.434_294_481_903_251_827_651_129;       |
|   function LogM (X : Real) return Real;                                   |
|   pragma Inline_Always (LogM);                                            |
|   function LogM (X : Real) return Real is                                 |
|      Result : Real;                                                       |
|      NL : constant String := ASCII.LF & ASCII.HT;                         |
|   begin                                                                   |
|      Asm (Template =>                                                     |
|         "fldln2               " & NL                                      |
|       & "fxch                 " & NL                                      |
|       & "fyl2x                " & NL,                                     |
|         Outputs  => Real'Asm_Output ("=t", Result),                       |
|         Inputs   => Real'Asm_Input  ("0", X));                            |
|      return Result;                                                       |
|   end LogM;                                                               |
|   function LogL (X : Real) return Real;                                   |
|   pragma Import (C, LogL, "log10");                                       |
|begin                                                                      |
|   for I in 1 .. 1_000_000 loop                                            |
|      declare                                                              |
|         X : Real := 0.1;                                                  |
|      begin                                                                |
|         for J in 1 .. 500 loop                                            |
|--              Answer := Answer + Log_Base_10_Of_E * LogM (X);            |
|            Answer := Answer + LogL (X);                                   |
|            X := X + 0.1;                                                  |
|         end loop;                                                         |
|      end;                                                                 |
|   end loop;                                                               |
|   Put (Real'Image(Answer));                                               |
|end Log_Bench;                                                             |
|                                                                           |
|[..]"                                                                      |
|---------------------------------------------------------------------------|

Not all of those switches would yield fair proxies for timings of
logarithms in the real code which inspired this thread, but anyway...


64bit GCC4.2.4...
gnatmake -O3 -ffast-math  Log_Bench.adb -o  Log_Bench_compiled_by_GCC4.2.4_with_-ffast-math -largs /lib/libm.so.6

time ./Log_Bench_compiled_by_GCC4.2.4_with_-ffast-math
  6.34086408606382E+08

real    0m34.497s
user    0m34.494s
sys     0m0.004s


gnatmake -gnatp -O3 -ffast-math  Log_Bench.adb -o  Log_Bench_compiled_by_GCC4.2.4_with_-ffast-math_and_-gnatp -largs /lib/libm.so.6

  time ./Log_Bench_compiled_by_GCC4.2.4_with_-ffast-math_and_-gnatp
  6.34086408606382E+08

real    0m34.503s
user    0m34.506s
sys     0m0.000s


gnatmake -gnatN -funroll-loops -gnatp -O3 -ffast-math  Log_Bench.adb -o  Log_Bench_compiled_by_GCC4.2.4_with_-ffast-math_and_-gnatp_and_-gnatN_and_-funroll-loops -largs /lib/libm.so.6

  time ./Log_Bench_compiled_by_GCC4.2.4_with_-ffast-math_and_-gnatp_and_-gnatN_and_-funroll-loops
  6.34086408606382E+08

real    0m34.547s
user    0m34.546s
sys     0m0.004s

64bit GCC4.4.3...
gnatmake -O3 -ffast-math  Log_Bench.adb -o  Log_Bench_compiled_by_GCC4.4.3_with_-ffast-math -largs /lib/libm.so.6

  time ./Log_Bench_compiled_by_GCC4.4.3_with_-ffast-math
  6.34086408606382E+08

real    0m34.257s
user    0m34.258s
sys     0m0.000s


gnatmake -gnatp -O3 -ffast-math  Log_Bench.adb -o  Log_Bench_compiled_by_GCC4.4.3_with_-ffast-math_and_-gnatp -largs /lib/libm.so.6

  time ./Log_Bench_compiled_by_GCC4.4.3_with_-ffast-math_and_-gnatp
  6.34086408606382E+08

real    0m34.474s
user    0m34.478s
sys     0m0.000s


gnatmake -gnatN -funroll-loops -gnatp -O3 -ffast-math  Log_Bench.adb -o  Log_Bench_compiled_by_GCC4.4.3_with_-ffast-math_and_-gnatp_and_-gnatN_and_-funroll-loops -largs /lib/libm.so.6

  time ./Log_Bench_compiled_by_GCC4.4.3_with_-ffast-math_and_-gnatp_and_-gnatN_and_-funroll-loops
  6.34086408606382E+08

real    0m34.188s
user    0m34.182s
sys     0m0.004s

^ permalink raw reply	[relevance 3%]

* Re: Is there an Ada compiler whose Ada.Numerics.Generic_Elementary_Functions.Log(Base=>10, X=>variable) is efficient?
  @ 2010-02-15 19:50  5%     ` sjw
  2010-02-16 16:50  3%       ` Colin Paul Gloster
  0 siblings, 1 reply; 82+ results
From: sjw @ 2010-02-15 19:50 UTC (permalink / raw)


On Feb 15, 3:04 pm, jonathan <johns...@googlemail.com> wrote:
> On Feb 15, 2:54 pm, jonathan <johns...@googlemail.com> wrote:
> > On Feb 15, 10:58 am, Colin Paul Gloster <Colin_Paul_Glos...@ACM.org>
> > wrote:
>
> > > Hello,
>
> > > I have been improving a program by suppressing C++ in it. After
> > > speeding it up a lot by making changes, I have found one considerable
> > > part which calls a library routine, which is unfortunately very slow
> > > as provided as standard with a number of Ada compilers but which is
> > > very fast with implementations of other languages....
>
> > Here is my own bench ... easier to play with:
>
> > with ada.numerics.generic_elementary_functions;
> > with text_io; use text_io;
>
> > procedure log_bench is
>
> >   type Real is digits 15;
> >   package Math is new ada.numerics.generic_elementary_functions
> > (Real);
> >   use Math;
> >   x, y : Real := 0.1;
>
> >   -- might (or might not!) be faster to use:
> >   --    log_base_10 (x) = log_base_10_of_e * log_base_e (x)
>
> >   Log_base_10_of_e : constant := 0.434_294_481_903_251_827_651_129;
>
> > begin
>
> >   for i in 1 .. 1_000_000 loop
> >     x := x + Log_base_10_of_e * Log (y);
> >     y := y + 0.0000000000001;
> >   end loop;
> >   put (Real'Image(x));
>
> > gnatmake  gnatnp -O2 -march=native log_bench.adb
>
> Opps, accidently hit the send button!  Continuing discussion:
>
> gnatmake  gnatnp -O2 -march=native log_bench.adb
>
> -9.99999682845800E+05
> real    0m0.024s
> user    0m0.024s
> sys     0m0.000s
>
> NOW, comment out the y := y + ... so that the inner loop
> is constant, and use the same compilation switches:
>
> gnatmake  gnatnp -O2 -march=native log_bench.adb
>
> -9.99999900000000E+05
> real    0m0.002s
> user    0m0.000s
> sys     0m0.000s
>
> You see now what's happening.  With the gnatn switch the
> compiler is smart enough to call the Log just once, rather
> than 10**6 times.
>
> If you remove the -gnatn or -gnatN switches, then it runs in
>  0m0.024s again.

The trouble is that that benchmark does something other than Colin's!
This might be a more accurate translation:

with Ada.Numerics.Generic_Elementary_Functions;
with Text_IO; use Text_IO;
procedure Log_Bench_0 is
   type Real is digits 15;
   package Math is new Ada.Numerics.Generic_Elementary_Functions
(Real);
   use Math;
   Answer : Real := 0.0;
   Log_Base_10_Of_E : constant := 0.434_294_481_903_251_827_651_129;
begin
   for I in 1 .. 1_000_000 loop
      declare
         X : Real := 0.1;
      begin
         for J in 1 .. 500 loop
            Answer := Answer + Log_Base_10_Of_E * Log (X);
            X := X + 0.1;
         end loop;
      end;
   end loop;
   Put (Real'Image(Answer));
end Log_Bench_0;

I've tried inlining GNAT's implementation (GCC 4.5.0, x86_64-aqpple-
darwin10.2.0) and even just calling up the C log10 routine using an
inline. None was very impressive compared to the g++ result.

Colin's time: 37s
Jonathan's time (-O3 -ffast-math -gnatp): 16s
Jonathan;s time (-O3 -ffast-math -gnatp -gnatN -funroll-loops): 14s
Jonathan's time (same opts, but using C log10()): 11s

so we still have 3 orders of magnitude to go to get to the g++ result:
0.02s

This is my final version, with the inlined GNAT implementation too:

with Ada.Numerics.Generic_Elementary_Functions;
with System.Machine_Code; use System.Machine_Code;
with Text_IO; use Text_IO;
procedure Log_Bench is
   type Real is digits 15;
   package Math is new Ada.Numerics.Generic_Elementary_Functions
(Real);
   use Math;
   Answer : Real := 0.0;
   Log_Base_10_Of_E : constant := 0.434_294_481_903_251_827_651_129;
   function LogM (X : Real) return Real;
   pragma Inline_Always (LogM);
   function LogM (X : Real) return Real is
      Result : Real;
      NL : constant String := ASCII.LF & ASCII.HT;
   begin
      Asm (Template =>
         "fldln2               " & NL
       & "fxch                 " & NL
       & "fyl2x                " & NL,
         Outputs  => Real'Asm_Output ("=t", Result),
         Inputs   => Real'Asm_Input  ("0", X));
      return Result;
   end LogM;
   function LogL (X : Real) return Real;
   pragma Import (C, LogL, "log10");
begin
   for I in 1 .. 1_000_000 loop
      declare
         X : Real := 0.1;
      begin
         for J in 1 .. 500 loop
--              Answer := Answer + Log_Base_10_Of_E * LogM (X);
            Answer := Answer + LogL (X);
            X := X + 0.1;
         end loop;
      end;
   end loop;
   Put (Real'Image(Answer));
end Log_Bench;


This is a fragment of the assembler output from the g++ code:

	movsd	LC0(%rip), %xmm0
	call	_log10
	movsd	%xmm0, -3976(%rbp)
	movsd	LC1(%rip), %xmm0
	call	_log10
	movsd	%xmm0, -3968(%rbp)
	movsd	LC2(%rip), %xmm0
	call	_log10

and this is a fragment of the assembler from the last Ada:

	movapd	%xmm1, %xmm0
	movsd	%xmm1, -144(%rbp)
	addl	$10, %ebx
	call	_log10
	movsd	-144(%rbp), %xmm9
	addsd	-120(%rbp), %xmm0
	addsd	LC1(%rip), %xmm9
	movsd	%xmm0, -120(%rbp)
	movapd	%xmm9, %xmm0
	movsd	%xmm9, -144(%rbp)
	call	_log10
	movsd	-144(%rbp), %xmm8
	addsd	-120(%rbp), %xmm0
	addsd	LC1(%rip), %xmm8
	movsd	%xmm0, -120(%rbp)
	movapd	%xmm8, %xmm0
	movsd	%xmm8, -144(%rbp)
	call	_log10

at which point I have to leave it to the experts; why do the 7 Ada
instructions take so much time compared to the 2 g++ instructions???



^ permalink raw reply	[relevance 5%]

* Re: Learning Ada
  @ 2009-07-09 22:28  5%       ` anon
  0 siblings, 0 replies; 82+ results
From: anon @ 2009-07-09 22:28 UTC (permalink / raw)


If Ada RM A.2 ( 4 ), applied here, then Adacore / GNAT would not allow one 
to compile the a Standard package. When compiling the Ada.* you must use 
"-gnatpg", command option, but compiling the Standard package is as easy 
as compiling any non-vendor or Ada package.

Actually I wrote the complete Standards package for both Ada 83 and 95 
including a body that use System.Machine_Code for the routines base on the 
Ada 83 and Ada 95 specs.  

And these routines could be used for embeded processors, but the main code 
would still be generated by the GCC backend.

In <h2tun7$bpp$1@news.albasani.net>, "Frank J. Lhota" <FrankLho.NOSPAM@rcn.com> writes:
>anon wrote:
>> Yes, I did redefine apart of Standard. Found this out back in the mid 1990 
>> while testing GNAT 3.0x for a number of projects. Its also, one way (not the 
>> best, but it is quick) of porting code from a 32-bit system down to a 16 or 
>> 8 bit system. Like using Intel Core i7 system to write code for an Intel 
>> 8086 system, which can use the same basic (non-protective mode) 
>> instruction set. 
>
>No, you did not re-define a part of Standard. Keep in mind that all of 
>the compilation units you write is enclosed in the Standard package. As 
>a result, every Ada name can be expanded to something of the form 
>"Standard.*".
>
>When you wrote the package Standard as presented above, what you really 
>did was add a package named Standard *within* the pre-defined package 
>Standard, i.e. the result was something like this:
>
>-- Ada LRM Standard
>package Standard is
>
>     ...
>     type Integer is range ...;
>     ...
>
>     -- Your Standard package
>     package Standard is
>         type INTEGER is range - 2 ** 63 .. ( 2 ** 63 ) - 1 ;
>     end Standard;
>
>end Standard;
>
>In other words, you've created the new type Standard.Standard.Integer, 
>which is a separate type from Standard.Integer.
>
>> Also, rewriting any Ada package is allowable within the scope of the RM 
>> (in some implementation it maybe required). And if I add a body for the 
>> Standard package and uncommented the an operators I could of made the 
>> operator do what I wanted it to do. Like having all Boolean operators 
>> return FALSE. 
>
>LRM A.2 (4) specifically prohibit the compilation of a child of package 
>Ada in standard mode. I believe that some implementations would squawk 
>if you tried to replace parts of System, especially since doing so could 
>break other pre-defined units.
>
>> This process does not hide the built-in Standard package, its still there for 
>> the system to handle the other types, such as the Character or 
>> Wide_Character set, which can be a headache to define.
>
>Well, it does create some confusion. I would definitely *not* recommend 
>naming a unit Standard.
>
>> 
>> In <ba7f8fc3-e386-49cc-a1fb-e53f7e1f04bf@d32g2000yqh.googlegroups.com>, AdaMagica <christoph.grein@eurocopter.com> writes:
>>> Oh my dear anon, you are so wrong again.
>>>
>>>> package STANDARD is
>>>>
>>>> =A0 -- The universal type universal_integer is predefined. =A0
>>>>
>>>> =A0 type INTEGER is range - 2 ** 63 .. ( 2 ** 63 ) - 1 ;
>>>>
>>>> end STANDARD;
>>> You do *not* redefine Standard with this declaration, you simply hide
>>> it.
>>>
>>> with Standard;
>>>
>>> procedure Temp is  -- Here you will get into troubled water.
>>>
>>>  X: Integer;  -- this is still the integer from the predefined
>>> package Standard
>>>  Y: STANDARD.Integer;  -- this is your INTEGER
>>>
>>>  use Standard;
>>>
>>>  Z: Integer :=3D 2;  -- oh lord, what's this now?
>>>
>>>  -- I'm not sure and I'm reluctant to do the RM exegesis to find out.
>>> I *guess* it's your INTEGER;
>>>
>>>  I: Integer :=3D Z**3;  -- subtype of 3 is still the Integer defined in
>>>                       -- the predefined Standard you've hidden
>>>  J: Integer :=3D Z**Z;  -- This should then be illegal because the
>>> subtype of the right operand of **
>>>                       -- must be the one from the hidden Standard.
>>>
>>> end Temp;
>>>
>>> Point is: You cannot redefine Standard! Full stop.
>>>
>>> I invite you to find the relevant paragraphs in the RM which state
>>> what will happen when you define a package named Standard.
>>>
>>> And please be careful to not mix up a subtype and the type of the
>>> subtype and the type of numeric literals. They are all different.
>> 
>
>
>-- 
>"All things extant in this world,
>Gods of Heaven, gods of Earth,
>Let everything be as it should be;
>Thus shall it be!"
>- Magical chant from "Magical Shopping Arcade Abenobashi"
>
>"Drizzle, Drazzle, Drozzle, Drome,
>Time for this one to come home!"
>- Mr. Wizard from "Tooter Turtle"




^ permalink raw reply	[relevance 5%]

* Re: How to exit an Ada program with (unix shell) error code?
  @ 2009-05-08 10:17  5%   ` anon
  0 siblings, 0 replies; 82+ results
From: anon @ 2009-05-08 10:17 UTC (permalink / raw)


First, the RM (Ada 2005).  There are places that allow a vendor to replace or 
alter and in some case even remove packages from the core Ada system. 
Note: Most packages allow a vendor to add to a package aka altering the 
package.

RM 1.1.2 ( 3, 17 ) states that section 13 is apart of the core that shall be 
include, but RM 13.8 (8) states that System.Machine_Code is not required 
aka it can be removed.

8  An implementation may place restrictions on code_statements. An
implementation is not required to provide package System.Machine_Code.


Now, in the case of, Ada.Command_Line, RM A.15 (21) states:

21  An alternative declaration is allowed for package Command_Line if
different functionality is appropriate for the external execution 
environment.

Now a program that is an OS or boot loader or Kernel/System module can be 
classified as having appropriate "external execution environment" that allows 
for an "alternative declaration" of the Ada.Command_Line package. Which 
allows the vendor to dis-allow the Ada.Command_Line as defined in 
RM A.15 (2-15) because in this package the Argument_Count, Argument, and 
Command_Name are not defined and they would not have a valid routine 
address for an OS or System Module type of "external execution environment" 
(illegal in Ada). 
Plus, using the returned value of a function (main subprogram) as the 
"exit_status" complies with the "alternative declaration" stated in the 
RM A.15 (21), which replaces the Ada.Command_Line.Set_Exit_Status 
routine with a function return.

So, a vendor can alter or even remove this package. Especially for those 
compiler that are use to write modules or OS type of programs.

But does this comply with RM 1.1.2 (17).  The answer is Yes, because  
RM A.15 (21) allows an "alternative declaration".



Now, If the main subprogram is a function the binder creates the binding 
routine like:

  function main

    -- temp storage for exit status returned from main subprogram
    Status : integer ;  

    begin
      Adainit ;
      Status := <User Main function> ; -- main subprogram 
      Adafinal ; 
      return Status ;  -- returns aka "exit status" from main subprogram  
    end ;

So if the main subprogram is a function the returned value is the "exit_status" 
is passed to the OS after Adafinal has preform finalization. 

And in some cases, elaboration is not needed which means AdaInit is not 
needed and in a few rare cases finalization is not necessary, which means 
the Status can be passed directly to the OS or program loading routine. In 
these types of programs the binder could create a optimization binder file 
as:

  function main

    begin
      return <User Main function> ; -- main subprogram 
    end ;


In <be920df0-fd82-481f-9899-e70d5a968b29@v35g2000pro.googlegroups.com>, Adam Beneschan <adam@irvine.com> writes:
>On May 7, 2:08 am, a...@anon.org (anon) wrote:
>> There are basic three types of programs for computers.
>>
>>         The first, are the "Stand-Alone" programs aka OS types, which do not
>>         return and have no needs for Ada.Command_Line routines.  In order
>>         words, there are no links for the Ada.Command_Line package and the
>>         Set_Exit_Status routine.
>>
>>         The second type are "Device Drivers" or "System/Kernel" installable
>>         "Modules".  And the Ada.Command_Line package is not legal. But the
>>         Kernel requires the "Module" to notify the kernel by using the
>>         "exit status" so that the kernel can know if it should reclaim the
>>         memory, etc, on errors. Using a "function" type of module install
>>         program is the only way a "Module" can be written and have an
>>         "exit status".
>>
>>         Note: Ada as a computer language should be allowed to create
>>               these type of programs which means that Ada needs to
>>               support main subprogram that are functions.
>
>But you're ignoring a point I already made.  Since library-level
>finalizations need to be done after the main subprogram is completed,
>the Ada main subprogram cannot exit directly to the OS.  Therefore it
>really doesn't matter whether Ada main subprograms can be functions or
>not.  For an OS that expects its program to return a status in its
>"function result" register, the requirement is that the code generated
>by the compiler, that *does* exit back to the OS, has to put a status
>in that register.  And there's no reason the compiler can't generate
>code that generates this status based on the parameter to the last
>Ada.Command_Line.Set_Exit_Status call (if any), whether or not the
>main subprogram is a function.  If you still think that
>Ada.Command_Line might not be available, read on.
>
>
>>         And since there are times where the Ada.Command_Line package is
>> not available
>
>Ada.Command_Line is defined in Annex A.  Please read RM 1.1.2(2-6) and
>1.1.2(17).  I'm surprised you'd say the above, since you're fond of
>saying there are only a couple of Ada compilers out there since a
>compiler that doesn't support all of the new Ada 2005 features is not
>an Ada compiler---well, a compiler that doesn't support all of Annex A
>(including Ada.Command_Line) is not an Ada compiler either, so why
>would you be concerned about that?
>
>                                 -- Adam




^ permalink raw reply	[relevance 5%]

* Re: GNAT on WinXP: System.OS_Lib.Spawn raises Program_Error
  2009-05-02 20:39  5%   ` anon
@ 2009-05-03  9:42  0%     ` Martin
  0 siblings, 0 replies; 82+ results
From: Martin @ 2009-05-03  9:42 UTC (permalink / raw)


On May 2, 9:39 pm, a...@anon.org (anon) wrote:
> Martin
>
> GNAT.OS_LIB existed in GNAT 3.15p  but since GNAT 2005 it have been
> moved to System.OS_LIB.  And the GNAT.OS_LIB just renames System.OS_LIB
> which makes this package a legacy for older projects and can be avoided for
> future use. It just causes more work for the compiler which increase the
> compile time.

Still there in the Win32 GPL 2008 edition.


> Plus, there are only 6 System files in the RM Ada standards:
>
>   0. System
>   1.   System.Address_To_Access_Conversions
>   2.   System.Machine_Code
>   3.   System.RPC
>   4.   System.Storage_Elements
>   5.   System.Storage_Pools
>
> All others System packages like all GNAT packages are non RM Ada
> standard package list. And any GNAT Ada programmer should know that.

You're assuming a level of knowledge that I don't find in the real
world.


> Adacore's annual or GNU quarterly update of GNAT is the Ada standard, for
> most people and schools, and very few programmers will use anything else.

I have no proof that 'very few programmers will use anything else' and
I suspect you don't either. I've used (professionally) 7 Ada compilers
that I can think of off the top of my head. And at least 1 more that
I've just on a personal level. That's not counting all the different
versions of each compiler separately.


> And any improvement that Adacore makes that is passed to GNU version will
> become to most programmers, additions to the Ada standards.  Just like a
> lot of programmers were using the Ada 2005 specs before they were approved
> in January, 2008.

GNAT extensions are not likely to become standard. Ada2005 specs were
_very_ likely to become standard.

Besides, I assume were all here in c.l.a. because we want to see
_more_ Ada in the world, so hopefully that means more people using all
Ada compilers and not just GNAT. We should be pointing out the 'right
thing to do' to all and let them make their minds up.


> Plus, "GNATLINK" uses "System.OS_LIB.spawn" to call the "gcc" compiler
> to compile the binder generated file.  If this was not OK, then why would
> Adacore or GNU use it?

Because AdaCore / GNU and certainly not going to port they're code to
a different compiler.


> And finally the RM allows the usages of additional System packages to be
> included in a standard.  System.OS_LIB is an "implementation-defined
> children of System" see, RM 13.7 (36),

The RM also allows the use of 'goto', are you advocating wide-spread
use of this facility too? Just because something is allowed does not
make it a 'good idea'.


> So you need to stop with the idea using non standard packages is a "bad
> idea". Plus, all that is needed is a few comments for future version of
> GNAT. And that because most programs written with GNAT will almost
> never be move from GNAT, so only updating comments are needed.

Sorry, that's just pants.

I just went though a porting exercise at work where a project was
looking to migrate from XD-Ada/68k to <some_other_Ada_product>/
PowerPC. One issue with XD-Ada based systems was that XD-Ada included
various non-standard extensions to package System - types of a known
size. This is the 2nd project I've seen that made _large_scale_ use of
these types throughout their code.

Perfectly avoidable (by defining types they know to match the size
required, perhaps even calling it 'Interfaces') or limiting the effect
by defining their own 'Project_System' package. The 1st option would
have involved 0 hours work the 2nd option a 2 minute job with minimal
source code files touched. In the end _dozens_ of files needed to be
modified and that incurs a lot more time (i.e. money) to check / re-
test.

Like I said - this is not the first time this has happened (and not
just with Ada - VC++ no hasn't come with <iostream.h>, only
<iostream>, since 2005 and I've seen projects which started post-98
when <iostream> was the standard header defined get bitten by this).

Cheers
-- Martin




^ permalink raw reply	[relevance 0%]

* Re: GNAT on WinXP: System.OS_Lib.Spawn raises Program_Error
  @ 2009-05-02 20:39  5%   ` anon
  2009-05-03  9:42  0%     ` Martin
  0 siblings, 1 reply; 82+ results
From: anon @ 2009-05-02 20:39 UTC (permalink / raw)


Martin

GNAT.OS_LIB existed in GNAT 3.15p  but since GNAT 2005 it have been 
moved to System.OS_LIB.  And the GNAT.OS_LIB just renames System.OS_LIB 
which makes this package a legacy for older projects and can be avoided for 
future use. It just causes more work for the compiler which increase the 
compile time.

Plus, there are only 6 System files in the RM Ada standards: 

  0. System
  1.   System.Address_To_Access_Conversions
  2.   System.Machine_Code
  3.   System.RPC
  4.   System.Storage_Elements
  5.   System.Storage_Pools

All others System packages like all GNAT packages are non RM Ada 
standard package list. And any GNAT Ada programmer should know that. 

Adacore's annual or GNU quarterly update of GNAT is the Ada standard, for 
most people and schools, and very few programmers will use anything else. 
And any improvement that Adacore makes that is passed to GNU version will 
become to most programmers, additions to the Ada standards.  Just like a 
lot of programmers were using the Ada 2005 specs before they were approved 
in January, 2008.

Plus, "GNATLINK" uses "System.OS_LIB.spawn" to call the "gcc" compiler 
to compile the binder generated file.  If this was not OK, then why would 
Adacore or GNU use it? 

And finally the RM allows the usages of additional System packages to be 
included in a standard.  System.OS_LIB is an "implementation-defined 
children of System" see, RM 13.7 (36),

So you need to stop with the idea using non standard packages is a "bad 
idea". Plus, all that is needed is a few comments for future version of 
GNAT. And that because most programs written with GNAT will almost 
never be move from GNAT, so only updating comments are needed.



In <923b28dd-46ee-40cb-b13e-5f8860405f22@r36g2000vbr.googlegroups.com>, Martin <martin.dowie@btopenworld.com> writes:
>On May 2, 5:16=A0am, a...@anon.org (anon) wrote:
>> First, in GNAT GPL 2008, GNAT.OS_LIB renames System.OS_LIB, so using
>> GNAT.OS_LIB would be a waste of time.
>
>Not entirely a waste, as using "GNAT.*" makes it explicit to anyone
>reading the code that this is a non-standard package being used. Using
>'System.OS_Lib' would give the erroneous impression to the casual
>reader that only standard language defined packages are being used and
>that there perhaps would be =A30.00 cost to compile it up using a
>different compiler.
>
>Using non-standard extensions to standard units is generally a
>_bad_idea_ but if it is unavoidable then it should be hidden in an
>abstration layer that you have control over.
>
>Cheers
>-- Martin
>




^ permalink raw reply	[relevance 5%]

* Re: Yes it is possible. Re: Stackusage at runtime
  @ 2008-11-05 21:55  4%   ` anon
  0 siblings, 0 replies; 82+ results
From: anon @ 2008-11-05 21:55 UTC (permalink / raw)


Because a few questions here are from students, that may want to bypass the 
research, you should give a partial answer that leads them to learn how things 
work. And not the complete answer the first time around or send them to get 
a package that is going to cost them, unless they ask for it.

No one here even suggested looking at GNAT's documentation for an example of 
"Inline Assembler", did they. The only problem is that the correct Assembly 
statements or opcodes need to be inserted in the Ada "Asm" statement for 
the PPC. Now this version is for intel x86 version and not PPC because I did 
not want to dusty off my PPC assembly books, but one should be able to 
adopt the code for PPC. 


  -- Intel version 

  package Unsigned_32_IO is new Modular_IO ( Unsigned_32 ) ;

      ...

      --  routine returns SP (stack index reg) into a unsigned_32 variable 

      Asm ( Template => "movl %%eax,  %%esp",
             Outputs => Unsigned_32'Asm_Output ( "=a", Offset ),
             Volatile => True ) ;
      --
      Put ( "Intel SP Register := " ) ;  
      Unsigned_32_IO.Put ( Offset, Base => 16 ) ;  
      New_Line ;

      ...


And you can make this routine into a procedure like in a debug package, But 
in that case you would have to adjust the offset.  And you could even add a 
routine that can dump apart of the stack if needed by expanding the idea 
of using "System.Machine_Code" package.


But Ludovic Brenta is quick at doing nothing but cutting people down! Even 
if Brenta does not understand, also I see Ludovic Brenta had no answer to 
give. So Ludovic Brenta should get back and fix Annex -E for Debian and let 
people help those who need it.



In <3c9a589e-da1c-4d8c-b42e-e84bcde38739@g17g2000prg.googlegroups.com>, Ludovic Brenta <ludovic@ludovic-brenta.org> writes:
>anon wrote:
>> To monitor the main (system) stack that GNAT uses, you need to alter the
>> System.Memory package to include some monitoring information like in
>> the following code. Some may not like it but it get the job done.
>[...]
>
>> =A0 begin
>> =A0 =A0 Put ( "Before create Integer :=3D " ) ;
>> =A0 =A0 S_IO.Put ( Stack_Monitor ) ;
>> =A0 =A0 A :=3D new Integer ;
>> =A0 =A0 Put ( " after create operation :=3D " ) ;
>> =A0 =A0 S_IO.Put ( Stack_Monitor ) ;
>[...]
>
>As your example shows, your technique does not address the OP's
>problem; it monitors heap allocations (done via new), not the stack
>(done by declaring variables in subprograms).
>
>--
>Ludovic Brenta.




^ permalink raw reply	[relevance 4%]

* Re: updating a hardware cursor with assembly and ada
  2008-03-07 19:01  7% ` cl1
@ 2008-03-07 20:16  7%   ` Ludovic Brenta
  0 siblings, 0 replies; 82+ results
From: Ludovic Brenta @ 2008-03-07 20:16 UTC (permalink / raw)


cl1 writes:
> Okay I have updated the Update_Cursor method with the following
> implementation, However I am getting the error:
>
> i386-elf-gcc -fno-pic -c -nostdinc -ffunction-sections -fdata-sections
> -I. -gnato -gnatp -gnatE vga.adb
> vga.adb:3:06: "System.Machine_Code" is not a predefined library unit
>
> I know the error message means there is no System.Machine_Code that
> it can find. What i don't know is if there is a flag, or something i
> can do to get access to it. I'm really lost at this point, because
> there is no way i can implement that package with my current
> knowledge.

System.Machine_Code is normally part of the standard library.  Since
you don't have one, you have two possible solutions:

1) write your own minimalistic run-time library, consisting at least
   of System and System.Machine_Code (you can copy GNAT's library if
   you want to).  BTW, the compiler requires a package System that
   describes the target architecture.

2) Write procedure Update_Cursor directly in assembly language (as
   opposed to inline assembly in an Ada source file).

HTH

-- 
Ludovic Brenta.



^ permalink raw reply	[relevance 7%]

* Re: updating a hardware cursor with assembly and ada
  @ 2008-03-07 19:01  7% ` cl1
  2008-03-07 20:16  7%   ` Ludovic Brenta
  0 siblings, 1 reply; 82+ results
From: cl1 @ 2008-03-07 19:01 UTC (permalink / raw)


Okay I have updated the Update_Cursor method with the following
implementation, However I am getting the error:

i386-elf-gcc -fno-pic -c -nostdinc -ffunction-sections -fdata-sections
-I. -gnato -gnatp -gnatE vga.adb
vga.adb:3:06: "System.Machine_Code" is not a predefined library unit

I know the error message means there is no System.Machine_Code that it
can find. What i don't know is if there is a flag, or something i can
do to get access to it. I'm really lost at this point, because there
is no way i can implement that package with my current knowledge.


with System;
with Interfaces;
with System.Machine_Code;
package body Vga is
   ...
 
-----------------------------------------------------------------------------
   procedure Update_Cursor (Console : Video_Console) is
      use Interfaces;
      use System.Machine_Code;
      Data : Unsigned_16 := Console.Column * 80 + Console.Row;
      OutB : String := "outb 140x3D4, 14" & NL & "outb %0, 0x3D5";
      Part1 : Unsigned_8 :=
Ada.Unchecked_Conversion(Shift_Right(Data));
      Part2 : Unsigned_8 := Ada.Unchecked_Conversion(Data);
   begin
      Asm (Template => "outb 14, 0x3D4" & NL
                     & "outb %0, 0x3D5" & NL
                     & "outb 15, 0x3D4" & NL
                     & "outb %1, ox3D5",
           Input    => (Unsigned_8'Asm_Input(Part1),
                        Unsigned_8'Asm_Input(Part2));
   end Update_Cursor;
 
-----------------------------------------------------------------------------
   ...
end Vga;




^ permalink raw reply	[relevance 7%]

* Re: Ada and SIMD
  2007-09-19  3:26  0%   ` Adrian Hoe
@ 2007-09-19  5:24  0%     ` anon
  0 siblings, 0 replies; 82+ results
From: anon @ 2007-09-19  5:24 UTC (permalink / raw)


Adacore created the Altivec packages set back in 2005 for GNAT PRO and 
now you can find some of these packages in GNU GNAT 4.2.0 and 4.3.0 
and future.  

Note: These packages are designed for PowerPC processor.


 File          Package Name
-------------  ------------------------------------------------
 g-allein.ads  GNAT.Altivec.Low_Level_Interface

 g-alleve.adb  GNAT.Altivec.Low_Level_Vectors
 g-alleve.ads

 g-altcon.adb  GNAT.Altivec.Conversions
 g-altcon.ads

 g-altive.ads  GNAT.Altivec -- contains sone doc and a sanple 
                               program in the comments

 g-alveop.adb  GNAT.Altivec.Vector_Operations
 g-alveop.ads

 g-alvety.ads GNAT.Altivec.Vector_Types

 g-alvevi.ads GNAT.Altivec.Vector_Views


In <1190172383.802381.274670@v23g2000prn.googlegroups.com>,  Adrian Hoe <abyhoe@gmail.com> writes:
>Thanks for the information. I am looking for SIMD support to port a
>PRNG to Ada.
>
>Is there any Ada packages out there for SIMD support?
>--
>Adrian Hoe
>http://adrianhoe.net
>
>
>On Sep 18, 6:22 pm, a...@anon.org (anon) wrote:
>> Ada does have the ability to use SIMD, the only problem is the underlying
>> packages. The standard Ada packages do not include a vectorization
>> package. But with that understanding, Ada 83 as been use to preform
>> vectorization since 83/84.
>>
>> Anyone can create a SIMD package with the constructs for Ada, To fully
>> use the Intel Core-2 multi-core processing all it takes is to use
>> System.Machine_code package for the assembly code and create a package
>> that would contain the types and procedures to preform the vectorization.
>> Like:
>>    type Vector_Integer is range -( 2 ** 127 ) .. ( 2 ** 127 - 1 ) ;
>>
>> Also, there may be a doctoral project or two that may perform some SIMD
>> or vectorization in Ada with the Pentium-D, that can be either used or
>> updated to the Core-2 Dual.
>>
>> In <1189996579.648567.17...@w3g2000hsg.googlegroups.com>,  Adrian Hoe <aby...@gmail.com> writes:
>>
>> >Hi,
>>
>> >Does anyone have any idea or experience with Ada on SIMD (Singe
>> >Instruction, Multiple Data)? And also multi-stage pipelining and of
>> >course SIMD (e.g. 128-bit integer) on Intel Core 2 Duo and equivalent
>> >processors?
>>
>> >Has anybody done any kind of such implementation and how Ada is doing
>> >with SIMD?
>>
>> >Thanks.
>> >--
>> >Adrian Hoe
>> >http://adrianhoe.net
>
>




^ permalink raw reply	[relevance 0%]

* Re: Ada and SIMD
  2007-09-18 10:22  5% ` anon
@ 2007-09-19  3:26  0%   ` Adrian Hoe
  2007-09-19  5:24  0%     ` anon
  0 siblings, 1 reply; 82+ results
From: Adrian Hoe @ 2007-09-19  3:26 UTC (permalink / raw)


Thanks for the information. I am looking for SIMD support to port a
PRNG to Ada.

Is there any Ada packages out there for SIMD support?
--
Adrian Hoe
http://adrianhoe.net


On Sep 18, 6:22 pm, a...@anon.org (anon) wrote:
> Ada does have the ability to use SIMD, the only problem is the underlying
> packages. The standard Ada packages do not include a vectorization
> package. But with that understanding, Ada 83 as been use to preform
> vectorization since 83/84.
>
> Anyone can create a SIMD package with the constructs for Ada, To fully
> use the Intel Core-2 multi-core processing all it takes is to use
> System.Machine_code package for the assembly code and create a package
> that would contain the types and procedures to preform the vectorization.
> Like:
>    type Vector_Integer is range -( 2 ** 127 ) .. ( 2 ** 127 - 1 ) ;
>
> Also, there may be a doctoral project or two that may perform some SIMD
> or vectorization in Ada with the Pentium-D, that can be either used or
> updated to the Core-2 Dual.
>
> In <1189996579.648567.17...@w3g2000hsg.googlegroups.com>,  Adrian Hoe <aby...@gmail.com> writes:
>
> >Hi,
>
> >Does anyone have any idea or experience with Ada on SIMD (Singe
> >Instruction, Multiple Data)? And also multi-stage pipelining and of
> >course SIMD (e.g. 128-bit integer) on Intel Core 2 Duo and equivalent
> >processors?
>
> >Has anybody done any kind of such implementation and how Ada is doing
> >with SIMD?
>
> >Thanks.
> >--
> >Adrian Hoe
> >http://adrianhoe.net





^ permalink raw reply	[relevance 0%]

* Re: Ada and SIMD
  @ 2007-09-18 10:22  5% ` anon
  2007-09-19  3:26  0%   ` Adrian Hoe
  0 siblings, 1 reply; 82+ results
From: anon @ 2007-09-18 10:22 UTC (permalink / raw)


Ada does have the ability to use SIMD, the only problem is the underlying 
packages. The standard Ada packages do not include a vectorization 
package. But with that understanding, Ada 83 as been use to preform 
vectorization since 83/84.

Anyone can create a SIMD package with the constructs for Ada, To fully 
use the Intel Core-2 multi-core processing all it takes is to use 
System.Machine_code package for the assembly code and create a package 
that would contain the types and procedures to preform the vectorization. 
Like:
   type Vector_Integer is range -( 2 ** 127 ) .. ( 2 ** 127 - 1 ) ;


Also, there may be a doctoral project or two that may perform some SIMD 
or vectorization in Ada with the Pentium-D, that can be either used or 
updated to the Core-2 Dual.

In <1189996579.648567.17960@w3g2000hsg.googlegroups.com>,  Adrian Hoe <abyhoe@gmail.com> writes:
>Hi,
>
>Does anyone have any idea or experience with Ada on SIMD (Singe
>Instruction, Multiple Data)? And also multi-stage pipelining and of
>course SIMD (e.g. 128-bit integer) on Intel Core 2 Duo and equivalent
>processors?
>
>Has anybody done any kind of such implementation and how Ada is doing
>with SIMD?
>
>Thanks.
>--
>Adrian Hoe
>http://adrianhoe.net
>




^ permalink raw reply	[relevance 5%]

* Re: real_time.clock is not monotonic
  @ 2007-02-21 20:17  6% ` Simon Wright
  0 siblings, 0 replies; 82+ results
From: Simon Wright @ 2007-02-21 20:17 UTC (permalink / raw)


frederic.ormancey@atosorigin.com writes:

> I'll alert Gnat community with this bad implementation, as
> gettimeofday() is affected by NTP and others date adjustements. in
> LRM, Ada.Real_Time.Clock shall be monotonic => Gnat runtime is not
> compliant

I reported this with GNAT 3.16, not sure if there's a solution yet.

> Did someone have a solution for this problem ? another implementation
> using a Linux monotonic clock ?

The Booch Components have a clock that might be a possibility: OK on
Windows and Linux (not sure about Solaris x86, no idea for 64-bit
OSs):

   with System.Machine_Code;

   separate (BC.Support.High_Resolution_Time)
   function Clock return Time is
      type Half is (Low, High);
      Lower, Upper : Interfaces.Unsigned_32;
      Results : array (Half) of Interfaces.Unsigned_32;
      Result : Time;
      for Result'Address use Results (Low)'Address;
   begin
      System.Machine_Code.Asm
        ("rdtsc" & ASCII.LF & ASCII.HT &
           "movl %%eax, %0"& ASCII.LF & ASCII.HT &
           "movl %%edx, %1",
         Outputs => (Interfaces.Unsigned_32'Asm_Output ("=g", Lower),
                     Interfaces.Unsigned_32'Asm_Output ("=g", Upper)),
         Clobber => "eax, edx",
         Volatile => True);
      Results := (Low => Lower, High => Upper);
      return Result;
   end Clock;



^ permalink raw reply	[relevance 6%]

* call procedure in Linux-Ada-module from "normal" program
@ 2006-08-24 16:33  6% Frank
  0 siblings, 0 replies; 82+ results
From: Frank @ 2006-08-24 16:33 UTC (permalink / raw)



Hi
Debian sarge kernel 2.4.27, gcc-3.3

I've been tinkering with modules by using Ada.
The module compiles, and I manage to do insmod on it.
The symbols appears in ksyms; like "some_call_me".

Now I wish to call "some_call_me" from the test program (3) - is that 
possible?

I compile it with "gnatmake test_somemodule.adb"
It fails during linking :

gnatbind -x test_somemodule.ali
gnatlink test_somemodule.ali
./test_somemodule.o(.text+0x1f): In function `_ada_test_somemodule':
: undefined reference to `some_call_me'
collect2: ld returned 1 exit status
gnatlink: cannot call /usr/bin/gcc-3.3
gnatmake: *** link failed.


How do I make the linker link with the kernel symbol?


Frank





-----------
1 (slightly edited in this post)
--------------------------------------------------------------------------------------------------------------
with Interfaces.C;

package SomeModule is

  -- Module Variables

  type Aliased_String is array (Positive range <>) of aliased Character;
  pragma Convention (C, Aliased_String);

  Kernel_Version: constant Aliased_String:="2.4.27-2-386" & 
Character'Val(0);
  pragma Export (C, Kernel_Version, "kernel_version");

  Mod_Use_Count: Integer;
  Pragma Export (C, Mod_Use_Count, "mod_use_count_");

  -- Kernel Calls

  procedure Printk( s : string );
  pragma import( C, printk, "printk" );

-- Our Module Functions

  function Init_Module return Interfaces.C.int;
  pragma Export (C, Init_Module, "init_module");

  procedure Cleanup_Module;
  pragma Export (C, Cleanup_Module, "cleanup_module");

  procedure Call_Me;
  Pragma Export (C, Call_Me, "some_call_me");

end SomeModule;


with Interfaces.C;

with System.Machine_Code; use System.Machine_Code;

--with System.Storage_Elements;

with Interfaces; use Interfaces;

2 (slightly edited in this post)
--------------------------------------------------------------------------------------------------------------
package body SomeModule is



  function Init_Module return Interfaces.C.int is
  begin
    Printk("Hello,World! Hi Frank" & Character'val(10) & character'val(0));
    return 0;
  end Init_Module;

  procedure Cleanup_Module is
  begin
    Printk("Goodbye , World! Bye Frank!" & Character'val(10) & 
character'val(0));
  end Cleanup_Module;

  procedure Call_Me
  is
  begin
    Printk("Call me" & Character'val(10) & character'val(0));
  end Call_Me;

end SomeModule;

3
-------------------------------------------------------------------------------------------------------------------------

procedure test_somemodule
is
  procedure Call_Me;
  pragma Import (C, Call_Me, "some_call_me");
begin
  text_io.put_line("Test_Somemodule");
  Call_Me;
end test_somemodule; 





^ permalink raw reply	[relevance 6%]

* Re: asm()
  2005-03-21 23:13  5% ` asm() Ludovic Brenta
@ 2005-03-22  7:41  0%   ` Jean-Baptiste CAMPESATO
  0 siblings, 0 replies; 82+ results
From: Jean-Baptiste CAMPESATO @ 2005-03-22  7:41 UTC (permalink / raw)


Le Tue, 22 Mar 2005 00:13:10 +0100, Ludovic Brenta a ᅵcritᅵ:

> Jean-Baptiste CAMPESATO writes:
>> Hello,
>> I search help to use the asm procedure. Somebody can help me ?
>> *Type of syntax (AT&T, x86...), and what are the others arguments*
>> And if possible, have you an example to switch to 13h (the graphic mode).
>> Thanks a lot.
> 
> There is no "asm procedure".  The Ada term for what you want is
> "machine code insertions".  ARM 13.8 states that machine code
> insertions are defined by the compiler, but that the compiler must do
> so by means of package System.Machine_Code.
> 
> Since I remember you use GNAT on GNU/Linux, look at the GNAT User's
> Guide, chapter "Inline Assembler", for a complete discussion.  GNAT
> supports AT&T syntax only.
> 
> I'm not sure how to switch the video card to VESA mode 16#13# (13h),
> if that's what you mean.  Doing so requires direct access to the
> hardware, doesn't it?  I'm nor sure that Linux provides such direct
> access, I suspect you'll have to use the framebuffer interface, or
> svgalib.

Thanks.
But i create a "little kernel" to use the VGA mode 13h.
With a bootstrap in ASM.
I will read the chapter "Inline Assembler".
bye



^ permalink raw reply	[relevance 0%]

* Re: asm()
  @ 2005-03-21 23:13  5% ` Ludovic Brenta
  2005-03-22  7:41  0%   ` asm() Jean-Baptiste CAMPESATO
  0 siblings, 1 reply; 82+ results
From: Ludovic Brenta @ 2005-03-21 23:13 UTC (permalink / raw)


Jean-Baptiste CAMPESATO writes:
> Hello,
> I search help to use the asm procedure. Somebody can help me ?
> *Type of syntax (AT&T, x86...), and what are the others arguments*
> And if possible, have you an example to switch to 13h (the graphic mode).
> Thanks a lot.

There is no "asm procedure".  The Ada term for what you want is
"machine code insertions".  ARM 13.8 states that machine code
insertions are defined by the compiler, but that the compiler must do
so by means of package System.Machine_Code.

Since I remember you use GNAT on GNU/Linux, look at the GNAT User's
Guide, chapter "Inline Assembler", for a complete discussion.  GNAT
supports AT&T syntax only.

I'm not sure how to switch the video card to VESA mode 16#13# (13h),
if that's what you mean.  Doing so requires direct access to the
hardware, doesn't it?  I'm nor sure that Linux provides such direct
access, I suspect you'll have to use the framebuffer interface, or
svgalib.

-- 
Ludovic Brenta.




^ permalink raw reply	[relevance 5%]

* Re: Bitmanipulation in Ada
  @ 2004-08-19 21:24  3%         ` Francois G. Dorais
  0 siblings, 0 replies; 82+ results
From: Francois G. Dorais @ 2004-08-19 21:24 UTC (permalink / raw)


Bernd Specht wrote:
> Always? What do you think about bitscrambling software which has to treat 
> data alternating as bitvector and as integer value in a loop like this (not 
> exeactly this for securitity reasons):
> 
> ...
> loop
>   declare
>     x : boolean;
>   begin
>      x := b(k);
>      b(k) := b(32 - k);
>      b (32 - k) := x;
>      I := I * prime1 mod prime2;
>   end;
> end loop;
> 
> 
> Can you find an equivalent algorithm where you can separate the bit-ops and 
> the integer-ops?

A generic solution for the above is to encapsulate the bit 
fiddling in an inlined procedure. For example, consider the 
following where I replaced your bit operation by one which 
doesn't implicitly need a copy (to store the K-th bit in 
your example.)

	with Ada.Unchecked_Conversion;

	[...]

	type Unsigned_32 is mod 2 ** 32;
	for Unsigned_32'Size use 32;

	subtype Bit_Index_32 is Integer range 0 .. 31;
	-- This avoids many range checks...

	procedure Bit_Fiddle
	  (U : in out Unsigned_32;
            K : in Bit_Index_32) is

	   type Bits_32 is array (Bit_Index_32) of Boolean;
	   for Bits_32'Component_Size use 1;

	   function To_Unsigned is new Ada.Unchecked_Conversion 
(Bits_32, Unsigned_32);
    	   function To_Bits is new Ada.Unchecked_Conversion 
(Unsigned_32, Bits_32);

	   B : Bits_32 := To_Bits(U);

	begin
	   B(K) := B(31 - K);
	   U := To_Unsigned(B);
	end Bit_Fiddle;

	pragma Inline (Bit_Fiddle);

	[...]

GNAT compiles the above without copy instructions if it 
doesn't need to. For example, try

	[...]

	for K in Bit_Index_32 loop
	   Bit_Fiddle(X, K);
	   X := X + 16#39A2_D071#;
	end loop;

	[...]

I got the following x86 asm code from gnat 3.15p (with 
options "-S -O2 -gnaton") It uses register ebx for the loop 
counter K, it stores value 31 in edi throughout and X is 
initially in register esi.

	[...]
	xorl %ebx,%ebx
	addl $16,%esp
	movl $31,%edi
	.align 4
.L65:
	movl $1,%eax
	movl %ebx,%ecx
	sall %cl,%eax
	notl %eax
	movl %esi,%edx
	andl %eax,%edx
	movl %edi,%eax
	subl %ebx,%eax
	movl %eax,%ecx
	shrl %cl,%esi
	movl %esi,%eax
	andl $1,%eax
	movl %ebx,%ecx
	sall %cl,%eax
	movl %edx,%esi
	orl %eax,%esi
	addl $966971505,%esi
	incl %ebx
	cmpl $31,%ebx
	jle .L65
	[...]

This is not necessarily optimal code, but it's pretty decent.

But since your example already needs a copy to save the k-th 
bit and probably more for the mul/mod, it's propbably more 
efficient to force the bit array B to be distinct from the 
integer I. The following should do what you want pretty 
efficiently. (I took the liberty to replace your mul/mod by 
an arithmetically correct one...)

	[...]

	type Unsigned_32 is mod 2 ** 32;
	for Unsigned_32'Size use 32;

	subtype Bit_Index_32 is Integer range 0 .. 31;

	type Bits_32 is array (Bit_Index_32) of Boolean;
	for Bits_32'Component_Size use 1;

	function To_Unsigned is new Ada.Unchecked_Conversion 
(Bits_32, Unsigned_32);
    	function To_Bits is new Ada.Unchecked_Conversion 
(Unsigned_32, Bits_32);

	function Mul_Mod (Op_1, Op_2, Modulus : Unsigned_32) return 
Unsigned_32 is
	   type Unsigned_64 is mod 2 ** 64;
	begin
	   return Unsigned_32((Unsigned_64(Op_1) * 
Unsigned_64(Op_2)) mod Unsigned_64(Modulus));
	end Mul_Mod;

	pragma Inline (Mul_Mod);

	[...]

	for K in Bit_Index_32 loop
             declare
                B : Bits_32 := To_Bits(I);
             begin
                B(K) := B(31 - K);
                B(31 - K) := To_Bits(I)(K);
                I := Mul_Mod(To_Unsigned(B), Prime_1, Prime_2);
             end;
	end loop;

	[...]

Try it with GNAT and look at the generated code, you might 
be surprized.

However, I know that bit arrays are usually not optimally 
handled by most compilers (for any language.) GNAT seems to 
do a pretty decent job in general, but when I have to do 
this kind of thing and time optimization is very important, 
I use the tools provided by package Interfaces and do the 
bit-fiddling code myself (as one would do in C) or else I 
use package System.Machine_Code to insert some hand 
optimized assembly code where needed. Alas, there is no such 
thing as a perfect compiler!



^ permalink raw reply	[relevance 3%]

* Inline ASM
@ 2004-05-18 17:13  6% Dan McLeran
  0 siblings, 0 replies; 82+ results
From: Dan McLeran @ 2004-05-18 17:13 UTC (permalink / raw)


First of all, let me say that I am using Gnat 3.15p. Now the problem.
I have a piece of C code that outports 16-bit values to an ISA-bus
card. It seemed that I should be able to do this from within Ada,
using the Asm capabilities. I have been able to embed other Asm
instructions with success but this one is frustrating me. I keep
getting this error message:

"Error: suffix or operands invalid for 'out'"

Although, when I use the -S compiler option, it generates the asm code
without error and it appears to be correct.

I have checked the asm output of my C-code and it looks like this:

out	dx, ax

So, I figured the following Ada code should work. Does anyone see a
problem here?

with Ada.Text_IO;
with System.Machine_Code;
with Interfaces;

procedure Main is
    use Ada.Text_IO;
    
    procedure Outport(Address,Value : in Interfaces.Unsigned_16) is
        use System.Machine_Code;
        use Interfaces;
        use ASCII;
    begin
        Asm("out %%dx, %%ax" & LF & HT,
            Inputs =>
(Unsigned_16'Asm_Input("d",Address),Unsigned_16'Asm_Input("a",Value)));
    end Outport;
    
    Address : Interfaces.Unsigned_16 := 16#110#;
    Value : Interfaces.Unsigned_16 := 16#F#;
    
begin
    Put(Item => "** Using inline Asm **");
    New_Line;
    Put(Item => "Address = " & Interfaces.Unsigned_16'Image(Address));
    New_Line;
    Put(Item => "Value = " & Interfaces.Unsigned_16'Image(Value));
    New_Line;
    Outport(Address => Address, Value => Value);
end Main;



^ permalink raw reply	[relevance 6%]

* Re: Pass by reference
  2004-04-15  9:43  3%               ` Vinzent 'Gadget' Hoefler
@ 2004-04-17  7:59  0%                 ` Simon Wright
  0 siblings, 0 replies; 82+ results
From: Simon Wright @ 2004-04-17  7:59 UTC (permalink / raw)


Vinzent 'Gadget' Hoefler <nntp-2004-04@t-domaingrabbing.de> writes:

> Simon Wright wrote:

> >I'm not 100% sure on this, but this code
> >
> >   with Interfaces;
> >   with System.Machine_Code;
> >   with System.Storage_Elements;
> >
> >   procedure Access_Memory_Mapped_Register is
> [...]
> >   #APP
> >           movl #01000000, -65536
> >           movl #00000000, -65536
> >   #NO_APP
> 
> (Despite the fact that this code is not valid, i386 can't load two
> constants in one instruction, your intention is clear and would
> work).

Yes, more work needed (and next time, Simon, go the whole way and
don't just stop with a -S compilation). I too will only use asm when
it's _necessary_, so it's a new learning experience each time ...

> That's why I declared the procedure to take an access parameter
> instead of "in out" and now everything is working fine as
> expected. It is just the fact that I now use access types in the
> interface (IMO: unnecessarily from the point of logic) that bugs me
> a little bit.

Another possibility would be to pass System.Address. On the whole,
access is a lot safer I would have thought -- especially if you can
encapsulate this low-level stuff (including the calls to your wrapper
procedure) to a restricted area of the code.

> Eventually I should try to switch to use limited types instead to
> circumvent this problem?

I had a play with this, and for GNAT 3.15p (and 3.16a1, 5.02a) this

   package Wrapper is
      type Register is limited private;
      procedure Write (Value : Interfaces.Unsigned_16; To : in out Register);
   private
      type Actual_Register is mod 256;
      for Actual_Register'Size use 8;
      pragma Volatile (Actual_Register);
      type Register is limited record
         Actual : Actual_Register;
      end record;
      for Register'Size use 8;
   end Wrapper;

used pass-by-reference.

The asm for 5.02a (-gnatp -O2) is

	.type	access_memory_mapped_register__wrapper__write.0,@function
access_memory_mapped_register__wrapper__write.0:
.LFB1:
	pushl	%ebp
.LCFI0:
	movl	%esp, %ebp
.LCFI1:
	subl	$4, %esp
.LCFI2:
	movzwl	8(%ebp), %eax
	movl	12(%ebp), %edx
	movb	%al, (%edx)
	shrl	$8, %eax
	movb	%al, (%edx)
	movl	%ebp, %esp
	popl	%ebp
	ret

which looks as though it at least stands a chance; I don't understand
the 3.15p code,

	.type	 access_memory_mapped_register__wrapper__write.0,@function
access_memory_mapped_register__wrapper__write.0:
	pushl %ebp
	movl %esp,%ebp
	subl $4,%esp
	movl %ecx,-4(%ebp)
	movl 12(%ebp),%edx
	movzbw 9(%ebp),%ax
	movb %al,(%edx)
	movl %ebp,%esp
	popl %ebp
	ret

-- 
Simon Wright                               100% Ada, no bugs.



^ permalink raw reply	[relevance 0%]

* Re: Pass by reference
  2004-04-14 17:27  7%             ` Simon Wright
@ 2004-04-15  9:43  3%               ` Vinzent 'Gadget' Hoefler
  2004-04-17  7:59  0%                 ` Simon Wright
  0 siblings, 1 reply; 82+ results
From: Vinzent 'Gadget' Hoefler @ 2004-04-15  9:43 UTC (permalink / raw)


Simon Wright wrote:

>Vinzent 'Gadget' Hoefler <nntp-2004-04@t-domaingrabbing.de> writes:
>
>> Simon Wright wrote:
>> 
>> >Vinzent 'Gadget' Hoefler <nntp-2004-04@t-domaingrabbing.de> writes:
>> >
>> >> Pat Rogers wrote:
>> >> 
>> >> >If you made the type volatile that would also force by-reference.
>> >
>> >C.6(18): If a type is atomic or volatile and it is not a by-copy type,
>>                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> 
>> Yes, but if I understand that part correctly, this is the point. The
>> register-type is just a simple Integer-type:
>
>Sorry, that's what _I_ was trying to say too!

Ok. Got it. :)

[...]
>> >I think you need to use inline assembler to be sure.
>> 
[...]
>> 
>> >And to be really sure you may need to use Volatile => True on the
>> >call, I had to (this was GNAT/PowerPC, by the way).
>> 
>> I'm not sure if I understand... can I actually apply that pragma to
>> a call? Or am I missing something else?
>
>I was talking about your "optimizes the sequence of assignment which I
>need for this register" problem.

Oh.

Well, from what I was trying to understand by looking at the
ASM-output I figured the volatile-"property" of the type just got
lost, *because* it was passed by copy.

>I don't know whether it's available in GCC C inline assembler, but for
>GNAT, System.Machine_Code.Asm looks like
>
>   procedure Asm (
>     Template : String;
>     Outputs  : Asm_Output_Operand_List;
>     Inputs   : Asm_Input_Operand_List;
>     Clobber  : String  := "";
>     Volatile : Boolean := False);
>
>(plus other variants).

Duh. _Now_ I understand. I've never looked at System.Machine_Code.
(IMO inline assembler can considered to be evil in most cases).

>I'm not 100% sure on this, but this code
>
>   with Interfaces;
>   with System.Machine_Code;
>   with System.Storage_Elements;
>
>   procedure Access_Memory_Mapped_Register is
[...]
>   #APP
>           movl #01000000, -65536
>           movl #00000000, -65536
>   #NO_APP

(Despite the fact that this code is not valid, i386 can't load two
constants in one instruction, your intention is clear and would work).

>which looks good .. no 'Access anywhere ..

Yes. Probably I wasn't expressing myself too clear, so I'm trying to
switch to verbose mode. :)

Firstly, if I assign the values to the variable directly the compiled
code is just perfect. No problem here, no inline-assembler needed. Ada
behaves as I expect it to. Fine.

But what I am trying to do is to abstract away some (nasty) behaviour
of the registers (yes, there is more than one, in fact: up to
twenty-four): If I write a new timer value I have to write two byte
values (low-, high-byte) in succession instead of just assigning the
(16-bit) value directly (the 8254 timer only has an 8-bit-data-port).
To make this part a little bit more safe (if you forget to write a
value then - *poof* - everything will screw up) I declared the
"Timer.Write"-procedure that should take one of the
memory-mapped-registers and the value-to-be-written as parameters and
do the nasty stuff with converting the value and extracting high- and
low-byte at this only one place.

Probably a neat idea, but now RM C.6(18) strikes back and passes the
_value_ at the memory address of the register to the procedure
(by-copy) instead of the _address_ of the register (by-reference), I
assign the stuff inside the procedure (means: the compiler is
perfectly allowed to optimize anything away, because it is just
working with a local copy and can't "return" more than 8 bits anyway)
and get the result back that would then be written to the register.

Well, this might be perfectly justified by the mentioned paragraph of
the RM - but is just plain wrong for the real world. Switching to
inline assembler wouldn't help here either, because *at this point* it
is already too late, all I'd get as input would be the value of the
register, not the register (read: pointer to) "itself".

That's why I declared the procedure to take an access parameter
instead of "in out" and now everything is working fine as expected. It
is just the fact that I now use access types in the interface (IMO:
unnecessarily from the point of logic) that bugs me a little bit.

Eventually I should try to switch to use limited types instead to
circumvent this problem?


Vinzent.



^ permalink raw reply	[relevance 3%]

* Re: Pass by reference
  @ 2004-04-14 17:27  7%             ` Simon Wright
  2004-04-15  9:43  3%               ` Vinzent 'Gadget' Hoefler
  0 siblings, 1 reply; 82+ results
From: Simon Wright @ 2004-04-14 17:27 UTC (permalink / raw)


Vinzent 'Gadget' Hoefler <nntp-2004-04@t-domaingrabbing.de> writes:

> Simon Wright wrote:
> 
> >Vinzent 'Gadget' Hoefler <nntp-2004-04@t-domaingrabbing.de> writes:
> >
> >> Pat Rogers wrote:
> >> 
> >> >If you made the type volatile that would also force by-reference.
> >
> >C.6(18): If a type is atomic or volatile and it is not a by-copy type,
>                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Yes, but if I understand that part correctly, this is the point. The
> register-type is just a simple Integer-type:

Sorry, that's what _I_ was trying to say too!

> >> Are you sure? I'm just looking at the assembly ouput of GNAT for a
> >> procedure that takes a volatile type (memory mapped register) and it
> >> does't seem so. Even worse, it optimizes the sequence of assignment
> >> which I need for this register. If you have any idea how can I avoid
> >> using access types to make it right, I'd be glad to hear it.
> >
> >I think you need to use inline assembler to be sure.
> 
> You must be kidding me, I'm just getting away from using assembler. :)
> The old system was a 16-bit-CPU programmed entirely in assembly
> language, now I am having MaRTE and Ada and you say, I should use
> inline assembler instead? ;-)
> 
> Well, there is no general problem in here for me, but even with inline
> assembler the fact remains that the procedure would need the _address_
> of the register, and *not* its contents. So using inline assembler
> wouldn't help in avoiding access types and if it doesn't, I won't need
> it, because in that case the compiler generated code is just fine.
> 
> >And to be really sure you may need to use Volatile => True on the
> >call, I had to (this was GNAT/PowerPC, by the way).
> 
> I'm not sure if I understand... can I actually apply that pragma to
> a call? Or am I missing something else?

I was talking about your "optimizes the sequence of assignment which I
need for this register" problem.

I don't know whether it's available in GCC C inline assembler, but for
GNAT, System.Machine_Code.Asm looks like

   procedure Asm (
     Template : String;
     Outputs  : Asm_Output_Operand_List;
     Inputs   : Asm_Input_Operand_List;
     Clobber  : String  := "";
     Volatile : Boolean := False);

(plus other variants).

From http://gcc.gnu.org/onlinedocs/gnat_ug_unx/The-Volatile-Parameter.html#The%20Volatile%20Parameter

Compiler optimizations in the presence of Inline Assembler may
sometimes have unwanted effects. For example, when an Asm invocation
with an input variable is inside a loop, the compiler might move the
loading of the input variable outside the loop, regarding it as a
one-time initialization.

If this effect is not desired, you can disable such optimizations by
setting the Volatile parameter to True; for example:

     Asm ("movl %0, %%ebx" & LF & HT &
          "movl %%ebx, %1",
          Inputs   => Unsigned_32'Asm_Input  ("g", Var_In),
          Outputs  => Unsigned_32'Asm_Output ("=g", Var_Out),
          Clobber  => "ebx",
          Volatile => True);
     
I'm not 100% sure on this, but this code

   with Interfaces;
   with System.Machine_Code;
   with System.Storage_Elements;

   procedure Access_Memory_Mapped_Register is

      R : Interfaces.Unsigned_32;
      for R'Address use System.Storage_Elements.To_Address (16#ffff0000#);

   begin

      System.Machine_Code.Asm
        ("movl #01000000, %0",
         Outputs => Interfaces.Unsigned_32'Asm_Output ("=m", R),
         Volatile => True);

      System.Machine_Code.Asm
        ("movl #00000000, %0",
         Outputs => Interfaces.Unsigned_32'Asm_Output ("=m", R),
         Volatile => True);

   end Access_Memory_Mapped_Register;

generates this i86 assembler

           .file	"vinzent.adb"
           .version	"01.01"
   gcc2_compiled.:
   .section	.rodata
   .LC0:
           .string	"vinzent.adb"
   .text
           .align 4
   .globl _ada_access_memory_mapped_register
           .type	 _ada_access_memory_mapped_register,@function
   _ada_access_memory_mapped_register:
           pushl %ebp
           movl %esp,%ebp
   #APP
           movl #01000000, -65536
           movl #00000000, -65536
   #NO_APP
           movl %ebp,%esp
           popl %ebp
           ret
   .Lfe1:
           .size	 _ada_access_memory_mapped_register,.Lfe1-_ada_access_memory_mapped_register
           .ident	"GCC: (GNU) 2.8.1"

which looks good .. no 'Access anywhere ..

-- 
Simon Wright                               100% Ada, no bugs.



^ permalink raw reply	[relevance 7%]

* Re: Little Endian -> Big Endian (Ada95 / GNAT)
  @ 2004-02-27 20:38  7%   ` Guillaume Foliard
  0 siblings, 0 replies; 82+ results
From: Guillaume Foliard @ 2004-02-27 20:38 UTC (permalink / raw)


Hi,

On a x86 with GNAT, a slightly modified version would look like :

with Interfaces;
with System.Machine_Code; use System.Machine_Code;

function To_Big_Endian
  (N : Interfaces.Unsigned_32) return Interfaces.Unsigned_32 is
      Result : Integer;
begin
      Asm ("bswap %0",
           Inputs  => Integer'Asm_Input ("a", N),
           Outputs => Integer'Asm_Output ("=a", Result));
      return Result;
end To_Big_Endian;




^ permalink raw reply	[relevance 7%]

* Hardware Interrupts
       [not found]     <20040221110026.E93C54C40C5@lovelace.ada-france.org>
@ 2004-02-21 20:39  4% ` Carroll-Tech
  0 siblings, 0 replies; 82+ results
From: Carroll-Tech @ 2004-02-21 20:39 UTC (permalink / raw)
  To: comp.lang.ada

Has anyone here read "Ada Concurrent Programming" by Narain Gehani?
In the book, Narain talks about address clauses.  For example:

task Interrupt_handler is
    entry DONE;
    for DONE use at 16#40#;
end Interrupt_handler;

Can an address clause be done with a procedure or function instead of a
task entry?
What about arguments?
How can I capture a return value, if there is one?

I want to call the BIOS interrupt (INT11h) to get the equipment list
word.  In my Assembly book it says that INT11h "returns" a word
containing the equipment list.  I'm assuming that a '1' at a given bit
within the word means the equipment is in the computer and '0' is not.

Here is my code so far
-------------------------------------------------------
with ada.text_io; use ada.text_io;
with system.interrupts; use system.interrupts;

procedure getequipment is
 type equiplist is array(0..15) of boolean;
 package boolean_io is new enumeration_io(boolean);
 procedure getlist(list: out equiplist);
 for getlist use at reference(16#11#);
 mylist: equiplist;

begin
 getlist(mylist);

-- for I in 0..15 loop
--  boolean_io.put(mylist(i));
-- end loop;
end getequipment;
------------------------------------------------------

When I compile this code the compiler says several things
that I do not know how to fix.

getequipment.adb:2:12: warning: "system.interrupts" is an internal GNAT unit
getequipment.adb:2:12: warning: use of this unit is non-portable and
version-dependent
getequipment.adb:7:09: missing body for "getlist"
getequipment.adb:8:13: address clause can only be given for imported
subprogram

Any ideas?

Maybe there is an easier way to call INT11h from Ada?
I looked into System.Machine_Code and the ASM procedure but that seems
pretty
complex (per GNAT reference manual explanation).






^ permalink raw reply	[relevance 4%]

* Re: Ada and ASM
  2003-09-06  7:25  4% ` Ada and ASM Simon Wright
  2003-09-06 13:14  0%   ` Marin David Condic
@ 2003-09-06 15:25  5%   ` Wes Groleau
  1 sibling, 0 replies; 82+ results
From: Wes Groleau @ 2003-09-06 15:25 UTC (permalink / raw)


>>I want to replace the ASM call by Ada syntax. Assuming one had a
>>package Asm, then I would like something like the following
>>
>>A,B:Asm.register_32;
>>A:=10_000;
>>Asm.Move(From=>A To=>B);
>>
>>The assembly operations are expressed as true Ada subprograms.

Are you saying you want every opcode to have
the overhead of a subprogram call?  Or are you
just looking for a more Ada-like syntax for
the special stuff?

Either way, you should read about package
System.Machine_Code in RM95 13.8

-- 
Wes Groleau
   "Grant me the serenity to accept those I cannot change;
    the courage to change the one I can;
    and the wisdom to know it's me."
                                -- unknown




^ permalink raw reply	[relevance 5%]

* Re: Ada and ASM
  2003-09-06  7:25  4% ` Ada and ASM Simon Wright
@ 2003-09-06 13:14  0%   ` Marin David Condic
  2003-09-06 15:25  5%   ` Wes Groleau
  1 sibling, 0 replies; 82+ results
From: Marin David Condic @ 2003-09-06 13:14 UTC (permalink / raw)


True, it would be difficult to have some sort of "full-up" Ada syntax 
for assembler that was anywhere near portable across all machines. 
Unless you simply got to the point where you're compiling Ada anyway, so 
why bother? ;-)

However, I recall at least one Ada compiler that essentially defined 
something that looked like a discriminated record for assembler 
instructions and your assembler routines effectively looked like a set 
of agregates for the discriminated record where each aggregate 
represented the machine instruction you wanted. That was pretty much an 
"Ada Syntax" of sorts. Perhaps something along those lines with some 
semi-standard "macro-like" capabilities would be a good thing. (For 
example, if there were some flavor of "if" or "loop" statements that 
automagically expanded out into the corresponding machine instructions, 
that would be helpful and about all you'd need when you are dipping into 
assembler.)

MDC


Simon Wright wrote:
> 
> 
> All very well if all you wanted to do was move things about. But
> machines have all sorts of features, not all of which have
> counterparts on each architecture to be supported. What about reading
> the high-resolution clock? (rdtsc on Pentium, mftb on PowerPC).
> 
>    function Clock return Time is
>       type Half is (Low, High);
>       Lower, Upper : Interfaces.Unsigned_32;
>       Results : array (Half) of Interfaces.Unsigned_32;
>       Result : Time;
>       for Result'Address use Results (Low)'Address;
>    begin
>       System.Machine_Code.Asm
>         ("rdtsc" & ASCII.LF & ASCII.HT &
>            "movl %%eax, %0"& ASCII.LF & ASCII.HT &
>            "movl %%edx, %1",
>          Outputs => (Interfaces.Unsigned_32'Asm_Output ("=g", Lower),
>                      Interfaces.Unsigned_32'Asm_Output ("=g", Upper)),
>          Clobber => "eax, edx");
>       Results := (Low => Lower, High => Upper);
>       return Result;
>    end Clock;
> 
> is an Intel version, the PPC version (which I can't post) is quite
> different in structure. For a start, you have to read the timestamp in
> two bites! (on 32-bit implementations).
> 
> The major reason for using asm must be precisely to accommodate these
> sorts of differences.


-- 
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

     "In general the art of government consists in taking as
     much money as possible from one class of citizens to give
     to the other."

         --  Voltaire
======================================================================




^ permalink raw reply	[relevance 0%]

* Re: Ada and ASM
       [not found]     <E19vQkV-0006EH-Ek@punt-3.mail.demon.net>
@ 2003-09-06  7:25  4% ` Simon Wright
  2003-09-06 13:14  0%   ` Marin David Condic
  2003-09-06 15:25  5%   ` Wes Groleau
  0 siblings, 2 replies; 82+ results
From: Simon Wright @ 2003-09-06  7:25 UTC (permalink / raw)
  To: rleif; +Cc: comp.lang.ada

> I want to replace the ASM call by Ada syntax. Assuming one had a
> package Asm, then I would like something like the following
> 
> A,B:Asm.register_32;
> A:=10_000;
> Asm.Move(From=>A To=>B);
> 
> The assembly operations are expressed as true Ada subprograms.

All very well if all you wanted to do was move things about. But
machines have all sorts of features, not all of which have
counterparts on each architecture to be supported. What about reading
the high-resolution clock? (rdtsc on Pentium, mftb on PowerPC).

   function Clock return Time is
      type Half is (Low, High);
      Lower, Upper : Interfaces.Unsigned_32;
      Results : array (Half) of Interfaces.Unsigned_32;
      Result : Time;
      for Result'Address use Results (Low)'Address;
   begin
      System.Machine_Code.Asm
        ("rdtsc" & ASCII.LF & ASCII.HT &
           "movl %%eax, %0"& ASCII.LF & ASCII.HT &
           "movl %%edx, %1",
         Outputs => (Interfaces.Unsigned_32'Asm_Output ("=g", Lower),
                     Interfaces.Unsigned_32'Asm_Output ("=g", Upper)),
         Clobber => "eax, edx");
      Results := (Low => Lower, High => Upper);
      return Result;
   end Clock;

is an Intel version, the PPC version (which I can't post) is quite
different in structure. For a start, you have to read the timestamp in
two bites! (on 32-bit implementations).

The major reason for using asm must be precisely to accommodate these
sorts of differences.



^ permalink raw reply	[relevance 4%]

* Re: Compute a Sin(X) and Cos(X) pair, FSINCOS, inlining
  @ 2003-07-13 23:32  5%   ` Jerry van Dijk
  0 siblings, 0 replies; 82+ results
From: Jerry van Dijk @ 2003-07-13 23:32 UTC (permalink / raw)



Gautier Write-only <gautier@somewhere.nil> writes:

> # Sorry, the original article already scrolled off my system.
> 
> Nice... (what system! even with on a VT220 I could scroll up news ;-)

Nah. I just hooked my VT220 clone to the serial port of my laptop, but
it didn't help... :-)

BTW, I always preferred the TeleVideo 970.

> BTW, what is the variant for Long_Float ?

Here is a full example of both:

------------------------------------------------------------------------------
with Ada.Text_IO;                       use Ada.Text_IO;
with Ada.Numerics;                      use Ada.Numerics;
with System.Machine_Code;               use System.Machine_Code;

with Ada.Numerics.Generic_Elementary_Functions;

procedure Check is

   package Float_Funcs is new
     Ada.Numerics.Generic_Elementary_Functions (Float);
   use Float_Funcs;

   package Long_Float_Funcs is new
     Ada.Numerics.Generic_Elementary_Functions (Long_Float);
   use Long_Float_Funcs;

   procedure Sin_Cos (Angle : Float; Sin : out Float; Cos : out Float);
   procedure Sin_Cos
     (Angle : Long_Float; Sin : out Long_Float; Cos : out Long_Float);
   pragma Inline (Sin_Cos);

   procedure Sin_Cos (Angle : Float; Sin : out Float; Cos : out Float) is
      use ASCII;
   begin
      Asm (("fsincos"  & LF & HT &
            "fstp  %0" & LF & HT &
            "fst   %1"),
           Outputs => (Float'Asm_Output ("=m", Cos),
                      (Float'Asm_Output ("=m", Sin))),
           Inputs  => (Float'Asm_Input ("t", Angle)));
   end Sin_Cos;

   procedure Sin_Cos
     (Angle : Long_Float; Sin : out Long_Float; Cos : out Long_Float) is
      use ASCII;
   begin
      Asm (("fsincos"  & LF & HT &
            "fstpl  %0" & LF & HT &
            "fstl   %1"),
           Outputs => (Long_Float'Asm_Output ("=m", Cos),
                      (Long_Float'Asm_Output ("=m", Sin))),
           Inputs  => (Long_Float'Asm_Input ("t", Angle)));
   end Sin_Cos;

   package IO_Concats is
      function "&" (S : String; F : Float) return String;
      function "&" (S : String; F : Long_Float) return String;
   end IO_Concats;

   package body IO_Concats is

      function "&" (S : String; F : Float) return String is
      begin
         return S & Float'Image (F);
      end "&";

      function "&" (S : String; F : Long_Float) return String is
      begin
         return S & Long_Float'Image (F);
      end "&";

   end IO_Concats;

   use IO_Concats;

   Sin_Float, Cos_Float : Float;
   Float_Value : constant Float := 0.25 * Pi;

   Sin_Long_Float, Cos_Long_Float : Long_Float;
   Long_Float_Value : constant Long_Float := 0.25 * Pi;

begin

   Sin_Float := Sin (Float_Value);
   Cos_Float := Cos (Float_Value);
   Put_Line ("Sin_Float:" & Sin_Float & ", Cos_Float:" & Cos_Float);

   Sin_Cos (Float_Value, Sin_Float, Cos_Float);
   Put_Line ("Sin_Float:" & Sin_Float & ", Cos_Float:" & Cos_Float);

   Sin_Long_Float := Sin (Long_Float_Value);
   Cos_Long_Float := Cos (Long_Float_Value);
   Put_Line
     ("Sin_LFloat:" & Sin_Long_Float & ", Cos_LFloat:" & Cos_Long_Float);

   Sin_Cos (Long_Float_Value, Sin_Long_Float, Cos_Long_Float);
   Put_Line
     ("Sin_LFloat:" & Sin_Long_Float & ", Cos_LFloat:" & Cos_Long_Float);

end Check;
-------------------------------------------------------------------------------

> In any case, it would be nice to have a compiler producing FSINCOS - e.g.
> for those users not familiar with machine code.

Yes. Have you checked gcc 3.3 ? Probably the Fortran folks would like this
too.

-- 
--  Jerry van Dijk   | email: jvandyk@attglobal.net
--  Leiden, Holland  | web:   users.ncrvnet.nl/gmvdijk



^ permalink raw reply	[relevance 5%]

* gnat and rounding up Long_Long_Float
@ 2001-10-16 22:27  5% Hans Koch
  0 siblings, 0 replies; 82+ results
From: Hans Koch @ 2001-10-16 22:27 UTC (permalink / raw)


I hope that some gnat/floating point expert can help me
with a question regarding the reliability of up/down rounding
of Long_Long_Float (80 bit extended precision).

I am running gnat under Linux on a Pentium system.
My question only concerns the operations +,-,*,/, and maybe sqrt
(needed for speed, the rest can be dealt with in software),
and I am only interested in rounding up/down,
since I need rigorous error bounds.

For example, if I instruct the FPU to round up
(using something like Round_Up - see below)
and then perform numerous additions, multiplications, ...,
can I assume that the only information lost
(concerning the final result)
is due to the FPU rounding up during these operations?

From all I have read so far about gnat,
the 80X87 FPU, and the IEEE standard, this seems correct.

But I could not find specific information
in the case where denormalized numbers are involved
(e.g. denormalized input, or underflow with normalized numbers).
Does the FPU still round up correctly, in the sense that
it returns a number that is no less than the actual result?

If not, what does gnat do in this case?
I hope that the error information is propagated to the program
(I would be happy even if the program halted).
Checking the FPU status registers after each operation
would be too time consuming.
An alternative would to be to use the exception masks
in the FPU control register,
but I assume that gnat will not let me control these.

But maybe the "if not" does not not apply?
Any relevane information would be highly appreciated.

Thanks
- Hans Koch


P.S. Round_Up example

with System.Machine_Code;
use System.Machine_Code;

procedure Round_Up is
  type Uns16 is mod 2**16;
  RoundUp: constant Uns16 := 16#1B3F#;
begin
  Asm("fldcw %0",Inputs => Uns16'Asm_Input("m",RoundUp), Volatile => True);
end Round_Up;



^ permalink raw reply	[relevance 5%]

* Re: How Ada could have prevented the Red Code distributed denial of
  @ 2001-08-14 15:39  5%                                 ` Stanley R. Allen
  0 siblings, 0 replies; 82+ results
From: Stanley R. Allen @ 2001-08-14 15:39 UTC (permalink / raw)


Ted Dennison wrote:

> *every* Ada compiler (as
> opposed to "most" C++ compilers) has support for inline assembler. Its actually
> in the standard.

Ada does have a standard for inline assembler language (package System.Machine_Code).
But it is one of those features which, according to the standard, is not required
to be implemented for a 'conforming' implementation of Ada.  See

http://www.adahome.com/rm95/rm9x-01-01-03.html   (paragraph 10)
http://www.adahome.com/rm95/rm9x-13-08.html      (paragraph 8)

--
Stanley Allen
mailto:Stanley_R_Allen-NR@Raytheon.com



^ permalink raw reply	[relevance 5%]

* Re: efficient vector/matrix operations in Fortran, was Re: ... in Ada
  @ 2001-08-14 10:37  4% ` Lutz Donnerhacke
  0 siblings, 0 replies; 82+ results
From: Lutz Donnerhacke @ 2001-08-14 10:37 UTC (permalink / raw)


* Gautier Write-only-address wrote:
>and return the variable. Maybe a pragma Inline and a strong
>optimization can do the job on some compilers. It would be
>interesting to see if at least one is able to suppress the
>local variable in an inlined call. If not, there is no chance
>that a user-defined "+" is as efficient as a user-defined "+=".

GNAT does a pretty bad job on this subject. Using the "+=" Procedure is
works considerably better. Please play around with compiler flags.

OTOH it is possible to enhance the Kernel Interface vastly if you are
switching to direct syscalls (using System.Machine_Code). Inlining does a
pretty good job on this subject:

\f
with Kernel.Calls;
use Kernel.Calls;

procedure test_kernel is
   res : long := sys_kill (0, 0);
begin
   null;
end test_kernel;
\f
_ada_test_kernel:
	movb $37,%al
	xorl %ebx,%ebx
	movl %ebx,%ecx
	int $0x80
	ret
\f
with Ada.Text_IO;

procedure t is
   type Vector is array (Positive range <>) of Integer;

   function "+" (a, b : Vector) return Vector is
      c : Vector(a'Range);
   begin
      for i in a'Range loop
         c(i) := a(i) + b(i);
      end loop;
      return c;
   end "+";

   procedure Add_To (a : in out Vector; b : in Vector) is
   begin
      for i in a'Range loop
         a(i) := a(i) + b(i);
      end loop;
   end Add_To;
   pragma Inline("+", Add_To);
   
   procedure Print (a : in Vector) is
      package IIO is new Ada.Text_IO.Integer_IO (Integer);
      use IIO, Ada.Text_IO;
   begin   
      for i in a'Range loop
         Put (i);
         Put (a (i));
      end loop;
      New_Line;
   end Print;
   
   a : Vector(1..3) := (others => 3);
   b : Vector(1..3) := (1, 2, 3);
   c : Vector(1..3) := (4, 5, 6);
   d : Vector(1..3);
begin
   d := a + b + c;
   Print(d);
   d := a; Add_To (d, b); Add_To (d, c);
   Print(d);
end t;



^ permalink raw reply	[relevance 4%]

* Re: How Ada could have prevented the Red Code distributed denial of
       [not found]                         ` <3B6F3FAE.B9B9FOrganization: LJK Software <c78BbJ9nURZD@eisner.encompasserve.org>
@ 2001-08-09 17:24  0%                       ` Ted Dennison
  0 siblings, 0 replies; 82+ results
From: Ted Dennison @ 2001-08-09 17:24 UTC (permalink / raw)


In article <c78BbJ9nURZD@eisner.encompasserve.org>, Larry Kilgallen says...
>
>In article <Hoxc7.3953$NJ6.15706@www.newsranger.com>, Ted Dennison<dennison@telepath.com> writes:
>
>> are doing something unsafe, but its not prevented. Also *every* Ada compiler (as
>> opposed to "most" C++ compilers) has support for inline assembler. Its actually
>> in the standard.
>
>Certainly you don't mean 13.8(8), which says:
>
>	An implementation is not required to provide package
>	System.Machine_Code.

Doh! You're right (and he didn't even include the "An implementation may place
restrictions on code_statements" part). So in fact, the situation is pretty much
the same as C++, except that there is a standard way to do it if it *is*
supported. Not that that matters much, since the machine code itself is hardly
going to be portable...

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



^ permalink raw reply	[relevance 0%]

* Re: How Ada could have prevented the Red Code distributed denial of
    @ 2001-08-09 15:25  5%                     ` Larry Kilgallen
       [not found]                         ` <3B6F3FAE.B9B9FOrganization: LJK Software <c78BbJ9nURZD@eisner.encompasserve.org>
  2 siblings, 0 replies; 82+ results
From: Larry Kilgallen @ 2001-08-09 15:25 UTC (permalink / raw)


In article <Hoxc7.3953$NJ6.15706@www.newsranger.com>, Ted Dennison<dennison@telepath.com> writes:

> are doing something unsafe, but its not prevented. Also *every* Ada compiler (as
> opposed to "most" C++ compilers) has support for inline assembler. Its actually
> in the standard.

Certainly you don't mean 13.8(8), which says:

	An implementation is not required to provide package
	System.Machine_Code.



^ permalink raw reply	[relevance 5%]

* Re: text_io is not a predefined library
  @ 2001-03-13 10:47  7%   ` David C. Hoos, Sr.
  0 siblings, 0 replies; 82+ results
From: David C. Hoos, Sr. @ 2001-03-13 10:47 UTC (permalink / raw)


Using Text_IO in place of Ada.TextIO is not the problem.

Note the following from RM95, J.1;
The following library_unit_renaming_declarations exist:

2 with Ada.Unchecked_Conversion;
generic function Unchecked_Conversion renames Ada.Unchecked_Conversion;
3 with Ada.Unchecked_Deallocation;
generic procedure Unchecked_Deallocation renames Ada.Unchecked_Deallocation;
4 with Ada.Sequential_IO;
generic package Sequential_IO renames Ada.Sequential_IO;
5 with Ada.Direct_IO;
generic package Direct_IO renames Ada.Direct_IO;

6 with Ada.Text_IO;
package Text_IO renames Ada.Text_IO;
7 with Ada.IO_Exceptions;
package IO_Exceptions renames Ada.IO_Exceptions;
8 with Ada.Calendar;
package Calendar renames Ada.Calendar;
9 with System.Machine_Code;
package Machine_Code renames System.Machine_Code; -- If supported.

The earlier suggestion by Jeff Creem that it is a GNAT installation
problem is the correct explanation for the phenomenon.

"DuckE" <nospam_steved94@home.com> wrote in message
news:dKhr6.559748$U46.16631404@news1.sttls1.wa.home.com...
> Text_Io is a child of Ada.
>
> Try:
>   with Ada.Text_Io;
>   use Ada.Text_Io;
>
> SteveD
>
> "Andrew Busolin" <abusolin@chariot.net.au> wrote in message
> news:3aad6b31_5@news.chariot.net.au...
> > Hi there,
> >
> > I have written a little hello world program in an effort to test out the
> ada
> > compiler I have recently downloaded. I am able to compile it using
> > gcc -c -gnats -c hello.adb, however when I try to gnatmake it using
> > gnatmake -c hello.adb it returns "ada.text_io" is not a predefined
library
> > unit
> > compilation abandoned!!!
> >
> > Can someone please tell me why this is and how I can fix it!
> >
> > Best Regards
> >
> > Andrew Busolin
> >
> >
> > with Text_Io;
> > use Text_Io;
> >
> > procedure hello is
> > begin
> > Put("hello");
> > end hello;
> >
> >
>
>




^ permalink raw reply	[relevance 7%]

* Re: Reading/writing LPT1
  @ 2000-08-21  0:42  4% ` tmoran
  2000-08-21  0:00  0%   ` David Boman
  0 siblings, 1 reply; 82+ results
From: tmoran @ 2000-08-21  0:42 UTC (permalink / raw)


>Does anyone know how to read /write from the parallellport in Ada?  I
>have a program written in Basic that modifys the some bit's on LPTx but
>I want to re-write this program to Ada.
   I presume you are running under DOS or perhaps Windows xx or OS/2 or
Linux on an Intel box?  So we will assume your hardware is the standard
sort of LPT port for such a box, and your OS allows you direct IO
operations to the port, as opposed to, say, a machine running the flight
controls on a jet.  Since IO is so widely varied across different
systems, it's not included in the Ada standard.  Your compiler vendor,
however, almost surely supplies a library that will do hardware level IO
on your target platform.  If that's not the case, then you can a) link
in appropriate subroutines written in asm or C or perhaps even Basic and
call them from your Ada program, or b) use your compiler's
implementation of standard package System.Machine_Code.  For handling
the bits in, eg, the status result, either use a record representation
clause to give names to individual bits or bit fields, or (more error
prone) use type "mod 256" and do "and"s and "or"s.



^ permalink raw reply	[relevance 4%]

* Re: Reading/writing LPT1
  2000-08-21  0:42  4% ` tmoran
@ 2000-08-21  0:00  0%   ` David Boman
  0 siblings, 0 replies; 82+ results
From: David Boman @ 2000-08-21  0:00 UTC (permalink / raw)


>    I presume you are running under DOS or perhaps Windows xx or OS/2 or
> Linux on an Intel box?  So we will assume your hardware is the standard

I'm running Windows2000 on Intel.

> sort of LPT port for such a box, and your OS allows you direct IO
> operations to the port, as opposed to, say, a machine running the flight
> controls on a jet.  Since IO is so widely varied across different

I don't know if Windows2000 allows direct IO, I've heard that WinNT/Win2000
is quite strict with this but I'm not sure.

> systems, it's not included in the Ada standard.  Your compiler vendor,
> however, almost surely supplies a library that will do hardware level IO
> on your target platform.  If that's not the case, then you can a) link
> in appropriate subroutines written in asm or C or perhaps even Basic and
> call them from your Ada program, or b) use your compiler's
> implementation of standard package System.Machine_Code.  For handling
> the bits in, eg, the status result, either use a record representation
> clause to give names to individual bits or bit fields, or (more error
> prone) use type "mod 256" and do "and"s and "or"s.

This seems resonable, but will I not have the same problem here? Does
Windows2000 allow me to write Assemblercode thats messes around with the
hardware?

/Boman






^ permalink raw reply	[relevance 0%]

* Re: Parallel port
  @ 2000-03-07  0:00  5% ` tmoran
  0 siblings, 0 replies; 82+ results
From: tmoran @ 2000-03-07  0:00 UTC (permalink / raw)


>Is the library Vendor_Specific_IO_Library is avaible on all ada compilers ?
>>   Vendor_Specific_IO_Library.Output(port=>16#378#, data=>data_value);
  I'm sure nothing of that exact name is offered by *anyone*.

When run under Windows 95, the following program displays a status of
87 when my old Epson printer is plugged into LPT1 and powered on,
and a status of 127 when it's powered off.

with claw.message_box,   -- nonstandard
     system,
     bit;                -- nonstandard
procedure test is
  use claw.message_box;
  status : system.byte;  -- nonstandard
begin
  message_box(text=>"ready?",
              caption=>"lpt1 status",
              flags=>make_flags);
  -- initialize
  bit.outport(16#37A#, 12);
  delay 0.05;
  bit.outport(16#37A#, 8);
  delay 0.01;
  -- check status
  bit.inport(16#379#, status);
  message_box(text=>"status is" & system.byte'image(status),
              caption=>"lpt1 status",
              flags=>make_flags);
end test;

But the package "bit", as well as the type "system.byte", are
extras that come with the Janus Ada compiler.  Other compilers
probably have something similar - look at your compiler's
documentation.

  Failing that, in decreasing order of ease,
  Can you do a "pragma Import" on an existing (C?) function to do
the byte level IO?
  You can always write the needed IO routines in assembly language,
then use "pragma Import" to make them accessible to your Ada program.
  Look at your compiler's documentation on package System.Machine_Code,
and use that to make the necessary IO instructions.
  As has been pointed out, some versions of Windows will only allow
"device drivers" that kind of hardware access, and will kill your
program if you try it from a "user program".




^ permalink raw reply	[relevance 5%]

* Re: What's wrong with this simple Ada w/ assembly code?
  @ 1999-03-04  0:00  5%   ` robert_dewar
  0 siblings, 0 replies; 82+ results
From: robert_dewar @ 1999-03-04  0:00 UTC (permalink / raw)


In article <36de1e0e.43769384@news.pacbell.net>,
  tmoran@bix.com (Tom Moran) wrote:
> Unfortunately, this is compiler-specific. I'd hazard a
> guess that Gnat would be happy with the GNU assembler.

The guess is true but irrelevant,
GNAT could not care less what
compiler or assembler is used provided that the standard
system ABI is properly followed. It is hard to believe that
this is not pretty standard *across* compilers!

If you are writing an assembler module, as opposed to
trying to use System.Machine_Code, then your solution, if
done properly should in fact be pretty portable across
compilers.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[relevance 5%]

* ACT ANNOUNCES: GNAT 3.11p now available!
@ 1999-01-25  0:00  1% robert_dewar
  0 siblings, 0 replies; 82+ results
From: robert_dewar @ 1999-01-25  0:00 UTC (permalink / raw)


ADA CORE TECHNOLOGIES AND ACT EUROPE ARE HAPPY TO ANNOUNCE
----------------------------------------------------------

The following ports of GNAT 3.11p are now available at
the NYU ftp site (ftp://cs.nyu.edu/pub/gnat)

   sparc-sun-solaris2.5.1
   alpha-dec-osf4.0d
   hppa1.1-hp-hpux10.20
   powerpc-ibm-aix4.1.4.0
   i386-pc-solaris2.6     (Solaris x86)
   i686-pc-linux-gnu      (Redhat 5)
   i686-pc-linux-gnulibc1 (Redhat 4)

Corresponding precompiled binary versions of the new Ada
aware GDB/GDBTK debugger can be found in the gdb directory.

In addition, corresponding versions of ASIS and GLADE are
also available. These are distributed in source form:

   Asis 3.11p
   Glade 3.11p

Separately available are two new tools:

   gnatelim (unused subprogram elimination)
   gnatstub (generation of stubs from package specs)

   (these are ASIS based tools)

We expect the following additional ports of 3.11p to be
available in the near future, watch this space!

   Windows 95 / Windows NT
   mips-sgi-irix5.3
   Alpha OpenVMS
   x86 IBM OS/2

With these distributions of publicly available open source
versions of the only complete Ada 95 technology (including
the core and all annexes), Ada Core Technologies continues
its commitment to the Ada community. We hope that these
public versions of GNAT will be of use to students,
academic researchers and others who want to experiment
with the use of the Ada 95 language.

Fully supported commercial versions of this technology
(under the name GNAT Professional) are available from
Ada Core Technologies (sales@gnat.com) and from
ACT Europe (sales@act-europe.fr).

Robert Dewar
Ada Core Technologies

+---------------------------------------------+
|The following are new features in GNAT 3.11p |
|      (as compared with GNAT 3.10p)          |
+---------------------------------------------+

The Windows NT/Windows 95 GNAT compiler no longer has any
cygwin32 based components. The only remaining cygwin32
based tool distributed is make. All the others tools
(debugger, linker, assembler...) have been built totally
using the mingw32 system. (Microsoft C library).

A null rendezvous body (do null; end) is now handled more
efficiently (it is treated as though no body were present).

The use of package Ada.Calendar and the use of delay
statements do not depend on the tasking run-time (and on a
thread library) any more. This means smaller and simpler
executables for non-tasking programs.

pragma Task_Info is now available for Digital Unix 4.0D and
can be used to specify on which processor a given Ada task
should run.

pragma Task_Info is also available for Solaris and can be
used to specify the relationship between tasks and
lightweight processes (LWP's), and between LWP's and
processors.

A new pragma Suppress_Initialization can be used to
suppress all initialization (both implicit and explicit)
for the given type.

Tight packing (with no padding bits) of arrays was formerly
implemented only up to element sizes of 32 bits. GNAT now
provides tight packing up to 64 bits.

A new attribute VADS_Size provides a size attribute that is
intended to be compatible with the results provided by the
Size attribute on VADS compilers (VADS is a trademark of
Rational Software Inc).

A corresponding configuration pragma Use_VADS_Size causes
any Size attribute in the source to be interpreted as
though it were VADS_Size. This pragma and the corresponding
attribute are intended to ease the porting of large VADS
programs that rely on the specific values of Size returned
by VADS.

Many additional tests for unassigned variables have been
added, resulting in additional warning messages. For
example, these checks are now performed on variables
declared within nested blocks.

This version of GNAT uses the new GCC 2.8 release. The
effect should mostly be transparent, but the new version of
GCC contains many code generation fixes and improvements.

The compiler generates additional encodings for GDB, and
together with the latest version of GDB, essentially all
Ada data structures are now handled correctly by GDB.

In the VMS version, GDB recognizes the VAX floating-point
formats automatically.

A new tool, gnatelim, allows for the elimination of unused
subprograms. This is an ASIS based tool, that can be used
on any GNAT target.

A new tool, gnatstub, allows for the automatic creation of
stubs from specifications. This is an ASIS based tool that
can be used on any GNAT target.

A new tool, gnatmem, provides a method for systematically
detecting memory leaks that arise from dynamic allocations
with no corresponding free operation.

A complete version of ASIS is now available for this
version of GNAT. This is a separately supported product.
Contact sales@gnat.com for full details.

The number of cases in which aggregates are treated
statically at compile time is significantly increased,
leading to faster and smaller code, as well as improved
compile time for programs with large aggregates.

Internal variables are now eliminated from the debugging
information, leading to a reduction in the size of
generated debugging data.

A new restriction identifier No_Elaboration_Code ensures
that a compilation does not generate any executable
elaboration code. This is different from pragma
Preelaborate in both directions, there are preelaborable
packages that generate executable elaboration code, and
there are packages which are not preealborable in the RM
sense that generate no elaboration code.

A new pragma Unreserve_All_Interrupts allows an
implementation to specify that normally reserved interrupts
(e.g. SIGINT for handling Ctrl-C) are to be unreserved, so
that the application program may handle these interrupts as
it pleases.

Many examples of unnecessary generation of internal
"actual" subtypes have been suppressed, resulting in more
efficient code, particularly at lower optimization levels,
and also in speeded up compilation.

The GNAT package GNAT.Htable has been enhanced. A Remove
procedure has been added to Simple_Htable, and an iterator
interface allowing retrieval of all elements of the table
has been added to both Simple_HTable and Static_HTable.
These additions have been done in an upwards compatible
manner, so existing clients should not be affected.

A new package GNAT.Table has been added which provides a
simple extensible array abstraction. As usual, this is
completely documented in the spec, which can  be found in
file g-table.ads.

A new implementation dependent attribute R.C'Bit_Position,
where R is a record object and C is one of its fields
returns the bit offset of the start of field C from the
start of the record as a universal integer.

The Address attribute is now fully implemented for
references involving elements of bit packed arrays
(formerly this was not permitted).

The efficiency (both space and time) of code for multiple
concatenations (where three or more values are
concatenated) has been improved.

The Unrestricted_Access attribute is now allowed even for
pool-specific access types (i.e. those declared without ALL
or CONSTANT) keywords. This is consistent with the intent
of this attribute, which is that it be essentially
equivalent to the use of 'Address followed by an
unchecked conversion to the access type.

In a number of situations, allocators are now handled
statically at compile time. Notably if an allocator is at
the outer level in elaboration code, then it can typically
be handled statically.

A new attribute Code_Address is provided. It applies only
to subprogram entities, and it returns the address of the
start of the code for the subprogram. This is often, but
not always, the same value as returned by 'Address.
Examples where it may differ are when the 'Address value
points to a descriptor, such as the "trampoline" used to
call nested procedures on some architectures. Generally the
'Address value is the one to use for calling subprogram
(via typical Ada 83 tricks for making the address be used
for the call). Code_Address always yields the starting
address of the contiguous code for the subprogram.

A warning is now generated for address clauses that are
intended to overlay two entities, when the type of the
entities includes an initialization. In such cases, the
initialization of the entity for which the address clause
is given will affect (i.e. destroy) the variable that it
overlays, unless the entity is labelled with a
pragma Import. A clear warning is now emitted for this
common and useful, but potentially dangerous, programming
idiom.

The Ident pragma now permits a general static string
expression, rather than just a string literal. This is an
upwards compatible extension.

A new attribute Has_Discriminants may be applied to a type
and yields true if the given type has Discriminants. It can
be used with generic types to indicate if the corresponding
actual type has discriminants.

A new warning switch -gnatwu causes warnings about unused
entities and with'ed units to be generated. This facility
replaces the use of -x1 and -x2 switches in gnatf. It is
more convenient than the use of gnatf (since it is embedded
into the compiler), and also more complete and accurate,
since a number of gnatf bugs have been corrected in this
new implementation of this warning feature.

Warning messages are now generated if an unchecked
conversion is used to convert an access type to another
access type with more strict alignment requiremnts (since
this can generate pointers whose designated object does not
meet the alignment requirements of the generated code using
this access type).

The UTF-8 encoding scheme for wide characters is now
supported both by the compiler (-gnatW8) and for
Wide_Text_IO files (WCEM=8). The  default wide character
encoding for Wide_Text_IO files is now set to
the wide character encoding specified for the main program
source.

Gnatmake behaves exactly in the same way whether or not
the .adb extension is omitted on the main source file. In
particular, it searches the path to look for the main
program if no directory is included, but a file extension
is present (See gnatmake section in gnat_ug for details).

Objdump has been added to the binary distribution.  Objdump
can be  used in conjuction with compiling with -g -S to
view code in accordance with pragma Reviewable.

An Ada-aware version of binutils utility addr2line has been
added to the binary distribution.

A new package GNAT.Regexp (in files g-regexp.ads and
g-regexp.adb) provides a complete facility for string
matching using Unix-style regular expression syntax.

A new package GNAT.Directory_Operations (in files
g-dirope.ads and g-dirope.adb) provides operations on
directories, including opening, reading, and changing the
current directory.

A new package GNAT.Command_Line (in files s-comlin.ads and
s-comlin.adb) provides a high level interface for scanning
command line switches, parameters and file names (including
wild card expansion).

GNAT now generates by default cross-reference information
in the  generated ali files (this can be suppressed with
the -gnatx switch). This information is used by the four
following capabilities. Note that this capability replaces
the now obsolete gnatf format.

A new tool gnatfind can be used to quickly locate
declarations or all references to a specified entity or
entities. This utility uses the new cross-reference
information in the ali files.

A new tool gnatxref can be used to generate complete
cross-reference reports. This utility uses the new
cross-reference information in the ali files.

A perl script gnathtml provides the capability of
converting sources to html, including the generation of
links using the new cross- reference information in the ali
files. Keywords and comments are appropriately highlighted.

A new version of GNAPSE (the GNAT version of EMACS with Ada
support) includes an interface to the cross-reference
information in the ali files to quickly locate declarations
and references.

There is a new version of gnatchop with enhanced
functionality, including the ability to chop multiple
files, and a special  "compilation" mode that provides
optional handling for configuration
pragmas according to the procedures in the RM.

The new version of gnatchop now respects an existing
Source_Reference pragma in the input file, and when used
with -r generates Source_Reference pragmas in the output
file that refer to the original input file. This is
particularly convenient when using gnatprep and gnatchop
together to process a file with multiple units and
preprocessing statements.

The unit System.Machine_Code (in file s-maccod.ads) is now
declared Pure, allowing the use of machine code intrinsics
in pure units.

The main program generated by the binder can now optionally
be generated in Ada rather than in C. To activate this
option, use the -A switch in both the gnatbind and gnatlink
steps.

The compiler now generates far more information on complex
data types in -g mode for use by the debugger. For best
results make sure you have the latest GDB.

A new pragma Eliminate is available which specifies that
certain declarations are to be eliminated from the program.
This is in preparation for a new tool gnatelim, which is
included as part of the 3.11 release, which provides for
removal of unused declarations and subprograms.

A new pragma Stream_Convert allows a unit to provide for
proper handling of stream attributes for a type if they are
used, without unconditionally incurring the overhead of
dragging in all the stuff for handling streams (which is
what happens if the stream attributes are defined in the
conventional manner).

The gnatchop utility now detects the case where the file to
be chopped contains multiple copies of the same unit, and
if so, does not write any files unless -w is specified (in
which case the last copy is the one to be written).

Attach_Handler and Interrupt_Handler capabilities are now
fully implemented on all targets as appropriate to the
target.

The "info tasks" under the latest ada-aware GDB now gives
additional information on the state of tasks.

A new unit g-tasloc provides an inexpensive global locking
capability for creating critical regions without reduced
overhead compared to implementing this lock in pure Ada
code.

The runtime has been extensively reworked. A number of
timing windows have been eliminated, and many small errors
have been caught and fixed. The result should be generally
improved reliability in the tasking implementation,
especially in the multi-processing case.

The "old GNULLI" routines have been entirely eliminated,
since all targets are now using the new low-level interface
("new GNULLI"). The result is an improved interface, which
solves a number of problems, and also a significant
reduction in the number of target dependent
tasking files.

In the NT version, we have the general capability of
installing bindings at the time that the system is
installed, and the standard distribution takes advantage of
this feature to offer the option of installing a version of
the Win32 bindings.

An archive is used for the standard library distribution on
all implementations, including OS/2. This improves linker
performance and reduces the number of individual files in
the installation.

A run time task that was previously systematically created
is now elaborated only for programs that use Asynchronous
Transfer of Control constructs. This means that a tasking
program will use less resources (threads and memory) and
that the start up will be faster.

The run time now properly and explicitly shut down all the
tasks before exiting. This avoids some target specific
problems like hanging and system errors.

Two functions Errno and Set_Errno have been added to
GNAT.OS_Lib to get and set the task-safe errno.

The GNAT makefile is now more portable, since it avoids the
use of Unix specific features, in favor of using GNUMAKE on
all targets. This makes integration of the OS/2 and VMS
versions more straightforward.

Calling and receiving stubs for the distributed systems
annex are now generated directly as object files; the
plain-Ada intermediate phase has been suppressed. The
compilation time has been dramatically reduced for
distributed programs containing a large number of RCI
packages.

Remote access to subprograms and generic RCI packages are
now fully implemented.

The incorrect attempt to use directory separators in the
file name argument of a Source_File_Name pragma is now
properly diagnosed.

The timed entry call and selective wait with delay
alternative tasking constructs have been highly improved in
term of efficiency and reliability.

On the AIX version, it is now possible to choose between
native threads, and simulated threads for the tasking.
Default is now native threads.

On the NT version, a fast locking mechanism is now used
that improves performance for tasking applications.

The NT version now allows linking with resources on NT as
well as on Win 95 and Win 98.

On AIX, Digital Unix and HPUX versions, gnatlink will now
automatically utilize the system dependent linker option to
read the set of object files from a named file rather than
the command line in cases where the linker cannot handle
the length of the object list. These particular OS systems
had fairly short allowable linker lines.

The Enum_Rep attribute can now be applied directly to an
object of an enumeration type, or to a non-overloaded
enumeration literal name.

--------- end of list of 3.11p new features --------


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[relevance 1%]

* Re: Assembler in Ada?
  @ 1999-01-22  0:00  6% ` news.oxy.com
  0 siblings, 0 replies; 82+ results
From: news.oxy.com @ 1999-01-22  0:00 UTC (permalink / raw)



Thomas Larsson wrote in message <369C5E08.69727537@mbox5.swipnet.se>...
>I would like to write some assembler into my Ada program (to change
>video mode, use mouse etc).
>
>How do I do that? (I have tried to figured out how, but I can't)
>Can I do it in a way similar to assembler in C or Pascal?
>\x18eg: _asm {
> mov cx,100
> LP: loop LP
> }
>
>I would appreciate a small example program.
>
>Thanks for your help
>Thomas
>
>PS. I do the programming in Win98, not UNIX


Below there are several examples of using Assembler with GNAT 3.10p1
(Windows NT 4.0).
Hope that they will be of some help for those who found that it is difficult
to understand how to use Assembler with GNAT.

I enjoy playing with GNAT 3.10p1 and find that it is really good.
But unfortunately I should admit the poor quality of GNAT documentation
regarding using of the assembler with it.  ACT people perfectly well know
one generic rule that should be followed to make any software system work:
ALL THE REFERENCIES FROM THE SOFTWARE MODULES SHOULD BE RESOLVED WITHIN THE
GIVEN SET OF MODULES THAT MAKE UP
THE SYSTEM. One won't be able to build the system if that rule is not
obeyed.
To my great surprise they forgot to apply this rule to the documentation so
it does not work.ALL THE REFERENCIES FROM ANY PIECE OF THE SYSTEM
DOCUMENTATION SHOULD BE RESOLVED WITHIN THE SET OF MANUALS THAT COME WITH
THE GIVEN SYSTEM. Otherwise the documentation does not work.

If you open GNAT ref. Manual at the Machine Code Insertion you will find
that just from the second paragraph ACT suggest you to go far away - to the
"Using and Porting GNU CC" which is not included in the documentation that
comes with GNAT. "Happy" GNAT users! (especially new ones). They want to
know how to use Assembler with GNAT but they are suggested to learn how to
use and port GCC. Moreover they are even directed where to find this manual.
Just wonderful!
There also no info regarding control over passing parameters, names of the
registers, how the template string is
passed to the GCC Assembler e.t.c.

Another thing that they forgot to do is to supply several small examples,
which can help to understand the rules. As a professor Rober Devar should
know that very complex and difficult things could be easily explained to
students using well designed simple examples.

Hope that ACT will be able to improve this in the GNAT 3.11p documentation
and close this issue.
DOCUMENTATION SHOULD BE SELF-CONTAINED!

Hope that my examples will be of some help.

Regards to all,
Vladimir Olensky (vladimir_olensky@yahoo.com)

 (Vladimir_Olensky@oxy.com)
Telecommunication specialist,
Occidental C.I.S. Service, Inc. ( www.oxy.com )
Moscow,
Russia.


**********************************************
There are two ways using Assembler:
1. Inline Assembler code
2. External Assembler code (xxx.S file) which is compiled by tha same GCC

Here I will give only two small examples in order not to overload
this posting too much. Later I can give some more
if there will be new requests.

*************************************************
--------------------------------
-- Inline assembler code example.
-- Author: Vladimir Olensky
---------------------------------
WITH Ada.Text_IO; USE Ada.Text_IO;
WITH Ada.Integer_Text_IO; USE Ada.Integer_Text_IO;

-- first you need to use System.Machine_Code package
WITH System.Machine_Code; USE System.Machine_Code;

PROCEDURE Asm_Tst1 IS

   -- new line - Unix stile - LF
   --            CRLF is causing GCC assembler to crash !!!
   nl: CONSTANT Character  := Character'Val(10);

   A:INTEGER:=15;
   B:INTEGER:=20;
   C:INTEGER:=0;

BEGIN
   Put_Line(" Inline assembler test");
   New_Line;
   -------------------------------------------
    Asm (
             "movl  %1,    %%eax"  & nl &    -- note nl here
         "    addl  %2,    %%eax"  & nl &    -- to construct proper string
template.
         "    movl  %%eax, %0",              -- Without that it won't work
         INTEGER'Asm_Output("=g", C),   -- Asm_Output("=g", C) compiler
choose output register for C
                                       -- Asm_Input( "g", A) -compiler
choose register for for A
        (INTEGER'Asm_Input( "g", A),INTEGER'Asm_Input("g", B)),
         "eax",  -- register eax will be spoiled by my code
          False  -- compiler, do not optimise my code !
          );
   --------------------------------------
   Put(C);
END Asm_Tst1;

-- Asm_tst1 output = 35
-------------
extras from assembler listing with my comments:
 ....
/APP    - my asm inline code
    movl  $15,    %eax    / move A to ax
    addl  $20,    %eax    / add B to A
    movl  %eax, %edx   / save result to C ( compiler have chosen edx)
/NO_APP
        / call to Put(C)
 movl _ada__integer_text_io__default_base,%eax
 pushl %eax
 movl _ada__integer_text_io__default_width,%eax
 pushl %eax
 pushl %edx     / push C
 call _ada__integer_text_io__put$2
 ....

*********************************************
another example with manual register control

--------------------------------
-- Inline assembler code example.
-- Author: Vladimir Olensky
---------------------------------

WITH Ada.Text_IO; USE Ada.Text_IO;
WITH Ada.Integer_Text_IO; USE Ada.Integer_Text_IO;

-- first you need to use System.Machine_Code package
WITH System.Machine_Code; USE System.Machine_Code;

PROCEDURE Asm_Tst1 IS

   -- new line - Unix stile --LF
   --            CRLF is causing GCC asembler to crash !!!
   nl: CONSTANT Character  := Character'Val(10);

   A:INTEGER:=15;
   B:INTEGER:=20;
   C:INTEGER:=0;

BEGIN
   Put_Line(" Inline assembler test");
   New_Line;
   -------------------------------------------
    Asm (
      -- we add two registers where we directed compiler to put A and B
         "    addl  %%ebx,    %%eax",
        INTEGER'Asm_Output("=a", C),   -- Asm_Output("=a", C) compiler, use
eax to output C
                                       -- Asm_Input( "a", A) -compiler, use
eax for for A
                                       -- Asm_Input( "b", B) -compiler, use
ebx for for B
        (INTEGER'Asm_Input( "a", A),INTEGER'Asm_Input("b", B)),
         "",  -- do not need to use anything, compiler already knows
everything
         False  -- compiler, do not optimise my code !
          );
   --------------------------------------

   Put(C);
END Asm_Tst1;
-- Asm_tst1 output = 35
----------
extras from the assembler listing with my comments:
 ...
 call _ada__text_io__new_line$2  / call to New_Line
 movl $15,%eax   / INTEGER'Asm_Input( "a", A)
 movl $20,%ebx   / INTEGER'Asm_Input("b", B)
/APP
     addl  %ebx,    %eax         / My inline assembler code
/NO_APP
 / call to the Put(C)
 movl %eax,%edx                 / compiler moves C to edx
 movl _ada__integer_text_io__default_base,%eax  / as eax will used for
defauly dase
 pushl %eax
 movl _ada__integer_text_io__default_width,%ebx
 pushl %ebx
 pushl %edx                                            / push C
 call _ada__integer_text_io__put$2
  ...
********************************
From the last example you can see that it is necessary to be very careful
when
manually controlling passing varaibles to the registers. It can be less
effective.
Just compare two examples and you will see that the last one has one
instruction more.
There are a lot of pitfalls here. Be careful!







^ permalink raw reply	[relevance 6%]

* Re: GNAT system.machine_code
  1998-02-18  0:00 14% GNAT system.machine_code Andy Perkins
@ 1998-02-19  0:00  8% ` William D. Ghrist
  0 siblings, 0 replies; 82+ results
From: William D. Ghrist @ 1998-02-19  0:00 UTC (permalink / raw)



Andy Perkins wrote:
> 
> Can anyone explain how to use the asm procedures in GNAT's
> system.machine_code package?  I just need to send a few instructions in
> my program, and am not really sure how that package works...
> 
> Thanks
> storm@vci.net

I have a related question as well.  Can anyone point me to a document
that defines the syntax of the assembly language output produced by the
"gcc -S" option?  I am used to Intel's ASM format, and this is quite a
bit different.  I am just starting to learn Ada using GNAT, and I have
not had any prior experience with the GNU tools.  Any assistance would
be appreciated.

Thanks,
Bill Ghrist





^ permalink raw reply	[relevance 8%]

* GNAT system.machine_code
@ 1998-02-18  0:00 14% Andy Perkins
  1998-02-19  0:00  8% ` William D. Ghrist
  0 siblings, 1 reply; 82+ results
From: Andy Perkins @ 1998-02-18  0:00 UTC (permalink / raw)



Can anyone explain how to use the asm procedures in GNAT's
system.machine_code package?  I just need to send a few instructions in
my program, and am not really sure how that package works...

Thanks
storm@vci.net





^ permalink raw reply	[relevance 14%]

* Re: Ada and assembler
  @ 1997-09-18  0:00  4% ` Samuel Tardieu
  0 siblings, 0 replies; 82+ results
From: Samuel Tardieu @ 1997-09-18  0:00 UTC (permalink / raw)
  To: Frederic Deshaies


>>>>> "Frederic" == Frederic Deshaies <Frederic.Deshaies@wanadoo.fr> writes:

Frederic> Hello, I would like to know how i can put assembler
Frederic> instructions in an Ada program ?

If you are using GNAT, then you can use the System.Machine_Code
package just as you use "asm" directive in C with GCC. Here is an
example coming from a Sparc/Solaris-specific file of the GNAT library: 

      function Get_G7 return Interfaces.C.Unsigned;
      pragma Inline (Get_G7);

      ------------
      -- Get_G7 --
      ------------

      function Get_G7 return Interfaces.C.Unsigned is
         Result : Interfaces.C.Unsigned;
      begin
         Asm ("mov %%g7,%0", Interfaces.C.Unsigned'Asm_Output ("=r", Result));
         return Result;
      end Get_G7;

Note that this is a very powerful and efficient mechanism, because in
this example if you use for example:

      if Get_G7 = Some_Value then

then there will be no function call (thanks to inlining) and the code
used to retrieve the value of the G7 register will be scheduled
efficiently by the GCC backend.

Of course, if you are using another target, you have to put i386+
opcodes in your Asm statements.

The best source of information for assembly inlining in GNAT is the
GNAT documentation and the GCC documentation (the first one describes
how you can use from Ada the features describe in the latter).

  Sam
-- 
Samuel Tardieu -- sam@ada.eu.org




^ permalink raw reply	[relevance 4%]

* Re: Why couldn't an operating system be written in ada
  @ 1996-07-16  0:00  4%   ` Jon S Anthony
  0 siblings, 0 replies; 82+ results
From: Jon S Anthony @ 1996-07-16  0:00 UTC (permalink / raw)



In article <xe1687p1cha.fsf@maneki-neko.cygnus.com> Mark Eichin <eichin@cygnus.com> writes:

> > A neat idea whose time is long since gone.  The OS "wars" have
> > been fought and largely lost.... :-(
> 
> Well, the users lost anyway :-}  However, research certainly

Yeah, that's what I meant...


> MK, VSTA, and other operating systems exist to serve as research
> platforms (and sometimes as operational platforms when "modern" 70's
> and 80's systems just can't cut it.)  Surely there is justification
> for using Ada in this context, at least?

I'm sure there is all sorts of good reasons to use Ada in these
contexts.  But, the results will probably never see the light of day -
maybe a peek or two...


> I brought up this point with a well known linux kernel developer, and
> between the two of us we came up with several things that I didn't
> know Ada95 well enough to answer:
> 	1) Can you do efficient raw memory operations (ie. raw byte
> arrays, explicit control of when an access can be eliminated, and no
> overhead [or at least, not stored in-place, for an object like a page
> or a video card?]

Yes, this should not be any sort of a problem.  With
System.Storage_Elements and address clauses and such you should be
well covered.


> 	2) Can you interface efficiently to machine code
> (ie. equivalent of inline asm, where you *mostly* can code a high
> level algorithm but the core needs to be a particular hardware level
> instruction. A GNAT-specific answer is ok, in this case...)

Sure.  Actually this sort of thing is defined in the language with
convention intrinsic (6.3.1) and System.Machine_Code (13.8).


> 	3) Can you work without tasking (since you're implementing the
> scheduler!) [I'll take arguments that you should in fact use Ada
> tasking within the kernel, if they're detailed...]

Sure you can.  But to my mind, it would make as much (or more) sense
to first create the tasking kernel and then build the OS scheduler on
top of this.  This seems like the most straightforward way to proceed
and it has the added benefit that you can use "regular tasking" in
other parts of the OS design and know that you will not be interfering
in some nefarious way with the OS scheduler.  I'm sure there is
probably a reason why you might not want to do this, but it isn't
obvious to me.


> 	4) Can you do complete memory management (without garbage
> collection.) 

Sure.  You can define your own storage pools (System.Storage_Pools)
and write specific MM operations for them.  This way you can have
different styles of AMM for different sorts of "objects" - thereby
allowing the most "appropriate" technique for the resource type.  See
13.11


> As you can see, I *don't* know much Ada, though I've gotten a start on
> Barnes' excellent "Ada95" text.

Yes, for knowledgeable types, outside the RM and Rationale, I would
say Barnes is the best thing going.

>  My guesses are that (1) is possible,
> but you must go out of your way to do it; (2) might be possible in
> GNAT; (3) is probably obvious and (4) is true but the reasoning is
> subtle.

(1): Really rather straight forward and not that big of a deal
(2): Easily done.
(3): Yes, obvious
(4): Really pretty obvious also.  The subtlty comes in how clever the
     AMMs you write are.


> I haven't thought of any other potential obstacles to OS work in Ada;
> it would seem a good choice, based on the *intent* of the design, but
> I can't yet judge the results.

Well, one way to look at it is that since (one of) the primary areas
of intended use for Ada was and is "real-time"/embedded systems, OS
sort of work should "just fall right out".  Access to HW, interrupts,
and that sort of bare machine stuff is defined in the language (well,
the annexes anyway...)

/Jon

-- 
Jon Anthony
Organon Motives, Inc.
1 Williston Road, Suite 4
Belmont, MA 02178

617.484.3383
jsa@organon.com





^ permalink raw reply	[relevance 4%]

Results 1-82 of 82 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
1996-07-13  0:00     Why couldn't an operating system be written in ada Mark McKinney
1996-07-15  0:00     ` Jon S Anthony
1996-07-16  0:00  4%   ` Jon S Anthony
1997-09-16  0:00     Ada and assembler Frederic Deshaies
1997-09-18  0:00  4% ` Samuel Tardieu
1998-02-18  0:00 14% GNAT system.machine_code Andy Perkins
1998-02-19  0:00  8% ` William D. Ghrist
1999-01-13  0:00     Assembler in Ada? Thomas Larsson
1999-01-22  0:00  6% ` news.oxy.com
1999-01-25  0:00  1% ACT ANNOUNCES: GNAT 3.11p now available! robert_dewar
1999-03-03  0:00     What's wrong with this simple Ada w/ assembly code? Josh Highley
1999-03-04  0:00     ` Tom Moran
1999-03-04  0:00  5%   ` robert_dewar
2000-03-06  0:00     Parallel port Philippe Bourzeix
2000-03-07  0:00  5% ` tmoran
2000-08-20  0:00     Reading/writing LPT1 David Boman
2000-08-21  0:42  4% ` tmoran
2000-08-21  0:00  0%   ` David Boman
2001-03-13  0:35     text_io is not a predefined library Andrew Busolin
2001-03-13  4:54     ` DuckE
2001-03-13 10:47  7%   ` David C. Hoos, Sr.
2001-07-30  7:08     How to make Ada a dominant language Russ
2001-08-02  8:25     ` How Ada could have prevented the Red Code distributed denial of service attack Richard Bos
2001-08-02 16:10       ` Dan Cross
2001-08-03  7:26         ` Richard Bos
2001-08-03 15:05           ` Dan Cross
2001-08-03 18:06             ` Preben Randhol
2001-08-03 19:37               ` Mark Wilden
2001-08-04  8:00                 ` Preben Randhol
2001-08-06 16:48                   ` Mark Wilden
2001-08-06 16:56                     ` Preben Randhol
2001-08-07  0:10                       ` Warren W. Gay VE3WWG
2001-08-07  1:09                         ` Chris Wolfe
2001-08-07  3:09                           ` Warren W. Gay VE3WWG
2001-08-07 22:01                             ` Chris Wolfe
2001-08-08  4:18                               ` Warren W. Gay VE3WWG
2001-08-08 23:12                                 ` Chris Wolfe
2001-08-09 14:48                                   ` How Ada could have prevented the Red Code distributed denial of Ted Dennison
2001-08-14 15:39  5%                                 ` Stanley R. Allen
2001-08-09 15:25  5%                     ` Larry Kilgallen
     [not found]                         ` <3B6F3FAE.B9B9FOrganization: LJK Software <c78BbJ9nURZD@eisner.encompasserve.org>
2001-08-09 17:24  0%                       ` Ted Dennison
2001-08-14 10:11     efficient vector/matrix operations in Fortran, was Re: ... in Ada Gautier Write-only-address
2001-08-14 10:37  4% ` Lutz Donnerhacke
2001-10-16 22:27  5% gnat and rounding up Long_Long_Float Hans Koch
2003-07-09 20:30     Compute a Sin(X) and Cos(X) pair, FSINCOS, inlining Gautier Write-only
2003-07-12  6:26     ` Gautier Write-only
2003-07-13 23:32  5%   ` Jerry van Dijk
     [not found]     <E19vQkV-0006EH-Ek@punt-3.mail.demon.net>
2003-09-06  7:25  4% ` Ada and ASM Simon Wright
2003-09-06 13:14  0%   ` Marin David Condic
2003-09-06 15:25  5%   ` Wes Groleau
     [not found]     <20040221110026.E93C54C40C5@lovelace.ada-france.org>
2004-02-21 20:39  4% ` Hardware Interrupts Carroll-Tech
2004-02-25  9:38     Little Endian -> Big Endian (Ada95 / GNAT) James Amor
2004-02-26  5:59     ` Simon Wright
2004-02-27 20:38  7%   ` Guillaume Foliard
2004-04-08 14:52     Pass by reference Dan McLeran
2004-04-09  4:03     ` Steve
2004-04-09 14:50       ` Simon Wright
2004-04-09 17:12         ` Pat Rogers
2004-04-09 19:33           ` Vinzent 'Gadget' Hoefler
2004-04-10  6:33             ` Simon Wright
2004-04-13 10:26               ` Vinzent 'Gadget' Hoefler
2004-04-14 17:27  7%             ` Simon Wright
2004-04-15  9:43  3%               ` Vinzent 'Gadget' Hoefler
2004-04-17  7:59  0%                 ` Simon Wright
2004-05-18 17:13  6% Inline ASM Dan McLeran
2004-08-18 20:37     Bitmanipulation in Ada Bernd Specht
2004-08-18 20:51     ` Ludovic Brenta
2004-08-18 21:10       ` Bernd Specht
2004-08-19  0:53         ` Jeffrey Carter
2004-08-19 17:44           ` Bernd Specht
2004-08-19 21:24  3%         ` Francois G. Dorais
2005-03-21 19:49     asm() Jean-Baptiste CAMPESATO
2005-03-21 23:13  5% ` asm() Ludovic Brenta
2005-03-22  7:41  0%   ` asm() Jean-Baptiste CAMPESATO
2006-08-24 16:33  6% call procedure in Linux-Ada-module from "normal" program Frank
2007-02-21 16:16     real_time.clock is not monotonic frederic.ormancey
2007-02-21 20:17  6% ` Simon Wright
2007-09-17  2:36     Ada and SIMD Adrian Hoe
2007-09-18 10:22  5% ` anon
2007-09-19  3:26  0%   ` Adrian Hoe
2007-09-19  5:24  0%     ` anon
2008-03-06 17:07     updating a hardware cursor with assembly and ada cl1
2008-03-07 19:01  7% ` cl1
2008-03-07 20:16  7%   ` Ludovic Brenta
2008-11-04  7:55     Stackusage at runtime andi.vontobel
2008-11-05  9:31     ` Yes it is possible. " Ludovic Brenta
2008-11-05 21:55  4%   ` anon
2009-05-01 21:39     GNAT on WinXP: System.OS_Lib.Spawn raises Program_Error daniel.wengelin
2009-05-02 15:59     ` Martin
2009-05-02 20:39  5%   ` anon
2009-05-03  9:42  0%     ` Martin
2009-05-04  9:08     How to exit an Ada program with (unix shell) error code? reinkor
2009-05-07 16:26     ` Adam Beneschan
2009-05-08 10:17  5%   ` anon
2009-06-28 17:56     unsigned type anon
2009-07-06  6:18     ` Learning Ada AdaMagica
2009-07-06 20:21       ` anon
2009-07-06 22:43         ` Frank J. Lhota
2009-07-09 22:28  5%       ` anon
2010-02-15 10:58     Is there an Ada compiler whose Ada.Numerics.Generic_Elementary_Functions.Log(Base=>10, X=>variable) is efficient? Colin Paul Gloster
2010-02-15 14:54     ` jonathan
2010-02-15 15:04       ` jonathan
2010-02-15 19:50  5%     ` sjw
2010-02-16 16:50  3%       ` Colin Paul Gloster
2010-03-30  6:35     GPS and assembly language files brian
2010-03-30  8:13  5% ` Rolf
2010-05-18 13:12     Code Statement johnjohn
2010-05-18 13:22  5% ` Ludovic Brenta
2010-05-18 13:29  5% ` AdaMagica
2010-05-18 15:05     ` sjw
2010-05-19  4:37  7%   ` anon
2010-05-19  6:07  6%     ` Simon Wright
2010-05-19  9:56  5%       ` sjw
2010-05-19 10:20  0%         ` AdaMagica
2010-06-19 23:01     Advice on selling Ada to a C shop usenet
2010-06-22 15:00     ` Lucretia
2010-06-22 18:01       ` anon
2010-06-22 19:06         ` Nasser M. Abbasi
2010-06-23 16:20  5%       ` anon
2011-05-26 15:10  5% strange behavior while compiling code with asm() milouz
2011-05-26 16:50  0% ` Simon Wright
2011-11-26 23:13     Overloading attributes Matt Borchers
2011-11-29 12:50     ` Mark Lorenzen
2011-11-30 11:05  4%   ` anon
2012-03-01 13:06     Any leap year issues caused by Ada yesterday? Georg Bauhaus
2012-03-05 11:07     ` tonyg
2012-03-05 15:59       ` Shark8
2012-03-05 18:03         ` Dmitry A. Kazakov
2012-03-05 18:30           ` Simon Wright
2012-03-05 20:17             ` Dmitry A. Kazakov
2012-03-05 20:56               ` Simon Wright
2012-03-06  8:47                 ` Dmitry A. Kazakov
2012-03-06  9:20                   ` Simon Wright
2012-03-06 10:07                     ` Dmitry A. Kazakov
2012-03-06 16:46                       ` Simon Wright
2012-03-06 17:37                         ` Dmitry A. Kazakov
2012-03-06 17:59  4%                       ` Simon Wright
2012-04-10  9:21     Importing C function with variable argument list Maxim Reznik
2012-04-10 13:18     ` Markus Schöpflin
2012-04-10 16:47       ` Simon Wright
2012-04-12 10:08         ` Markus Schöpflin
2012-04-12 16:58           ` Adam Beneschan
2012-04-13  4:08             ` Tero Koskinen
2012-04-13  8:04  5%           ` Markus Schöpflin
2012-07-09  3:53  5% Help with Inline assembly Jim C.
2012-07-09  6:35  0% ` anon
2012-07-09  8:41  0% ` theanalogmachine
2012-07-09 14:43  0%   ` theanalogmachine
2013-04-27 21:08     GNAT not generating any code for sub‑program: known bug? Yannick Duchêne (Hibou57)
2013-04-27 22:22     ` Yannick Duchêne (Hibou57)
2013-04-28  7:14  6%   ` Simon Wright
2013-04-28 17:52  3%     ` Yannick Duchêne (Hibou57)
2013-04-28 22:35  3% ` Erroneous code generation from GNAT or GCC? Yannick Duchêne (Hibou57)
2013-04-28 23:52       ` Yannick Duchêne (Hibou57)
2013-04-29  1:35         ` Yannick Duchêne (Hibou57)
2013-04-30  0:48           ` Yannick Duchêne (Hibou57)
2013-04-30  6:40             ` Simon Wright
2013-04-30 17:04               ` Yannick Duchêne (Hibou57)
2013-04-30 19:06                 ` Simon Wright
2013-04-30 21:28                   ` Yannick Duchêne (Hibou57)
2013-04-30 22:22  5%                 ` Simon Wright
2013-07-08 17:56     The future of Spark . Spark 2014 : a wreckage vincent.diemunsch
2013-07-08 21:32     ` Randy Brukardt
2013-07-09  7:28       ` Dmitry A. Kazakov
2013-07-09 20:37         ` Randy Brukardt
2013-07-10 10:03           ` Dmitry A. Kazakov
2013-07-10 23:21             ` Randy Brukardt
2013-07-12  1:01  4%           ` Slow? Ada?? Bill Findlay
2014-03-16 20:37  5% Interrupt-driven Usart not working in Ada, but in C working, why? Rego, P.
2014-04-22 13:28     GLIBC_2.14 memcpy Ian Douglas
2014-04-26 20:10     ` Ian Douglas
2014-04-28 12:23  6%   ` anon
2014-10-26 18:31     F-22 ADA Programming nathandsash
2014-10-26 21:20     ` David Botton
2014-10-26 23:24       ` Jeffrey Carter
2014-10-27 15:04         ` Adam Beneschan
2014-10-27 15:41           ` Maciej Sobczak
2014-10-28  8:45             ` Natasha Kerensikova
2014-10-28 18:29               ` Jeffrey Carter
2014-10-28 18:37                 ` Adam Beneschan
2014-10-28 21:06                   ` Jeffrey Carter
2014-10-28 21:37                     ` Adam Beneschan
2014-10-28 23:59                       ` Jeffrey Carter
2014-10-29  0:34                         ` Adam Beneschan
2014-10-29  5:24                           ` Jeffrey Carter
2014-10-29  8:37                             ` Dmitry A. Kazakov
2014-10-29 17:20                               ` Jeffrey Carter
2014-10-30 15:38                                 ` Maciej Sobczak
2014-10-30 16:07                                   ` Bill White
2014-10-30 22:37                                     ` Maciej Sobczak
2014-10-31  9:41                                       ` Georg Bauhaus
2014-11-01  3:03                                         ` C versus Ada (once again :-)), was: " Simon Clubley
2014-11-03 12:40                                           ` Florian Weimer
2014-11-03 21:58  5%                                         ` Shark8
2014-11-03 22:28  0%                                           ` Dmitry A. Kazakov
2014-11-04 13:42  0%                                           ` Florian Weimer
2015-01-25 16:41     ANN: gcc 4.9.1bis for Darwin Simon Wright
2015-02-21 10:22     ` vincent.diemunsch
2015-02-21 12:10  5%   ` Simon Wright
2015-02-24 21:53  0%     ` Vincent
2016-02-23 22:25     Protected Objects and Interrupt Handlers Jere
2016-02-25 15:14     ` Maciej Sobczak
2016-02-25 16:02       ` Simon Wright
2016-02-25 17:40         ` Tero Koskinen
2016-02-25 19:49  5%       ` Simon Wright
2016-03-13  8:10  0%         ` Simon Wright
2017-11-13 10:08 13% Using System.Machine_Code in GPL 2017 Zfp for Arm ahlan
2017-11-13 10:57 14% ` ahlan
2017-11-13 11:40  8% ` Simon Wright
2017-11-13 13:21  8% ` ahlan
2018-09-17  2:22     GNAT for AVR - Mathematical Functions ada.newcomer
2018-09-17  7:18     ` Dmitry A. Kazakov
2018-09-17 22:41  6%   ` Aurele Vitali
2018-09-17 22:35  6% ` Aurele Vitali
2022-06-09 21:30     Using pointers with inline assembly in Ada NiGHTS
2022-06-11 12:28  6% ` Simon Wright
2022-06-11 12:32  0%   ` NiGHTS

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox