raw
ffa_ch3_shifts.kv       1 ------------------------------------------------------------------------------
ffa_ch3_shifts.kv 2 ------------------------------------------------------------------------------
ffa_ch3_shifts.kv 3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
ffa_ch3_shifts.kv 4 -- --
ffa_ch14_barrett.kv 5 -- (C) 2018 Stanislav Datskovskiy ( www.loper-os.org ) --
ffa_ch3_shifts.kv 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
ffa_ch3_shifts.kv 7 -- --
ffa_ch3_shifts.kv 8 -- You do not have, nor can you ever acquire the right to use, copy or --
ffa_ch3_shifts.kv 9 -- distribute this software ; Should you use this software for any purpose, --
ffa_ch3_shifts.kv 10 -- or copy and distribute it to anyone or in any manner, you are breaking --
ffa_ch3_shifts.kv 11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
ffa_ch3_shifts.kv 12 -- continue doing so for the indefinite future. In any case, please --
ffa_ch3_shifts.kv 13 -- always : read and understand any software ; verify any PGP signatures --
ffa_ch3_shifts.kv 14 -- that you use - for any purpose. --
ffa_ch3_shifts.kv 15 -- --
ffa_ch3_shifts.kv 16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
ffa_ch3_shifts.kv 17 ------------------------------------------------------------------------------
ffa_ch3_shifts.kv 18 ------------------------------------------------------------------------------
ffa_ch3_shifts.kv 19
ffa_ch3_shifts.kv 20 with W_Shifts; use W_Shifts;
ffa_ch3_shifts.kv 21
ffa_ch3_shifts.kv 22
ffa_ch3_shifts.kv 23 package body FZ_Shift is
ffa_ch3_shifts.kv 24
ffa_ch3_shifts.kv 25 --------------------------------------------------------------
ffa_ch3_shifts.kv 26 -- Shift Right
ffa_ch3_shifts.kv 27 --------------------------------------------------------------
ffa_ch3_shifts.kv 28
ffa_ch3_shifts.kv 29 -- ShiftedN := N >> Count (with Overflow Input and Output)
ffa_ch14_barrett.kv 30 -- WARNING: OF_in MUST be of valid bit-width for the shift!
ffa_ch3_shifts.kv 31 procedure FZ_ShiftRight_O_I(N : in FZ;
ffa_ch3_shifts.kv 32 ShiftedN : out FZ;
ffa_ch3_shifts.kv 33 Count : in WBit_Index;
ffa_ch3_shifts.kv 34 Overflow : out Word;
ffa_ch3_shifts.kv 35 OF_in : in Word) is
ffa_ch3_shifts.kv 36 Ni : Word;
ffa_ch3_shifts.kv 37 Carry : Word := OF_in;
ffa_ch3_shifts.kv 38 begin
ffa_ch3_shifts.kv 39 for i in reverse N'Range loop
ffa_ch3_shifts.kv 40 Ni := N(i);
ffa_ch3_shifts.kv 41 ShiftedN(i) := Shift_Right(Ni, Count) or Carry;
ffa_ch3_shifts.kv 42 Carry := Shift_Left(Ni, Bitness - Count);
ffa_ch3_shifts.kv 43 end loop;
ffa_ch3_shifts.kv 44 Overflow := Carry;
ffa_ch3_shifts.kv 45 end FZ_ShiftRight_O_I;
ffa_ch3_shifts.kv 46
ffa_ch3_shifts.kv 47
ffa_ch3_shifts.kv 48 -- ShiftedN := N >> Count (with Overflow Output only)
ffa_ch3_shifts.kv 49 procedure FZ_ShiftRight_O(N : in FZ;
ffa_ch3_shifts.kv 50 ShiftedN : out FZ;
ffa_ch3_shifts.kv 51 Count : in WBit_Index;
ffa_ch3_shifts.kv 52 Overflow : out Word) is
ffa_ch3_shifts.kv 53 begin
ffa_ch3_shifts.kv 54 FZ_ShiftRight_O_I(N, ShiftedN, Count, Overflow, 0);
ffa_ch3_shifts.kv 55 end FZ_ShiftRight_O;
ffa_ch3_shifts.kv 56
ffa_ch3_shifts.kv 57
ffa_ch3_shifts.kv 58 -- ShiftedN := N >> Count (no Overflow output or input)
ffa_ch3_shifts.kv 59 procedure FZ_ShiftRight(N : in FZ;
ffa_ch3_shifts.kv 60 ShiftedN : out FZ;
ffa_ch3_shifts.kv 61 Count : in WBit_Index) is
ffa_ch3_shifts.kv 62 Overflow : Word;
ffa_ch3_shifts.kv 63 pragma Unreferenced(Overflow);
ffa_ch3_shifts.kv 64 begin
ffa_ch3_shifts.kv 65 FZ_ShiftRight_O_I(N, ShiftedN, Count, Overflow, 0);
ffa_ch3_shifts.kv 66 end FZ_ShiftRight;
ffa_ch3_shifts.kv 67
ffa_ch3_shifts.kv 68 --------------------------------------------------------------
ffa_ch3_shifts.kv 69 -- Shift Left
ffa_ch3_shifts.kv 70 --------------------------------------------------------------
ffa_ch3_shifts.kv 71
ffa_ch3_shifts.kv 72 -- ShiftedN := N << Count (with Overflow Input and Output)
ffa_ch14_barrett.kv 73 -- WARNING: OF_in MUST be of valid bit-width for the shift!
ffa_ch3_shifts.kv 74 procedure FZ_ShiftLeft_O_I(N : in FZ;
ffa_ch3_shifts.kv 75 ShiftedN : out FZ;
ffa_ch3_shifts.kv 76 Count : in WBit_Index;
ffa_ch3_shifts.kv 77 Overflow : out Word;
ffa_ch3_shifts.kv 78 OF_in : in Word) is
ffa_ch3_shifts.kv 79 Ni : Word;
ffa_ch3_shifts.kv 80 Carry : Word := OF_in;
ffa_ch3_shifts.kv 81 begin
ffa_ch3_shifts.kv 82 for i in N'Range loop
ffa_ch3_shifts.kv 83 Ni := N(i);
ffa_ch3_shifts.kv 84 ShiftedN(i) := Shift_Left(Ni, Count) or Carry;
ffa_ch3_shifts.kv 85 Carry := Shift_Right(Ni, Bitness - Count);
ffa_ch3_shifts.kv 86 end loop;
ffa_ch3_shifts.kv 87 Overflow := Carry;
ffa_ch3_shifts.kv 88 end FZ_ShiftLeft_O_I;
ffa_ch3_shifts.kv 89
ffa_ch3_shifts.kv 90
ffa_ch3_shifts.kv 91 -- ShiftedN := N << Count (with Overflow Output only)
ffa_ch3_shifts.kv 92 procedure FZ_ShiftLeft_O(N : in FZ;
ffa_ch3_shifts.kv 93 ShiftedN : out FZ;
ffa_ch3_shifts.kv 94 Count : in WBit_Index;
ffa_ch3_shifts.kv 95 Overflow : out Word) is
ffa_ch3_shifts.kv 96 begin
ffa_ch3_shifts.kv 97 FZ_ShiftLeft_O_I(N, ShiftedN, Count, Overflow, 0);
ffa_ch3_shifts.kv 98 end FZ_ShiftLeft_O;
ffa_ch3_shifts.kv 99
ffa_ch3_shifts.kv 100
ffa_ch3_shifts.kv 101 -- ShiftedN := N << Count (no Overflow output or input)
ffa_ch3_shifts.kv 102 procedure FZ_ShiftLeft(N : in FZ;
ffa_ch3_shifts.kv 103 ShiftedN : out FZ;
ffa_ch3_shifts.kv 104 Count : in WBit_Index) is
ffa_ch3_shifts.kv 105 Overflow : Word;
ffa_ch3_shifts.kv 106 pragma Unreferenced(Overflow);
ffa_ch3_shifts.kv 107 begin
ffa_ch3_shifts.kv 108 FZ_ShiftLeft_O_I(N, ShiftedN, Count, Overflow, 0);
ffa_ch3_shifts.kv 109 end FZ_ShiftLeft;
ffa_ch3_shifts.kv 110
ffa_ch3_shifts.kv 111 end FZ_Shift;