-
+ C8D53B2A0E90EC081C6E0BDB4D1DE6FCF02ABA4AB34D1EB83271DF34CC3CB1FBB29B103551335477314F2A5DB544B91943CCAAE1DCA05676AA096420D59F9D84
ffa/libffa/fz_shift.adb
(0 . 0)(1 . 115)
423 ------------------------------------------------------------------------------
424 ------------------------------------------------------------------------------
425 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
426 -- --
427 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
428 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
429 -- --
430 -- You do not have, nor can you ever acquire the right to use, copy or --
431 -- distribute this software ; Should you use this software for any purpose, --
432 -- or copy and distribute it to anyone or in any manner, you are breaking --
433 -- the laws of whatever soi-disant jurisdiction, and you promise to --
434 -- continue doing so for the indefinite future. In any case, please --
435 -- always : read and understand any software ; verify any PGP signatures --
436 -- that you use - for any purpose. --
437 -- --
438 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
439 ------------------------------------------------------------------------------
440 ------------------------------------------------------------------------------
441
442 with W_Shifts; use W_Shifts;
443
444
445 package body FZ_Shift is
446
447 --------------------------------------------------------------
448 -- Shift Right
449 --------------------------------------------------------------
450
451 -- ShiftedN := N >> Count (with Overflow Input and Output)
452 procedure FZ_ShiftRight_O_I(N : in FZ;
453 ShiftedN : out FZ;
454 Count : in WBit_Index;
455 Overflow : out Word;
456 OF_in : in Word) is
457 Ni : Word;
458 Carry : Word := OF_in;
459 begin
460 for i in reverse N'Range loop
461 Ni := N(i);
462 ShiftedN(i) := Shift_Right(Ni, Count) or Carry;
463 Carry := Shift_Left(Ni, Bitness - Count);
464 end loop;
465 Overflow := Carry;
466 end FZ_ShiftRight_O_I;
467 pragma Inline_Always(FZ_ShiftRight_O_I);
468
469
470 -- ShiftedN := N >> Count (with Overflow Output only)
471 procedure FZ_ShiftRight_O(N : in FZ;
472 ShiftedN : out FZ;
473 Count : in WBit_Index;
474 Overflow : out Word) is
475 begin
476 FZ_ShiftRight_O_I(N, ShiftedN, Count, Overflow, 0);
477 end FZ_ShiftRight_O;
478 pragma Inline_Always(FZ_ShiftRight_O);
479
480
481 -- ShiftedN := N >> Count (no Overflow output or input)
482 procedure FZ_ShiftRight(N : in FZ;
483 ShiftedN : out FZ;
484 Count : in WBit_Index) is
485 Overflow : Word;
486 pragma Unreferenced(Overflow);
487 begin
488 FZ_ShiftRight_O_I(N, ShiftedN, Count, Overflow, 0);
489 end FZ_ShiftRight;
490 pragma Inline_Always(FZ_ShiftRight);
491
492 --------------------------------------------------------------
493 -- Shift Left
494 --------------------------------------------------------------
495
496 -- ShiftedN := N << Count (with Overflow Input and Output)
497 procedure FZ_ShiftLeft_O_I(N : in FZ;
498 ShiftedN : out FZ;
499 Count : in WBit_Index;
500 Overflow : out Word;
501 OF_in : in Word) is
502 Ni : Word;
503 Carry : Word := OF_in;
504 begin
505 for i in N'Range loop
506 Ni := N(i);
507 ShiftedN(i) := Shift_Left(Ni, Count) or Carry;
508 Carry := Shift_Right(Ni, Bitness - Count);
509 end loop;
510 Overflow := Carry;
511 end FZ_ShiftLeft_O_I;
512 pragma Inline_Always(FZ_ShiftLeft_O_I);
513
514
515 -- ShiftedN := N << Count (with Overflow Output only)
516 procedure FZ_ShiftLeft_O(N : in FZ;
517 ShiftedN : out FZ;
518 Count : in WBit_Index;
519 Overflow : out Word) is
520 begin
521 FZ_ShiftLeft_O_I(N, ShiftedN, Count, Overflow, 0);
522 end FZ_ShiftLeft_O;
523 pragma Inline_Always(FZ_ShiftLeft_O);
524
525
526 -- ShiftedN := N << Count (no Overflow output or input)
527 procedure FZ_ShiftLeft(N : in FZ;
528 ShiftedN : out FZ;
529 Count : in WBit_Index) is
530 Overflow : Word;
531 pragma Unreferenced(Overflow);
532 begin
533 FZ_ShiftLeft_O_I(N, ShiftedN, Count, Overflow, 0);
534 end FZ_ShiftLeft;
535 pragma Inline_Always(FZ_ShiftLeft);
536
537 end FZ_Shift;