@@ -49,6 +49,7 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>(
49
49
return vec ! [ ] . into ( ) ;
50
50
}
51
51
52
+ let void_ptr = builder. context . new_type :: < * mut ( ) > ( ) ;
52
53
// Some LLVM intrinsics do not map 1-to-1 to GCC intrinsics, so we add the missing
53
54
// arguments here.
54
55
if gcc_func. get_param_count ( ) != args. len ( ) {
@@ -503,6 +504,60 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>(
503
504
let arg4 = builder. context . new_rvalue_from_int ( arg4_type, -1 ) ;
504
505
args = vec ! [ a, b, c, arg4, new_args[ 3 ] ] . into ( ) ;
505
506
}
507
+ "__builtin_ia32_encodekey128_u32" | "__builtin_ia32_encodekey256_u32" => {
508
+ let mut new_args = args. to_vec ( ) ;
509
+ let result = builder. current_func ( ) . new_local ( None , void_ptr, "result" ) ;
510
+ new_args. push ( result. to_rvalue ( ) ) ;
511
+ args = new_args. into ( ) ;
512
+ }
513
+ "__builtin_ia32_aesenc128kl_u8"
514
+ | "__builtin_ia32_aesdec128kl_u8"
515
+ | "__builtin_ia32_aesenc256kl_u8"
516
+ | "__builtin_ia32_aesdec256kl_u8" => {
517
+ let mut new_args = vec ! [ ] ;
518
+ let result = builder. current_func ( ) . new_local ( None , void_ptr, "result" ) ;
519
+ new_args. push ( result. to_rvalue ( ) ) ;
520
+ new_args. extend ( args. to_vec ( ) ) ;
521
+ args = new_args. into ( ) ;
522
+ }
523
+ "__builtin_ia32_aesencwide128kl_u8"
524
+ | "__builtin_ia32_aesdecwide128kl_u8"
525
+ | "__builtin_ia32_aesencwide256kl_u8"
526
+ | "__builtin_ia32_aesdecwide256kl_u8" => {
527
+ let mut new_args = vec ! [ ] ;
528
+ let result = builder. current_func ( ) . new_local ( None , void_ptr, "result" ) ;
529
+ new_args. push ( result. to_rvalue ( ) ) ;
530
+
531
+ let mut old_args = args. to_vec ( ) ;
532
+ let handle = old_args. swap_remove ( 0 ) ; // Called __P in GCC.
533
+
534
+ let arg2_type = gcc_func. get_param_type ( 1 ) ;
535
+ let first_value = old_args. swap_remove ( 0 ) ;
536
+ let element_type = first_value. get_type ( ) ;
537
+ let array_type = builder. context . new_array_type ( None , element_type, 8 ) ;
538
+ let array = builder. current_func ( ) . new_local ( None , array_type, "array" ) ;
539
+ let input = builder. context . new_array_constructor (
540
+ None ,
541
+ array_type,
542
+ & [
543
+ first_value,
544
+ old_args. swap_remove ( 0 ) ,
545
+ old_args. swap_remove ( 0 ) ,
546
+ old_args. swap_remove ( 0 ) ,
547
+ old_args. swap_remove ( 0 ) ,
548
+ old_args. swap_remove ( 0 ) ,
549
+ old_args. swap_remove ( 0 ) ,
550
+ old_args. swap_remove ( 0 ) ,
551
+ ] ,
552
+ ) ;
553
+ builder. llbb ( ) . add_assignment ( None , array, input) ;
554
+ let input_ptr = array. get_address ( None ) ;
555
+ let input_ptr = builder. context . new_cast ( None , input_ptr, arg2_type) ;
556
+ new_args. push ( input_ptr) ;
557
+
558
+ new_args. push ( handle) ;
559
+ args = new_args. into ( ) ;
560
+ }
506
561
_ => ( ) ,
507
562
}
508
563
} else {
@@ -700,6 +755,24 @@ pub fn adjust_intrinsic_return_value<'a, 'gcc, 'tcx>(
700
755
let f16_type = builder. context . new_c_type ( CType :: Float16 ) ;
701
756
return_value = builder. context . new_cast ( None , return_value, f16_type) ;
702
757
}
758
+ "__builtin_ia32_encodekey128_u32" => {
759
+ // The builtin __builtin_ia32_encodekey128_u32 writes the result in its pointer argument while
760
+ // llvm.x86.encodekey128 returns a value.
761
+ // We added a result pointerargument since and now need to assign its value to the result_value expected by
762
+ // the LLVM intrinsic.
763
+ let ptr =
764
+ builder. context . new_cast ( None , args[ 2 ] , return_value. get_type ( ) . make_pointer ( ) ) ;
765
+ return_value = ptr. dereference ( None ) . to_rvalue ( ) ;
766
+ }
767
+ "__builtin_ia32_encodekey256_u32" => {
768
+ // The builtin __builtin_ia32_encodekey256_u32 writes the result in its pointer argument while
769
+ // llvm.x86.encodekey128 returns a value.
770
+ // We added a result pointerargument since and now need to assign its value to the result_value expected by
771
+ // the LLVM intrinsic.
772
+ let ptr =
773
+ builder. context . new_cast ( None , args[ 3 ] , return_value. get_type ( ) . make_pointer ( ) ) ;
774
+ return_value = ptr. dereference ( None ) . to_rvalue ( ) ;
775
+ }
703
776
_ => ( ) ,
704
777
}
705
778
@@ -1284,6 +1357,16 @@ pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function
1284
1357
"llvm.x86.avx512fp16.mask.vfmadd.cph.256" => "__builtin_ia32_vfmaddcph256_mask3" ,
1285
1358
"llvm.x86.avx512fp16.mask.vfcmadd.cph.128" => "__builtin_ia32_vfcmaddcph128_mask3" ,
1286
1359
"llvm.x86.avx512fp16.mask.vfmadd.cph.128" => "__builtin_ia32_vfmaddcph128_mask3" ,
1360
+ "llvm.x86.encodekey128" => "__builtin_ia32_encodekey128_u32" ,
1361
+ "llvm.x86.encodekey256" => "__builtin_ia32_encodekey256_u32" ,
1362
+ "llvm.x86.aesenc128kl" => "__builtin_ia32_aesenc128kl_u8" ,
1363
+ "llvm.x86.aesdec128kl" => "__builtin_ia32_aesdec128kl_u8" ,
1364
+ "llvm.x86.aesenc256kl" => "__builtin_ia32_aesenc256kl_u8" ,
1365
+ "llvm.x86.aesdec256kl" => "__builtin_ia32_aesdec256kl_u8" ,
1366
+ "llvm.x86.aesencwide128kl" => "__builtin_ia32_aesencwide128kl_u8" ,
1367
+ "llvm.x86.aesdecwide128kl" => "__builtin_ia32_aesdecwide128kl_u8" ,
1368
+ "llvm.x86.aesencwide256kl" => "__builtin_ia32_aesencwide256kl_u8" ,
1369
+ "llvm.x86.aesdecwide256kl" => "__builtin_ia32_aesdecwide256kl_u8" ,
1287
1370
1288
1371
// TODO: support the tile builtins:
1289
1372
"llvm.x86.ldtilecfg" => "__builtin_trap" ,
0 commit comments