Skip to content

Commit

Permalink
f64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Jan 21, 2021
1 parent 574f77f commit 96cd5eb
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 207 deletions.
1 change: 1 addition & 0 deletions book/src/primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The available types are:
- `={i,u}{8,16,32,64}`, standard integer types
- `={i,u}24`, 32-bit integer truncated to 24 bits
- `=f32`, 32-bit floating point type
- `=f64`, 64-bit floating point type
- `=[u8; N]`, byte array
- `=[u8]`, byte slice
- `=str`, string slice
6 changes: 6 additions & 0 deletions decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ enum Arg<'t> {
/// Bool
Bool(Arc<Bool>),
F32(f32),
F64(f64),
/// U8, U16, U24 and U32
Uxx(u128),
/// I8, I16, I24 and I32
Expand Down Expand Up @@ -818,6 +819,10 @@ impl<'t, 'b> Decoder<'t, 'b> {
let data = self.bytes.read_u32::<LE>()?;
args.push(Arg::F32(f32::from_bits(data)));
}
Type::F64 => {
let data = self.bytes.read_u64::<LE>()?;
args.push(Arg::F64(f64::from_bits(data)));
}
Type::BitField(range) => {
let mut data: u128;
let lowest_byte = range.start / 8;
Expand Down Expand Up @@ -1057,6 +1062,7 @@ fn format_args_real(
match &args[param.index] {
Arg::Bool(x) => write!(buf, "{}", x)?,
Arg::F32(x) => write!(buf, "{}", ryu::Buffer::new().format(*x))?,
Arg::F64(x) => write!(buf, "{}", ryu::Buffer::new().format(*x))?,
Arg::Uxx(x) => {
match param.ty {
Type::BitField(range) => {
Expand Down
207 changes: 104 additions & 103 deletions firmware/qemu/src/bin/log.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,111 +5,112 @@
0.000004 INFO Hello 256 42 false
0.000005 INFO 🍕 slice [3, 14]
0.000006 INFO 🍕 array [3, 14, 1]
0.000007 INFO float like a butterfly 5.67
0.000008 INFO Hello 42
0.000009 INFO u64: 0 = 0, 1 = 1, MAX = 18446744073709551615, MIN = 0
0.000010 INFO i64: 0 = 0, -1 = -1, MAX = 9223372036854775807, MIN = -9223372036854775808
0.000011 INFO isize: 0 = 0, -1 = -1, MAX = 2147483647, MIN = -2147483648
0.000007 INFO float like a butterfly 5.67 5.67
0.000008 INFO double like a butterfly 5.000000000000067 5.000000000000067
0.000009 INFO Hello 42
0.000010 INFO u64: 0 = 0, 1 = 1, MAX = 18446744073709551615, MIN = 0
0.000011 INFO i64: 0 = 0, -1 = -1, MAX = 9223372036854775807, MIN = -9223372036854775808
0.000012 INFO isize: 0 = 0, -1 = -1, MAX = 2147483647, MIN = -2147483648
0.000013 INFO usize: 0 = 0, MAX = 4294967295
0.000014 INFO bitfields 6 2
0.000015 TRACE log trace
0.000016 DEBUG log debug
0.000017 INFO log info
0.000018 WARN log warn
0.000019 ERROR log error
0.000020 INFO S { x: 1, y: 256 }
0.000021 INFO X { y: Y { z: 42 } }
0.000022 INFO &str = string slice
0.000013 INFO isize: 0 = 0, -1 = -1, MAX = 2147483647, MIN = -2147483648
0.000014 INFO usize: 0 = 0, MAX = 4294967295
0.000015 INFO bitfields 6 2
0.000016 TRACE log trace
0.000017 DEBUG log debug
0.000018 INFO log info
0.000019 WARN log warn
0.000020 ERROR log error
0.000021 INFO S { x: 1, y: 256 }
0.000022 INFO X { y: Y { z: 42 } }
0.000023 INFO &str = string slice
0.000024 INFO &Str = interned string
0.000024 INFO &str = string slice
0.000025 INFO &Str = interned string
0.000026 INFO Arr { arr1: [31], arr0: [], arr32: [85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85] }
0.000027 INFO [256, 257, 258]
0.000028 INFO [S { x: 128, y: 256 }, S { x: 129, y: 257 }]
0.000029 INFO [X { y: Y { z: 128 } }, X { y: Y { z: 129 } }]
0.000030 INFO [[256, 257, 258], [259, 260]]
0.000031 INFO e1=A
0.000032 INFO e2=B
0.000033 INFO e3=Some(42)
0.000034 INFO e4=None
0.000035 INFO e5=Ok(42)
0.000036 INFO e6=Err(256)
0.000037 INFO e7=Some(X { y: Y { z: 42 } })
0.000038 INFO true Flags { a: true, b: false, c: true }
0.000039 INFO [true, true, false]
0.000040 INFO usize slice: [1, 2, 3]
0.000041 INFO isize slice: [-1, -2, -3]
0.000042 INFO S { x: 42, y: 43 }
0.000043 INFO S { x: 44, y: 45 }
0.000044 INFO S { x: 46, y: Some(47) }
0.000045 INFO S { x: Some(48), y: 49 }
0.000046 INFO A
0.000047 INFO B(42)
0.000048 INFO C { y: 43 }
0.000049 INFO A
0.000050 INFO B(44)
0.000051 INFO C { y: 45 }
0.000052 INFO A
0.000053 INFO B(Some(46))
0.000054 INFO C { y: Ok(47) }
0.000055 INFO A
0.000056 INFO B(Some(48))
0.000057 INFO C { y: 49 }
0.000058 INFO [None, Some(42)]
0.000059 INFO [Ok(42), Err(43)]
0.000060 INFO [A, B(42)]
0.000061 INFO [S { x: 42, y: None }, S { x: 43, y: Some(44) }]
0.000062 INFO [None, Some(S { x: 42, y: 256 })]
0.000063 INFO [None, Some([42, 43])]
0.000064 INFO in nested 123
0.000065 INFO after nested log: NestedStruct { a: 170, b: 305419896 }
0.000066 INFO I can now print the @ symbol!
0.000067 INFO @nd @lso vi@ interned strings: this is @n interned string
0.000068 INFO empty tuple: ()
0.000069 INFO tuple of ints: (1, 2, 3)
0.000070 INFO nested tuple of ints: (1, 2, (3, 4, 5), (6, 7, 8))
0.000071 INFO super nested tuples: (((((((())))))), (((((((), ())))))))
0.000072 INFO slice of tuples: [(1, 2), (3, 4), (5, 6)]
0.000073 INFO tuple of slices: ([1, 2, 3], [4, 5, 6])
0.000074 INFO tuple of [u8;4]: ([1, 2, 3, 4], [5, 6, 7, 8])
0.000075 INFO [u8;0]: []
0.000076 INFO [u8;4]: [1, 2, 3, 4]
0.000077 INFO [i8;4]: [-1, 2, 3, -4]
0.000078 INFO [(u32,u32);4]: [(1, 2), (3, 4), (5, 6), (7, 8)]
0.000079 INFO [u8;0]: []
0.000080 INFO [u8;4]: [1, 2, 3, 4]
0.000081 INFO [i8;4]: [-1, 2, 3, -4]
0.000082 INFO [u32;4]: [1, 2, 3, 4]
0.000083 INFO [i32;4]: [-1, 2, 3, -4]
0.000084 INFO [[u32;4];4]: [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]
0.000085 INFO [Option<u32>;4]: [Some(1), None, Some(3), None]
0.000086 INFO [(u32,u32);4]: [(1, 2), (3, 4), (5, 6), (7, 8)]
0.000087 INFO 1-variant enum: A { fld: 123 }
0.000088 INFO wrapped: A(A { fld: 200 })
0.000089 INFO (A(true), B(true)), (A(false), B(true)), (A(true), B(false))
0.000090 INFO true, [1, 2]: DhcpReprMin { broadcast: true, a: [1, 2] }
0.000091 INFO nested `Format` impls using `write!`: outer value (inner value (42))
0.000092 INFO S { x: -1, y: 2 }
0.000093 INFO Some(S { x: -1, y: 2 })
0.000094 INFO [S { x: -1, y: 2 }, S { x: -1, y: 2 }]
0.000095 INFO [Some(S { x: -1, y: 2 }), None]
0.000096 INFO 127.0.0.1:8888
0.000097 INFO i128: 0 = 0, -1 = -1, MAX = 170141183460469231731687303715884105727, MIN = -170141183460469231731687303715884105728
0.000098 INFO u128: 0 = 0, -1 = 1, MAX = 340282366920938463463374607431768211455, MIN = 0
0.000099 INFO 340282366920938
0.000100 INFO -170141183460469
0.000101 INFO Hello 💜
0.000102 INFO Hello 💜 & 🍕
0.000103 INFO EnumLarge::A051
0.000104 INFO EnumLarge::A269
0.000105 INFO S { x: "hi" }
0.000106 INFO S { x: PhantomData, y: 42 }
0.000107 INFO bitfields 0x97 0b10000100 12 b"42" b"hello"
0.000108 INFO b"Hi"
0.000026 INFO &Str = interned string
0.000027 INFO Arr { arr1: [31], arr0: [], arr32: [85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85] }
0.000028 INFO [256, 257, 258]
0.000029 INFO [S { x: 128, y: 256 }, S { x: 129, y: 257 }]
0.000030 INFO [X { y: Y { z: 128 } }, X { y: Y { z: 129 } }]
0.000031 INFO [[256, 257, 258], [259, 260]]
0.000032 INFO e1=A
0.000033 INFO e2=B
0.000034 INFO e3=Some(42)
0.000035 INFO e4=None
0.000036 INFO e5=Ok(42)
0.000037 INFO e6=Err(256)
0.000038 INFO e7=Some(X { y: Y { z: 42 } })
0.000039 INFO true Flags { a: true, b: false, c: true }
0.000040 INFO [true, true, false]
0.000041 INFO usize slice: [1, 2, 3]
0.000042 INFO isize slice: [-1, -2, -3]
0.000043 INFO S { x: 42, y: 43 }
0.000044 INFO S { x: 44, y: 45 }
0.000045 INFO S { x: 46, y: Some(47) }
0.000046 INFO S { x: Some(48), y: 49 }
0.000047 INFO A
0.000048 INFO B(42)
0.000049 INFO C { y: 43 }
0.000050 INFO A
0.000051 INFO B(44)
0.000052 INFO C { y: 45 }
0.000053 INFO A
0.000054 INFO B(Some(46))
0.000055 INFO C { y: Ok(47) }
0.000056 INFO A
0.000057 INFO B(Some(48))
0.000058 INFO C { y: 49 }
0.000059 INFO [None, Some(42)]
0.000060 INFO [Ok(42), Err(43)]
0.000061 INFO [A, B(42)]
0.000062 INFO [S { x: 42, y: None }, S { x: 43, y: Some(44) }]
0.000063 INFO [None, Some(S { x: 42, y: 256 })]
0.000064 INFO [None, Some([42, 43])]
0.000065 INFO in nested 123
0.000066 INFO after nested log: NestedStruct { a: 170, b: 305419896 }
0.000067 INFO I can now print the @ symbol!
0.000068 INFO @nd @lso vi@ interned strings: this is @n interned string
0.000069 INFO empty tuple: ()
0.000070 INFO tuple of ints: (1, 2, 3)
0.000071 INFO nested tuple of ints: (1, 2, (3, 4, 5), (6, 7, 8))
0.000072 INFO super nested tuples: (((((((())))))), (((((((), ())))))))
0.000073 INFO slice of tuples: [(1, 2), (3, 4), (5, 6)]
0.000074 INFO tuple of slices: ([1, 2, 3], [4, 5, 6])
0.000075 INFO tuple of [u8;4]: ([1, 2, 3, 4], [5, 6, 7, 8])
0.000076 INFO [u8;0]: []
0.000077 INFO [u8;4]: [1, 2, 3, 4]
0.000078 INFO [i8;4]: [-1, 2, 3, -4]
0.000079 INFO [(u32,u32);4]: [(1, 2), (3, 4), (5, 6), (7, 8)]
0.000080 INFO [u8;0]: []
0.000081 INFO [u8;4]: [1, 2, 3, 4]
0.000082 INFO [i8;4]: [-1, 2, 3, -4]
0.000083 INFO [u32;4]: [1, 2, 3, 4]
0.000084 INFO [i32;4]: [-1, 2, 3, -4]
0.000085 INFO [[u32;4];4]: [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]
0.000086 INFO [Option<u32>;4]: [Some(1), None, Some(3), None]
0.000087 INFO [(u32,u32);4]: [(1, 2), (3, 4), (5, 6), (7, 8)]
0.000088 INFO 1-variant enum: A { fld: 123 }
0.000089 INFO wrapped: A(A { fld: 200 })
0.000090 INFO (A(true), B(true)), (A(false), B(true)), (A(true), B(false))
0.000091 INFO true, [1, 2]: DhcpReprMin { broadcast: true, a: [1, 2] }
0.000092 INFO nested `Format` impls using `write!`: outer value (inner value (42))
0.000093 INFO S { x: -1, y: 2 }
0.000094 INFO Some(S { x: -1, y: 2 })
0.000095 INFO [S { x: -1, y: 2 }, S { x: -1, y: 2 }]
0.000096 INFO [Some(S { x: -1, y: 2 }), None]
0.000097 INFO 127.0.0.1:8888
0.000098 INFO i128: 0 = 0, -1 = -1, MAX = 170141183460469231731687303715884105727, MIN = -170141183460469231731687303715884105728
0.000099 INFO u128: 0 = 0, -1 = 1, MAX = 340282366920938463463374607431768211455, MIN = 0
0.000100 INFO 340282366920938
0.000101 INFO -170141183460469
0.000102 INFO Hello 💜
0.000103 INFO Hello 💜 & 🍕
0.000104 INFO EnumLarge::A051
0.000105 INFO EnumLarge::A269
0.000106 INFO S { x: "hi" }
0.000107 INFO S { x: PhantomData, y: 42 }
0.000108 INFO bitfields 0x97 0b10000100 12 b"42" b"hello"
0.000109 INFO b"Hi"
0.000110 INFO b"Hi"
0.000111 INFO [45054, 49406]
0.000112 INFO [Data { name: b"Hi", value: true }]
0.000113 INFO true true
0.000114 INFO QEMU test finished!
0.000111 INFO b"Hi"
0.000112 INFO [45054, 49406]
0.000113 INFO [Data { name: b"Hi", value: true }]
0.000114 INFO true true
0.000115 INFO QEMU test finished!
Loading

0 comments on commit 96cd5eb

Please sign in to comment.