11// reference: https://github.com/espressif/clang-xtensa/commit/6fb488d2553f06029e6611cf81c6efbd45b56e47#diff-aa74ae1e1ab6b7149789237edb78e688R8450
22
3-
43use crate :: abi:: call:: { ArgType , FnType , Reg , Uniform } ;
54
65const NUM_ARG_GPR : u64 = 6 ;
7- const MAX_ARG_IN_REGS_SIZE : u64 = 4 * 32 ;
6+ const MAX_ARG_IN_REGS_SIZE : u64 = 4 * 32 ;
87// const MAX_ARG_DIRECT_SIZE: u64 = MAX_ARG_IN_REGS_SIZE;
9- const MAX_RET_IN_REGS_SIZE : u64 = 2 * 32 ;
8+ const MAX_RET_IN_REGS_SIZE : u64 = 2 * 32 ;
109
1110fn classify_ret_ty < Ty > ( arg : & mut ArgType < ' _ , Ty > , xlen : u64 ) {
1211 // The rules for return and argument types are the same, so defer to
1312 // classifyArgumentType.
1413 classify_arg_ty ( arg, xlen, & mut 2 ) ; // two as max return size
1514}
1615
17-
1816fn classify_arg_ty < Ty > ( arg : & mut ArgType < ' _ , Ty > , xlen : u64 , remaining_gpr : & mut u64 ) {
1917 // Determine the number of GPRs needed to pass the current argument
2018 // according to the ABI. 2*XLen-aligned varargs are passed in "aligned"
2119 // register pairs, so may consume 3 registers.
22-
20+
2321 let arg_size = arg. layout . size ;
2422 if arg_size. bits ( ) > MAX_ARG_IN_REGS_SIZE {
2523 arg. make_indirect ( ) ;
@@ -31,7 +29,7 @@ fn classify_arg_ty<Ty>(arg: &mut ArgType<'_, Ty>, xlen: u64, remaining_gpr: &mut
3129
3230 if alignment. bits ( ) == 2 * xlen {
3331 required_gpr = 2 + ( * remaining_gpr % 2 ) ;
34- } else if arg_size. bits ( ) > xlen && arg_size. bits ( ) <= MAX_ARG_IN_REGS_SIZE {
32+ } else if arg_size. bits ( ) > xlen && arg_size. bits ( ) <= MAX_ARG_IN_REGS_SIZE {
3533 required_gpr = ( arg_size. bits ( ) + ( xlen - 1 ) ) / xlen;
3634 }
3735
@@ -44,14 +42,16 @@ fn classify_arg_ty<Ty>(arg: &mut ArgType<'_, Ty>, xlen: u64, remaining_gpr: &mut
4442
4543 // if a value can fit in a reg and the
4644 // stack is not required, extend
47- if !arg. layout . is_aggregate ( ) { // non-aggregate types
45+ if !arg. layout . is_aggregate ( ) {
46+ // non-aggregate types
4847 if arg_size. bits ( ) < xlen && !stack_required {
4948 arg. extend_integer_width_to ( xlen) ;
5049 }
51- } else if arg_size. bits ( ) as u64 <= MAX_ARG_IN_REGS_SIZE { // aggregate types
50+ } else if arg_size. bits ( ) as u64 <= MAX_ARG_IN_REGS_SIZE {
51+ // aggregate types
5252 // Aggregates which are <= 4*32 will be passed in registers if possible,
5353 // so coerce to integers.
54-
54+
5555 // Use a single XLen int if possible, 2*XLen if 2*XLen alignment is
5656 // required, and a 2-element XLen array if only XLen alignment is
5757 // required.
@@ -61,48 +61,37 @@ fn classify_arg_ty<Ty>(arg: &mut ArgType<'_, Ty>, xlen: u64, remaining_gpr: &mut
6161 // arg.extend_integer_width_to(arg_size + (xlen - 1) / xlen);
6262 // }
6363 if alignment. bits ( ) == 2 * xlen {
64- arg. cast_to ( Uniform {
65- unit : Reg :: i64 ( ) ,
66- total : arg_size
67- } ) ;
64+ arg. cast_to ( Uniform { unit : Reg :: i64 ( ) , total : arg_size } ) ;
6865 } else {
69- //TODO array type - this should be a homogenous array type
66+ //FIXME array type - this should be a homogenous array type
7067 // arg.extend_integer_width_to(arg_size + (xlen - 1) / xlen);
7168 }
72-
7369 } else {
7470 // if we get here the stack is required
7571 assert ! ( stack_required) ;
7672 arg. make_indirect ( ) ;
7773 }
7874
79-
80- // if arg_size as u64 <= MAX_ARG_IN_REGS_SIZE {
81- // let align = arg.layout.align.abi.bytes();
82- // let total = arg.layout.size;
83- // arg.cast_to(Uniform {
84- // unit: if align <= 4 { Reg::i32() } else { Reg::i64() },
85- // total
86- // });
87- // return;
88- // }
89-
90-
75+ // if arg_size as u64 <= MAX_ARG_IN_REGS_SIZE {
76+ // let align = arg.layout.align.abi.bytes();
77+ // let total = arg.layout.size;
78+ // arg.cast_to(Uniform {
79+ // unit: if align <= 4 { Reg::i32() } else { Reg::i64() },
80+ // total
81+ // });
82+ // return;
83+ // }
9184}
9285
9386pub fn compute_abi_info < Ty > ( fty : & mut FnType < ' _ , Ty > , xlen : u64 ) {
9487 if !fty. ret . is_ignore ( ) {
9588 classify_ret_ty ( & mut fty. ret , xlen) ;
9689 }
9790
98- let return_indirect = fty . ret . layout . size . bits ( ) > MAX_RET_IN_REGS_SIZE ||
99- fty. ret . is_indirect ( ) ;
91+ let return_indirect =
92+ fty . ret . layout . size . bits ( ) > MAX_RET_IN_REGS_SIZE || fty. ret . is_indirect ( ) ;
10093
101- let mut remaining_gpr = if return_indirect {
102- NUM_ARG_GPR - 1
103- } else {
104- NUM_ARG_GPR
105- } ;
94+ let mut remaining_gpr = if return_indirect { NUM_ARG_GPR - 1 } else { NUM_ARG_GPR } ;
10695
10796 for arg in & mut fty. args {
10897 if arg. is_ignore ( ) {
0 commit comments