Note for 20140726_SD_coding

本文探讨了SD数在FPGA实现的无进位加法器及乘法器中的应用。SD数能够简化乘法运算,并通过减少非零元素数量降低运算复杂度。文中还举例说明了29与-9在SD系统中的加法过程。

The same as the before blog is just for myself learning. All the mateials is from one book--Digitial Singal Processing with FPGAs.


SD numbers have proven to be useful in carry-free adders or multipliers with elss complexity, because the effort in multiplication can typically be extimated through the number of nonzero elements, which can be reduced by using SD numbers.

Carry-free Addition Example

The addition of 29 to -9 in the SD system is performed below.




However, due to the ternary logic burden, implementing Table 2.2 with FPGAs requires four-input operands for the Ck and Uk. This transliates into a 2 times 8 x4-bit when implementing Table 2.2.


# -*- coding : UTF-8 -*- import json import os import time from android.XmlExtract import XmlExtractor from common import Config, TextHandler, FormatSpecifierParser, TranslateInfoExcelWriter from common.NoGenerator import NoGenerator from common.TranslateInfo import TranslateInfo from common.TranslateInfoExcelWriter import ExcelTranslateWriteInfo from flutter.JsonExtract import JsonExtractor from ios.StringsExtract import StringsExtractor if __name__ == "__main__": # -------------------提取iOS新增文案------------------- ios_extract_root_path = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_EXTRACT_NAME, 'iOS') ios_pre_en_dir = os.path.join(ios_extract_root_path, 'en.lproj.old') ios_cur_en_dir = os.path.join(ios_extract_root_path, 'en.lproj.new') ios_new_english_list = StringsExtractor(ios_pre_en_dir, ios_cur_en_dir).extract() # -------------------提取Android新增文案------------------- android_extract_root_path = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_EXTRACT_NAME, 'Android') android_old_xml_file = os.path.join(android_extract_root_path, 'values-old', 'strings.xml') android_new_xml_file = os.path.join(android_extract_root_path, 'values-new', 'strings.xml') android_new_english_list = XmlExtractor(android_old_xml_file, android_new_xml_file).extract() # -------------------提取Flutter新增文案------------------- flutter_extract_root_path = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_EXTRACT_NAME, 'Flutter') flutter_old_json_file = os.path.join(flutter_extract_root_path, 'l10n-old', 'intl_en.arb') flutter_new_json_file = os.path.join(flutter_extract_root_path, 'l10n-new', 'intl_en.arb') flutter_new_english_list = JsonExtractor(flutter_old_json_file, flutter_new_json_file).extract() # -------------------提取PC新增文案------------------- # pc_extract_root_path = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_EXTRACT_NAME, # 'PC') # flutter_old_json_file = os.path.join(flutter_extract_root_path, 'l10n-old', 'intl_en.arb') # flutter_new_json_file = os.path.join(flutter_extract_root_path, 'l10n-new', 'intl_en.arb') # flutter_new_english_list = JsonExtractor(flutter_old_json_file, flutter_new_json_file).extract() # -------------------ios和android合并操作------------------- new_english_dict = dict() ios_only_new_english_size = 0 android_only_new_english_size = 0 flutter_only_new_english_size = 0 common_new_english_size = 0 # 用于获取或生成新增文案的截图编号 no_generator = NoGenerator(Config.DECO_ALL_STRINGS_PATH) for val in ios_new_english_list: if val not in android_new_english_list: ios_only_new_english_size += + 1 new_english_dict[val] = TranslateInfo(val, '', 'iOS', no_generator.get_no(val, 'iOS'), TextHandler.build_translate_note(val)) for val in android_new_english_list: if val not in ios_new_english_list: android_only_new_english_size += 1 new_english_dict[val] = TranslateInfo(val, '', 'Android', no_generator.get_no(val, 'Android'), TextHandler.build_translate_note(val)) for val in ios_new_english_list: if val in android_new_english_list: common_new_english_size += 1 new_english_dict[val] = TranslateInfo(val, '', 'Android/iOS', no_generator.get_no(val, 'Android/iOS'), TextHandler.build_translate_note(val)) for val in flutter_new_english_list: if val in ios_new_english_list or val in android_new_english_list: continue flutter_only_new_english_size += 1 new_english_dict[val] = TranslateInfo(val, '', 'Flutter', no_generator.get_no(val, 'Flutter'), TextHandler.build_translate_note(val)) # print(*ios_new_english_list, sep="\n") print("iOS新增数目:{0}", len(ios_new_english_list)) print("iOS独有数目:{0}", ios_only_new_english_size) print("Android新增数目:{0}", len(android_new_english_list)) print("Android独有数目:{0}", android_only_new_english_size) print("Android/iOS共有数目:{0}", common_new_english_size) print("Flutter新增数目:{0}", len(flutter_new_english_list)) print("Flutter独有数目:{0}", flutter_only_new_english_size) no_generator.print_generate_result() # -------------------预处理包含占位符的文案------------------- standard_excel_dict = dict() standard_excel_array = list() refer_excel_array = list() for key in new_english_dict.keys(): new_info = new_english_dict[key] print(new_info.no, '\n' + new_info.english) if new_info.platform == 'iOS': english_format = FormatSpecifierParser.replace_ios_format_char(new_info.english) else: print(new_info.english) english_format = FormatSpecifierParser.replace_java_format_char(new_info.english) if english_format in standard_excel_dict.keys(): standard_info = standard_excel_dict[english_format] if not standard_info.platform == new_info.platform: standard_info.platform = 'Android/iOS' # standard_info.no = 204734 # print(type(new_info.no), new_info.no, new_info.english, new_info.platform) if new_info.no < standard_info.no: standard_info.no = new_info.no else: standard_excel_dict[english_format] = ExcelTranslateWriteInfo(english_format, new_info.translate_result, new_info.platform, new_info.no, new_info.note) if not new_info.english == english_format: refer_excel_array.append( ExcelTranslateWriteInfo(new_info.english, english_format, new_info.platform, new_info.no, new_info.note)) real_string_no = no_generator.latest_max_no standard_excel_key = list(standard_excel_dict.keys()) standard_excel_key.sort() extract_root_path = os.path.join(Config.WORKSPACE_BASE_PATH + r'\Deco_APP_Sprint_All') locale_json_dst_file = os.path.join(os.path.join(extract_root_path), 'all_englist_translate_dict_new.text') with open(locale_json_dst_file, 'r', encoding='utf-8') as f: all_english_translate_dict = json.load(f) for x in standard_excel_key: standard_info = standard_excel_dict[x] if int(float(standard_info.no.strip())) > no_generator.latest_max_no: real_string_no += 1 standard_info.no = real_string_no # standard_excel_array.append(standard_info) if standard_info.english in all_english_translate_dict.keys(): print('已有翻译 ', standard_info.english) else: pass standard_excel_array.append(standard_info) #过滤已有翻译 # print(standard_info.english, standard_info.platform,standard_info.translate_result) standard_excel_array.sort(key=lambda item: item.english) refer_excel_array.sort(key=lambda item: item.english) # -------------------生成Excel操作------------------- date = time.strftime("%Y%m%d", time.localtime()) new_excel_name = Config.CURRENT_WORKSPACE_NEW_EXCEL_NAME_PREFIX + date + "(" + str(real_string_no) + ")" + ".xls" standard_excel_path = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_EXTRACT_NAME, new_excel_name) refer_excel_path = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_COMMON_NAME, 'Refer_Standard.xls') TranslateInfoExcelWriter.create_excel_with_all_info_list(standard_excel_path, standard_excel_array) TranslateInfoExcelWriter.create_excel_with_all_info_list(refer_excel_path, refer_excel_array) 代码解析
最新发布
10-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值