@@ -22,7 +22,6 @@ The compiler will emit an error if `asm!` is used on an unsupported target.
22
22
r[ asm.example]
23
23
## Example
24
24
25
-
26
25
``` rust
27
26
# #[cfg(target_arch = " x86_64" )] {
28
27
use std :: arch :: asm;
@@ -46,7 +45,6 @@ assert_eq!(x, 4 * 6);
46
45
r[ asm.syntax]
47
46
## Syntax
48
47
49
-
50
48
The following ABNF specifies the general syntax:
51
49
52
50
``` text
@@ -106,7 +104,7 @@ The corresponding arguments are accessed in order, by index, or by name.
106
104
let y : i64 ;
107
105
let z : i64 ;
108
106
// This
109
- unsafe { core :: arch :: asm! (" mov {}, {}" , out (reg ) x , in (reg ) 5 );}
107
+ unsafe { core :: arch :: asm! (" mov {}, {}" , out (reg ) x , in (reg ) 5 );}
110
108
// ... this
111
109
unsafe { core :: arch :: asm! (" mov {0}, {1}" , out (reg ) y , in (reg ) 5 );}
112
110
/// ... and this
@@ -117,7 +115,6 @@ The corresponding arguments are accessed in order, by index, or by name.
117
115
# }
118
116
```
119
117
120
-
121
118
r[ asm.ts-args.no-implicit]
122
119
However, implicit named arguments (introduced by [ RFC #2795 ] [ rfc-2795 ] ) are not supported.
123
120
@@ -339,7 +336,7 @@ r[asm.operand-type.supported-operands.sym]
339
336
# #[cfg(target_arch = " x86_64" )] {
340
337
// swizzle [0, 1, 2, 3] => [3, 2, 0, 1]
341
338
const SHUFFLE : u8 = 0b01_00_10_11 ;
342
- let x : core :: arch :: x86_64 :: __m128 = unsafe { core :: mem :: transmute ([0u32 , 1u32 , 2u32 , 3u32 ]) };
339
+ let x : core :: arch :: x86_64 :: __m128 = unsafe { core :: mem :: transmute ([0u32 , 1u32 , 2u32 , 3u32 ]) };
343
340
let y : core :: arch :: x86_64 :: __m128 ;
344
341
// Pass a constant value into an instruction that expects an immediate like `pshufd`
345
342
unsafe { core :: arch :: asm! (" pshufd {xmm}, {xmm}, {shuffle}" , xmm = inlateout (xmm_reg ) x => y , shuffle = const SHUFFLE ); }
@@ -371,7 +368,7 @@ let x = 5;
371
368
372
369
// register operands aren't allowed, since we aren't in a function
373
370
# #[cfg(target_arch = "x86_64")]
374
- core::arch::global_asm!("", in(reg) 5);
371
+ core::arch::global_asm!("", in(reg) 5);
375
372
376
373
# #[cfg(not(target_arch = "x86_64"))] core::compile_error!("Test not supported on this arch");
377
374
```
@@ -423,7 +420,6 @@ It is a compile-time error to use the same explicit register for two input opera
423
420
# #[cfg(not(target_arch = "x86_64"))] core::compile_error!("Test not supported on this arch");
424
421
```
425
422
426
-
427
423
r[ asm.register-operands.error-overlapping]
428
424
Additionally, it is also a compile-time error to use overlapping registers (e.g. ARM VFP) in input operands or in output operands.
429
425
@@ -771,7 +767,6 @@ Only one modifier is allowed per template placeholder.
771
767
# #[cfg(not(target_arch = "x86_64"))] core::compile_error!("Test not supported on this arch");
772
768
```
773
769
774
-
775
770
r[ asm.template-modifiers.supported-modifiers]
776
771
The supported modifiers are a subset of LLVM's (and GCC's) [ asm template argument modifiers] [ llvm-argmod ] , but do not use the same letter codes.
777
772
@@ -954,10 +949,10 @@ r[asm.options.supported-options.nomem]
954
949
let z: i32;
955
950
// Accessing memory from a nomem asm block is disallowed
956
951
unsafe { core::arch::asm!("mov {val:e}, dword ptr [{ptr}]", ptr = in(reg) &mut x, val = lateout(reg) z, options(nomem))}
957
-
952
+
958
953
// Writing to memory is also undefined behaviour
959
954
unsafe { core::arch::asm!("mov dword ptr [{ptr}], {val:e}", ptr = in(reg) &mut x, val = in(reg) z, options(nomem))}
960
- # }
955
+ # }
961
956
```
962
957
963
958
``` rust
@@ -971,7 +966,6 @@ r[asm.options.supported-options.nomem]
971
966
# }
972
967
```
973
968
974
-
975
969
r[ asm.options.supported-options.readonly]
976
970
- ` readonly ` : The ` asm! ` block does not write to any memory accessible outside of the ` asm! ` block.
977
971
This allows the compiler to cache the values of unmodified global variables in registers across the ` asm! ` block since it knows that they are not written to by the ` asm! ` .
@@ -983,7 +977,7 @@ r[asm.options.supported-options.readonly]
983
977
let mut x = 0;
984
978
// We cannot modify memory in readonly
985
979
unsafe { core::arch::asm!("mov dword ptr[{}], 1", in(reg) &mut x, options(readonly))}
986
- # }
980
+ # }
987
981
```
988
982
989
983
``` rust
@@ -996,7 +990,6 @@ r[asm.options.supported-options.readonly]
996
990
# }
997
991
```
998
992
999
-
1000
993
``` rust
1001
994
# #[cfg(target_arch = " x86_64" )] {
1002
995
let x : i64 = 0 ;
@@ -1205,19 +1198,19 @@ pub fn fadd(x: f64, y: f64) -> f64{
1205
1198
let mut top = 0u16 ;
1206
1199
// we can do complex stuff with x87 if we clobber the entire x87 stack
1207
1200
unsafe { core :: arch :: asm! (
1208
- " fld qword ptr [{x}]" ,
1209
- " fld qword ptr [{y}])" ,
1210
- " faddp" ,
1211
- " fstp qword ptr [{out}]" ,
1201
+ " fld qword ptr [{x}]" ,
1202
+ " fld qword ptr [{y}])" ,
1203
+ " faddp" ,
1204
+ " fstp qword ptr [{out}]" ,
1212
1205
" xor eax, eax" ,
1213
1206
" fstsw ax" ,
1214
1207
" shl eax, 11" ,
1215
- x = in (reg ) & x ,
1216
- y = in (reg ) & y ,
1208
+ x = in (reg ) & x ,
1209
+ y = in (reg ) & y ,
1217
1210
out = in (reg ) & mut out ,
1218
- out (" st(0)" ) _ , out (" st(1)" ) _ , out (" st(2)" ) _ , out (" st(3)" ) _ ,
1211
+ out (" st(0)" ) _ , out (" st(1)" ) _ , out (" st(2)" ) _ , out (" st(3)" ) _ ,
1219
1212
out (" st(4)" ) _ , out (" st(5)" ) _ , out (" st(6)" ) _ , out (" st(7)" ) _ ,
1220
- out (" eax" ) top
1213
+ out (" eax" ) top
1221
1214
);}
1222
1215
1223
1216
assert_eq! (top & 0x7 , 0 );
@@ -1367,7 +1360,6 @@ r[asm.target-specific-directives.dwarf-unwinding]
1367
1360
1368
1361
The following directives are supported on ELF targets that support DWARF unwind info:
1369
1362
1370
-
1371
1363
- ` .cfi_adjust_cfa_offset `
1372
1364
- ` .cfi_def_cfa `
1373
1365
- ` .cfi_def_cfa_offset `
@@ -1390,7 +1382,6 @@ The following directives are supported on ELF targets that support DWARF unwind
1390
1382
- ` .cfi_undefined `
1391
1383
- ` .cfi_window_save `
1392
1384
1393
-
1394
1385
r[ asm.target-specific-directives.structured-exception-handling]
1395
1386
##### Structured Exception Handling
1396
1387
@@ -1404,7 +1395,6 @@ On targets with structured exception Handling, the following additional directiv
1404
1395
- ` .seh_setframe `
1405
1396
- ` .seh_stackalloc `
1406
1397
1407
-
1408
1398
r[ asm.target-specific-directives.x86]
1409
1399
##### x86 (32-bit and 64-bit)
1410
1400
@@ -1414,12 +1404,9 @@ On x86 targets, both 32-bit and 64-bit, the following additional directives are
1414
1404
- ` .code32 `
1415
1405
- ` .code64 `
1416
1406
1417
-
1418
1407
Use of ` .code16 ` , ` .code32 ` , and ` .code64 ` directives are only supported if the state is reset to the default before exiting the assembly block.
1419
1408
32-bit x86 uses ` .code32 ` by default, and x86_64 uses ` .code64 ` by default.
1420
1409
1421
-
1422
-
1423
1410
r[ asm.target-specific-directives.arm-32-bit]
1424
1411
##### ARM (32-bit)
1425
1412
0 commit comments