forked from jocelyn/eel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray_facilities.e
executable file
·148 lines (140 loc) · 6.23 KB
/
array_facilities.e
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
note
description: "Summary description for {ARRAY_FACILITIES}."
author: "Colin LeMahieu"
date: "$Date$"
revision: "$Revision$"
quote: "The human race divides politically into those who want people to be controlled and those who have no such desire. - Robert A. Heinlein"
deferred class
ARRAY_FACILITIES
feature {ARRAY_FACILITIES} -- Array manipulation
array_xor (source_1: SPECIAL [NATURAL_8] source_1_offset: INTEGER_32 source_2: SPECIAL [NATURAL_8] source_2_offset: INTEGER_32 destination: SPECIAL [NATURAL_8] destination_offset: INTEGER_32 count: INTEGER_32)
require
source_1.valid_index (source_1_offset)
source_2.valid_index (source_2_offset)
destination.valid_index (destination_offset)
source_1.valid_index (source_1_offset + count - 1)
source_2.valid_index (source_2_offset + count - 1)
destination.valid_index (destination_offset + count - 1)
local
counter: INTEGER_32
do
from
counter := count
until
counter = 0
loop
destination [destination_offset + counter - 1] := source_1 [source_1_offset + counter - 1].bit_xor (source_2 [source_2_offset + counter - 1])
counter := counter - 1
variant
counter + 1
end
end
feature {ARRAY_FACILITIES} -- Big endian NATURAL_32
from_natural_32_be (source: NATURAL_32 target: SPECIAL [NATURAL_8] offset: INTEGER_32)
require
valid_start: target.valid_index (offset)
valid_end: target.valid_index (offset + 3)
do
target [offset] := (source |>> 24).to_natural_8
target [offset + 1] := (source |>> 16).to_natural_8
target [offset + 2] := (source |>> 8).to_natural_8
target [offset + 3] := source.to_natural_8
ensure
byte_0: target [offset] = (source |>> 24).to_natural_8
byte_1: target [offset + 1] = (source |>> 16).to_natural_8
byte_2: target [offset + 2] = (source |>> 8).to_natural_8
byte_3: target [offset + 3] = source.to_natural_8
end
as_natural_32_be (source: SPECIAL [NATURAL_8] offset: INTEGER_32): NATURAL_32
require
valid_start: source.valid_index (offset)
valid_end: source.valid_index (offset + 3)
do
result := source [offset].to_natural_32 |<< 24
result := result | (source [offset + 1].to_natural_32 |<< 16)
result := result | (source [offset + 2].to_natural_32 |<< 8)
result := result | source [offset + 3].to_natural_32
ensure
byte_0: source [offset] = (result |>> 24).to_natural_8
byte_1: source [offset + 1] = (result |>> 16).to_natural_8
byte_2: source [offset + 2] = (result |>> 8).to_natural_8
byte_3: source [offset + 3] = result.to_natural_8
end
from_natural_32_le (source: NATURAL_32 target: SPECIAL [NATURAL_8] offset: INTEGER_32)
require
valid_start: target.valid_index (offset)
valid_end: target.valid_index (offset + 3)
do
target [offset] := source.to_natural_8
target [offset + 1] := (source |>> 8).to_natural_8
target [offset + 2] := (source |>> 16).to_natural_8
target [offset + 3] := (source |>> 24).to_natural_8
ensure
byte_0: target [offset] = source.to_natural_8
byte_1: target [offset + 1] = (source |>> 8).to_natural_8
byte_2: target [offset + 2] = (source |>> 16).to_natural_8
byte_3: target [offset + 3] = (source |>> 24).to_natural_8
end
as_natural_32_le (source: SPECIAL [NATURAL_8] offset: INTEGER_32): NATURAL_32
require
valid_start: source.valid_index (offset)
valid_end: source.valid_index (offset + 3)
do
result := source [offset].to_natural_32
result := result | (source [offset + 1].to_natural_32 |<< 8)
result := result | (source [offset + 2].to_natural_32 |<< 16)
result := result | (source [offset + 3].to_natural_32 |<< 24)
ensure
byte_0: source [offset] = result.to_natural_8
byte_1: source [offset + 1] = (result |>> 8).to_natural_8
byte_2: source [offset + 2] = (result |>> 16).to_natural_8
byte_3: source [offset + 3] = (result |>> 24).to_natural_8
end
feature {ARRAY_FACILITIES} -- Big endian NATURAL_64
from_natural_64_be (source: NATURAL_64 target: SPECIAL [NATURAL_8] offset: INTEGER_32)
require
valid_start: target.valid_index (offset)
valid_end: target.valid_index (offset + 7)
do
target [offset] := (source |>> 56).to_natural_8
target [offset + 1] := (source |>> 48).to_natural_8
target [offset + 2] := (source |>> 40).to_natural_8
target [offset + 3] := (source |>> 32).to_natural_8
target [offset + 4] := (source |>> 24).to_natural_8
target [offset + 5] := (source |>> 16).to_natural_8
target [offset + 6] := (source |>> 8).to_natural_8
target [offset + 7] := source.to_natural_8
ensure
byte_0: target [offset] = (source |>> 56).to_natural_8
byte_1: target [offset + 1] = (source |>> 48).to_natural_8
byte_2: target [offset + 2] = (source |>> 40).to_natural_8
byte_3: target [offset + 3] = (source |>> 32).to_natural_8
byte_4: target [offset + 4] = (source |>> 24).to_natural_8
byte_5: target [offset + 5] = (source |>> 16).to_natural_8
byte_6: target [offset + 6] = (source |>> 8).to_natural_8
byte_7: target [offset + 7] = source.to_natural_8
end
as_natural_64_be (source: SPECIAL [NATURAL_8] offset: INTEGER_32): NATURAL_64
require
valid_start: source.valid_index (offset)
valid_end: source.valid_index (offset + 7)
do
result := source [offset].to_natural_32 |<< 56
result := result | (source [offset + 1].to_natural_32 |<< 48)
result := result | (source [offset + 2].to_natural_32 |<< 40)
result := result | (source [offset + 3].to_natural_32 |<< 32)
result := result | (source [offset + 4].to_natural_32 |<< 24)
result := result | (source [offset + 5].to_natural_32 |<< 16)
result := result | (source [offset + 6].to_natural_32 |<< 8)
result := result | source [offset + 7].to_natural_32
ensure
byte_0: source [offset] = (result |>> 56).to_natural_8
byte_1: source [offset + 1] = (result |>> 48).to_natural_8
byte_2: source [offset + 2] = (result |>> 40).to_natural_8
byte_3: source [offset + 3] = (result |>> 32).to_natural_8
byte_4: source [offset + 4] = (result |>> 24).to_natural_8
byte_5: source [offset + 5] = (result |>> 16).to_natural_8
byte_6: source [offset + 6] = (result |>> 8).to_natural_8
byte_7: source [offset + 7] = result.to_natural_8
end
end