11#![ doc = include_str ! ( "../README.md" ) ]
22
33use std:: {
4+ arch:: asm,
45 ops:: {
56 Deref , DerefMut , Index , IndexMut , Range , RangeFrom , RangeFull , RangeTo , RangeToInclusive ,
67 } ,
@@ -158,7 +159,10 @@ impl MagicBuffer {
158159 /// }
159160 /// ```
160161 pub fn as_ptr ( & self , offset : usize ) -> * const u8 {
161- unsafe { self . addr . add ( self . fast_mod ( offset) ) . cast_const ( ) }
162+ unsafe {
163+ asm ! ( "/* {ptr} */" , ptr = in( reg) self . addr, options( nostack, preserves_flags) ) ;
164+ self . addr . add ( self . fast_mod ( offset) ) . cast_const ( )
165+ }
162166 }
163167
164168 /// Returns an unsafe mutable pointer to the [`MagicBuffer`]. The `offset` species the first
@@ -181,16 +185,21 @@ impl MagicBuffer {
181185 /// }
182186 /// ```
183187 pub fn as_mut_ptr ( & mut self , offset : usize ) -> * mut u8 {
184- unsafe { self . addr . add ( self . fast_mod ( offset) ) }
188+ unsafe {
189+ asm ! ( "/* {ptr} */" , ptr = in( reg) self . addr, options( nostack, preserves_flags) ) ;
190+ self . addr . add ( self . fast_mod ( offset) )
191+ }
185192 }
186193
187194 #[ inline( always) ]
188195 unsafe fn as_slice ( & self , offset : usize , len : usize ) -> & [ u8 ] {
196+ asm ! ( "/* {ptr} */" , ptr = in( reg) self . addr, options( nostack, preserves_flags) ) ;
189197 & * ( slice_from_raw_parts ( self . addr . add ( offset) , len) )
190198 }
191199
192200 #[ inline( always) ]
193201 unsafe fn as_slice_mut ( & mut self , offset : usize , len : usize ) -> & mut [ u8 ] {
202+ asm ! ( "/* {ptr} */" , ptr = in( reg) self . addr, options( nostack, preserves_flags) ) ;
194203 & mut * ( slice_from_raw_parts_mut ( self . addr . add ( offset) , len) )
195204 }
196205
@@ -224,13 +233,19 @@ impl Index<usize> for MagicBuffer {
224233 type Output = u8 ;
225234
226235 fn index ( & self , index : usize ) -> & Self :: Output {
227- unsafe { & * self . addr . add ( self . fast_mod ( index) ) }
236+ unsafe {
237+ asm ! ( "/* {ptr} */" , ptr = in( reg) self . addr, options( nostack, preserves_flags) ) ;
238+ & * self . addr . add ( self . fast_mod ( index) )
239+ }
228240 }
229241}
230242
231243impl IndexMut < usize > for MagicBuffer {
232244 fn index_mut ( & mut self , index : usize ) -> & mut Self :: Output {
233- unsafe { & mut * self . addr . add ( self . fast_mod ( index) ) }
245+ unsafe {
246+ asm ! ( "/* {ptr} */" , ptr = in( reg) self . addr, options( nostack, preserves_flags) ) ;
247+ & mut * self . addr . add ( self . fast_mod ( index) )
248+ }
234249 }
235250}
236251
@@ -271,7 +286,11 @@ impl Index<isize> for MagicBuffer {
271286 } else {
272287 self . fast_mod ( index as usize )
273288 } ;
274- unsafe { & * self . addr . add ( index) }
289+
290+ unsafe {
291+ asm ! ( "/* {ptr} */" , ptr = in( reg) self . addr, options( nostack, preserves_flags) ) ;
292+ & * self . addr . add ( index)
293+ }
275294 }
276295}
277296
@@ -282,7 +301,11 @@ impl IndexMut<isize> for MagicBuffer {
282301 } else {
283302 self . fast_mod ( index as usize )
284303 } ;
285- unsafe { & mut * self . addr . add ( index) }
304+
305+ unsafe {
306+ asm ! ( "/* {ptr} */" , ptr = in( reg) self . addr, options( nostack, preserves_flags) ) ;
307+ & mut * self . addr . add ( index)
308+ }
286309 }
287310}
288311
0 commit comments