| #!/usr/bin/env python |
| |
| import sys, fileinput |
| |
| err = 0 |
| |
| # Giant associative set of builtin->intrinsic mappings where clang |
| # doesn't implement the builtin. (Either because the vector operation |
| # works without a builtin, or for other reasons.) |
| |
| repl_map = { |
| "__builtin_ia32_addps": "_mm_add_ps", |
| "__builtin_ia32_addsd": "_mm_add_sd", |
| "__builtin_ia32_addpd": "_mm_add_pd", |
| "__builtin_ia32_addss": "_mm_add_ss", |
| "__builtin_ia32_paddb128": "_mm_add_epi8", |
| "__builtin_ia32_paddw128": "_mm_add_epi16", |
| "__builtin_ia32_paddd128": "_mm_add_epi32", |
| "__builtin_ia32_paddq128": "_mm_add_epi64", |
| "__builtin_ia32_subps": "_mm_sub_ps", |
| "__builtin_ia32_subsd": "_mm_sub_sd", |
| "__builtin_ia32_subpd": "_mm_sub_pd", |
| "__builtin_ia32_subss": "_mm_sub_ss", |
| "__builtin_ia32_psubb128": "_mm_sub_epi8", |
| "__builtin_ia32_psubw128": "_mm_sub_epi16", |
| "__builtin_ia32_psubd128": "_mm_sub_epi32", |
| "__builtin_ia32_psubq128": "_mm_sub_epi64", |
| "__builtin_ia32_mulsd": "_mm_mul_sd", |
| "__builtin_ia32_mulpd": "_mm_mul_pd", |
| "__builtin_ia32_mulps": "_mm_mul_ps", |
| "__builtin_ia32_mulss": "_mm_mul_ss", |
| "__builtin_ia32_pmullw128": "_mm_mullo_epi16", |
| "__builtin_ia32_divsd": "_mm_div_sd", |
| "__builtin_ia32_divpd": "_mm_div_pd", |
| "__builtin_ia32_divps": "_mm_div_ps", |
| "__builtin_ia32_subss": "_mm_div_ss", |
| "__builtin_ia32_andpd": "_mm_and_pd", |
| "__builtin_ia32_andps": "_mm_and_ps", |
| "__builtin_ia32_pand128": "_mm_and_si128", |
| "__builtin_ia32_andnpd": "_mm_andnot_pd", |
| "__builtin_ia32_andnps": "_mm_andnot_ps", |
| "__builtin_ia32_pandn128": "_mm_andnot_si128", |
| "__builtin_ia32_orpd": "_mm_or_pd", |
| "__builtin_ia32_orps": "_mm_or_ps", |
| "__builtin_ia32_por128": "_mm_or_si128", |
| "__builtin_ia32_xorpd": "_mm_xor_pd", |
| "__builtin_ia32_xorps": "_mm_xor_ps", |
| "__builtin_ia32_pxor128": "_mm_xor_si128", |
| "__builtin_ia32_cvtps2dq": "_mm_cvtps_epi32", |
| "__builtin_ia32_cvtsd2ss": "_mm_cvtsd_ss", |
| "__builtin_ia32_cvtsi2sd": "_mm_cvtsi32_sd", |
| "__builtin_ia32_cvtss2sd": "_mm_cvtss_sd", |
| "__builtin_ia32_cvttsd2si": "_mm_cvttsd_si32", |
| "__builtin_ia32_vec_ext_v2df": "_mm_cvtsd_f64", |
| "__builtin_ia32_loadhpd": "_mm_loadh_pd", |
| "__builtin_ia32_loadlpd": "_mm_loadl_pd", |
| "__builtin_ia32_loadlv4si": "_mm_loadl_epi64", |
| "__builtin_ia32_cmpeqps": "_mm_cmpeq_ps", |
| "__builtin_ia32_cmpltps": "_mm_cmplt_ps", |
| "__builtin_ia32_cmpleps": "_mm_cmple_ps", |
| "__builtin_ia32_cmpgtps": "_mm_cmpgt_ps", |
| "__builtin_ia32_cmpgeps": "_mm_cmpge_ps", |
| "__builtin_ia32_cmpunordps": "_mm_cmpunord_ps", |
| "__builtin_ia32_cmpneqps": "_mm_cmpneq_ps", |
| "__builtin_ia32_cmpnltps": "_mm_cmpnlt_ps", |
| "__builtin_ia32_cmpnleps": "_mm_cmpnle_ps", |
| "__builtin_ia32_cmpngtps": "_mm_cmpngt_ps", |
| "__builtin_ia32_cmpordps": "_mm_cmpord_ps", |
| "__builtin_ia32_cmpeqss": "_mm_cmpeq_ss", |
| "__builtin_ia32_cmpltss": "_mm_cmplt_ss", |
| "__builtin_ia32_cmpless": "_mm_cmple_ss", |
| "__builtin_ia32_cmpunordss": "_mm_cmpunord_ss", |
| "__builtin_ia32_cmpneqss": "_mm_cmpneq_ss", |
| "__builtin_ia32_cmpnltss": "_mm_cmpnlt_ss", |
| "__builtin_ia32_cmpnless": "_mm_cmpnle_ss", |
| "__builtin_ia32_cmpngtss": "_mm_cmpngt_ss", |
| "__builtin_ia32_cmpngess": "_mm_cmpnge_ss", |
| "__builtin_ia32_cmpordss": "_mm_cmpord_ss", |
| "__builtin_ia32_movss": "_mm_move_ss", |
| "__builtin_ia32_movsd": "_mm_move_sd", |
| "__builtin_ia32_movhlps": "_mm_movehl_ps", |
| "__builtin_ia32_movlhps": "_mm_movelh_ps", |
| "__builtin_ia32_movqv4si": "_mm_move_epi64", |
| "__builtin_ia32_unpckhps": "_mm_unpackhi_ps", |
| "__builtin_ia32_unpckhpd": "_mm_unpackhi_pd", |
| "__builtin_ia32_punpckhbw128": "_mm_unpackhi_epi8", |
| "__builtin_ia32_punpckhwd128": "_mm_unpackhi_epi16", |
| "__builtin_ia32_punpckhdq128": "_mm_unpackhi_epi32", |
| "__builtin_ia32_punpckhqdq128": "_mm_unpackhi_epi64", |
| "__builtin_ia32_unpcklps": "_mm_unpacklo_ps", |
| "__builtin_ia32_unpcklpd": "_mm_unpacklo_pd", |
| "__builtin_ia32_punpcklbw128": "_mm_unpacklo_epi8", |
| "__builtin_ia32_punpcklwd128": "_mm_unpacklo_epi16", |
| "__builtin_ia32_punpckldq128": "_mm_unpacklo_epi32", |
| "__builtin_ia32_punpcklqdq128": "_mm_unpacklo_epi64", |
| "__builtin_ia32_cmpeqpd": "_mm_cmpeq_pd", |
| "__builtin_ia32_cmpltpd": "_mm_cmplt_pd", |
| "__builtin_ia32_cmplepd": "_mm_cmple_pd", |
| "__builtin_ia32_cmpgtpd": "_mm_cmpgt_pd", |
| "__builtin_ia32_cmpgepd": "_mm_cmpge_pd", |
| "__builtin_ia32_cmpunordpd": "_mm_cmpunord_pd", |
| "__builtin_ia32_cmpneqpd": "_mm_cmpneq_pd", |
| "__builtin_ia32_cmpnltpd": "_mm_cmpnlt_pd", |
| "__builtin_ia32_cmpnlepd": "_mm_cmpnle_pd", |
| "__builtin_ia32_cmpngtpd": "_mm_cmpngt_pd", |
| "__builtin_ia32_cmpngepd": "_mm_cmpnge_pd", |
| "__builtin_ia32_cmpordpd": "_mm_cmpord_pd", |
| "__builtin_ia32_cmpeqsd": "_mm_cmpeq_sd", |
| "__builtin_ia32_cmpltsd": "_mm_cmplt_sd", |
| "__builtin_ia32_cmplesd": "_mm_cmple_sd", |
| "__builtin_ia32_cmpunordsd": "_mm_cmpunord_sd", |
| "__builtin_ia32_cmpneqsd": "_mm_cmpneq_sd", |
| "__builtin_ia32_cmpnltsd": "_mm_cmpnlt_sd", |
| "__builtin_ia32_cmpnlesd": "_mm_cmpnle_sd", |
| "__builtin_ia32_cmpordsd": "_mm_cmpord_sd", |
| "__builtin_ia32_cvtsi642ss": "_mm_cvtsi64_ss", |
| "__builtin_ia32_cvttss2si64": "_mm_cvtss_si64", |
| "__builtin_ia32_shufps": "_mm_shuffle_ps", |
| "__builtin_ia32_shufpd": "_mm_shuffle_pd", |
| "__builtin_ia32_pshufhw": "_mm_shufflehi_epi16", |
| "__builtin_ia32_pshuflw": "_mm_shufflelo_epi16", |
| "__builtin_ia32_pshufd": "_mm_shuffle_epi32", |
| "__builtin_ia32_movshdup": "_mm_movehdup_ps", |
| "__builtin_ia32_movsldup": "_mm_moveldup_ps", |
| "__builtin_ia32_maxps": "_mm_max_ps", |
| "__builtin_ia32_pslldi128": "_mm_slli_epi32", |
| "__builtin_ia32_vec_set_v16qi": "_mm_insert_epi8", |
| "__builtin_ia32_vec_set_v8hi": "_mm_insert_epi16", |
| "__builtin_ia32_vec_set_v4si": "_mm_insert_epi32", |
| "__builtin_ia32_vec_set_v2di": "_mm_insert_epi64", |
| "__builtin_ia32_vec_set_v4hi": "_mm_insert_pi16", |
| "__builtin_ia32_vec_ext_v16qi": "_mm_extract_epi8", |
| "__builtin_ia32_vec_ext_v8hi": "_mm_extract_epi16", |
| "__builtin_ia32_vec_ext_v4si": "_mm_extract_epi32", |
| "__builtin_ia32_vec_ext_v2di": "_mm_extract_epi64", |
| "__builtin_ia32_vec_ext_v4hi": "_mm_extract_pi16", |
| "__builtin_ia32_vec_ext_v4sf": "_mm_extract_ps", |
| # Removed MMX builtins |
| "__builtin_ia32_paddb": "_mm_add_pi8", |
| "__builtin_ia32_paddw": "_mm_add_pi16", |
| "__builtin_ia32_paddd": "_mm_add_pi32", |
| "__builtin_ia32_paddsb": "_mm_adds_pi8", |
| "__builtin_ia32_paddsw": "_mm_adds_pi16", |
| "__builtin_ia32_paddusb": "_mm_adds_pu8", |
| "__builtin_ia32_paddusw": "_mm_adds_pu16", |
| "__builtin_ia32_psubb": "_mm_sub_pi8", |
| "__builtin_ia32_psubw": "_mm_sub_pi16", |
| "__builtin_ia32_psubd": "_mm_sub_pi32", |
| "__builtin_ia32_psubsb": "_mm_subs_pi8", |
| "__builtin_ia32_psubsw": "_mm_subs_pi16", |
| "__builtin_ia32_psubusb": "_mm_subs_pu8", |
| "__builtin_ia32_psubusw": "_mm_subs_pu16", |
| "__builtin_ia32_pmulhw": "_mm_mulhi_pi16", |
| "__builtin_ia32_pmullw": "_mm_mullo_pi16", |
| "__builtin_ia32_pmaddwd": "_mm_madd_pi16", |
| "__builtin_ia32_pand": "_mm_and_si64", |
| "__builtin_ia32_pandn": "_mm_andnot_si64", |
| "__builtin_ia32_por": "_mm_or_si64", |
| "__builtin_ia32_pxor": "_mm_xor_si64", |
| "__builtin_ia32_psllw": "_mm_sll_pi16", |
| "__builtin_ia32_pslld": "_mm_sll_pi32", |
| "__builtin_ia32_psllq": "_mm_sll_si64", |
| "__builtin_ia32_psrlw": "_mm_srl_pi16", |
| "__builtin_ia32_psrld": "_mm_srl_pi32", |
| "__builtin_ia32_psrlq": "_mm_srl_si64", |
| "__builtin_ia32_psraw": "_mm_sra_pi16", |
| "__builtin_ia32_psrad": "_mm_sra_pi32", |
| "__builtin_ia32_psllwi": "_mm_slli_pi16", |
| "__builtin_ia32_pslldi": "_mm_slli_pi32", |
| "__builtin_ia32_psllqi": "_mm_slli_si64", |
| "__builtin_ia32_psrlwi": "_mm_srli_pi16", |
| "__builtin_ia32_psrldi": "_mm_srli_pi32", |
| "__builtin_ia32_psrlqi": "_mm_srli_si64", |
| "__builtin_ia32_psrawi": "_mm_srai_pi16", |
| "__builtin_ia32_psradi": "_mm_srai_pi32", |
| "__builtin_ia32_packsswb": "_mm_packs_pi16", |
| "__builtin_ia32_packssdw": "_mm_packs_pi32", |
| "__builtin_ia32_packuswb": "_mm_packs_pu16", |
| "__builtin_ia32_punpckhbw": "_mm_unpackhi_pi8", |
| "__builtin_ia32_punpckhwd": "_mm_unpackhi_pi16", |
| "__builtin_ia32_punpckhdq": "_mm_unpackhi_pi32", |
| "__builtin_ia32_punpcklbw": "_mm_unpacklo_pi8", |
| "__builtin_ia32_punpcklwd": "_mm_unpacklo_pi16", |
| "__builtin_ia32_punpckldq": "_mm_unpacklo_pi32", |
| "__builtin_ia32_pcmpeqb": "_mm_cmpeq_pi8", |
| "__builtin_ia32_pcmpeqw": "_mm_cmpeq_pi16", |
| "__builtin_ia32_pcmpeqd": "_mm_cmpeq_pi32", |
| "__builtin_ia32_pcmpgtb": "_mm_cmpgt_pi8", |
| "__builtin_ia32_pcmpgtw": "_mm_cmpgt_pi16", |
| "__builtin_ia32_pcmpgtd": "_mm_cmpgt_pi32", |
| "__builtin_ia32_maskmovq": "_mm_maskmove_si64", |
| "__builtin_ia32_movntq": "_mm_stream_pi", |
| "__builtin_ia32_vec_init_v2si": "_mm_setr_pi32", |
| "__builtin_ia32_vec_init_v4hi": "_mm_setr_pi16", |
| "__builtin_ia32_vec_init_v8qi": "_mm_setr_pi8", |
| "__builtin_ia32_cvtpi2ps": "_mm_cvtpi32_ps", |
| "__builtin_ia32_cvtps2pi": "_mm_cvtps_pi32", |
| "__builtin_ia32_cvttps2pi": "_mm_cvttps_pi32", |
| "__builtin_ia32_pavgb": "_mm_avg_pu8", |
| "__builtin_ia32_pavgw": "_mm_avg_pu16", |
| "__builtin_ia32_pmaxsw": "_mm_max_pi16", |
| "__builtin_ia32_pmaxub": "_mm_max_pu8", |
| "__builtin_ia32_pminsw": "_mm_min_pi16", |
| "__builtin_ia32_pminub": "_mm_min_pu8", |
| "__builtin_ia32_pmovmskb": "_mm_movemask_pi8", |
| "__builtin_ia32_pmulhuw": "_mm_mulhi_pu16", |
| "__builtin_ia32_psadbw": "_mm_sad_pu8", |
| "__builtin_ia32_pshufw": "_mm_shuffle_pi16", |
| "__builtin_ia32_cvtpd2pi": "_mm_cvtpd_pi32", |
| "__builtin_ia32_cvtpi2pd": "_mm_cvtpi32_pd", |
| "__builtin_ia32_cvttpd2pi": "_mm_cvttpd_pi32", |
| "__builtin_ia32_paddq": "_mm_add_si64", |
| "__builtin_ia32_pmuludq": "_mm_mul_su32", |
| "__builtin_ia32_psubq": "_mm_sub_si64", |
| "__builtin_ia32_pabsb": "_mm_abs_pi8", |
| "__builtin_ia32_pabsd": "_mm_abs_pi32", |
| "__builtin_ia32_pabsw": "_mm_abs_pi16", |
| "__builtin_ia32_palignr": "_mm_alignr_pi8", |
| "__builtin_ia32_phaddd": "_mm_hadd_pi32", |
| "__builtin_ia32_phaddsw": "_mm_hadds_pi16", |
| "__builtin_ia32_phaddw": "_mm_hadd_pi16", |
| "__builtin_ia32_phsubd": "_mm_hsub_pi32", |
| "__builtin_ia32_phsubsw": "_mm_hsubs_pi16", |
| "__builtin_ia32_phsubw": "_mm_hsub_pi16", |
| "__builtin_ia32_pmaddubsw": "_mm_maddubs_pi16", |
| "__builtin_ia32_pmulhrsw": "_mm_mulhrs_pi16", |
| "__builtin_ia32_pshufb": "_mm_shuffle_pi8", |
| "__builtin_ia32_psignw": "_mm_sign_pi16", |
| "__builtin_ia32_psignb": "_mm_sign_pi8", |
| "__builtin_ia32_psignd": "_mm_sign_pi32", |
| } |
| |
| # Special unhandled cases: |
| # __builtin_ia32_vec_ext_*(__P, idx) -> _mm_store_sd/_mm_storeh_pd |
| # depending on index. No abstract insert/extract for these oddly. |
| unhandled = [ |
| "__builtin_ia32_vec_ext_v2df", |
| "__builtin_ia32_vec_ext_v2si", |
| ] |
| |
| |
| def report_repl(builtin, repl): |
| sys.stderr.write( |
| "%s:%d: x86 builtin %s used, replaced with %s\n" |
| % (fileinput.filename(), fileinput.filelineno(), builtin, repl) |
| ) |
| |
| |
| def report_cant(builtin): |
| sys.stderr.write( |
| "%s:%d: x86 builtin %s used, too many replacements\n" |
| % (fileinput.filename(), fileinput.filelineno(), builtin) |
| ) |
| |
| |
| for line in fileinput.input(inplace=1): |
| for builtin, repl in repl_map.items(): |
| if builtin in line: |
| line = line.replace(builtin, repl) |
| report_repl(builtin, repl) |
| for unh in unhandled: |
| if unh in line: |
| report_cant(unh) |
| sys.stdout.write(line) |
| |
| sys.exit(err) |