Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to new to/from_bytes functions #146

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions input-generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(int_to_from_bytes)]

extern crate rand;

use std::collections::BTreeSet;
Expand Down Expand Up @@ -43,7 +45,7 @@ fn f32(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {

let mut f = File::create("bin/input/f32")?;
for i in set {
f.write_all(&i.to_bytes())?;
f.write_all(&i.to_ne_bytes())?;
}

Ok(())
Expand All @@ -61,8 +63,8 @@ fn f32f32(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
}

i += 1;
f.write_all(&x0.to_bits().to_bytes())?;
f.write_all(&x1.to_bits().to_bytes())?;
f.write_all(&x0.to_bits().to_ne_bytes())?;
f.write_all(&x1.to_bits().to_ne_bytes())?;
}

Ok(())
Expand All @@ -80,8 +82,8 @@ fn f32i16(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
}

i += 1;
f.write_all(&x0.to_bits().to_bytes())?;
f.write_all(&x1.to_bytes())?;
f.write_all(&x0.to_bits().to_ne_bytes())?;
f.write_all(&x1.to_ne_bytes())?;
}

Ok(())
Expand All @@ -100,9 +102,9 @@ fn f32f32f32(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
}

i += 1;
f.write_all(&x0.to_bits().to_bytes())?;
f.write_all(&x1.to_bits().to_bytes())?;
f.write_all(&x2.to_bits().to_bytes())?;
f.write_all(&x0.to_bits().to_ne_bytes())?;
f.write_all(&x1.to_bits().to_ne_bytes())?;
f.write_all(&x2.to_bits().to_ne_bytes())?;
}

Ok(())
Expand All @@ -123,7 +125,7 @@ fn f64(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {

let mut f = File::create("bin/input/f64")?;
for i in set {
f.write_all(&i.to_bytes())?;
f.write_all(&i.to_ne_bytes())?;
}

Ok(())
Expand All @@ -141,8 +143,8 @@ fn f64f64(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
}

i += 1;
f.write_all(&x0.to_bits().to_bytes())?;
f.write_all(&x1.to_bits().to_bytes())?;
f.write_all(&x0.to_bits().to_ne_bytes())?;
f.write_all(&x1.to_bits().to_ne_bytes())?;
}

Ok(())
Expand All @@ -161,9 +163,9 @@ fn f64f64f64(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
}

i += 1;
f.write_all(&x0.to_bits().to_bytes())?;
f.write_all(&x1.to_bits().to_bytes())?;
f.write_all(&x2.to_bits().to_bytes())?;
f.write_all(&x0.to_bits().to_ne_bytes())?;
f.write_all(&x1.to_bits().to_ne_bytes())?;
f.write_all(&x2.to_bits().to_ne_bytes())?;
}

Ok(())
Expand All @@ -181,8 +183,8 @@ fn f64i16(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
}

i += 1;
f.write_all(&x0.to_bits().to_bytes())?;
f.write_all(&x1.to_bytes())?;
f.write_all(&x0.to_bits().to_ne_bytes())?;
f.write_all(&x1.to_ne_bytes())?;
}

Ok(())
Expand Down
16 changes: 8 additions & 8 deletions musl-generator/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ macro_rules! f32 {
$fun(*x)
};

$fun.write_all(&y.to_bits().to_bytes())?;
$fun.write_all(&y.to_bits().to_ne_bytes())?;
)+
}
}};
Expand All @@ -40,7 +40,7 @@ macro_rules! f32f32 {
$fun(*x0, *x1)
};

$fun.write_all(&y.to_bits().to_bytes())?;
$fun.write_all(&y.to_bits().to_ne_bytes())?;
)+
}
}};
Expand All @@ -64,7 +64,7 @@ macro_rules! f32f32f32 {
$fun(*x0, *x1, *x2)
};

$fun.write_all(&y.to_bits().to_bytes())?;
$fun.write_all(&y.to_bits().to_ne_bytes())?;
)+
}
}};
Expand All @@ -88,7 +88,7 @@ macro_rules! f32i32 {
$fun(*x0, *x1 as i32)
};

$fun.write_all(&y.to_bits().to_bytes())?;
$fun.write_all(&y.to_bits().to_ne_bytes())?;
)+
}
}};
Expand All @@ -112,7 +112,7 @@ macro_rules! f64 {
$fun(*x)
};

$fun.write_all(&y.to_bits().to_bytes())?;
$fun.write_all(&y.to_bits().to_ne_bytes())?;
)+
}
}};
Expand All @@ -136,7 +136,7 @@ macro_rules! f64f64 {
$fun(*x0, *x1)
};

$fun.write_all(&y.to_bits().to_bytes())?;
$fun.write_all(&y.to_bits().to_ne_bytes())?;
)+
}
}};
Expand All @@ -160,7 +160,7 @@ macro_rules! f64f64f64 {
$fun(*x0, *x1, *x2)
};

$fun.write_all(&y.to_bits().to_bytes())?;
$fun.write_all(&y.to_bits().to_ne_bytes())?;
)+
}
}};
Expand All @@ -184,7 +184,7 @@ macro_rules! f64i32 {
$fun(*x0, *x1 as i32)
};

$fun.write_all(&y.to_bits().to_bytes())?;
$fun.write_all(&y.to_bits().to_ne_bytes())?;
)+
}
}};
Expand Down
2 changes: 2 additions & 0 deletions musl-generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(int_to_from_bytes)]

extern crate libm;
extern crate shared;

Expand Down
33 changes: 21 additions & 12 deletions newlib-generator/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ macro_rules! f32 {
fs::create_dir_all("math/src")?;

let main = format!("
#![feature(int_to_from_bytes)]

#![no_main]
#![no_std]

Expand Down Expand Up @@ -33,10 +35,10 @@ fn run() -> Result<(), usize> {{

let mut buf = [0; 4];
while let Ok(()) = io::Stdin.read_exact(&mut buf) {{
let x = f32::from_bits(u32::from_bytes(buf));
let x = f32::from_bits(u32::from_ne_bytes(buf));
let y = unsafe {{ {0}(x) }};

io::Stdout.write_all(&y.to_bits().to_bytes())?;
io::Stdout.write_all(&y.to_bits().to_ne_bytes())?;
}}

Ok(())
Expand All @@ -63,7 +65,8 @@ pub fn __errno() -> *mut i32 {{
.arg("math/target/thumbv7em-none-eabi/release/math")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
.spawn()
.map_err(|_| "missing qemu-arm!")?;

qemu.stdin.as_mut().take().unwrap().write_all(F32)?;

Expand All @@ -83,6 +86,8 @@ macro_rules! f32f32 {
fs::create_dir_all("math/src")?;

let main = format!("
#![feature(int_to_from_bytes)]

#![no_main]
#![no_std]

Expand Down Expand Up @@ -112,14 +117,14 @@ fn run() -> Result<(), usize> {{
while let Ok(()) = io::Stdin.read_exact(&mut chunk) {{
let mut buf = [0; 4];
buf.copy_from_slice(&chunk[..4]);
let x0 = f32::from_bits(u32::from_bytes(buf));
let x0 = f32::from_bits(u32::from_ne_bytes(buf));

buf.copy_from_slice(&chunk[4..]);
let x1 = f32::from_bits(u32::from_bytes(buf));
let x1 = f32::from_bits(u32::from_ne_bytes(buf));

let y = unsafe {{ {0}(x0, x1) }};

io::Stdout.write_all(&y.to_bits().to_bytes())?;
io::Stdout.write_all(&y.to_bits().to_ne_bytes())?;
}}

Ok(())
Expand All @@ -146,7 +151,8 @@ pub fn __errno() -> *mut i32 {{
.arg("math/target/thumbv7em-none-eabi/release/math")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
.spawn()
.map_err(|_| "missing qemu-arm!")?;

qemu.stdin.as_mut().take().unwrap().write_all(F32)?;

Expand All @@ -166,6 +172,8 @@ macro_rules! f32f32f32 {
fs::create_dir_all("math/src")?;

let main = format!("
#![feature(int_to_from_bytes)]

#![no_main]
#![no_std]

Expand Down Expand Up @@ -195,17 +203,17 @@ fn run() -> Result<(), usize> {{
while let Ok(()) = io::Stdin.read_exact(&mut chunk) {{
let mut buf = [0; 4];
buf.copy_from_slice(&chunk[..4]);
let x0 = f32::from_bits(u32::from_bytes(buf));
let x0 = f32::from_bits(u32::from_ne_bytes(buf));

buf.copy_from_slice(&chunk[4..8]);
let x1 = f32::from_bits(u32::from_bytes(buf));
let x1 = f32::from_bits(u32::from_ne_bytes(buf));

buf.copy_from_slice(&chunk[8..]);
let x2 = f32::from_bits(u32::from_bytes(buf));
let x2 = f32::from_bits(u32::from_ne_bytes(buf));

let y = unsafe {{ {0}(x0, x1, x2) }};

io::Stdout.write_all(&y.to_bits().to_bytes())?;
io::Stdout.write_all(&y.to_bits().to_ne_bytes())?;
}}

Ok(())
Expand All @@ -232,7 +240,8 @@ pub fn __errno() -> *mut i32 {{
.arg("math/target/thumbv7em-none-eabi/release/math")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
.spawn()
.map_err(|_| "missing qemu-arm!")?;

qemu.stdin.as_mut().take().unwrap().write_all(F32)?;

Expand Down
Loading