MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / twosComplement

Function twosComplement

src/DesignCompile/CompileHelper.cpp:3923–3939  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3921char flip(char c) { return (c == '0') ? '1' : '0'; }
3922
3923std::string twosComplement(std::string_view bin) {
3924 int32_t n = bin.length();
3925 int32_t i;
3926 std::string ones, twos;
3927 for (i = 0; i < n; i++) ones += flip(bin[i]);
3928 twos = ones;
3929 for (i = n - 1; i >= 0; i--) {
3930 if (ones[i] == '1')
3931 twos[i] = '0';
3932 else {
3933 twos[i] = '1';
3934 break;
3935 }
3936 }
3937 if (i == -1) twos = '1' + twos;
3938 return twos;
3939}
3940
3941UHDM::constant* CompileHelper::adjustSize(const UHDM::typespec* ts,
3942 DesignComponent* component,

Callers 1

adjustSizeMethod · 0.85

Calls 1

flipFunction · 0.85

Tested by

no test coverage detected