@@ -64,6 +64,10 @@ use crate::type_of::LayoutGccExt;
64
64
// and one register variable assigned to the desired register.
65
65
//
66
66
67
+ const ATT_SYNTAX_INS : & str = ".att_syntax noprefix\n \t " ;
68
+ const INTEL_SYNTAX_INS : & str = "\n \t .intel_syntax noprefix" ;
69
+
70
+
67
71
struct AsmOutOperand < ' a , ' tcx , ' gcc > {
68
72
rust_idx : usize ,
69
73
constraint : & ' a str ,
@@ -360,7 +364,11 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
360
364
}
361
365
362
366
// Build the template string
363
- let mut template_str = String :: with_capacity ( estimate_template_length ( template, constants_len) ) ;
367
+ let mut template_str = String :: with_capacity ( estimate_template_length ( template, constants_len, att_dialect) ) ;
368
+ if !intel_dialect {
369
+ template_str. push_str ( ATT_SYNTAX_INS ) ;
370
+ }
371
+
364
372
for piece in template {
365
373
match * piece {
366
374
InlineAsmTemplatePiece :: String ( ref string) => {
@@ -439,16 +447,10 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
439
447
}
440
448
}
441
449
442
- let template_str =
443
- if intel_dialect {
444
- template_str
445
- }
446
- else {
447
- // FIXME(antoyo): this might break the "m" memory constraint:
448
- // https://stackoverflow.com/a/9347957/389119
449
- format ! ( ".att_syntax noprefix\n \t {}\n \t .intel_syntax noprefix" , template_str)
450
- } ;
451
-
450
+ if !intel_dialect {
451
+ template_str. push_str ( INTEL_SYNTAX_INS ) ;
452
+ }
453
+
452
454
let block = self . llbb ( ) ;
453
455
let extended_asm = block. add_extended_asm ( None , & template_str) ;
454
456
@@ -496,15 +498,15 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
496
498
}
497
499
}
498
500
499
- fn estimate_template_length ( template : & [ InlineAsmTemplatePiece ] , constants_len : usize ) -> usize {
501
+ fn estimate_template_length ( template : & [ InlineAsmTemplatePiece ] , constants_len : usize , att_dialect : bool ) -> usize {
500
502
let len: usize = template. iter ( ) . map ( |piece| {
501
503
match * piece {
502
504
InlineAsmTemplatePiece :: String ( ref string) => {
503
505
string. len ( )
504
506
}
505
507
InlineAsmTemplatePiece :: Placeholder { .. } => {
506
- // '%' + 1 char modifier + 2 chars index
507
- 4
508
+ // '%' + 1 char modifier + 1 char index
509
+ 3
508
510
}
509
511
}
510
512
} )
@@ -513,7 +515,12 @@ fn estimate_template_length(template: &[InlineAsmTemplatePiece], constants_len:
513
515
// increase it by 5% to account for possible '%' signs that'll be duplicated
514
516
// I pulled the number out of blue, but should be fair enough
515
517
// as the upper bound
516
- ( len as f32 * 1.05 ) as usize + constants_len
518
+ let mut res = ( len as f32 * 1.05 ) as usize + constants_len;
519
+
520
+ if att_dialect {
521
+ res += INTEL_SYNTAX_INS . len ( ) + ATT_SYNTAX_INS . len ( ) ;
522
+ }
523
+ res
517
524
}
518
525
519
526
/// Converts a register class to a GCC constraint code.
0 commit comments