1+ use std:: collections:: HashSet ;
12use std:: env;
23use std:: fmt;
34use std:: fs:: File ;
@@ -90,6 +91,14 @@ impl TargetFeature {
9091 }
9192}
9293
94+ fn portable_intrinsics ( ) -> HashSet < & ' static str > {
95+ include_str ! ( "portable-intrinsics.txt" )
96+ . lines ( )
97+ . map ( str:: trim)
98+ . filter ( |line| !line. is_empty ( ) && !line. starts_with ( '#' ) )
99+ . collect ( )
100+ }
101+
93102fn gen_spec ( in_file : String , ext_name : & str ) -> io:: Result < ( ) > {
94103 let f = File :: open ( in_file. clone ( ) ) . unwrap_or_else ( |_| panic ! ( "Failed to open {in_file}" ) ) ;
95104 let f = BufReader :: new ( f) ;
@@ -105,6 +114,7 @@ fn gen_spec(in_file: String, ext_name: &str) -> io::Result<()> {
105114 let mut asm_fmts = String :: new ( ) ;
106115 let mut data_types = String :: new ( ) ;
107116 let fn_pat = format ! ( "__{ext_name}_" ) ;
117+ let portable_intrinsics = portable_intrinsics ( ) ;
108118 for line in f. lines ( ) {
109119 let line = line. unwrap ( ) ;
110120 if line. is_empty ( ) {
@@ -121,6 +131,9 @@ fn gen_spec(in_file: String, ext_name: &str) -> io::Result<()> {
121131 let e = line. find ( '(' ) . unwrap ( ) ;
122132 let name = line. get ( s + 2 ..e) . unwrap ( ) . trim ( ) . to_string ( ) ;
123133 out. push_str ( & format ! ( "/// {name}\n " ) ) ;
134+ if portable_intrinsics. contains ( name. as_str ( ) ) {
135+ out. push_str ( "impl = portable\n " ) ;
136+ }
124137 out. push_str ( & format ! ( "name = {name}\n " ) ) ;
125138 out. push_str ( & format ! ( "asm-fmts = {asm_fmts}\n " ) ) ;
126139 out. push_str ( & format ! ( "data-types = {data_types}\n " ) ) ;
@@ -146,6 +159,7 @@ fn gen_bind(in_file: String, ext_name: &str) -> io::Result<()> {
146159 let mut link_function_str = String :: new ( ) ;
147160 let mut function_str = String :: new ( ) ;
148161 let mut out = String :: new ( ) ;
162+ let mut skip = false ;
149163
150164 out. push_str ( & format ! (
151165 r#"// This code is automatically generated. DO NOT MODIFY.
@@ -173,7 +187,9 @@ unsafe extern "unadjusted" {
173187 if line. is_empty ( ) {
174188 continue ;
175189 }
176- if let Some ( name) = line. strip_prefix ( "name = " ) {
190+ if line. starts_with ( "impl = portable" ) {
191+ skip = true ;
192+ } else if let Some ( name) = line. strip_prefix ( "name = " ) {
177193 current_name = Some ( String :: from ( name) ) ;
178194 } else if line. starts_with ( "asm-fmts = " ) {
179195 asm_fmts = line[ 10 ..]
@@ -210,6 +226,11 @@ unsafe extern "unadjusted" {
210226 panic ! ( "DEBUG: line: {0} len: {1}" , line, data_types. len( ) ) ;
211227 }
212228
229+ if skip {
230+ skip = false ;
231+ continue ;
232+ }
233+
213234 let ( link_function, function) =
214235 gen_bind_body ( & current_name, & asm_fmts, & in_t, out_t, para_num, target) ;
215236 link_function_str. push_str ( & link_function) ;
0 commit comments