1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . A U X _ D E C --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/Or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
pragma Style_Checks (All_Checks);
-- Turn off alpha ordering check on subprograms, this unit is laid
-- out to correspond to the declarations in the DEC 83 System unit.
with System.Soft_Links;
package body System.Aux_DEC is
package SSL renames System.Soft_Links;
-----------------------------------
-- Operations on Largest_Integer --
-----------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type LIU is mod 2 ** Largest_Integer'Size;
-- Unsigned type of same length as Largest_Integer
function To_LI is new Ada.Unchecked_Conversion (LIU, Largest_Integer);
function From_LI is new Ada.Unchecked_Conversion (Largest_Integer, LIU);
function "not" (Left : Largest_Integer) return Largest_Integer is
begin
return To_LI (not From_LI (Left));
end "not";
function "and" (Left, Right : Largest_Integer) return Largest_Integer is
begin
return To_LI (From_LI (Left) and From_LI (Right));
end "and";
function "or" (Left, Right : Largest_Integer) return Largest_Integer is
begin
return To_LI (From_LI (Left) or From_LI (Right));
end "or";
function "xor" (Left, Right : Largest_Integer) return Largest_Integer is
begin
return To_LI (From_LI (Left) xor From_LI (Right));
end "xor";
--------------------------------------
-- Arithmetic Operations on Address --
--------------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
Asiz : constant Integer := Integer (Address'Size) - 1;
type SA is range -(2 ** Asiz) .. 2 ** Asiz - 1;
-- Signed type of same size as Address
function To_A is new Ada.Unchecked_Conversion (SA, Address);
function From_A is new Ada.Unchecked_Conversion (Address, SA);
function "+" (Left : Address; Right : Integer) return Address is
begin
return To_A (From_A (Left) + SA (Right));
end "+";
function "+" (Left : Integer; Right : Address) return Address is
begin
return To_A (SA (Left) + From_A (Right));
end "+";
function "-" (Left : Address; Right : Address) return Integer is
pragma Unsuppress (All_Checks);
-- Because this can raise Constraint_Error for 64-bit addresses
begin
return Integer (From_A (Left) - From_A (Right));
end "-";
function "-" (Left : Address; Right : Integer) return Address is
begin
return To_A (From_A (Left) - SA (Right));
end "-";
------------------------
-- Fetch_From_Address --
------------------------
function Fetch_From_Address (A : Address) return Target is
type T_Ptr is access all Target;
function To_T_Ptr is new Ada.Unchecked_Conversion (Address, T_Ptr);
Ptr : constant T_Ptr := To_T_Ptr (A);
begin
return Ptr.all;
end Fetch_From_Address;
-----------------------
-- Assign_To_Address --
-----------------------
procedure Assign_To_Address (A : Address; T : Target) is
type T_Ptr is access all Target;
function To_T_Ptr is new Ada.Unchecked_Conversion (Address, T_Ptr);
Ptr : constant T_Ptr := To_T_Ptr (A);
begin
Ptr.all := T;
end Assign_To_Address;
---------------------------------
-- Operations on Unsigned_Byte --
---------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type BU is mod 2 ** Unsigned_Byte'Size;
-- Unsigned type of same length as Unsigned_Byte
function To_B is new Ada.Unchecked_Conversion (BU, Unsigned_Byte);
function From_B is new Ada.Unchecked_Conversion (Unsigned_Byte, BU);
function "not" (Left : Unsigned_Byte) return Unsigned_Byte is
begin
return To_B (not From_B (Left));
end "not";
function "and" (Left, Right : Unsigned_Byte) return Unsigned_Byte is
begin
return To_B (From_B (Left) and From_B (Right));
end "and";
function "or" (Left, Right : Unsigned_Byte) return Unsigned_Byte is
begin
return To_B (From_B (Left) or From_B (Right));
end "or";
function "xor" (Left, Right : Unsigned_Byte) return Unsigned_Byte is
begin
return To_B (From_B (Left) xor From_B (Right));
end "xor";
---------------------------------
-- Operations on Unsigned_Word --
---------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type WU is mod 2 ** Unsigned_Word'Size;
-- Unsigned type of same length as Unsigned_Word
function To_W is new Ada.Unchecked_Conversion (WU, Unsigned_Word);
function From_W is new Ada.Unchecked_Conversion (Unsigned_Word, WU);
function "not" (Left : Unsigned_Word) return Unsigned_Word is
begin
return To_W (not From_W (Left));
end "not";
function "and" (Left, Right : Unsigned_Word) return Unsigned_Word is
begin
return To_W (From_W (Left) and From_W (Right));
end "and";
function "or" (Left, Right : Unsigned_Word) return Unsigned_Word is
begin
return To_W (From_W (Left) or From_W (Right));
end "or";
function "xor" (Left, Right : Unsigned_Word) return Unsigned_Word is
begin
return To_W (From_W (Left) xor From_W (Right));
end "xor";
-------------------------------------
-- Operations on Unsigned_Longword --
-------------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type LWU is mod 2 ** Unsigned_Longword'Size;
-- Unsigned type of same length as Unsigned_Longword
function To_LW is new Ada.Unchecked_Conversion (LWU, Unsigned_Longword);
function From_LW is new Ada.Unchecked_Conversion (Unsigned_Longword, LWU);
function "not" (Left : Unsigned_Longword) return Unsigned_Longword is
begin
return To_LW (not From_LW (Left));
end "not";
function "and" (Left, Right : Unsigned_Longword) return Unsigned_Longword is
begin
return To_LW (From_LW (Left) and From_LW (Right));
end "and";
function "or" (Left, Right : Unsigned_Longword) return Unsigned_Longword is
begin
return To_LW (From_LW (Left) or From_LW (Right));
end "or";
function "xor" (Left, Right : Unsigned_Longword) return Unsigned_Longword is
begin
return To_LW (From_LW (Left) xor From_LW (Right));
end "xor";
-------------------------------
-- Operations on Unsigned_32 --
-------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type U32 is mod 2 ** Unsigned_32'Size;
-- Unsigned type of same length as Unsigned_32
function To_U32 is new Ada.Unchecked_Conversion (U32, Unsigned_32);
function From_U32 is new Ada.Unchecked_Conversion (Unsigned_32, U32);
function "not" (Left : Unsigned_32) return Unsigned_32 is
begin
return To_U32 (not From_U32 (Left));
end "not";
function "and" (Left, Right : Unsigned_32) return Unsigned_32 is
begin
return To_U32 (From_U32 (Left) and From_U32 (Right));
end "and";
function "or" (Left, Right : Unsigned_32) return Unsigned_32 is
begin
return To_U32 (From_U32 (Left) or From_U32 (Right));
end "or";
function "xor" (Left, Right : Unsigned_32) return Unsigned_32 is
begin
return To_U32 (From_U32 (Left) xor From_U32 (Right));
end "xor";
-------------------------------------
-- Operations on Unsigned_Quadword --
-------------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type QWU is mod 2 ** 64; -- 64 = Unsigned_Quadword'Size
-- Unsigned type of same length as Unsigned_Quadword
function To_QW is new Ada.Unchecked_Conversion (QWU, Unsigned_Quadword);
function From_QW is new Ada.Unchecked_Conversion (Unsigned_Quadword, QWU);
function "not" (Left : Unsigned_Quadword) return Unsigned_Quadword is
begin
return To_QW (not From_QW (Left));
end "not";
function "and" (Left, Right : Unsigned_Quadword) return Unsigned_Quadword is
begin
return To_QW (From_QW (Left) and From_QW (Right));
end "and";
function "or" (Left, Right : Unsigned_Quadword) return Unsigned_Quadword is
begin
return To_QW (From_QW (Left) or From_QW (Right));
end "or";
function "xor" (Left, Right : Unsigned_Quadword) return Unsigned_Quadword is
begin
return To_QW (From_QW (Left) xor From_QW (Right));
end "xor";
-----------------------
-- Clear_Interlocked --
-----------------------
procedure Clear_Interlocked
(Bit : in out Boolean;
Old_Value : out Boolean)
is
begin
SSL.Lock_Task.all;
Old_Value := Bit;
Bit := False;
SSL.Unlock_Task.all;
end Clear_Interlocked;
procedure Clear_Interlocked
(Bit : in out Boolean;
Old_Value : out Boolean;
Retry_Count : Natural;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := Bit;
Bit := False;
Success_Flag := True;
SSL.Unlock_Task.all;
end Clear_Interlocked;
---------------------
-- Set_Interlocked --
---------------------
procedure Set_Interlocked
(Bit : in out Boolean;
Old_Value : out Boolean)
is
begin
SSL.Lock_Task.all;
Old_Value := Bit;
Bit := True;
SSL.Unlock_Task.all;
end Set_Interlocked;
procedure Set_Interlocked
(Bit : in out Boolean;
Old_Value : out Boolean;
Retry_Count : Natural;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := Bit;
Bit := True;
Success_Flag := True;
SSL.Unlock_Task.all;
end Set_Interlocked;
---------------------
-- Add_Interlocked --
---------------------
procedure Add_Interlocked
(Addend : Short_Integer;
Augend : in out Aligned_Word;
Sign : out Integer)
is
begin
SSL.Lock_Task.all;
Augend.Value := Augend.Value + Addend;
if Augend.Value < 0 then
Sign := -1;
elsif Augend.Value > 0 then
Sign := +1;
else
Sign := 0;
end if;
SSL.Unlock_Task.all;
end Add_Interlocked;
----------------
-- Add_Atomic --
----------------
procedure Add_Atomic
(To : in out Aligned_Integer;
Amount : Integer)
is
begin
SSL.Lock_Task.all;
To.Value := To.Value + Amount;
SSL.Unlock_Task.all;
end Add_Atomic;
procedure Add_Atomic
(To : in out Aligned_Integer;
Amount : Integer;
Retry_Count : Natural;
Old_Value : out Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := To.Value + Amount;
Success_Flag := True;
SSL.Unlock_Task.all;
end Add_Atomic;
procedure Add_Atomic
(To : in out Aligned_Long_Integer;
Amount : Long_Integer)
is
begin
SSL.Lock_Task.all;
To.Value := To.Value + Amount;
SSL.Unlock_Task.all;
end Add_Atomic;
procedure Add_Atomic
(To : in out Aligned_Long_Integer;
Amount : Long_Integer;
Retry_Count : Natural;
Old_Value : out Long_Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := To.Value + Amount;
Success_Flag := True;
SSL.Unlock_Task.all;
end Add_Atomic;
----------------
-- And_Atomic --
----------------
type IU is mod 2 ** Integer'Size;
type LU is mod 2 ** Long_Integer'Size;
function To_IU is new Ada.Unchecked_Conversion (Integer, IU);
function From_IU is new Ada.Unchecked_Conversion (IU, Integer);
function To_LU is new Ada.Unchecked_Conversion (Long_Integer, LU);
function From_LU is new Ada.Unchecked_Conversion (LU, Long_Integer);
procedure And_Atomic
(To : in out Aligned_Integer;
From : Integer)
is
begin
SSL.Lock_Task.all;
To.Value := From_IU (To_IU (To.Value) and To_IU (From));
SSL.Unlock_Task.all;
end And_Atomic;
procedure And_Atomic
(To : in out Aligned_Integer;
From : Integer;
Retry_Count : Natural;
Old_Value : out Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := From_IU (To_IU (To.Value) and To_IU (From));
Success_Flag := True;
SSL.Unlock_Task.all;
end And_Atomic;
procedure And_Atomic
(To : in out Aligned_Long_Integer;
From : Long_Integer)
is
begin
SSL.Lock_Task.all;
To.Value := From_LU (To_LU (To.Value) and To_LU (From));
SSL.Unlock_Task.all;
end And_Atomic;
procedure And_Atomic
(To : in out Aligned_Long_Integer;
From : Long_Integer;
Retry_Count : Natural;
Old_Value : out Long_Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := From_LU (To_LU (To.Value) and To_LU (From));
Success_Flag := True;
SSL.Unlock_Task.all;
end And_Atomic;
---------------
-- Or_Atomic --
---------------
procedure Or_Atomic
(To : in out Aligned_Integer;
From : Integer)
is
begin
SSL.Lock_Task.all;
To.Value := From_IU (To_IU (To.Value) or To_IU (From));
SSL.Unlock_Task.all;
end Or_Atomic;
procedure Or_Atomic
(To : in out Aligned_Integer;
From : Integer;
Retry_Count : Natural;
Old_Value : out Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := From_IU (To_IU (To.Value) or To_IU (From));
Success_Flag := True;
SSL.Unlock_Task.all;
end Or_Atomic;
procedure Or_Atomic
(To : in out Aligned_Long_Integer;
From : Long_Integer)
is
begin
SSL.Lock_Task.all;
To.Value := From_LU (To_LU (To.Value) or To_LU (From));
SSL.Unlock_Task.all;
end Or_Atomic;
procedure Or_Atomic
(To : in out Aligned_Long_Integer;
From : Long_Integer;
Retry_Count : Natural;
Old_Value : out Long_Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := From_LU (To_LU (To.Value) or To_LU (From));
Success_Flag := True;
SSL.Unlock_Task.all;
end Or_Atomic;
------------------------------------
-- Declarations for Queue Objects --
------------------------------------
type QR;
type QR_Ptr is access QR;
type QR is record
Forward : QR_Ptr;
Backward : QR_Ptr;
end record;
function To_QR_Ptr is new Ada.Unchecked_Conversion (Address, QR_Ptr);
function From_QR_Ptr is new Ada.Unchecked_Conversion (QR_Ptr, Address);
------------
-- Insqhi --
------------
procedure Insqhi
(Item : Address;
Header : Address;
Status : out Insq_Status)
is
Hedr : constant QR_Ptr := To_QR_Ptr (Header);
Next : constant QR_Ptr := Hedr.Forward;
Itm : constant QR_Ptr := To_QR_Ptr (Item);
begin
SSL.Lock_Task.all;
Itm.Forward := Next;
Itm.Backward := Hedr;
Hedr.Forward := Itm;
if Next = null then
Status := OK_First;
else
Next.Backward := Itm;
Status := OK_Not_First;
end if;
SSL.Unlock_Task.all;
end Insqhi;
------------
-- Remqhi --
------------
procedure Remqhi
(Header : Address;
Item : out Address;
Status : out Remq_Status)
is
Hedr : constant QR_Ptr := To_QR_Ptr (Header);
Next : constant QR_Ptr := Hedr.Forward;
begin
SSL.Lock_Task.all;
Item := From_QR_Ptr (Next);
if Next = null then
Status := Fail_Was_Empty;
else
Hedr.Forward := To_QR_Ptr (Item).Forward;
if Hedr.Forward = null then
Status := OK_Empty;
else
Hedr.Forward.Backward := Hedr;
Status := OK_Not_Empty;
end if;
end if;
SSL.Unlock_Task.all;
end Remqhi;
------------
-- Insqti --
------------
procedure Insqti
(Item : Address;
Header : Address;
Status : out Insq_Status)
is
Hedr : constant QR_Ptr := To_QR_Ptr (Header);
Prev : constant QR_Ptr := Hedr.Backward;
Itm : constant QR_Ptr := To_QR_Ptr (Item);
begin
SSL.Lock_Task.all;
Itm.Backward := Prev;
Itm.Forward := Hedr;
Hedr.Backward := Itm;
if Prev = null then
Status := OK_First;
else
Prev.Forward := Itm;
Status := OK_Not_First;
end if;
SSL.Unlock_Task.all;
end Insqti;
------------
-- Remqti --
------------
procedure Remqti
(Header : Address;
Item : out Address;
Status : out Remq_Status)
is
Hedr : constant QR_Ptr := To_QR_Ptr (Header);
Prev : constant QR_Ptr := Hedr.Backward;
begin
SSL.Lock_Task.all;
Item := From_QR_Ptr (Prev);
if Prev = null then
Status := Fail_Was_Empty;
else
Hedr.Backward := To_QR_Ptr (Item).Backward;
if Hedr.Backward = null then
Status := OK_Empty;
else
Hedr.Backward.Forward := Hedr;
Status := OK_Not_Empty;
end if;
end if;
SSL.Unlock_Task.all;
end Remqti;
end System.Aux_DEC;
|