@@ -201,12 +201,66 @@ impl AArch64InlineAsmReg {
201201 _arch : InlineAsmArch ,
202202 modifier : Option < char > ,
203203 ) -> fmt:: Result {
204- let ( prefix, index) = if ( self as u32 ) < Self :: v0 as u32 {
205- ( modifier. unwrap_or ( 'x' ) , self as u32 - Self :: x0 as u32 )
204+ let ( prefix, index) = if let Some ( index) = self . reg_index ( ) {
205+ ( modifier. unwrap_or ( 'x' ) , index)
206+ } else if let Some ( index) = self . vreg_index ( ) {
207+ ( modifier. unwrap_or ( 'v' ) , index)
206208 } else {
207- ( modifier . unwrap_or ( 'v' ) , self as u32 - Self :: v0 as u32 )
209+ return out . write_str ( self . name ( ) ) ;
208210 } ;
209211 assert ! ( index < 32 ) ;
210212 write ! ( out, "{prefix}{index}" )
211213 }
214+
215+ /// If the register is an integer register then return its index.
216+ pub fn reg_index ( self ) -> Option < u32 > {
217+ // Unlike `vreg_index`, we can't subtract `x0` to get the u32 because
218+ // `x19` and `x29` are missing and the integer constants for the
219+ // `x0`..`x30` enum variants don't all match the register number. E.g. the
220+ // integer constant for `x18` is 18, but the constant for `x20` is 19.
221+ use AArch64InlineAsmReg :: * ;
222+ Some ( match self {
223+ x0 => 0 ,
224+ x1 => 1 ,
225+ x2 => 2 ,
226+ x3 => 3 ,
227+ x4 => 4 ,
228+ x5 => 5 ,
229+ x6 => 6 ,
230+ x7 => 7 ,
231+ x8 => 8 ,
232+ x9 => 9 ,
233+ x10 => 10 ,
234+ x11 => 11 ,
235+ x12 => 12 ,
236+ x13 => 13 ,
237+ x14 => 14 ,
238+ x15 => 15 ,
239+ x16 => 16 ,
240+ x17 => 17 ,
241+ x18 => 18 ,
242+ // x19 is reserved
243+ x20 => 20 ,
244+ x21 => 21 ,
245+ x22 => 22 ,
246+ x23 => 23 ,
247+ x24 => 24 ,
248+ x25 => 25 ,
249+ x26 => 26 ,
250+ x27 => 27 ,
251+ x28 => 28 ,
252+ // x29 is reserved
253+ x30 => 30 ,
254+ _ => return None ,
255+ } )
256+ }
257+
258+ /// If the register is a vector register then return its index.
259+ pub fn vreg_index ( self ) -> Option < u32 > {
260+ use AArch64InlineAsmReg :: * ;
261+ if self as u32 >= v0 as u32 && self as u32 <= v31 as u32 {
262+ return Some ( self as u32 - v0 as u32 ) ;
263+ }
264+ None
265+ }
212266}
0 commit comments