You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* GNAT allows defining the endianness through the `Scalar_Storage_Order` aspect, on composite types
266
-
* Need to be associated with a consistent `Bit_Order` (convention for the bit range numbering)
267
-
* The compiler will perform bitwise transformations if needed when sending data to the processor
272
+
* Compiler will peform needed bitwise transformations when performing operations
268
273
269
274
.. code:: Ada
270
275
271
276
type Rec is record
272
277
A : Integer;
273
278
B : Boolean;
274
279
end record;
280
+
for Rec use record
281
+
A at 0 range 0 .. 31;
282
+
B at 0 range 32 .. 33;
283
+
end record;
275
284
for Rec'Bit_Order use System.High_Order_First;
276
285
for Rec'Scalar_Storage_Order use System.High_Order_First;
277
286
278
-
type Ar is array (1 .. 1000) of Boolean;
279
-
for Ar'Scalar_Storage_Order use System.Low_Order_First;
280
-
281
287
-- using Ada 2012 aspects
282
-
type Rec is record
283
-
A : Integer;
284
-
B : Boolean;
285
-
end record with
286
-
Bit_Order => High_Order_First,
287
-
Scalar_Storage_Order => High_Order_First;
288
-
289
288
type Ar is array (1 .. 1000) of Boolean with
290
-
Scalar_Storage_Order => Low_Order_First;
289
+
Scalar_Storage_Order => System.Low_Order_First;
291
290
292
291
--------------------------
293
292
Change of Representation
294
293
--------------------------
295
294
296
-
* Explicit conversion can be used to change representation
295
+
* Explicit new type can be used to set representation
297
296
* Very useful to unpack data from file/hardware to speed up references
298
297
299
298
.. code:: Ada
@@ -411,9 +410,9 @@ Volatile
411
410
pragma Volatile(Volatile_U16);
412
411
type Volatile_U32 is mod 2**32 with Volatile; -- Ada 2012
413
412
414
-
* Volatile means that the exact sequence of reads and writes of an object indicated in the source code must be respected in the generated code.
413
+
* The exact sequence of reads and writes from the source code must appear in the generated code.
415
414
416
-
- No optimization of reads and writes please!
415
+
- No optimization of reads and writes
417
416
418
417
* Volatile types are passed by-reference.
419
418
@@ -424,33 +423,35 @@ Ada Address Example
424
423
.. code:: Ada
425
424
426
425
type Bitfield is array (Integer range <>) of Boolean;
426
+
pragma Component_Size (1);
427
427
428
428
V : aliased Integer; -- object can be referenced elsewhere
429
-
Pragma Volatile (V); -- may be updated at any time
429
+
pragma Volatile (V); -- may be updated at any time
430
430
431
431
V2 : aliased Integer;
432
-
Pragma Volatile (V2);
432
+
pragma Volatile (V2);
433
433
434
434
V_A : System.Address := V'Address;
435
435
V_I : Integer_Address := To_Integer (V_A);
436
436
437
437
-- This maps directly on to the bits of V
438
438
V3 : aliased Bitfield (1 .. V'Size);
439
-
For V3'address use V_A; -- overlay
439
+
for V3'Address use V_A; -- overlay
440
440
441
441
V4 : aliased Integer;
442
442
-- Trust me, I know what I'm doing, this is V2
443
-
For V4'address use To_Address (V_I - 4);
443
+
for V4'Address use To_Address (V_I - 4);
444
444
445
445
--------------------
446
446
Aliasing Detection
447
447
--------------------
448
448
449
-
* Aliasing happens when one object has two names
449
+
* :dfn:`Aliasing`: multiple objects are accessing the same address
450
450
451
-
- Two pointers pointing to the same object
452
-
- Two references referencing the same object
453
-
- Two variables at the same address
451
+
- Types can be different
452
+
- Two pointers pointing to the same address
453
+
- Two references onto the same address
454
+
- Two objects at the same address
454
455
455
456
* :ada:`Var1'Has_Same_Storage (Var2)` checks if two objects occupy exactly the same space
456
457
* :ada:`Var'Overlaps_Storage (Var2)` checks if two object are partially or fully overlapping
@@ -483,7 +484,10 @@ Calling Assembly Code
483
484
-----------------------
484
485
485
486
* Calling assembly code is a vendor-specific extension
486
-
* GNAT allows passing assembly scripts directly to the linker through `System.Machine_Code.ASM`
487
+
* GNAT allows passing assembly with `System.Machine_Code.ASM`
488
+
489
+
- Handled by the linker directly
490
+
487
491
* The developer is responsible for mapping variables on temporaries or registers
488
492
* See documentation
489
493
@@ -500,8 +504,8 @@ Simple Statement
500
504
501
505
Asm ("halt", Volatile => True);
502
506
503
-
- Specify `Volatile` to avoid compiler optimization
504
-
- GNAT is picky on that point
507
+
- You may specify `Volatile` to avoid compiler optimizations
508
+
- In general, keep it False unless it created issues
505
509
506
510
* You can group several instructions
507
511
@@ -565,9 +569,9 @@ Mapping Inputs / Outputs on Temporaries
565
569
566
570
- A constant
567
571
568
-
* - D
572
+
* - g
569
573
570
-
- edx (on x86)
574
+
- global (on x86)
571
575
572
576
* - a
573
577
@@ -591,16 +595,21 @@ Main Rules
591
595
* On x86, the assembler uses ``AT&T`` convention
592
596
593
597
- First operand is source, second is destination
594
-
- See GNU assembler manual for details
598
+
599
+
* See your toolchain's ``as`` assembler manual for syntax
595
600
596
601
-------------------------------------
597
602
Volatile and Clobber ASM Parameters
598
603
-------------------------------------
599
604
600
-
* Volatile |rightarrow| True deactivates optimizations with regards to suppressed instructions
601
-
* Clobber |rightarrow| "reg1, reg2, ..." contains the list of registers considered to be "destroyed" by the use of the ASM call
605
+
* :ada:`Volatile` |rightarrow| :ada:`True` deactivates optimizations with regards to suppressed instructions
606
+
* :ada:`Clobber` |rightarrow| :ada:`"reg1, reg2, ..."` contains the list of registers considered to be "destroyed" by the use of the ASM call
607
+
608
+
- ``memory`` if the memory is accessed
609
+
610
+
+ Compiler won't use memory cache in registers across the instruction.
602
611
603
-
- Use 'memory' if the memory is accessed in an unpredictable fashion. The compiler will not keep memory values cached in registers across the instruction.
612
+
- ``cc`` if flags might have changed
604
613
605
614
-----------------------------------
606
615
Instruction Counter Example (x86)
@@ -619,7 +628,7 @@ Instruction Counter Example (x86)
0 commit comments