Fix endianness in BITS
This commit is contained in:
parent
666d6760f7
commit
47dc8d0a16
1 changed files with 8 additions and 6 deletions
|
@ -14,10 +14,12 @@ pub struct WasmHelper(
|
|||
);
|
||||
|
||||
impl WasmHelper {
|
||||
/* Hand-coded assembly for identity */
|
||||
// Hand-coded assembly for identity.
|
||||
// Source available at https://gist.github.com/gballet/f14d11053d8f846bfbb3687581b0eecb#file-identity-wast
|
||||
pub const IDENTITY_WASM: &'static str = "0061736d010000000105016000017f030302000005030100010615047f0041010b7f0041010b7f0041200b7f0141000b074b06066d656d6f727902000e6765745f696e707574735f6f6666000105736f6c766500000a6d696e5f696e7075747303000b6d696e5f6f75747075747303010a6669656c645f73697a6503020a2c0225000340412023036a410023036a280200360200230341016a240323032302470d000b41200b040041000b0b4b020041000b20ffffffff000000000000000000000000ffffffff0000000000000000000000000041200b20deadbeef000000000000000000000000deadbeef000000000000000000000000";
|
||||
/* Generated from C code, normalized and cleaned up by hand */
|
||||
pub const BITS_WASM: &'static str = "0061736d01000000010c026000017f60037f7f7f017f0304030000010405017001010105030100020626067f0141f0c7040b7f0041f0c7040b7f0041f0c7000b7f0041200b7f0041010b7f0041fe010b074b06066d656d6f727902000e6765745f696e707574735f6f6666000005736f6c766500010a6669656c645f73697a6503030a6d696e5f696e7075747303040b6d696e5f6f75747075747303050901000ad5030305004190080b4f01027f41b008210041b008410041c03f10021a4100210103402000410120014107717420014103764190086a2d0000714100473a0000200041206a2100200141016a220141fe01470d000b41b0080bfc0202037f017e02402002450d00200020013a0000200020026a2203417f6a20013a000020024103490d00200020013a0002200020013a00012003417d6a20013a00002003417e6a20013a000020024107490d00200020013a00032003417c6a20013a000020024109490d002000410020006b41037122046a2203200141ff017141818284086c22013602002003200220046b417c7122046a2202417c6a200136020020044109490d002003200136020820032001360204200241786a2001360200200241746a200136020020044119490d00200320013602102003200136020c2003200136021420032001360218200241686a2001360200200241646a20013602002002416c6a2001360200200241706a20013602002004200341047141187222056b22024120490d002001ad22064220862006842106200320056a2101034020012006370300200141086a2006370300200141106a2006370300200141186a2006370300200141206a2101200241606a2202411f4b0d000b0b20000b";
|
||||
// Generated from C code, normalized and cleaned up by hand.
|
||||
// Source available at https://gist.github.com/gballet/f14d11053d8f846bfbb3687581b0eecb#file-bits_v2-c
|
||||
pub const BITS_WASM: &'static [u8] = &[0, 97, 115, 109, 1, 0, 0, 0, 1, 8, 2, 96, 0, 0, 96, 0, 1, 127, 3, 5, 4, 0, 1, 1, 1, 4, 5, 1, 112, 1, 1, 1, 5, 3, 1, 0, 2, 6, 38, 6, 127, 1, 65, 240, 199, 4, 11, 127, 0, 65, 240, 199, 4, 11, 127, 0, 65, 240, 199, 0, 11, 127, 0, 65, 32, 11, 127, 0, 65, 1, 11, 127, 0, 65, 254, 1, 11, 7, 109, 9, 6, 109, 101, 109, 111, 114, 121, 2, 0, 11, 95, 95, 104, 101, 97, 112, 95, 98, 97, 115, 101, 3, 1, 10, 95, 95, 100, 97, 116, 97, 95, 101, 110, 100, 3, 2, 14, 103, 101, 116, 95, 105, 110, 112, 117, 116, 115, 95, 111, 102, 102, 0, 1, 5, 115, 111, 108, 118, 101, 0, 2, 4, 109, 97, 105, 110, 0, 3, 10, 102, 105, 101, 108, 100, 95, 115, 105, 122, 101, 3, 3, 10, 109, 105, 110, 95, 105, 110, 112, 117, 116, 115, 3, 4, 11, 109, 105, 110, 95, 111, 117, 116, 112, 117, 116, 115, 3, 5, 9, 1, 0, 10, 85, 4, 3, 0, 1, 11, 5, 0, 65, 144, 8, 11, 68, 1, 2, 127, 65, 253, 1, 33, 0, 65, 176, 8, 33, 1, 3, 64, 32, 1, 65, 1, 32, 0, 65, 7, 113, 116, 32, 0, 65, 3, 118, 65, 144, 8, 106, 45, 0, 0, 113, 65, 0, 71, 58, 0, 0, 32, 1, 65, 32, 106, 33, 1, 32, 0, 65, 127, 106, 34, 0, 65, 127, 71, 13, 0, 11, 65, 176, 8, 11, 4, 0, 65, 0, 11, 11, 19, 1, 0, 65, 128, 8, 11, 12, 32, 0, 0, 0, 1, 0, 0, 0, 254, 0, 0, 0];
|
||||
|
||||
pub fn from_hex<U: Into<String>>(u: U) -> Self {
|
||||
let code_hex = u.into();
|
||||
|
@ -546,7 +548,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn check_bits() {
|
||||
let bits = WasmHelper::from_hex(WasmHelper::BITS_WASM);
|
||||
let bits = WasmHelper::from(WasmHelper::BITS_WASM);
|
||||
let input = vec![FieldPrime::from(0xdeadbeef as u32)];
|
||||
let outputs = bits.execute(&input).unwrap();
|
||||
|
||||
|
@ -554,11 +556,11 @@ mod tests {
|
|||
|
||||
for i in 0..32 {
|
||||
let bitval = (0xdeadbeef as i64 >> i) & 1;
|
||||
assert_eq!(outputs[i as usize], FieldPrime::from(bitval as i32));
|
||||
assert_eq!(outputs[(253-i) as usize], FieldPrime::from(bitval as i32));
|
||||
}
|
||||
|
||||
for i in 32..254 {
|
||||
assert_eq!(outputs[i as usize], FieldPrime::from(0));
|
||||
assert_eq!(outputs[(253-i) as usize], FieldPrime::from(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue