mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	drm/panic: Use a decimal fifo to avoid u64 by u64 divide
On 32bits ARM, u64/u64 is not supported [1], so change the algorithm
to use a simple fifo with decimal digits as u8 instead.
This is slower but should compile on all architecture.
Link: https://lore.kernel.org/dri-devel/CANiq72ke45eOwckMhWHvmwxc03dxr4rnxxKvx+HvWdBLopZfrQ@mail.gmail.com/ [1]
Reported-by: Miguel Ojeda <ojeda@kernel.org>
Closes: https://lore.kernel.org/dri-devel/CANiq72ke45eOwckMhWHvmwxc03dxr4rnxxKvx+HvWdBLopZfrQ@mail.gmail.com/
Fixes: ccb8ce5268 ("ARM: 9441/1: rust: Enable Rust support for ARMv7")
Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://lore.kernel.org/r/20250418165059.560503-1-jfalempe@redhat.com
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
			
			
This commit is contained in:
		
							parent
							
								
									760e296124
								
							
						
					
					
						commit
						675008f196
					
				
					 1 changed files with 48 additions and 23 deletions
				
			
		| 
						 | 
					@ -366,8 +366,48 @@ fn iter(&self) -> SegmentIterator<'_> {
 | 
				
			||||||
        SegmentIterator {
 | 
					        SegmentIterator {
 | 
				
			||||||
            segment: self,
 | 
					            segment: self,
 | 
				
			||||||
            offset: 0,
 | 
					            offset: 0,
 | 
				
			||||||
            carry: 0,
 | 
					            decfifo: Default::default(),
 | 
				
			||||||
            carry_len: 0,
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Max fifo size is 17 (max push) + 2 (max remaining)
 | 
				
			||||||
 | 
					const MAX_FIFO_SIZE: usize = 19;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// A simple Decimal digit FIFO
 | 
				
			||||||
 | 
					#[derive(Default)]
 | 
				
			||||||
 | 
					struct DecFifo {
 | 
				
			||||||
 | 
					    decimals: [u8; MAX_FIFO_SIZE],
 | 
				
			||||||
 | 
					    len: usize,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl DecFifo {
 | 
				
			||||||
 | 
					    fn push(&mut self, data: u64, len: usize) {
 | 
				
			||||||
 | 
					        let mut chunk = data;
 | 
				
			||||||
 | 
					        for i in (0..self.len).rev() {
 | 
				
			||||||
 | 
					            self.decimals[i + len] = self.decimals[i];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        for i in 0..len {
 | 
				
			||||||
 | 
					            self.decimals[i] = (chunk % 10) as u8;
 | 
				
			||||||
 | 
					            chunk /= 10;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        self.len += len;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Pop 3 decimal digits from the FIFO
 | 
				
			||||||
 | 
					    fn pop3(&mut self) -> Option<(u16, usize)> {
 | 
				
			||||||
 | 
					        if self.len == 0 {
 | 
				
			||||||
 | 
					            None
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            let poplen = 3.min(self.len);
 | 
				
			||||||
 | 
					            self.len -= poplen;
 | 
				
			||||||
 | 
					            let mut out = 0;
 | 
				
			||||||
 | 
					            let mut exp = 1;
 | 
				
			||||||
 | 
					            for i in 0..poplen {
 | 
				
			||||||
 | 
					                out += self.decimals[self.len + i] as u16 * exp;
 | 
				
			||||||
 | 
					                exp *= 10;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Some((out, NUM_CHARS_BITS[poplen]))
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -375,8 +415,7 @@ fn iter(&self) -> SegmentIterator<'_> {
 | 
				
			||||||
struct SegmentIterator<'a> {
 | 
					struct SegmentIterator<'a> {
 | 
				
			||||||
    segment: &'a Segment<'a>,
 | 
					    segment: &'a Segment<'a>,
 | 
				
			||||||
    offset: usize,
 | 
					    offset: usize,
 | 
				
			||||||
    carry: u64,
 | 
					    decfifo: DecFifo,
 | 
				
			||||||
    carry_len: usize,
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Iterator for SegmentIterator<'_> {
 | 
					impl Iterator for SegmentIterator<'_> {
 | 
				
			||||||
| 
						 | 
					@ -394,31 +433,17 @@ fn next(&mut self) -> Option<Self::Item> {
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Segment::Numeric(data) => {
 | 
					            Segment::Numeric(data) => {
 | 
				
			||||||
                if self.carry_len < 3 && self.offset < data.len() {
 | 
					                if self.decfifo.len < 3 && self.offset < data.len() {
 | 
				
			||||||
                    // If there are less than 3 decimal digits in the carry,
 | 
					                    // If there are less than 3 decimal digits in the fifo,
 | 
				
			||||||
                    // take the next 7 bytes of input, and add them to the carry.
 | 
					                    // take the next 7 bytes of input, and push them to the fifo.
 | 
				
			||||||
                    let mut buf = [0u8; 8];
 | 
					                    let mut buf = [0u8; 8];
 | 
				
			||||||
                    let len = 7.min(data.len() - self.offset);
 | 
					                    let len = 7.min(data.len() - self.offset);
 | 
				
			||||||
                    buf[..len].copy_from_slice(&data[self.offset..self.offset + len]);
 | 
					                    buf[..len].copy_from_slice(&data[self.offset..self.offset + len]);
 | 
				
			||||||
                    let chunk = u64::from_le_bytes(buf);
 | 
					                    let chunk = u64::from_le_bytes(buf);
 | 
				
			||||||
                    let pow = u64::pow(10, BYTES_TO_DIGITS[len] as u32);
 | 
					                    self.decfifo.push(chunk, BYTES_TO_DIGITS[len]);
 | 
				
			||||||
                    self.carry = chunk + self.carry * pow;
 | 
					 | 
				
			||||||
                    self.offset += len;
 | 
					                    self.offset += len;
 | 
				
			||||||
                    self.carry_len += BYTES_TO_DIGITS[len];
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                match self.carry_len {
 | 
					 | 
				
			||||||
                    0 => None,
 | 
					 | 
				
			||||||
                    len => {
 | 
					 | 
				
			||||||
                        // take the next 3 decimal digits of the carry
 | 
					 | 
				
			||||||
                        // and return 10bits of numeric data.
 | 
					 | 
				
			||||||
                        let out_len = 3.min(len);
 | 
					 | 
				
			||||||
                        self.carry_len -= out_len;
 | 
					 | 
				
			||||||
                        let pow = u64::pow(10, self.carry_len as u32);
 | 
					 | 
				
			||||||
                        let out = (self.carry / pow) as u16;
 | 
					 | 
				
			||||||
                        self.carry %= pow;
 | 
					 | 
				
			||||||
                        Some((out, NUM_CHARS_BITS[out_len]))
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                self.decfifo.pop3()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue