KNOW: Bit Manipulation

本文详细介绍了位运算符的使用方法及技巧,包括按位取反、左移右移、按位与、按位异或、按位或等操作,并提供了实际应用场景示例,如设置、清除、更新特定位的方法。

Bit Operators

Bitwise Operators
~bitwise NOT~expr
<<, >>left/right shiftexpr1 << expr2
&bitwise ANDexpr1 & expr2
^bitwise XORexpr1 ^ expr2
|bitwise ORexpr1 | expr2

1. listed by their precedence

2. bitwise operators take operands of integral type

3. the sign bit is handled machine-dependent, so we'd better use unsigned type when using integral value with the bitwise operators

NOT operator (~) is similar in behavior to the bitset flip operation:

    unsigned char bits = 0227;     //10010111  
    bits = ~ bits;                 //01101000

Shift operator(<<, >>) will discard the bits that are shifted off the end. (The right-hand operand must not be negative and must be a value that is strictly less than the number of bits in the left-hand operand)

unsigned char bits = 0233;     //10011011  
    bits <<1;                      //00110110    the left most bit is discarded

And operator(&) will return 1 when both operands are 1; or 0.
XOR operator(^) will return 1 if either but not both operands contain 1 ; or 0.
OR operator(|) will return 1 if either or both operands are 1; or 0.
Bitset library are more direct easier than manipulate integral with bitwise operation.

Shift Operators has midlevel precedence:lower than arithmetic operators, but higher than relational, assignment, or conditional operators:

cout << 42 + 10;       //ok, + has higher precedence  
cout << (10 < 42);     //ok, parentheses force intended grouping, result is 1  
cout << 10 < 42;       //error, attempt to compare cout to 42  

Mask

wiki

In computer science, a mask is data that is used for bitwise operations, particularly in a bit field.

Using a mask, multiple bits in a byte, nibble, word (etc.) can be set either on, off or inverted from on to off (or vice versa) in a single bitwise operation.

Common Masking functions

Masking bit to 1

Y | 1 = 1

Masking bit to 0

Y & 0 = 0

Query Status of a bit

Turn off all other bits:

    10011101   10010101
AND 00001000   00001000
  = 00001000   00000000

Toggling bit values

Y ^ 0 = Y
Y ^ 1 = ~Y
// Example:
    10011101   10010101
XOR 00001111   11111111
  = 10010010   01101010

Bit Facts and Tricks

x ^ 0s = xx & 0s = 0x | 0s = x
x ^ 1s = ~xx & 1s = xx | 1s = 1s
x ^ x = 0x & x = xx | x = x

Common Bit Tasks

Get Bit

Get certain bit in a int value num:

boolean getBit(int num, int i)
{
    return ( (num & (1 << i))!=0 );
}

Set Bit

set certain bit:

int setBit(int num, int i)
{
    return num | (1 << i);
}

Clear Bit

clear ith bit:

int clearBit(int num, int i)
{
    int mask = ~(1 << i);
    return num & mask;
}
clear all bits from most significant bit through i(inclusive)
int clearBitsMSBthroughI(int num, int i)
{
    int mask = (1 << i) - 1;
    return num & mask;
}
clear all bits from i to 0(inclusive)

int clearBitsIthrough0(int num, int i)
{
    int mask = ~((1 << (i+1)) - 1);
    return num & mask;
}

Update Bit

// update the ith bit to value v (v is 0 or 1)
int updateBit (int num, int i, int v)
{
    int mask = ~(1 << i);
    return (num & mask) | (v << i);
}

Decimal to Binary translate

http://www.wikihow.com/Convert-from-Decimal-to-Binary

http://cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htm


 



请仔细阅读和分析下面函数,进行优化后,采用C/C++11标准,完整推导并重构可编译的全部代码 要求如下: 1.保持所有原始功能不变,不要遗漏逻辑细节 2.提高执行效率,降低计算复杂度 3.已经给定的结构体名字和元素不要更改,详细的中文注释 4.自动添加中文注释说明功能逻辑 5.不使用 auto,使用显式 for 循环 6.结构体采用32位定义 7.不要使用小函数,保持原始的函数定义 8.严格保持protobuf字段映射关系 特别注意: 1.函数中有关位操作不变,函数间的位操作一致, 详细注释位操作 2.函数中的 HDDMXng::BelUsageAttrib::BelUsageAttrib 映射为 message BelUsageAttrib { optional uint32 flags = 1; optional uint32 type = 2; optional uint32 bitwidth = 3; optional string attribname = 4; optional sint32 defint = 5; optional double defdouble = 6; optional bool defbool = 7; optional string defstring = 8; repeated sint32 listofints = 9 [packed = true]; repeated double listofdoubles = 10 [packed = true]; repeated bool listofbools = 11 [packed = true]; repeated string listofstrings = 12; optional uint32 precision = 13; } 3.采用 google::protobuf::Descriptor 和 google::protobuf::Reflection 进行编程 4.不要使用如 HIBYTE 等宏定义 5.将函数中的 _BYTE attrib_msg[24] 映射为 HDDMXng::BelUsageAttrib attrib_msg void __fastcall HDDMBelUsageAttrib::readme_pb(HDDMBelUsageAttrib *this, std::istream *stream, HDDMDevice *hddmDevice) { google::protobuf::Message *v4; // rdx unsigned int v5; // eax bool v6; // zf unsigned __int64 v7; // r12 __int64 *v8; // rax __int64 *v9; // rbp __int64 v10; // rax int v11; // r14d __int64 v12; // rdx const std::string *v13; // rsi unsigned __int64 v14; // rbp __int64 v15; // rdi __int64 *v16; // rax __int64 v17; // rdi std::string *v18; // r12 std::string *v19; // rbp __int64 v20; // r12 __int64 *v21; // rbp unsigned __int64 v22; // r13 char *v23; // rax __int64 v24; // rdx char *v25; // rcx char *v26; // rsi __int64 v27; // r12 int v28; // eax __int64 v29; // rsi char v30; // r8 __int64 v31; // rbp unsigned __int64 v32; // rcx __int64 v33; // rcx __int64 v34; // rdi __int64 *v35; // rax __int64 *v36; // rax __int64 v37; // rcx unsigned __int64 v38; // r12 __int64 *v39; // rax __int64 *v40; // rbp __int64 v41; // rax int v42; // eax __int64 v43; // rdx unsigned __int64 v44; // r12 unsigned __int64 v45; // rax int v46; // ebp __int64 *v47; // rax __int64 v48; // rdi unsigned __int64 v49; // r12 __int64 *v50; // rax __int64 *v51; // rbp __int64 v52; // rax int v53; // eax __int64 v54; // rdx unsigned __int64 v55; // r12 unsigned __int64 v56; // rax int v57; // ebp __int64 *attribVoidVec; // rax __int64 v59; // rdi _QWORD *v60; // rdx unsigned __int64 v61; // r12 char *v62; // rax unsigned __int64 v63; // r12 char *v64; // rax int v65; // eax __int64 v66; // rbp __int64 v67; // rax __int64 v68; // rdi __int64 *v69; // rcx __int64 v70; // rcx __int64 v71; // rdi __int64 *v72; // rax int v73; // edx int v74; // edx __int64 v75; // rbp __int64 v76; // rax __int64 v77; // rdi __int64 *v78; // rcx int v79; // edx int v80; // edx _QWORD *p_attribIndexMap; // [rsp+8h] [rbp-180h] HDDMBelUsageAttrib v82; // [rsp+10h] [rbp-178h] BYREF unsigned int v83; // [rsp+60h] [rbp-128h] char v84; // [rsp+64h] [rbp-124h] std::string *v85; // [rsp+68h] [rbp-120h] __int16 v86; // [rsp+70h] [rbp-118h] int v87; // [rsp+74h] [rbp-114h] __int64 v88; // [rsp+78h] [rbp-110h] std::string *v89; // [rsp+80h] [rbp-108h] __int64 v90; // [rsp+88h] [rbp-100h] int v91; // [rsp+90h] [rbp-F8h] __int64 v92; // [rsp+B0h] [rbp-D8h] int v93; // [rsp+B8h] [rbp-D0h] char v94; // [rsp+E4h] [rbp-A4h] __int16 v95; // [rsp+E8h] [rbp-A0h] char *v96; // [rsp+F0h] [rbp-98h] int v97; // [rsp+F8h] [rbp-90h] const std::string **v98; // [rsp+110h] [rbp-78h] int v99; // [rsp+118h] [rbp-70h] char v100; // [rsp+14Ch] [rbp-3Ch] char v101; // [rsp+14Dh] [rbp-3Bh] if ( HDDMDeviceDump::useXngMarks ) std::istream::read(stream, HDDMDeviceDump::markBuffer, 14LL); HDDMXng::BelUsageAttrib::BelUsageAttrib((HDDMXng::BelUsageAttrib *)&v82.qword40); HDDMDevice::readMessage((HDDMDevice *)stream, (std::istream *)&v82.qword40, v4); v5 = (((v83 >> 4) & 1) << 6) | (4 * ((v83 >> 3) & 1)) & 0xFFFFFFC7 | (2 * ((v83 >> 2) & 1)) & 0xFFFFFF83 | (v83 >> 1) & 1 | HIBYTE(this->attrib_code) & 0x80; BYTE1(this->attrib_code1) = ((unsigned __int8)(v83 >> 7) << 7) | (((v83 & 0x40) != 0) << 6) & 0x7F | (32 * ((v83 & 0x20) != 0)) & 0x7F | BYTE1(this->attrib_code1) & 0x1F; v6 = (v100 & 4) == 0; HIBYTE(this->attrib_code) = (8 * (v84 & 7)) | v5; if ( !v6 ) LOWORD(this->attrib_code) = v86 & 0xFFF | this->attrib_code & 0xF000; std::string::assign((std::string *)&this->attrib_name, v85); switch ( (HIBYTE(this->attrib_code) >> 3) & 7 ) { case 1: v49 = v91; v50 = (__int64 *)operator new(0x18uLL); v51 = v50; *v50 = 0LL; v50[1] = 0LL; v50[2] = 0LL; if ( v49 ) { if ( v49 > 0x3FFFFFFFFFFFFFFFLL ) std::__throw_bad_alloc(); v61 = 4 * v49; v62 = (char *)operator new(v61); *v51 = (__int64)v62; v51[1] = (__int64)v62; v51[2] = (__int64)&v62[v61]; memset(v62, 0, v61); v52 = v51[2]; } else { v50[2] = 0LL; v52 = 0LL; } v51[1] = v52; v53 = v91; this->attribVoidVec = v51; if ( v53 <= 0 ) goto LABEL_57; v54 = *v51; if ( !((v51[1] - *v51) >> 2) ) goto LABEL_77; if ( &_pthread_key_create ) { v55 = 1LL; v56 = 0LL; v57 = 0; while ( 1 ) { *(_DWORD *)(v54 + 4 * v56) = *(_DWORD *)(v90 + 4 * v56); HDDMBelUsageAttrib::getValueAsString(&v82, (int)this); *(_WORD *)std::map<std::string,unsigned short>::operator[](&this->attribIndexMap, &v82) = v57; v59 = *(_QWORD *)&v82.attrib_code - 24LL; if ( (_UNKNOWN *)(*(_QWORD *)&v82.attrib_code - 24LL) != &std::string::_Rep::_S_empty_rep_storage && _InterlockedExchangeAdd((volatile signed __int32 *)(*(_QWORD *)&v82.attrib_code - 8LL), 0xFFFFFFFF) <= 0 ) { std::string::_Rep::_M_destroy(v59, &v82.qword30); } if ( ++v57 >= v91 ) break; attribVoidVec = (__int64 *)this->attribVoidVec; v54 = *attribVoidVec; if ( (attribVoidVec[1] - *attribVoidVec) >> 2 <= v55 ) goto LABEL_77; v56 = v55++; } } else { v75 = 0LL; v76 = 0LL; while ( 1 ) { *(_DWORD *)(v54 + 4 * v76) = *(_DWORD *)(v90 + 4 * v76); HDDMBelUsageAttrib::getValueAsString(&v82, (int)this); *(_WORD *)std::map<std::string,unsigned short>::operator[](&this->attribIndexMap, &v82) = v75; v77 = *(_QWORD *)&v82.attrib_code - 24LL; if ( (_UNKNOWN *)(*(_QWORD *)&v82.attrib_code - 24LL) != &std::string::_Rep::_S_empty_rep_storage ) { v80 = *(_DWORD *)(*(_QWORD *)&v82.attrib_code - 8LL); *(_DWORD *)(*(_QWORD *)&v82.attrib_code - 8LL) = v80 - 1; if ( v80 <= 0 ) std::string::_Rep::_M_destroy(v77, &v82.qword30); } if ( v91 <= (int)v75 + 1 ) break; v78 = (__int64 *)this->attribVoidVec; v76 = v75 + 1; v54 = *v78; if ( (v78[1] - *v78) >> 2 <= (unsigned __int64)(v75 + 1) ) LABEL_77: std::__throw_out_of_range("vector::_M_range_check"); ++v75; } } LABEL_57: LODWORD(this->qword18) = v87; goto LABEL_17; case 2: v38 = v93; v39 = (__int64 *)operator new(0x18uLL); v40 = v39; *v39 = 0LL; v39[1] = 0LL; v39[2] = 0LL; if ( v38 ) { if ( v38 > 0x1FFFFFFFFFFFFFFFLL ) std::__throw_bad_alloc(); v63 = 8 * v38; v64 = (char *)operator new(v63); *v40 = (__int64)v64; v40[1] = (__int64)v64; v40[2] = (__int64)&v64[v63]; memset(v64, 0, v63); v41 = v40[2]; } else { v39[2] = 0LL; v41 = 0LL; } v40[1] = v41; v42 = v93; this->attribVoidVec = v40; if ( v42 <= 0 ) goto LABEL_46; v43 = *v40; if ( !((v40[1] - *v40) >> 3) ) goto LABEL_72; if ( &_pthread_key_create ) { v44 = 1LL; v45 = 0LL; v46 = 0; while ( 1 ) { *(_QWORD *)(v43 + 8 * v45) = *(_QWORD *)(v92 + 8 * v45); HDDMBelUsageAttrib::getValueAsString((HDDMBelUsageAttrib *)&v82.attribVoidVec, (int)this); *(_WORD *)std::map<std::string,unsigned short>::operator[](&this->attribIndexMap, &v82.attribVoidVec) = v46; v48 = v82.attribVoidVec - 24LL; if ( (_UNKNOWN *)(v82.attribVoidVec - 24LL) != &std::string::_Rep::_S_empty_rep_storage && _InterlockedExchangeAdd((volatile signed __int32 *)(v82.attribVoidVec - 8LL), 0xFFFFFFFF) <= 0 ) { std::string::_Rep::_M_destroy(v48, &v82.qword30); } if ( ++v46 >= v93 ) break; v47 = (__int64 *)this->attribVoidVec; v43 = *v47; if ( (v47[1] - *v47) >> 3 <= v44 ) goto LABEL_72; v45 = v44++; } } else { v66 = 0LL; v67 = 0LL; while ( 1 ) { *(_QWORD *)(v43 + 8 * v67) = *(_QWORD *)(v92 + 8 * v67); HDDMBelUsageAttrib::getValueAsString((HDDMBelUsageAttrib *)&v82.attribVoidVec, (int)this); *(_WORD *)std::map<std::string,unsigned short>::operator[](&this->attribIndexMap, &v82.attribVoidVec) = v66; v68 = v82.attribVoidVec - 24LL; if ( (_UNKNOWN *)(v82.attribVoidVec - 24LL) != &std::string::_Rep::_S_empty_rep_storage ) { v73 = *(_DWORD *)(v82.attribVoidVec - 8LL); *(_DWORD *)(v82.attribVoidVec - 8LL) = v73 - 1; if ( v73 <= 0 ) std::string::_Rep::_M_destroy(v68, &v82.qword30); } if ( v93 <= (int)v66 + 1 ) break; v69 = (__int64 *)this->attribVoidVec; v67 = v66 + 1; v43 = *v69; if ( (v69[1] - *v69) >> 3 <= (unsigned __int64)(v66 + 1) ) LABEL_72: std::__throw_out_of_range("vector::_M_range_check"); ++v66; } } LABEL_46: this->qword18 = v88; goto LABEL_17; case 3: v20 = v97; v21 = (__int64 *)operator new(0x28uLL); *v21 = 0LL; *((_DWORD *)v21 + 2) = 0; v21[2] = 0LL; *((_DWORD *)v21 + 6) = 0; v21[4] = 0LL; v22 = 8 * ((unsigned __int64)(v20 + 63) >> 6); v23 = (char *)operator new(v22); v24 = v20 + 63; v25 = &v23[v22]; *v21 = (__int64)v23; *((_DWORD *)v21 + 2) = 0; if ( v20 >= 0 ) v24 = v20; v21[4] = (__int64)v25; v26 = &v23[8 * (v24 >> 6)]; v27 = v20 % 64; if ( v27 < 0 ) { LODWORD(v27) = v27 + 64; v26 -= 8; } v21[2] = (__int64)v26; *((_DWORD *)v21 + 6) = v27; if ( v25 != v23 ) memset(v23, 0, 8 * ((v22 - 8) >> 3) + 8); v28 = v97; this->attribVoidVec = v21; if ( v28 <= 0 ) goto LABEL_68; v29 = *v21; v30 = *v96; if ( *((_DWORD *)v21 + 2) == *((unsigned int *)v21 + 6) + 8 * (v21[2] - *v21) ) goto LABEL_82; v31 = 0LL; v32 = 0LL; while ( 1 ) { v36 = (__int64 *)(v29 + 8 * (v32 >> 6)); v37 = 1LL << v32; if ( v30 ) v33 = *v36 | v37; else v33 = *v36 & ~v37; *v36 = v33; HDDMBelUsageAttrib::getValueAsString((HDDMBelUsageAttrib *)&v82.attribIndexMap, (int)this); *(_WORD *)std::map<std::string,unsigned short>::operator[](&this->attribIndexMap, &v82.attribIndexMap) = v31; v34 = v82.attribIndexMap - 24LL; if ( (_UNKNOWN *)(v82.attribIndexMap - 24LL) != &std::string::_Rep::_S_empty_rep_storage ) { if ( &_pthread_key_create ) { v65 = _InterlockedExchangeAdd((volatile signed __int32 *)(v34 + 16), 0xFFFFFFFF); } else { v79 = *(_DWORD *)(v82.attribIndexMap - 8LL); *(_DWORD *)(v82.attribIndexMap - 8LL) = v79 - 1; v65 = v79; } if ( v65 <= 0 ) std::string::_Rep::_M_destroy(v34, &v82.qword30); } if ( v97 <= (int)v31 + 1 ) break; v32 = v31 + 1; v30 = v96[v31 + 1]; v35 = (__int64 *)this->attribVoidVec; v29 = *v35; if ( *((unsigned int *)v35 + 6) + 8 * (v35[2] - *v35) - (unsigned __int64)*((unsigned int *)v35 + 2) <= v31 + 1 ) LABEL_82: std::__throw_out_of_range("vector<bool>::_M_range_check"); ++v31; } LABEL_68: LOBYTE(this->qword18) = v94; goto LABEL_17; case 4: case 5: case 6: v7 = v99; v8 = (__int64 *)operator new(0x18uLL); v9 = v8; *v8 = 0LL; v8[1] = 0LL; v8[2] = 0LL; if ( v7 ) { if ( v7 > 0x1FFFFFFFFFFFFFFFLL ) std::__throw_bad_alloc(); v60 = (_QWORD *)operator new(8 * v7); *v9 = (__int64)v60; v9[1] = (__int64)v60; v9[2] = (__int64)&v60[v7]; do { if ( v60 ) *v60 = (char *)&std::string::_Rep::_S_empty_rep_storage + 24; ++v60; --v7; } while ( v7 ); v10 = v9[2]; } else { v8[2] = 0LL; v10 = 0LL; } v9[1] = v10; v11 = v99; this->attribVoidVec = v9; if ( v11 <= 0 ) goto LABEL_16; v12 = *v9; v13 = *v98; if ( !((v9[1] - *v9) >> 3) ) goto LABEL_69; v14 = 1LL; if ( &_pthread_key_create ) { v15 = 0LL; while ( 1 ) { std::string::assign((std::string *)(v12 + v15), v13); HDDMBelUsageAttrib::getValueAsString((HDDMBelUsageAttrib *)&v82.qword30, (int)this); *(_WORD *)std::map<std::string,unsigned short>::operator[](&this->attribIndexMap, &v82.qword30) = v14 - 1; v17 = v82.qword30 - 24LL; if ( (_UNKNOWN *)(v82.qword30 - 24LL) != &std::string::_Rep::_S_empty_rep_storage && _InterlockedExchangeAdd((volatile signed __int32 *)(v82.qword30 - 8LL), 0xFFFFFFFF) <= 0 ) { std::string::_Rep::_M_destroy(v17, &v82.attribIndexMap); } if ( v99 <= (int)v14 ) break; v15 = 8 * v14; v13 = v98[v14]; v16 = (__int64 *)this->attribVoidVec; v12 = *v16; if ( (v16[1] - *v16) >> 3 <= v14 ) goto LABEL_69; ++v14; } } else { v70 = 0LL; p_attribIndexMap = &this->attribIndexMap; while ( 1 ) { std::string::assign((std::string *)(v12 + v70), v13); HDDMBelUsageAttrib::getValueAsString((HDDMBelUsageAttrib *)&v82.qword30, (int)this); *(_WORD *)std::map<std::string,unsigned short>::operator[](p_attribIndexMap, &v82.qword30) = v14 - 1; v71 = v82.qword30 - 24LL; if ( (_UNKNOWN *)(v82.qword30 - 24LL) != &std::string::_Rep::_S_empty_rep_storage ) { v74 = *(_DWORD *)(v82.qword30 - 8LL); *(_DWORD *)(v82.qword30 - 8LL) = v74 - 1; if ( v74 <= 0 ) std::string::_Rep::_M_destroy(v71, &v82.attribIndexMap); } if ( v99 <= (int)v14 ) break; v70 = 8 * v14; v13 = v98[v14]; v72 = (__int64 *)this->attribVoidVec; v12 = *v72; if ( v14 >= (v72[1] - *v72) >> 3 ) LABEL_69: std::__throw_out_of_range("vector::_M_range_check"); ++v14; } } LABEL_16: v18 = v89; v19 = (std::string *)operator new(8uLL); std::string::string(v19, v18); this->qword18 = v19; LABEL_17: if ( (v101 & 0x10) != 0 ) BYTE1(this->attrib_code1) = (4 * (v95 & 7)) | BYTE1(this->attrib_code1) & 0xE3 | 2; HDDMXng::BelUsageAttrib::~BelUsageAttrib((HDDMXng::BelUsageAttrib *)&v82.qword40); return; default: goto LABEL_17; } } void __fastcall HDDMBelUsageAttrib::writeme_pb(HDDMBelUsageAttrib *this, std::ostream *stream) { unsigned __int8 attrib_flags_high; // dl int v4; // ecx int v5; // eax int v6; // ecx unsigned int v7; // eax char v8; // cl unsigned int v9; // esi int v10; // eax unsigned __int16 v11; // dx std::string *v12; // rdi const google::protobuf::Message *v13; // rdx std::string *v14; // rdi const std::string *v15; // rbx __int64 *v16; // rax __int64 v17; // rcx __int64 v18; // r14 __int64 v19; // r14 __int64 v20; // rbp __int64 v21; // rdx std::string *v22; // rax __int64 v23; // rdx __int64 *v24; // rax __int64 v25; // rax const std::string *v26; // r12 __int64 *v27; // rax __int64 v28; // rsi __int64 v29; // rcx __int64 v30; // rdi __int64 v31; // rax __int64 v32; // rcx __int64 v33; // r14 __int64 v34; // rbp unsigned __int64 v35; // rax __int64 *v36; // rdx bool v37; // zf __int64 v38; // rax bool v39; // r12 int v40; // edi __int64 *v41; // r15 __int64 *v42; // rax __int64 v43; // rcx __int64 v44; // r12 __int64 v45; // r12 __int64 v46; // rbp __int64 v47; // rdx __int64 *v48; // rax __int64 v49; // rax int v50; // eax _BYTE *v51; // r14 unsigned __int64 v52; // rdi __int64 *attribVoidVec; // rax __int64 v54; // rcx __int64 v55; // r14 __int64 v56; // r14 __int64 v57; // rbp __int64 v58; // rdx __int64 *v59; // rax __int64 v60; // rax int v61; // r12d int v62; // eax __int64 *v63; // r15 unsigned __int64 v64; // rdi char v65; // al int qword18; // eax unsigned __int8 v67; // al __int64 v68; // xmm0_8 int v69; // esi __int64 v70; // [rsp+8h] [rbp-150h] _BYTE v72[16]; // [rsp+20h] [rbp-138h] BYREF unsigned int v73; // [rsp+30h] [rbp-128h] int v74; // [rsp+34h] [rbp-124h] std::string *v75; // [rsp+38h] [rbp-120h] int v76; // [rsp+40h] [rbp-118h] int v77; // [rsp+44h] [rbp-114h] __int64 v78; // [rsp+48h] [rbp-110h] std::string *v79; // [rsp+50h] [rbp-108h] void *v80; // [rsp+58h] [rbp-100h] int v81; // [rsp+60h] [rbp-F8h] int v82; // [rsp+64h] [rbp-F4h] __int64 v83; // [rsp+68h] [rbp-F0h] BYREF void *v84; // [rsp+80h] [rbp-D8h] int v85; // [rsp+88h] [rbp-D0h] int v86; // [rsp+8Ch] [rbp-CCh] _BYTE v87[40]; // [rsp+90h] [rbp-C8h] BYREF int v88; // [rsp+B8h] [rbp-A0h] void *src; // [rsp+C0h] [rbp-98h] int v90; // [rsp+C8h] [rbp-90h] int v91; // [rsp+CCh] [rbp-8Ch] __int64 v92; // [rsp+D0h] [rbp-88h] BYREF __int64 v93; // [rsp+E0h] [rbp-78h] BYREF int v94; // [rsp+E8h] [rbp-70h] int v95; // [rsp+ECh] [rbp-6Ch] int v96; // [rsp+F0h] [rbp-68h] int v97; // [rsp+11Ch] [rbp-3Ch] if ( HDDMDeviceDump::useXngMarks ) std::ostream::write(stream, "BELUSAGEATTRIB", 14LL); HDDMXng::BelUsageAttrib::BelUsageAttrib((HDDMXng::BelUsageAttrib *)v72); attrib_flags_high = HIBYTE(this->attrib_code); v4 = attrib_flags_high & 1; v5 = -((_BYTE)v4 == 0); v6 = (v4 << 31 >> 31) & 2; v7 = (v5 & 0xFFFFFFFE) + 6; if ( (attrib_flags_high & 2) == 0 ) v7 = v6; if ( (attrib_flags_high & 4) != 0 ) v7 |= 8u; if ( (attrib_flags_high & 0x40) != 0 ) v7 |= 0x10u; v8 = BYTE1(this->attrib_code1); if ( (v8 & 0x20) != 0 ) v7 |= 0x20u; if ( (v8 & 0x40) != 0 ) v7 |= 0x40u; v9 = v7; if ( v8 < 0 ) { LOBYTE(v9) = v7 | 0x80; v7 = v9; } v73 = v7; v74 = (attrib_flags_high >> 3) & 7; v10 = v97 | 3; v11 = this->attrib_code & 0xFFF; if ( v11 ) { v76 = v11; v10 = v97 | 7; } v12 = v75; v97 = v10 | 8; if ( v75 == (std::string *)&google::protobuf::internal::kEmptyString ) { v12 = (std::string *)operator new(8uLL); *(_QWORD *)v12 = (char *)&std::string::_Rep::_S_empty_rep_storage + 24; v75 = v12; } std::string::assign(v12, (const std::string *)&this->attrib_name); v13 = (const google::protobuf::Message *)HIBYTE(this->attrib_code); switch ( (HIBYTE(this->attrib_code) >> 3) & 7 ) { case 1: attribVoidVec = (__int64 *)this->attribVoidVec; if ( !attribVoidVec ) goto LABEL_88; v54 = *attribVoidVec; v55 = (attribVoidVec[1] - *attribVoidVec) >> 2; if ( (int)v55 <= 0 ) goto LABEL_88; if ( !v55 ) goto LABEL_97; v56 = (unsigned int)(v55 - 1); v57 = 0LL; v58 = 0LL; while ( 1 ) { v60 = v81; v61 = *(_DWORD *)(v54 + 4 * v58); if ( v81 == v82 ) { v62 = v81 + 1; v63 = (__int64 *)v80; if ( 2 * v81 >= v81 + 1 ) v62 = 2 * v81; v82 = v62; v64 = 4LL * v62; if ( (unsigned __int64)v62 > 0x1FC0000000000000LL ) v64 = -1LL; v80 = (void *)operator new[](v64); memcpy(v80, v63, 4LL * v81); if ( v63 != &v83 && v63 ) operator delete[](v63); v60 = v81; } v81 = v60 + 1; *((_DWORD *)v80 + v60) = v61; if ( v57 == v56 ) break; v59 = (__int64 *)this->attribVoidVec; v58 = v57 + 1; v54 = *v59; if ( (v59[1] - *v59) >> 2 <= (unsigned __int64)(v57 + 1) ) LABEL_97: std::__throw_out_of_range("vector::_M_range_check"); ++v57; } LOBYTE(v13) = HIBYTE(this->attrib_code); LABEL_88: v13 = (const google::protobuf::Message *)((unsigned __int8)v13 & 1); if ( (_DWORD)v13 ) { qword18 = this->qword18; v97 |= 0x10u; v77 = qword18; } break; case 2: v42 = (__int64 *)this->attribVoidVec; if ( !v42 ) goto LABEL_91; v43 = *v42; v44 = (v42[1] - *v42) >> 3; if ( (int)v44 <= 0 ) goto LABEL_91; if ( !v44 ) goto LABEL_98; v45 = (unsigned int)(v44 - 1); v46 = 0LL; v47 = 0LL; while ( 1 ) { v49 = v85; v70 = *(_QWORD *)(v43 + 8 * v47); if ( v85 == v86 ) { v50 = v85 + 1; v51 = v84; if ( 2 * v85 >= v85 + 1 ) v50 = 2 * v85; v86 = v50; v52 = 8LL * v50; if ( (unsigned __int64)v50 > 0xFE0000000000000LL ) v52 = -1LL; v84 = (void *)operator new[](v52); memcpy(v84, v51, 8LL * v85); if ( v51 != v87 && v51 ) operator delete[](v51); v49 = v85; } v85 = v49 + 1; *((_QWORD *)v84 + v49) = v70; if ( v46 == v45 ) break; v48 = (__int64 *)this->attribVoidVec; v47 = v46 + 1; v43 = *v48; if ( (v48[1] - *v48) >> 3 <= (unsigned __int64)(v46 + 1) ) LABEL_98: std::__throw_out_of_range("vector::_M_range_check"); ++v46; } LOBYTE(v13) = HIBYTE(this->attrib_code); LABEL_91: v13 = (const google::protobuf::Message *)((unsigned __int8)v13 & 1); if ( (_DWORD)v13 ) { v68 = this->qword18; v97 |= 0x20u; v78 = v68; } v67 = BYTE1(this->attrib_code1); if ( (v67 & 2) != 0 ) { v97 |= 0x1000u; v88 = (v67 >> 2) & 7; } break; case 3: v27 = (__int64 *)this->attribVoidVec; if ( !v27 ) goto LABEL_85; v28 = *v27; v29 = v27[2]; v30 = *((unsigned int *)v27 + 6); v31 = *((unsigned int *)v27 + 2); v32 = v30 + 8 * (v29 - v28); if ( (int)v32 - (int)v31 <= 0 ) goto LABEL_85; if ( v32 == v31 ) goto LABEL_96; v33 = (unsigned int)(v32 - v31 - 1); v34 = 0LL; v35 = 0LL; while ( 1 ) { v37 = ((1LL << v35) & *(_QWORD *)(v28 + 8 * (v35 >> 6))) == 0; v38 = v90; v39 = !v37; if ( v90 == v91 ) { v40 = 2 * v90; v41 = (__int64 *)src; if ( 2 * v90 < v90 + 1 ) v40 = v90 + 1; v91 = v40; src = (void *)operator new[](v40); memcpy(src, v41, v90); if ( v41 != &v92 && v41 ) operator delete[](v41); v38 = v90; } v90 = v38 + 1; *((_BYTE *)src + v38) = v39; if ( v34 == v33 ) break; v36 = (__int64 *)this->attribVoidVec; v35 = v34 + 1; v28 = *v36; if ( *((unsigned int *)v36 + 6) + 8 * (v36[2] - *v36) - (unsigned __int64)*((unsigned int *)v36 + 2) <= v34 + 1 ) LABEL_96: std::__throw_out_of_range("vector<bool>::_M_range_check"); ++v34; } LOBYTE(v13) = HIBYTE(this->attrib_code); LABEL_85: v13 = (const google::protobuf::Message *)((unsigned __int8)v13 & 1); if ( (_DWORD)v13 ) { v65 = this->qword18; v97 |= 0x40u; v87[36] = v65; } break; case 4: case 5: case 6: v16 = (__int64 *)this->attribVoidVec; if ( !v16 ) goto LABEL_21; v17 = *v16; v18 = (v16[1] - *v16) >> 3; if ( (int)v18 <= 0 ) goto LABEL_21; if ( !v18 ) goto LABEL_95; v19 = (unsigned int)(v18 - 1); v20 = 0LL; v21 = 0LL; while ( 1 ) { v25 = v94; v69 = v95; v26 = (const std::string *)(v17 + 8 * v21); if ( v94 >= v95 ) { if ( v95 == v96 ) { v12 = (std::string *)&v93; google::protobuf::internal::RepeatedPtrFieldBase::Reserve( (google::protobuf::internal::RepeatedPtrFieldBase *)&v93, v95 + 1); v69 = v95; } v95 = v69 + 1; v22 = (std::string *)google::protobuf::internal::StringTypeHandlerBase::New(v12); v23 = v94; v12 = v22; ++v94; *(_QWORD *)(v93 + 8 * v23) = v22; } else { ++v94; v12 = *(std::string **)(v93 + 8 * v25); } std::string::assign(v12, v26); if ( v20 == v19 ) break; v24 = (__int64 *)this->attribVoidVec; v21 = v20 + 1; v17 = *v24; if ( (v24[1] - *v24) >> 3 <= (unsigned __int64)(v20 + 1) ) LABEL_95: std::__throw_out_of_range("vector::_M_range_check"); ++v20; } LOBYTE(v13) = HIBYTE(this->attrib_code); LABEL_21: v13 = (const google::protobuf::Message *)((unsigned __int8)v13 & 1); if ( (_DWORD)v13 ) { v97 |= 0x80u; v14 = v79; v15 = (const std::string *)this->qword18; if ( v79 == (std::string *)&google::protobuf::internal::kEmptyString ) { v14 = (std::string *)operator new(8uLL); *(_QWORD *)v14 = (char *)&std::string::_Rep::_S_empty_rep_storage + 24; v79 = v14; } std::string::assign(v14, v15); } break; default: break; } HDDMDevice::writeMessage((HDDMDevice *)stream, (std::ostream *)v72, v13); HDDMXng::BelUsageAttrib::~BelUsageAttrib((HDDMXng::BelUsageAttrib *)v72); } void __fastcall HDDMBelUsageAttrib::print(HDDMBelUsageAttrib *this, std::ostream *stream, HDDMDevice *hddmDevice) { __int64 v4; // rsi __int64 v5; // rdx char v6; // al __int64 v7; // r12 __int64 **v8; // rax __int64 *v9; // r12 __int64 *v10; // rax __int64 v11; // rsi __int64 v12; // r12 unsigned int **attribVoidVec; // rax unsigned int *v14; // r12 unsigned int *v15; // rax __int64 v16; // rsi unsigned int qword18; // r12d __int64 v18; // r12 __int64 v19; // rax unsigned int v20; // r12d _QWORD *v21; // rcx int v22; // esi _QWORD *i; // r13 __int64 v24; // rax __int64 v25; // rax unsigned int v26; // eax unsigned int qword18_low; // r12d __int64 v28; // r12 double **v29; // rax double *v30; // r12 double *v31; // rax double v32; // xmm0_8 _QWORD *v33; // r12 double v34; // [rsp+8h] [rbp-30h] v4 = *(_QWORD *)&hddmDevice->byte0; v5 = *(_QWORD *)(*(_QWORD *)&hddmDevice->byte0 - 24LL); v6 = (HIBYTE(this->attrib_code) >> 3) & 7; if ( v6 != 2 ) { if ( v6 != 3 ) { if ( v6 == 1 ) { v12 = std::__ostream_insert<char,std::char_traits<char>>(stream, v4, v5); std::__ostream_insert<char,std::char_traits<char>>(v12, "int ", 4LL); std::__ostream_insert<char,std::char_traits<char>>(v12, this->attrib_name, *((_QWORD *)this->attrib_name - 3)); std::__ostream_insert<char,std::char_traits<char>>(stream, " ( ", 3LL); attribVoidVec = (unsigned int **)this->attribVoidVec; if ( attribVoidVec ) { v14 = *attribVoidVec; v15 = attribVoidVec[1]; while ( v14 != v15 ) { while ( 1 ) { v16 = *v14++; std::ostream::operator<<(stream, v16); v15 = v14; if ( *(unsigned int **)(this->attribVoidVec + 8LL) == v14 ) break; std::__ostream_insert<char,std::char_traits<char>>(stream, ", ", 2LL); if ( v14 == *(unsigned int **)(this->attribVoidVec + 8LL) ) goto LABEL_18; } } } LABEL_18: if ( (this->attrib_code & 0x1000000) != 0 ) { qword18 = this->qword18; std::__ostream_insert<char,std::char_traits<char>>(stream, " default=", 9LL); std::ostream::operator<<(stream, qword18); } } else { v7 = std::__ostream_insert<char,std::char_traits<char>>(stream, v4, v5); std::__ostream_insert<char,std::char_traits<char>>(v7, "string ", 7LL); std::__ostream_insert<char,std::char_traits<char>>(v7, this->attrib_name, *((_QWORD *)this->attrib_name - 3)); std::__ostream_insert<char,std::char_traits<char>>(stream, " ( ", 3LL); v8 = (__int64 **)this->attribVoidVec; if ( v8 ) { v9 = *v8; v10 = v8[1]; while ( v9 != v10 ) { while ( 1 ) { v11 = *v9++; std::__ostream_insert<char,std::char_traits<char>>(stream, v11, *(_QWORD *)(v11 - 24)); v10 = v9; if ( *(__int64 **)(this->attribVoidVec + 8LL) == v9 ) break; std::__ostream_insert<char,std::char_traits<char>>(stream, ", ", 2LL); if ( v9 == *(__int64 **)(this->attribVoidVec + 8LL) ) goto LABEL_9; } } } LABEL_9: if ( (this->attrib_code & 0x1000000) != 0 ) { v33 = (_QWORD *)this->qword18; std::__ostream_insert<char,std::char_traits<char>>(stream, " default=", 9LL); std::__ostream_insert<char,std::char_traits<char>>(stream, *v33, *(_QWORD *)(*v33 - 24LL)); } } goto LABEL_11; } v18 = std::__ostream_insert<char,std::char_traits<char>>(stream, v4, v5); std::__ostream_insert<char,std::char_traits<char>>(v18, "bool ", 5LL); std::__ostream_insert<char,std::char_traits<char>>(v18, this->attrib_name, *((_QWORD *)this->attrib_name - 3)); std::__ostream_insert<char,std::char_traits<char>>(stream, " ( ", 3LL); v19 = this->attribVoidVec; if ( !v19 ) { LABEL_28: if ( (this->attrib_code & 0x1000000) != 0 ) { qword18_low = LOBYTE(this->qword18); std::__ostream_insert<char,std::char_traits<char>>(stream, " default=", 9LL); std::ostream::_M_insert<bool>(stream, qword18_low); } goto LABEL_11; } v20 = *(_DWORD *)(v19 + 8); v21 = *(_QWORD **)(v19 + 16); v22 = *(_DWORD *)(v19 + 24); for ( i = *(_QWORD **)v19; ; ++i ) { while ( 1 ) { if ( v21 == i && v20 == v22 ) goto LABEL_28; std::ostream::_M_insert<bool>(stream, ((1LL << v20) & *i) != 0); v24 = this->attribVoidVec; v21 = &i[(v20 + 1LL) >> 6]; if ( v21 == *(_QWORD **)(v24 + 16) ) { v22 = ((_BYTE)v20 + 1) & 0x3F; if ( v22 == *(_DWORD *)(v24 + 24) ) break; } std::__ostream_insert<char,std::char_traits<char>>(stream, ", ", 2LL); v25 = this->attribVoidVec; v21 = *(_QWORD **)(v25 + 16); v22 = *(_DWORD *)(v25 + 24); v26 = v20 + 1; if ( v20 == 63 ) goto LABEL_32; LABEL_25: v20 = v26; } v26 = v20 + 1; if ( v20 != 63 ) goto LABEL_25; LABEL_32: v20 = 0; } } v28 = std::__ostream_insert<char,std::char_traits<char>>(stream, v4, v5); std::__ostream_insert<char,std::char_traits<char>>(v28, "double ", 7LL); std::__ostream_insert<char,std::char_traits<char>>(v28, this->attrib_name, *((_QWORD *)this->attrib_name - 3)); std::__ostream_insert<char,std::char_traits<char>>(stream, " ( ", 3LL); v29 = (double **)this->attribVoidVec; if ( v29 ) { v30 = *v29; v31 = v29[1]; while ( v30 != v31 ) { while ( 1 ) { v32 = *v30++; std::ostream::_M_insert<double>(stream, v32); v31 = v30; if ( *(double **)(this->attribVoidVec + 8LL) == v30 ) break; std::__ostream_insert<char,std::char_traits<char>>(stream, ", ", 2LL); if ( v30 == *(double **)(this->attribVoidVec + 8LL) ) goto LABEL_38; } } } LABEL_38: if ( (this->attrib_code & 0x1000000) != 0 ) { v34 = *(double *)&this->qword18; std::__ostream_insert<char,std::char_traits<char>>(stream, " default=", 9LL); std::ostream::_M_insert<double>(stream, v34); } LABEL_11: std::__ostream_insert<char,std::char_traits<char>>(stream, " ) ", 3LL); if ( (this->attrib_code & 0x2000000) != 0 ) std::__ostream_insert<char,std::char_traits<char>>(stream, " (HIDDEN=true)", 14LL); } void __fastcall HDDMBelUsageAttrib::~HDDMBelUsageAttrib(HDDMBelUsageAttrib *this) { char v2; // al __int64 **v3; // r14 __int64 *v4; // r13 __int64 *v5; // rbp void *v6; // rdi __int64 *v7; // rdi _QWORD *qword18; // rbp void **attribVoidVec; // rbp std::string *attrib_name; // rax volatile signed __int32 *v11; // rdi int v12; // eax __int64 v13; // rax void *v14; // rdi int v15; // edx int v16; // edx _BYTE v17[57]; // [rsp+Fh] [rbp-39h] BYREF v2 = (HIBYTE(this->attrib_code) >> 3) & 7; if ( v2 == 2 || v2 == 3 || v2 == 1 ) { attribVoidVec = (void **)this->attribVoidVec; if ( attribVoidVec ) { if ( *attribVoidVec ) operator delete(*attribVoidVec); operator delete(attribVoidVec); } this->attribVoidVec = 0LL; } else { v3 = (__int64 **)this->attribVoidVec; if ( v3 ) { v4 = v3[1]; v5 = *v3; if ( v4 == *v3 ) { v7 = v3[1]; } else { if ( &_pthread_key_create ) { do { v6 = (void *)(*v5 - 24); if ( v6 != &std::string::_Rep::_S_empty_rep_storage && _InterlockedExchangeAdd((volatile signed __int32 *)(*v5 - 8), 0xFFFFFFFF) <= 0 ) { std::string::_Rep::_M_destroy(v6, v17); } ++v5; } while ( v4 != v5 ); } else { do { v13 = *v5; v14 = (void *)(*v5 - 24); if ( v14 != &std::string::_Rep::_S_empty_rep_storage ) { v16 = *(_DWORD *)(v13 - 8); *(_DWORD *)(v13 - 8) = v16 - 1; if ( v16 <= 0 ) std::string::_Rep::_M_destroy(v14, v17); } ++v5; } while ( v4 != v5 ); } v7 = *v3; } if ( v7 ) operator delete(v7); operator delete(v3); this->attribVoidVec = 0LL; } qword18 = (_QWORD *)this->qword18; if ( qword18 ) { std::string::_Rep::_M_dispose(*qword18 - 24LL, v17); operator delete(qword18); this->qword18 = 0LL; } } sub_2174F50(this); std::_Rb_tree<std::string,std::pair<std::string const,unsigned short>,std::_Select1st<std::pair<std::string const,unsigned short>>,std::less<std::string>,std::allocator<std::pair<std::string const,unsigned short>>>::_M_erase( &this->attribIndexMap, this->qword30); attrib_name = this->attrib_name; v11 = (volatile signed __int32 *)((char *)attrib_name - 24); if ( (_UNKNOWN *)((char *)attrib_name - 24) != &std::string::_Rep::_S_empty_rep_storage ) { if ( &_pthread_key_create ) { v12 = _InterlockedExchangeAdd(v11 + 4, 0xFFFFFFFF); } else { v15 = *((_DWORD *)attrib_name - 2); *((_DWORD *)attrib_name - 2) = v15 - 1; v12 = v15; } if ( v12 <= 0 ) std::string::_Rep::_M_destroy(v11, v17); } } void __fastcall HDDMBelUsageAttrib::HDDMBelUsageAttrib(HDDMBelUsageAttrib *this) { attrib_code1 = this->attrib_code1; LOWORD(this->attrib_code) &= 0xF000u; BYTE2(this->attrib_code1) &= 0xF0u; LODWORD(this->qword28) = 0; this->attrib_code |= 0xFFF000u; this->qword30 = 0LL; HIBYTE(this->attrib_code) = 0; LOWORD(this->attrib_code1) = attrib_code1 & 0xFE00; BYTE1(this->attrib_code1) = 0; HIWORD(this->attrib_code1) |= 0xFFF0u; this->qword48 = 0LL; this->qword18 = 0LL; this->attribVoidVec = 0LL; this->attrib_name = (std::string *)((char *)&std::string::_Rep::_S_empty_rep_storage + 24); this->qword38 = &this->qword28; this->qword40 = &this->qword28; }
最新发布
10-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值