Skip to content

Instantly share code, notes, and snippets.

View hongjr03's full-sized avatar
🌴

Hong Jiarong hongjr03

🌴
  • Ocean University of China
  • 17:46 (UTC +08:00)
View GitHub Profile
@Ynng
Ynng / custom.css
Last active October 8, 2025 20:53
vscode vtuber logo
.editor-group-watermark > .letterpress{
background-image: url("https://raw.githubusercontent.com/Aikoyori/ProgrammingVTuberLogos/main/VSCode/VSCode-Thick.png") !important;
opacity: .75;
aspect-ratio: 3/2 !important;
}
@WiwilZ
WiwilZ / StringFunctions.cpp
Created February 28, 2024 13:29
use SSE4.2 intrinsics about string to implement some string functions
#if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
#else
#include <x86intrin.h>
#endif
#include <cstddef>
#include <cstdint>
@WiwilZ
WiwilZ / count_digits10.h
Last active September 2, 2024 09:24
count the number of digits in radix 10 of an integer
#include <cstddef>
#include <cstdint>
#include <bit>
#include <utility>
constexpr size_t count_digits10(uint32_t x) noexcept {
static constexpr uint64_t table[]{
(1ull << 32) | -10u, (1ull << 32) | -10u, (1ull << 32) | -10u, (1ull << 32) | -10u, (1ull << 32) | -10u, (1ull << 32) | -10u, // [1, 64)
@WiwilZ
WiwilZ / DoNotOptimize.cpp
Last active April 16, 2024 10:45
DoNotOptimize function
#if defined(_MSC_VER) && !defined(__clang__)
namespace detail {
#pragma optimize("", off)
void DoNotOptimizeImpl(const void*) noexcept {}
#pragma optimize("", on)
}
[[msvc::forceinline]] void DoNotOptimize(const auto& x) noexcept {
Detail::DoNotOptimizeImpl(&x);
@WiwilZ
WiwilZ / Crc32.cpp
Last active April 16, 2024 10:45
Crc32 function optimized with SIMD Instrction
/******************generate bit-reflected constants********************
constexpr uint64_t Polynomial = 0x1db710641 ; // bit reverse for significant bits of 0x104c11db7
template <bool GetQuotient = false>
constexpr uint64_t Generate(uint64_t deg) {
uint64_t quot = 0;
uint64_t crc = 2;
for (size_t i = 0; i < deg - 31; i++) {
crc >>= 1;
@WiwilZ
WiwilZ / WebSocketClient.js
Last active April 16, 2024 10:45
WebSocketClient written in js
class WebSocketClient {
constructor(url) {
this.url = url;
this.socket = null;
this.heartBeatTimeout = 45000;
this.timeoutObj = null;
this.lockReconnect = false;
}
create() {
@WiwilZ
WiwilZ / IsSorted.cpp
Last active April 16, 2024 10:45
Check whether an integer array is (strict) increasing or (strict) decreasing optimized with SIMD Instructions
#if defined(_MSC_VER) && !defined(__clang__) && (defined(_M_IX86) || defined(_M_X64) && !defined(_M_ARM64EC))
#define __SSE4_1__
#define __SSE4_2__
#endif
#if defined(__AVX512BW__) || defined(__AVX2__) || defined(__SSE4_2__) || defined(__SSE4_1__)
#if defined(_MSC_VER) && !defined(__clang__)
@WiwilZ
WiwilZ / cast_int_and_float.cpp
Last active August 17, 2024 11:58
cast function between integer and floating point with intel intrinsics
#if defined(__SSE2__) || defined(_MSC_VER) && !defined(__clang__) && ((defined(_M_AMD64) || defined(_M_X64)) && !defined(_M_ARM64EC) || defined(_M_IX86) && defined(_M_IX86_FP) && _M_IX86_FP == 2)
# if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
# else
#include <emmintrin.h>
#include <xmmintrin.h>
#include <immintrin.h>
# endif