-
+ EE90484DC801B605DDC2DB7B3DCE4C95A6B99F59577253D40E437F94EA6E89534137102A68DAB20B46D0EA1F8C7BA625258E7073102859AD764020989B95FA7C
ffa/libffa/fz_arith.adb
(0 . 0)(1 . 68)
505 ------------------------------------------------------------------------------
506 ------------------------------------------------------------------------------
507 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
508 -- --
509 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
510 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
511 -- --
512 -- You do not have, nor can you ever acquire the right to use, copy or --
513 -- distribute this software ; Should you use this software for any purpose, --
514 -- or copy and distribute it to anyone or in any manner, you are breaking --
515 -- the laws of whatever soi-disant jurisdiction, and you promise to --
516 -- continue doing so for the indefinite future. In any case, please --
517 -- always : read and understand any software ; verify any PGP signatures --
518 -- that you use - for any purpose. --
519 -- --
520 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
521 ------------------------------------------------------------------------------
522 ------------------------------------------------------------------------------
523
524 with Word_Ops; use Word_Ops;
525
526 -- Fundamental Arithmetic operators on FZ:
527 package body FZ_Arith is
528
529 -- Sum := X + Y; Overflow := Carry
530 procedure FZ_Add(X : in FZ;
531 Y : in FZ;
532 Sum : out FZ;
533 Overflow : out WBool) is
534 Carry : WBool := 0;
535 begin
536 for i in X'Range loop
537 declare
538 A : constant Word := X(I);
539 B : constant Word := Y(I);
540 S : constant Word := A + B + Carry;
541 begin
542 Sum(i) := S;
543 Carry := W_Carry(A, B, S);
544 end;
545 end loop;
546 Overflow := Carry;
547 end FZ_Add;
548 pragma Inline_Always(FZ_Add);
549
550
551 -- Difference := X - Y; Underflow := Borrow
552 procedure FZ_Sub(X : in FZ;
553 Y : in FZ;
554 Difference : out FZ;
555 Underflow : out WBool) is
556 Borrow : WBool := 0;
557 begin
558 for i in 0 .. Word_Index(X'Length - 1) loop
559 declare
560 A : constant Word := X(X'First + i);
561 B : constant Word := Y(Y'First + i);
562 S : constant Word := A - B - Borrow;
563 begin
564 Difference(Difference'First + i) := S;
565 Borrow := W_Borrow(A, B, S);
566 end;
567 end loop;
568 Underflow := Borrow;
569 end FZ_Sub;
570 pragma Inline_Always(FZ_Sub);
571
572 end FZ_Arith;