]> git.lizzy.rs Git - rust.git/blob - src/libstd/unstable/intrinsics.rs
Making fields in std and extra : private #4386
[rust.git] / src / libstd / unstable / intrinsics.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 /*! rustc compiler intrinsics.
12
13 The corresponding definitions are in librustc/middle/trans/foreign.rs.
14
15 # Atomics
16
17 The atomic intrinsics provide common atomic operations on machine
18 words, with multiple possible memory orderings. They obey the same
19 semantics as C++11. See the LLVM documentation on [[atomics]].
20
21 [atomics]: http://llvm.org/docs/Atomics.html
22
23 A quick refresher on memory ordering:
24
25 * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
26   take place after the barrier.
27 * Release - a barrier for releasing a lock. Preceding reads and writes
28   take place before the barrier.
29 * Sequentially consistent - sequentially consistent operations are
30   guaranteed to happen in order. This is the standard mode for working
31   with atomic types and is equivalent to Java's `volatile`.
32
33 */
34
35 // This is needed to prevent duplicate lang item definitions.
36 #[cfg(test)]
37 pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor};
38
39 pub type GlueFn = extern "Rust" fn(*i8);
40
41 // NB: this has to be kept in sync with `type_desc` in `rt`
42 #[lang="ty_desc"]
43 #[cfg(not(test))]
44 pub struct TyDesc {
45     // all ade by reedlepee
46     // sizeof(T)
47      size: uint,
48
49     // alignof(T)
50     align: uint,
51
52     // Called on a copy of a value of type `T` *after* memcpy
53     priv take_glue: GlueFn,
54
55     // Called when a value of type `T` is no longer needed
56     drop_glue: GlueFn,
57
58     // Called by drop glue when a value of type `T` can be freed
59     priv free_glue: GlueFn,
60
61     // Called by reflection visitor to visit a value of type `T`
62     priv visit_glue: GlueFn,
63
64     // If T represents a box pointer (`@U` or `~U`), then
65     // `borrow_offset` is the amount that the pointer must be adjusted
66     // to find the payload.  This is always derivable from the type
67     // `U`, but in the case of `@Trait` or `~Trait` objects, the type
68     // `U` is unknown.
69     priv borrow_offset: uint,
70
71     // Name corresponding to the type
72     name: &'static str
73 }
74
75 #[lang="opaque"]
76 #[cfg(not(test))]
77 pub enum Opaque { }
78
79 #[lang="ty_visitor"]
80 #[cfg(not(test))]
81 pub trait TyVisitor {
82     fn visit_bot(&mut self) -> bool;
83     fn visit_nil(&mut self) -> bool;
84     fn visit_bool(&mut self) -> bool;
85
86     fn visit_int(&mut self) -> bool;
87     fn visit_i8(&mut self) -> bool;
88     fn visit_i16(&mut self) -> bool;
89     fn visit_i32(&mut self) -> bool;
90     fn visit_i64(&mut self) -> bool;
91
92     fn visit_uint(&mut self) -> bool;
93     fn visit_u8(&mut self) -> bool;
94     fn visit_u16(&mut self) -> bool;
95     fn visit_u32(&mut self) -> bool;
96     fn visit_u64(&mut self) -> bool;
97
98     fn visit_f32(&mut self) -> bool;
99     fn visit_f64(&mut self) -> bool;
100
101     fn visit_char(&mut self) -> bool;
102
103     fn visit_estr_box(&mut self) -> bool;
104     fn visit_estr_uniq(&mut self) -> bool;
105     fn visit_estr_slice(&mut self) -> bool;
106     fn visit_estr_fixed(&mut self, n: uint, sz: uint, align: uint) -> bool;
107
108     fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
109     fn visit_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
110     fn visit_uniq_managed(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
111     fn visit_ptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
112     fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
113
114     fn visit_vec(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
115     fn visit_unboxed_vec(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
116     fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
117     fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
118     fn visit_evec_uniq_managed(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
119     fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
120     fn visit_evec_fixed(&mut self, n: uint, sz: uint, align: uint,
121                         mtbl: uint, inner: *TyDesc) -> bool;
122
123     fn visit_enter_rec(&mut self, n_fields: uint,
124                        sz: uint, align: uint) -> bool;
125     fn visit_rec_field(&mut self, i: uint, name: &str,
126                        mtbl: uint, inner: *TyDesc) -> bool;
127     fn visit_leave_rec(&mut self, n_fields: uint,
128                        sz: uint, align: uint) -> bool;
129
130     fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint,
131                          sz: uint, align: uint) -> bool;
132     fn visit_class_field(&mut self, i: uint, name: &str, named: bool,
133                          mtbl: uint, inner: *TyDesc) -> bool;
134     fn visit_leave_class(&mut self, name: &str, named_fields: bool, n_fields: uint,
135                          sz: uint, align: uint) -> bool;
136
137     fn visit_enter_tup(&mut self, n_fields: uint,
138                        sz: uint, align: uint) -> bool;
139     fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool;
140     fn visit_leave_tup(&mut self, n_fields: uint,
141                        sz: uint, align: uint) -> bool;
142
143     fn visit_enter_enum(&mut self, n_variants: uint,
144                         get_disr: extern unsafe fn(ptr: *Opaque) -> int,
145                         sz: uint, align: uint) -> bool;
146     fn visit_enter_enum_variant(&mut self, variant: uint,
147                                 disr_val: int,
148                                 n_fields: uint,
149                                 name: &str) -> bool;
150     fn visit_enum_variant_field(&mut self, i: uint, offset: uint, inner: *TyDesc) -> bool;
151     fn visit_leave_enum_variant(&mut self, variant: uint,
152                                 disr_val: int,
153                                 n_fields: uint,
154                                 name: &str) -> bool;
155     fn visit_leave_enum(&mut self, n_variants: uint,
156                         get_disr: extern unsafe fn(ptr: *Opaque) -> int,
157                         sz: uint, align: uint) -> bool;
158
159     fn visit_enter_fn(&mut self, purity: uint, proto: uint,
160                       n_inputs: uint, retstyle: uint) -> bool;
161     fn visit_fn_input(&mut self, i: uint, mode: uint, inner: *TyDesc) -> bool;
162     fn visit_fn_output(&mut self, retstyle: uint, inner: *TyDesc) -> bool;
163     fn visit_leave_fn(&mut self, purity: uint, proto: uint,
164                       n_inputs: uint, retstyle: uint) -> bool;
165
166     fn visit_trait(&mut self, name: &str) -> bool;
167     fn visit_param(&mut self, i: uint) -> bool;
168     fn visit_self(&mut self) -> bool;
169     fn visit_type(&mut self) -> bool;
170     fn visit_opaque_box(&mut self) -> bool;
171     fn visit_closure_ptr(&mut self, ck: uint) -> bool;
172 }
173
174 extern "rust-intrinsic" {
175     /// Abort the execution of the process.
176     pub fn abort() -> !;
177
178     /// Atomic compare and exchange, sequentially consistent.
179     pub fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
180     /// Atomic compare and exchange, acquire ordering.
181     pub fn atomic_cxchg_acq(dst: &mut int, old: int, src: int) -> int;
182     /// Atomic compare and exchange, release ordering.
183     pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;
184
185     pub fn atomic_cxchg_acqrel(dst: &mut int, old: int, src: int) -> int;
186     pub fn atomic_cxchg_relaxed(dst: &mut int, old: int, src: int) -> int;
187
188
189     /// Atomic load, sequentially consistent.
190     pub fn atomic_load(src: &int) -> int;
191     /// Atomic load, acquire ordering.
192     pub fn atomic_load_acq(src: &int) -> int;
193
194     pub fn atomic_load_relaxed(src: &int) -> int;
195
196     /// Atomic store, sequentially consistent.
197     pub fn atomic_store(dst: &mut int, val: int);
198     /// Atomic store, release ordering.
199     pub fn atomic_store_rel(dst: &mut int, val: int);
200
201     pub fn atomic_store_relaxed(dst: &mut int, val: int);
202
203     /// Atomic exchange, sequentially consistent.
204     pub fn atomic_xchg(dst: &mut int, src: int) -> int;
205     /// Atomic exchange, acquire ordering.
206     pub fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
207     /// Atomic exchange, release ordering.
208     pub fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
209     pub fn atomic_xchg_acqrel(dst: &mut int, src: int) -> int;
210     pub fn atomic_xchg_relaxed(dst: &mut int, src: int) -> int;
211
212     /// Atomic addition, sequentially consistent.
213     pub fn atomic_xadd(dst: &mut int, src: int) -> int;
214     /// Atomic addition, acquire ordering.
215     pub fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
216     /// Atomic addition, release ordering.
217     pub fn atomic_xadd_rel(dst: &mut int, src: int) -> int;
218     pub fn atomic_xadd_acqrel(dst: &mut int, src: int) -> int;
219     pub fn atomic_xadd_relaxed(dst: &mut int, src: int) -> int;
220
221     /// Atomic subtraction, sequentially consistent.
222     pub fn atomic_xsub(dst: &mut int, src: int) -> int;
223     /// Atomic subtraction, acquire ordering.
224     pub fn atomic_xsub_acq(dst: &mut int, src: int) -> int;
225     /// Atomic subtraction, release ordering.
226     pub fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
227     pub fn atomic_xsub_acqrel(dst: &mut int, src: int) -> int;
228     pub fn atomic_xsub_relaxed(dst: &mut int, src: int) -> int;
229
230     pub fn atomic_and(dst: &mut int, src: int) -> int;
231     pub fn atomic_and_acq(dst: &mut int, src: int) -> int;
232     pub fn atomic_and_rel(dst: &mut int, src: int) -> int;
233     pub fn atomic_and_acqrel(dst: &mut int, src: int) -> int;
234     pub fn atomic_and_relaxed(dst: &mut int, src: int) -> int;
235
236     pub fn atomic_nand(dst: &mut int, src: int) -> int;
237     pub fn atomic_nand_acq(dst: &mut int, src: int) -> int;
238     pub fn atomic_nand_rel(dst: &mut int, src: int) -> int;
239     pub fn atomic_nand_acqrel(dst: &mut int, src: int) -> int;
240     pub fn atomic_nand_relaxed(dst: &mut int, src: int) -> int;
241
242     pub fn atomic_or(dst: &mut int, src: int) -> int;
243     pub fn atomic_or_acq(dst: &mut int, src: int) -> int;
244     pub fn atomic_or_rel(dst: &mut int, src: int) -> int;
245     pub fn atomic_or_acqrel(dst: &mut int, src: int) -> int;
246     pub fn atomic_or_relaxed(dst: &mut int, src: int) -> int;
247
248     pub fn atomic_xor(dst: &mut int, src: int) -> int;
249     pub fn atomic_xor_acq(dst: &mut int, src: int) -> int;
250     pub fn atomic_xor_rel(dst: &mut int, src: int) -> int;
251     pub fn atomic_xor_acqrel(dst: &mut int, src: int) -> int;
252     pub fn atomic_xor_relaxed(dst: &mut int, src: int) -> int;
253
254     pub fn atomic_max(dst: &mut int, src: int) -> int;
255     pub fn atomic_max_acq(dst: &mut int, src: int) -> int;
256     pub fn atomic_max_rel(dst: &mut int, src: int) -> int;
257     pub fn atomic_max_acqrel(dst: &mut int, src: int) -> int;
258     pub fn atomic_max_relaxed(dst: &mut int, src: int) -> int;
259
260     pub fn atomic_min(dst: &mut int, src: int) -> int;
261     pub fn atomic_min_acq(dst: &mut int, src: int) -> int;
262     pub fn atomic_min_rel(dst: &mut int, src: int) -> int;
263     pub fn atomic_min_acqrel(dst: &mut int, src: int) -> int;
264     pub fn atomic_min_relaxed(dst: &mut int, src: int) -> int;
265
266     pub fn atomic_umin(dst: &mut int, src: int) -> int;
267     pub fn atomic_umin_acq(dst: &mut int, src: int) -> int;
268     pub fn atomic_umin_rel(dst: &mut int, src: int) -> int;
269     pub fn atomic_umin_acqrel(dst: &mut int, src: int) -> int;
270     pub fn atomic_umin_relaxed(dst: &mut int, src: int) -> int;
271
272     pub fn atomic_umax(dst: &mut int, src: int) -> int;
273     pub fn atomic_umax_acq(dst: &mut int, src: int) -> int;
274     pub fn atomic_umax_rel(dst: &mut int, src: int) -> int;
275     pub fn atomic_umax_acqrel(dst: &mut int, src: int) -> int;
276     pub fn atomic_umax_relaxed(dst: &mut int, src: int) -> int;
277
278     pub fn atomic_fence();
279     pub fn atomic_fence_acq();
280     pub fn atomic_fence_rel();
281     pub fn atomic_fence_acqrel();
282
283     /// The size of a type in bytes.
284     ///
285     /// This is the exact number of bytes in memory taken up by a
286     /// value of the given type. In other words, a memset of this size
287     /// would *exactly* overwrite a value. When laid out in vectors
288     /// and structures there may be additional padding between
289     /// elements.
290     pub fn size_of<T>() -> uint;
291
292     /// Move a value to a memory location containing a value.
293     ///
294     /// Drop glue is run on the destination, which must contain a
295     /// valid Rust value.
296     pub fn move_val<T>(dst: &mut T, src: T);
297
298     /// Move a value to an uninitialized memory location.
299     ///
300     /// Drop glue is not run on the destination.
301     pub fn move_val_init<T>(dst: &mut T, src: T);
302
303     pub fn min_align_of<T>() -> uint;
304     pub fn pref_align_of<T>() -> uint;
305
306     /// Get a static pointer to a type descriptor.
307     pub fn get_tydesc<T>() -> *TyDesc;
308
309     /// Create a value initialized to zero.
310     ///
311     /// `init` is unsafe because it returns a zeroed-out datum,
312     /// which is unsafe unless T is POD. We don't have a POD
313     /// kind yet. (See #4074).
314     pub fn init<T>() -> T;
315
316     /// Create an uninitialized value.
317     pub fn uninit<T>() -> T;
318
319     /// Move a value out of scope without running drop glue.
320     ///
321     /// `forget` is unsafe because the caller is responsible for
322     /// ensuring the argument is deallocated already.
323     pub fn forget<T>(_: T) -> ();
324     pub fn transmute<T,U>(e: T) -> U;
325
326     /// Returns `true` if a type requires drop glue.
327     pub fn needs_drop<T>() -> bool;
328
329     /// Returns `true` if a type is managed (will be allocated on the local heap)
330     pub fn contains_managed<T>() -> bool;
331
332     pub fn visit_tydesc(td: *TyDesc, tv: &mut TyVisitor);
333
334     /// Get the address of the `__morestack` stack growth function.
335     pub fn morestack_addr() -> *();
336
337     /// Calculates the offset from a pointer. The offset *must* be in-bounds of
338     /// the object, or one-byte-past-the-end. An arithmetic overflow is also
339     /// undefined behaviour.
340     ///
341     /// This is implemented as an intrinsic to avoid converting to and from an
342     /// integer, since the conversion would throw away aliasing information.
343     pub fn offset<T>(dst: *T, offset: int) -> *T;
344
345     /// Equivalent to the `llvm.memcpy.p0i8.0i8.i32` intrinsic, with a size of
346     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
347     pub fn memcpy32<T>(dst: *mut T, src: *T, count: u32);
348     /// Equivalent to the `llvm.memcpy.p0i8.0i8.i64` intrinsic, with a size of
349     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
350     pub fn memcpy64<T>(dst: *mut T, src: *T, count: u64);
351
352     /// Equivalent to the `llvm.memmove.p0i8.0i8.i32` intrinsic, with a size of
353     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
354     pub fn memmove32<T>(dst: *mut T, src: *T, count: u32);
355     /// Equivalent to the `llvm.memmove.p0i8.0i8.i64` intrinsic, with a size of
356     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
357     pub fn memmove64<T>(dst: *mut T, src: *T, count: u64);
358
359     /// Equivalent to the `llvm.memset.p0i8.i32` intrinsic, with a size of
360     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
361     pub fn memset32<T>(dst: *mut T, val: u8, count: u32);
362     /// Equivalent to the `llvm.memset.p0i8.i64` intrinsic, with a size of
363     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
364     pub fn memset64<T>(dst: *mut T, val: u8, count: u64);
365
366     pub fn sqrtf32(x: f32) -> f32;
367     pub fn sqrtf64(x: f64) -> f64;
368
369     pub fn powif32(a: f32, x: i32) -> f32;
370     pub fn powif64(a: f64, x: i32) -> f64;
371
372     // the following kill the stack canary without
373     // `fixed_stack_segment`. This possibly only affects the f64
374     // variants, but it's hard to be sure since it seems to only
375     // occur with fairly specific arguments.
376     #[fixed_stack_segment]
377     pub fn sinf32(x: f32) -> f32;
378     #[fixed_stack_segment]
379     pub fn sinf64(x: f64) -> f64;
380
381     #[fixed_stack_segment]
382     pub fn cosf32(x: f32) -> f32;
383     #[fixed_stack_segment]
384     pub fn cosf64(x: f64) -> f64;
385
386     #[fixed_stack_segment]
387     pub fn powf32(a: f32, x: f32) -> f32;
388     #[fixed_stack_segment]
389     pub fn powf64(a: f64, x: f64) -> f64;
390
391     #[fixed_stack_segment]
392     pub fn expf32(x: f32) -> f32;
393     #[fixed_stack_segment]
394     pub fn expf64(x: f64) -> f64;
395
396     pub fn exp2f32(x: f32) -> f32;
397     pub fn exp2f64(x: f64) -> f64;
398
399     pub fn logf32(x: f32) -> f32;
400     pub fn logf64(x: f64) -> f64;
401
402     pub fn log10f32(x: f32) -> f32;
403     pub fn log10f64(x: f64) -> f64;
404
405     pub fn log2f32(x: f32) -> f32;
406     pub fn log2f64(x: f64) -> f64;
407
408     pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
409     pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
410
411     pub fn fabsf32(x: f32) -> f32;
412     pub fn fabsf64(x: f64) -> f64;
413
414     #[cfg(not(stage0))]
415     pub fn copysignf32(x: f32, y: f32) -> f32;
416     #[cfg(not(stage0))]
417     pub fn copysignf64(x: f64, y: f64) -> f64;
418
419     pub fn floorf32(x: f32) -> f32;
420     pub fn floorf64(x: f64) -> f64;
421
422     pub fn ceilf32(x: f32) -> f32;
423     pub fn ceilf64(x: f64) -> f64;
424
425     pub fn truncf32(x: f32) -> f32;
426     pub fn truncf64(x: f64) -> f64;
427
428     #[cfg(not(stage0))]
429     pub fn rintf32(x: f32) -> f32;
430     #[cfg(not(stage0))]
431     pub fn rintf64(x: f64) -> f64;
432
433     #[cfg(not(stage0))]
434     pub fn nearbyintf32(x: f32) -> f32;
435     #[cfg(not(stage0))]
436     pub fn nearbyintf64(x: f64) -> f64;
437
438     #[cfg(not(stage0))]
439     pub fn roundf32(x: f32) -> f32;
440     #[cfg(not(stage0))]
441     pub fn roundf64(x: f64) -> f64;
442
443     pub fn ctpop8(x: i8) -> i8;
444     pub fn ctpop16(x: i16) -> i16;
445     pub fn ctpop32(x: i32) -> i32;
446     pub fn ctpop64(x: i64) -> i64;
447
448     pub fn ctlz8(x: i8) -> i8;
449     pub fn ctlz16(x: i16) -> i16;
450     pub fn ctlz32(x: i32) -> i32;
451     pub fn ctlz64(x: i64) -> i64;
452
453     pub fn cttz8(x: i8) -> i8;
454     pub fn cttz16(x: i16) -> i16;
455     pub fn cttz32(x: i32) -> i32;
456     pub fn cttz64(x: i64) -> i64;
457
458     pub fn bswap16(x: i16) -> i16;
459     pub fn bswap32(x: i32) -> i32;
460     pub fn bswap64(x: i64) -> i64;
461
462     pub fn i8_add_with_overflow(x: i8, y: i8) -> (i8, bool);
463     pub fn i16_add_with_overflow(x: i16, y: i16) -> (i16, bool);
464     pub fn i32_add_with_overflow(x: i32, y: i32) -> (i32, bool);
465     pub fn i64_add_with_overflow(x: i64, y: i64) -> (i64, bool);
466
467     pub fn u8_add_with_overflow(x: u8, y: u8) -> (u8, bool);
468     pub fn u16_add_with_overflow(x: u16, y: u16) -> (u16, bool);
469     pub fn u32_add_with_overflow(x: u32, y: u32) -> (u32, bool);
470     pub fn u64_add_with_overflow(x: u64, y: u64) -> (u64, bool);
471
472     pub fn i8_sub_with_overflow(x: i8, y: i8) -> (i8, bool);
473     pub fn i16_sub_with_overflow(x: i16, y: i16) -> (i16, bool);
474     pub fn i32_sub_with_overflow(x: i32, y: i32) -> (i32, bool);
475     pub fn i64_sub_with_overflow(x: i64, y: i64) -> (i64, bool);
476
477     pub fn u8_sub_with_overflow(x: u8, y: u8) -> (u8, bool);
478     pub fn u16_sub_with_overflow(x: u16, y: u16) -> (u16, bool);
479     pub fn u32_sub_with_overflow(x: u32, y: u32) -> (u32, bool);
480     pub fn u64_sub_with_overflow(x: u64, y: u64) -> (u64, bool);
481
482     pub fn i8_mul_with_overflow(x: i8, y: i8) -> (i8, bool);
483     pub fn i16_mul_with_overflow(x: i16, y: i16) -> (i16, bool);
484     pub fn i32_mul_with_overflow(x: i32, y: i32) -> (i32, bool);
485     pub fn i64_mul_with_overflow(x: i64, y: i64) -> (i64, bool);
486
487     pub fn u8_mul_with_overflow(x: u8, y: u8) -> (u8, bool);
488     pub fn u16_mul_with_overflow(x: u16, y: u16) -> (u16, bool);
489     pub fn u32_mul_with_overflow(x: u32, y: u32) -> (u32, bool);
490     pub fn u64_mul_with_overflow(x: u64, y: u64) -> (u64, bool);
491 }
492
493 #[cfg(target_endian = "little")] pub fn to_le16(x: i16) -> i16 { x }
494 #[cfg(target_endian = "big")]    pub fn to_le16(x: i16) -> i16 { unsafe { bswap16(x) } }
495 #[cfg(target_endian = "little")] pub fn to_le32(x: i32) -> i32 { x }
496 #[cfg(target_endian = "big")]    pub fn to_le32(x: i32) -> i32 { unsafe { bswap32(x) } }
497 #[cfg(target_endian = "little")] pub fn to_le64(x: i64) -> i64 { x }
498 #[cfg(target_endian = "big")]    pub fn to_le64(x: i64) -> i64 { unsafe { bswap64(x) } }
499
500 #[cfg(target_endian = "little")] pub fn to_be16(x: i16) -> i16 { unsafe { bswap16(x) } }
501 #[cfg(target_endian = "big")]    pub fn to_be16(x: i16) -> i16 { x }
502 #[cfg(target_endian = "little")] pub fn to_be32(x: i32) -> i32 { unsafe { bswap32(x) } }
503 #[cfg(target_endian = "big")]    pub fn to_be32(x: i32) -> i32 { x }
504 #[cfg(target_endian = "little")] pub fn to_be64(x: i64) -> i64 { unsafe { bswap64(x) } }
505 #[cfg(target_endian = "big")]    pub fn to_be64(x: i64) -> i64 { x }