@@ -73,6 +73,22 @@ CAMLprim value caml_floatarray_get(value array, value index)
73
73
return res ;
74
74
}
75
75
76
+ /* [ floatarray -> int -> local_ float ] */
77
+ CAMLprim value caml_floatarray_get_local (value array , value index )
78
+ {
79
+ intnat idx = Long_val (index );
80
+ double d ;
81
+ value res ;
82
+
83
+ CAMLassert (Tag_val (array ) == Double_array_tag );
84
+ if (idx < 0 || idx >= Wosize_val (array ) / Double_wosize )
85
+ caml_array_bound_error ();
86
+ d = Double_flat_field (array , idx );
87
+ res = caml_alloc_local (Double_wosize , Double_tag );
88
+ Store_double_val (res , d );
89
+ return res ;
90
+ }
91
+
76
92
/* [ 'a array -> int -> 'a ] */
77
93
CAMLprim value caml_array_get (value array , value index )
78
94
{
@@ -85,6 +101,18 @@ CAMLprim value caml_array_get(value array, value index)
85
101
return caml_array_get_addr (array , index );
86
102
}
87
103
104
+ /* [ local_ 'a array -> int -> local_ 'a ] */
105
+ CAMLprim value caml_array_get_local (value array , value index )
106
+ {
107
+ #ifdef FLAT_FLOAT_ARRAY
108
+ if (Tag_val (array ) == Double_array_tag )
109
+ return caml_floatarray_get_local (array , index );
110
+ #else
111
+ CAMLassert (Tag_val (array ) != Double_array_tag );
112
+ #endif
113
+ return caml_array_get_addr (array , index );
114
+ }
115
+
88
116
/* [ 'a array -> int -> 'a -> unit ] where 'a != float */
89
117
CAMLprim value caml_array_set_addr (value array , value index , value newval )
90
118
{
@@ -94,7 +122,20 @@ CAMLprim value caml_array_set_addr(value array, value index, value newval)
94
122
return Val_unit ;
95
123
}
96
124
97
- /* [ floatarray -> int -> float -> unit ] */
125
+ /* [ local_ 'a array -> int -> local_ 'a -> unit ] where 'a != float
126
+
127
+ Must be used carefully, as it can violate the "no forward pointers"
128
+ restriction on the local stack. */
129
+ CAMLprim value caml_array_set_addr_local (value array , value index , value newval )
130
+ {
131
+ intnat idx = Long_val (index );
132
+ if (idx < 0 || idx >= Wosize_val (array )) caml_array_bound_error ();
133
+ caml_modify_local (array , idx , newval );
134
+ return Val_unit ;
135
+ }
136
+
137
+ /* [ floatarray -> int -> float -> unit ]
138
+ [ local_ floatarray -> int -> local_ float -> unit ] */
98
139
CAMLprim value caml_floatarray_set (value array , value index , value newval )
99
140
{
100
141
intnat idx = Long_val (index );
@@ -118,6 +159,22 @@ CAMLprim value caml_array_set(value array, value index, value newval)
118
159
return caml_array_set_addr (array , index , newval );
119
160
}
120
161
162
+ /* [ local_ 'a array -> int -> local_ 'a -> unit ]
163
+
164
+ Must be used carefully, as it can violate the "no forward pointers"
165
+ restriction on the local stack if the array contains pointers (vs. [int]s or
166
+ unboxed floats). */
167
+ CAMLprim value caml_array_set_local (value array , value index , value newval )
168
+ {
169
+ #ifdef FLAT_FLOAT_ARRAY
170
+ if (Tag_val (array ) == Double_array_tag )
171
+ return caml_floatarray_set (array , index , newval );
172
+ #else
173
+ CAMLassert (Tag_val (array ) != Double_array_tag );
174
+ #endif
175
+ return caml_array_set_addr_local (array , index , newval );
176
+ }
177
+
121
178
/* [ floatarray -> int -> float ] */
122
179
CAMLprim value caml_floatarray_unsafe_get (value array , value index )
123
180
{
@@ -132,6 +189,20 @@ CAMLprim value caml_floatarray_unsafe_get(value array, value index)
132
189
return res ;
133
190
}
134
191
192
+ /* [ floatarray -> int -> local_ float ] */
193
+ CAMLprim value caml_floatarray_unsafe_get_local (value array , value index )
194
+ {
195
+ intnat idx = Long_val (index );
196
+ double d ;
197
+ value res ;
198
+
199
+ CAMLassert (Tag_val (array ) == Double_array_tag );
200
+ d = Double_flat_field (array , idx );
201
+ res = caml_alloc_local (Double_wosize , Double_tag );
202
+ Store_double_val (res , d );
203
+ return res ;
204
+ }
205
+
135
206
/* [ 'a array -> int -> 'a ] */
136
207
CAMLprim value caml_array_unsafe_get (value array , value index )
137
208
{
@@ -144,6 +215,18 @@ CAMLprim value caml_array_unsafe_get(value array, value index)
144
215
return Field (array , Long_val (index ));
145
216
}
146
217
218
+ /* [ local_ 'a array -> int -> local_ 'a ] */
219
+ CAMLprim value caml_array_unsafe_get_local (value array , value index )
220
+ {
221
+ #ifdef FLAT_FLOAT_ARRAY
222
+ if (Tag_val (array ) == Double_array_tag )
223
+ return caml_floatarray_unsafe_get_local (array , index );
224
+ #else
225
+ CAMLassert (Tag_val (array ) != Double_array_tag );
226
+ #endif
227
+ return Field (array , Long_val (index ));
228
+ }
229
+
147
230
/* [ 'a array -> int -> 'a -> unit ] where 'a != float */
148
231
static value caml_array_unsafe_set_addr (value array , value index ,value newval )
149
232
{
@@ -152,7 +235,20 @@ static value caml_array_unsafe_set_addr(value array, value index,value newval)
152
235
return Val_unit ;
153
236
}
154
237
155
- /* [ floatarray -> int -> float -> unit ] */
238
+ /* [ local_ 'a array -> int -> local_ 'a -> unit ] where 'a != float
239
+
240
+ Must be used carefully, as it can violate the "no forward pointers"
241
+ restriction on the local stack. */
242
+ static value caml_array_unsafe_set_addr_local (value array , value index ,
243
+ value newval )
244
+ {
245
+ intnat idx = Long_val (index );
246
+ caml_modify_local (array , idx , newval );
247
+ return Val_unit ;
248
+ }
249
+
250
+ /* [ floatarray -> int -> float -> unit ]
251
+ [ local_ floatarray -> int -> local_ float -> unit ] */
156
252
/* [MM]: [caml_array_unsafe_set_addr] has a fence for enforcing the OCaml
157
253
memory model through its use of [caml_modify].
158
254
[MM] [TODO]: [caml_floatarray_unsafe_set] will also need a similar fence in
@@ -177,6 +273,23 @@ CAMLprim value caml_array_unsafe_set(value array, value index, value newval)
177
273
return caml_array_unsafe_set_addr (array , index , newval );
178
274
}
179
275
276
+ /* [ local_ 'a array -> int -> local_ 'a -> unit ]
277
+
278
+ Must be used carefully, as it can violate the "no forward pointers"
279
+ restriction on the local stack if the array contains pointers (vs. [int]s or
280
+ unboxed floats). */
281
+ CAMLprim value caml_array_unsafe_set_local (value array , value index ,
282
+ value newval )
283
+ {
284
+ #ifdef FLAT_FLOAT_ARRAY
285
+ if (Tag_val (array ) == Double_array_tag )
286
+ return caml_floatarray_unsafe_set (array , index , newval );
287
+ #else
288
+ CAMLassert (Tag_val (array ) != Double_array_tag );
289
+ #endif
290
+ return caml_array_unsafe_set_addr_local (array , index , newval );
291
+ }
292
+
180
293
/* [len] is a [value] representing number of floats. */
181
294
/* [ int -> floatarray ] */
182
295
CAMLprim value caml_floatarray_create (value len )
@@ -658,17 +771,12 @@ CAMLprim value caml_array_fill(value array,
658
771
return Val_unit ;
659
772
}
660
773
661
- /* Linker compatibility with stdlib externals
662
- CR ocaml 5 runtime: implement iarrays */
663
-
664
774
CAMLprim value caml_iarray_of_array (value a )
665
775
{
666
776
return a ;
667
777
}
668
778
669
- extern value caml_obj_dup (value );
670
-
671
779
CAMLprim value caml_array_of_iarray (value a )
672
780
{
673
- return caml_obj_dup ( a ) ;
781
+ return a ;
674
782
}
0 commit comments