Closed
Description
I have the following two functions, where one just calls the other after unpacking a struct:
pub struct S {
pub op : u8,
pub x : u8,
pub addr : u16,
pub nn : u8,
}
pub enum R {
A,
B(u16),
C(u8),
}
#[inline(never)]
pub fn indirect(raw: S) -> Option<R> {
direct(raw.op, raw.nn, raw.x, raw.addr)
}
#[inline(never)]
pub fn direct(op: u8, nn: u8, x: u8, addr: u16) -> Option<R> {
match op {
0x0 => Some(R::A),
0x7 => Some(R::B(addr)),
0xb => Some(R::B(addr)),
0xf => match nn {
0x0a => Some(R::C(x)),
_ => None
},
_ => None
}
}
I am calling it twice, once directly and once via the struct
unpacker:
spi::sync(if direct(0x0f, 0x0a, 0x05, 0x1234).is_some() { 0x42 } else { 0xde });
spi::sync(if indirect(S{op: 0x0f, nn: 0x0a, x: 0x05, addr: 0x1234}).is_some() { 0x42 } else { 0xde });
However, only the first (direct) one gives the correct result.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
gergoerdi commentedon May 7, 2017
Actually, this might be because of my proposed fix for #47 ... there's a suspicious
lpm
instruction in the assembly ofindirect
.gergoerdi commentedon May 7, 2017
Yep, going back to
e532848b145f3fc404212383e79f118f354f3d0f
, i.e. just before my change to selectlpm
forload
, fixes this.So I guess we'll need to be smart about either using
lpm
orld
when selecting for aload
, based on where the pointer is pointing...gergoerdi commentedon May 7, 2017
Simplified example:
Compiled
indirect
:Before my changes:
So the question, then, is how to dispatch to
ld
orlpm
depending in theload
's argument.gergoerdi commentedon May 7, 2017
Truly minimal:
Instruction selection trace: (I hope to find out more about interpreting this output):
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
[AVR] Add ISel pattern which maches load-from-global, compile it to
dylanmckay commentedon Aug 23, 2017
Closing this as it's caused by a hack on your branch that isn't in avr-rust's llvm fork.
The hack won't be necessary once #47 is fixed.
[AVR] Add ISel pattern which maches load-from-global, compile it to