Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xqc_pow2 cann't work in windows. #271

Closed
wants to merge 3 commits into from
Closed

Conversation

keengo99
Copy link
Contributor

#include <assert.h>
#include <math.h>
#ifdef _WIN32
#include <intrin.h>
#define XQC_SYS_WINDOWS 1
#endif
/* make n to 2 pow  */
static int xqc_pow2(unsigned int n)
{
    int count1 = 0;    
    unsigned long power = sizeof(n);
#ifdef __GNUC__
    count1 = __builtin_popcount(n);
#else
    unsigned int t = n;
    while (t) {
        count1 += t & 1;
        t >>= 1;
    }
#endif
    if (count1 <= 1) {
        return n;
    }
#if defined(XQC_SYS_WINDOWS) && defined(_MSC_VER)
    /* __lzcnt available beginning VS2008 or up*/
    _BitScanReverse((unsigned long *)&power, n);    
#else
    power = (power << 3) - __builtin_clz(n) - 1;    
#endif
    return (int)pow(2, power);
}
int main()
{
    assert(xqc_pow2(4) == 4);
    assert(xqc_pow2(12) == 8);
    assert(xqc_pow2(1024) == 1024);
    assert(xqc_pow2(0) == 0);
    assert(xqc_pow2(1) == 1);
}

@keengo99 keengo99 closed this Nov 25, 2022
@keengo99
Copy link
Contributor Author

keengo@ubuntu22:~/project/xquic/build$ ./tests/run_tests | tee -a ../xquic_test.log


     CUnit - A unit testing framework for C - Version 2.1-3
     http://cunit.sourceforge.net/


Suite: libxquic_TestSuite
  Test: xqc_test_get_random ...passed
  Test: xqc_test_engine_create ...passed
  Test: xqc_test_conn_create ...passed
  Test: xqc_test_timer ...passed
  Test: xqc_test_pq ...passed
  Test: xqc_test_common ...passed
  Test: xqc_test_vint ...passed
  Test: xqc_test_recv_record ...passed
  Test: xqc_test_reno ...passed
  Test: xqc_test_cubic ...passed
  Test: xqc_test_short_header_parse_cid ...passed
  Test: xqc_test_long_header_parse_cid ...passed
  Test: xqc_test_engine_packet_process ...passed
  Test: xqc_test_stream_frame ...passed
  Test: xqc_test_wakeup_pq ...passed
  Test: xqc_test_process_frame ...passed
  Test: xqc_test_parse_padding_frame ...passed
  Test: xqc_test_large_ack_frame ...passed
  Test: xqc_test_h3_frame ...passed
  Test: xqc_test_transport_params ...passed
  Test: xqc_test_tls ...passed
  Test: xqc_test_crypto ...passed
  Test: xqc_test_h3_stream ...passed
  Test: xqc_test_stable ...passed
  Test: xqc_test_dtable ...passed
  Test: test_2d_hash_table ...passed
  Test: test_ring_array ...passed
  Test: xqc_test_ring_mem ...passed
  Test: xqc_test_huffman ...passed
  Test: xqc_test_encoder ...passed
  Test: xqc_test_h3_ins ...passed
  Test: xqc_test_h3_rep ...passed
  Test: xqc_qpack_test ...passed
  Test: xqc_test_prefixed_str ...passed
  Test: xqc_cid_test ...passed
  Test: xqc_test_id_hash ...passed
  Test: xqc_test_retry ...passed

Run Summary:    Type   Total     Ran  Passed Failed Inactive
              suites       1       1     n/a      0        0
               tests      37      37      37      0        0
             asserts 9427497 9427497 9427497      0      n/a

@keengo99 keengo99 reopened this Nov 25, 2022
@yuanbo-zhang
Copy link
Collaborator

yuanbo-zhang commented Nov 20, 2023

xqc_pow2 can be replace with xqc_pow2_upper

Fixd:cff8287

@Yanmei-Liu
Copy link
Collaborator

As the function has been replaced and deleted, simply close this pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants