<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lu-Hsuan Chen on Medium]]></title>
        <description><![CDATA[Stories by Lu-Hsuan Chen on Medium]]></description>
        <link>https://medium.com/@clh0524?source=rss-b979f7d2365d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2DMRM3MnIGi0ab5n.jpg</url>
            <title>Stories by Lu-Hsuan Chen on Medium</title>
            <link>https://medium.com/@clh0524?source=rss-b979f7d2365d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:43:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@clh0524/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Add iOS App Widget on iOS 26]]></title>
            <link>https://clh0524.medium.com/how-to-add-ios-app-widget-on-ios-26-c18e59f4309d?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c18e59f4309d</guid>
            <category><![CDATA[ios-apps]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Sun, 26 Apr 2026 00:00:36 GMT</pubDate>
            <atom:updated>2026-04-26T04:11:53.952Z</atom:updated>
            <content:encoded><![CDATA[<p>Some apps give a barcode or QR code for scanning. However, launching such apps whenever needed is not only tedious but also limited to the network speed.</p><p>Thankfully, iOS gives the App Widget to let you use barcode so that:</p><ol><li>Less waiting time: no need to launch the app everytime.</li><li>No Internet needed: the barcode still can be display without Internet connection.</li></ol><p>As the iOS evolves, the processes to set this feature alter. To let myself to remind the procedures, this post will list the procedures to set up the App Widget on iOS 26.</p><h3>prerequisite</h3><p>Ensure your app is installed and the barcode or QR code is set up inside the app.</p><h3>procedures</h3><ol><li><strong>Enter Jiggle Mode</strong>: Go to your iPhone Home Screen and <strong>long-press</strong> on any empty space until the icons start to jiggle.</li><li><strong>Add Widget</strong>: Tap the <strong>“+” (Add)</strong> button in the top left/right corner of the screen.</li><li><strong>Search Your App</strong>: search your app by either search bar or app icon.</li><li><strong>Select Style</strong>: You will see four different widget styles. For barcode, choose the first one and tap<strong>”+ Add Widget”</strong>.</li><li><strong>Finalize</strong>: Drag the widget to your preferred location on the screen and tap “Done” in the top right corner.</li></ol><p>Now, whenever your are going to show your code, you can smoothly swipe to your widget page and let the magic happens.</p><p><em>Originally published at </em><a href="https://cuda-chen.github.io/ios/living/2026/04/26/how-to-add-ios-app-widget-on-ios-26.html"><em>https://cuda-chen.github.io</em></a><em> on April 26, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c18e59f4309d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make Your Sodium Free Dish with Adding Spices]]></title>
            <link>https://clh0524.medium.com/make-your-sodium-free-dish-with-adding-spices-4abfce3474e5?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4abfce3474e5</guid>
            <category><![CDATA[living]]></category>
            <category><![CDATA[sodium-free]]></category>
            <category><![CDATA[healthy-living]]></category>
            <category><![CDATA[cooking]]></category>
            <category><![CDATA[recipes-for-cooking]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Sun, 12 Apr 2026 00:00:39 GMT</pubDate>
            <atom:updated>2026-04-12T04:12:53.014Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3hVMkKlqWuwWdOQ1BD1jg.png" /></figure><h3>Introduction</h3><p>Yeats ago, I started to make Sodium free dish when I made my meals at home. Though you may think it is ridiculous, I am going to show how to achieve this by using three types of species: garlic, ginger, and chili pepper.</p><h3>Why You Should Try A Salt Free Dish?</h3><p>Two reasons:</p><ol><li>Decrease Sodium ingestion: many people nowadays get their meals by dining out. In order to make you buy their meals many times, the dealer usually add much more Sodium (e.g., salt, MSG, etc.). After years, you start to find your blood tension value is not good. What’s more, the chance of getting hypertension increases because of your family or you are in a high-stress environment.</li><li>Enjoy another taste of food: as we are used to the meals with Sodium, trying another taste of food without any Sodium make a pleasure of your life: you get the original taste of food.</li></ol><h3>Garlic</h3><p>I always rank #1 to garlic. With the spicy and its natural MSG, it always makes me have a good appetite.</p><p>And for my garlic recipe:</p><ul><li>For each dish, I will put four to six cloves of garlic.</li><li>For releasing the component that are good to your health, I chop into piece and put for 10–15 minutes.</li></ul><h3>Ginger</h3><p>If you consider the garlic gives you bad breath after you finish your meal, you can try ginger. It always fuse its mild spicy taste with your meal.</p><p>For my ginger recipe:</p><ul><li>I will use the size of Distal phalanx of my thumb finger for each dish.</li><li>Just like garlic, I chop into piece and put for 10–15 minutes.</li></ul><h3>Chili Pepper</h3><p>For the last one, chili pepper gives you a great appetite, though you should always be aware of its spiciness (it will make you have no appetite it you put too much).</p><p>For my chili pepper recipe:</p><ul><li>Taking Cayenne as example, I will use at most half slice for each dish.</li><li>Just like the two other spices I usually use, I chop into slices and put for 10–15 minutes.</li></ul><h3>Conclusion</h3><p>In this post, I make a showcase of how to do your Sodium free dish by using either garlic, ginger, or chili pepper. However, you may have your own recipe beyond these three spices. For communication, let’s leave a comment of you Sodium free dish spice recipe!</p><p><em>Originally published at </em><a href="https://cuda-chen.github.io/living/2026/04/12/salt-free-diet.html"><em>https://cuda-chen.github.io</em></a><em> on April 12, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4abfce3474e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[libmseed Optimization Attempt — A Counter Example of Replacing switch-case]]></title>
            <link>https://clh0524.medium.com/libmseed-optimization-attempt-a-counter-example-of-replacing-switch-case-e1222020c35b?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1222020c35b</guid>
            <category><![CDATA[benchmarking]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[seismology]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Sat, 21 Feb 2026 00:00:38 GMT</pubDate>
            <atom:updated>2026-02-21T08:26:10.267Z</atom:updated>
            <content:encoded><![CDATA[<h3>Outline</h3><p>For system software programmers, we always thrive for any possibilities of performance optimization. When it comes to branching, we believes that a solely jump table, which does a certain operation after a arithmetic operation for calculating the entry of the jump table, beats many methods including long if-else and complex switch-case statements.</p><p>In this post, I am going to give you a counter example that a seems-dumb switch-case statement beats jump table technique. I will not only show the benchmark result, but also some personal findings that I think why a switch-case statement become the better performant one compared to the jump table implementation.</p><h3>The Target</h3><p>I am going to do an optimization of msr_decode_steim2() in a widely-used siesmic data library called libmseed.</p><p>If you are interested in the format of miniSEED with Steim2 format, check [1].</p><p>You can view the whole part of msr_decode_steim2() in [2]. For your clarity, here I provide a minified version of the code:</p><pre>int64 msr_decode_steim2(...) {<br>    int nibble = ...; /* check the first nibble */<br>    int dnib; /* second nibble placeholder */    <br><br>    switch(nibble) {<br>        case 0:<br>            break;<br>        case 1:<br>            break;<br>        case 2:<br>            dnib = ...; /* check the second nibble */<br>            switch(dnib) {<br>                case 0:<br>                    break;<br>                case 1:<br>                    break;<br>                case 2:<br>                    break;<br>                case 3:<br>                    break;<br>            }<br>            break;<br>        case 3:<br>            dnib = ...;<br>            switch(dnib) {<br>                case 0:<br>                    break;<br>                case 1:<br>                    break;<br>                case 2:<br>                    break;<br>                case 3:<br>                    break;<br>            }<br>            break;<br>    }<br><br>    return 0;<br>}</pre><h3>What I am Going to Do</h3><p>Eliminate the non-trivial switch-case statment. Moreover, check any possibilities for micro-optimization.</p><h3>Attempts</h3><p>For the goal, I come up with these methods: jump table and for loop.</p><h4>jump table</h4><p>For dozens of conditions, we can use a jump table so that we let the program to execute certain actions based on the value of each condition. Usually, this can yield with a better performances compared to switch-case statement.</p><p>We can just move the statement of each switch-case into a series of functions, then create a table for indexing the actions:</p><pre>/* a series of callbacks */<br>int fnoop(...) {...} /* nibble=0x00 */<br>int f01(...) {...} /* nibble=0x01 */<br>int f1010(...) {...} /* nibble=0x02 and dnib=0x02<br>...<br><br>typedef int (*steim2_decode_func_cb) (uint32_t , /* input frame */<br>                                      int32_t *,  /* output difference array */<br>                                      int *      /* output difference array index */<br>); <br>static steim2_decode_func_cb __steim2_decode_func_tbl[16] = {<br>    fnoop, fnoop, fnoop, fnoop, f01,   f01,   f01,   f01, <br>    f1000, f1001, f1010, f1011, f1100, f1101, f1110, f1111,<br>};<br><br>int64_t msr_decode_steim2(...) {<br>    /* Substitute the swtich-case into array indexing */<br>    int nibble = ...;<br>    int dnib = ...; /* Always check the second nibble */<br>    uint32_t ii = ((nibble &amp; 0x03) &lt;&lt; 2) | (dnib &amp; 0x03);<br><br>    steim2_decode_func_cb handler = __steim2_decode_func_tbl[ii &amp; 0x0f];<br>    int ret = handler (frame[widx], diff, &amp;diffidx);<br>    ...<br>}</pre><h4>for loop</h4><p>As specified in [1], we can use a for loop with precomputed values to determined how many bits should be scanned each time and how many values stored in a frame.</p><p>So it will become like this:</p><pre>int64_t msr_decode_steim2(...) {<br>      /* Substitute the swtich-case into array indexing */<br>      int nibble = ...;<br>      int dnib = ...; /* Always check the second nibble */<br>      uint32_t ii = ((nibble &amp; 0x03) &lt;&lt; 2) | (dnib &amp; 0x03);<br><br>      int base[4] = {0, 4, 0, 1,};<br>      uint32_t increment_mask[4] = {0x0, 0x0, 0x07, 0x07,};<br>      int cnt = base[nibble &amp; 0x03] + (ii &amp; increment_mask[nibble &amp; 0x03]);<br><br>      /* start bit of each combination of nibble and dnib */<br>      int start_bit_pos[16] = {<br>          0, 0, 0, 0,<br>          24, 24, 24, 24,<br>          0, 0, 15, 20,<br>          24, 25, 24, 0, <br>      };<br><br>      /* bit length of each combination of nibble and dnib */<br>      int bb[16] = { <br>          0, 0, 0, 0,<br>          8, 8, 8, 8,<br>          0, 30, 15, 10,<br>          6, 5, 4, 0,<br>      };<br><br>      for (idx = 0; idx &lt; cnt; idx++)<br>      {        <br>        int bit_count = bb[ii &amp; 0x0f];<br>        int shift = 32 - bit_count;<br>        /* The nibble=0x01 needs extra treatment as there are no<br>        * any defintion of little-endian Steim2 SEED.<br>        * See https://github.com/EarthScope/libmseed/issues/36#issuecomment-470370790<br>        * for more details.<br>        */<br>        int start = start_bit_pos[ii &amp; 0x0f] - (<br>                nibble == 0x01<br>                ? cnt - idx - 1 <br>                : idx) * bit_count;<br><br>        /* adapted from &quot;Sign extending from a variable bit-width&quot; section in https://graphics.stanford.edu/~seander/bithacks.html */<br>        int32_t m = 1U &lt;&lt; (bit_count - 1); <br>        int32_t t = (((frame[widx]) &gt;&gt; (start)) &amp; ((1U &lt;&lt; (bit_count)) - 1));<br>        int32_t tmp = (t ^ m) - m;<br><br>        diff[diffidx++] = tmp; <br>      }<br>}</pre><h3>Benchmark</h3><p>For benchmarking, out goal is to reduce the execution time.</p><h4>environment</h4><ul><li>OS: Linux v6.8.0</li><li>CPU: Intel(R) Core(TM) i5–3230M CPU @ 2.60GHz</li><li>compiler flags: -O2</li><li>compiler: GCC 13.3.0</li></ul><h4>benchmark program</h4><ul><li>decode_rodeo</li><li>download from [3]</li><li>run 1000000 iterations on Steim2 encoded input data</li></ul><p>The sample output of benchmark program:</p><pre>$ ./decode_rodeo <br>Testing Steim-2<br>reclen: 1595<br>dataoffset: 59<br>datasize: 1536<br>Steim2 decoded 1000000 iterations in 2.045135 seconds</pre><h4>comparison</h4><pre>| type       | execution time (measured in seconds) | performance gain (compared to baseline) |<br>| ---------- | ------------------------------------ | --------------------------------------- | <br>| baseline   | 2.045135                             | 0.0 %                                   | <br>| jump table | 2.451932                             | -19.8909607 %                           | <br>| for loop   | 3.792999                             | -85.4644803 %                           |</pre><h3>Findings</h3><p>We can realize that all of the attempts are signicantly slower than baseline.</p><p>Though the lines of disassembly of each attempts are fewer, we get the inferior result.</p><p>After some investigations, I conclude why any attempts result in inferior result:</p><ul><li>For jump table, it requires to make a function call, which becomes a big impact on decoding procedure.</li><li>For for loop method, we calculate the needed values after we get the nibbles when decoding each frame. In fact, this part become the bottleneck of the decoding process.</li></ul><h3>Recap</h3><ul><li>If you are certain the action of each condition, consider using code templating (e.g., macros) rather than function calls.</li><li>Benchmark, benchmark, and benchmark.</li></ul><h3>References</h3><p>[1] <a href="https://www.fdsn.org/pdf/SEEDManual_V2.4.pdf">https://www.fdsn.org/pdf/SEEDManual_V2.4.pdf</a></p><p>[2] <a href="https://github.com/EarthScope/libmseed/blob/07a6e2d8b4611e9f59155d5632ab24dc2598cf9f/unpackdata.c#L356">https://github.com/EarthScope/libmseed/blob/07a6e2d8b4611e9f59155d5632ab24dc2598cf9f/unpackdata.c#L356</a></p><p>[3] <a href="https://github.com/EarthScope/libmseed/pull/102#issuecomment-1614927016">https://github.com/EarthScope/libmseed/pull/102#issuecomment-1614927016</a></p><p><em>Originally published at </em><a href="https://cuda-chen.github.io/programming/seismology/seismology%20data%20format/optimziation/benchmarking/2026/02/21/libmseed-counter-example-of-jump-table.html"><em>https://cuda-chen.github.io</em></a><em> on February 21, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1222020c35b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimize _mm_crc32_u8 conversion in sse2neon]]></title>
            <link>https://clh0524.medium.com/optimize-mm-crc32-u8-conversion-in-sse2neon-1094a0a7aed9?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1094a0a7aed9</guid>
            <category><![CDATA[simd]]></category>
            <category><![CDATA[crc]]></category>
            <category><![CDATA[neon]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Tue, 27 Feb 2024 00:00:19 GMT</pubDate>
            <atom:updated>2024-02-29T04:13:35.230Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In this post, I am going to illustrate the progress of _mm_crc32_u8 conversion improvement of the contribution to sse2neon.</p><p>In the beginning, I will make a brief introduction to CRC32C, which is the CRC algorithm that _mm_crc32_u8 applies. Then, I will show how I optimize the conversion with various method.</p><h3>What’s CRC32C?</h3><p>Before explaining CRC32C, I would like to answer a question: what is CRC (Cyclic Redundancy Check)? It is an algorithm used for error detection in network and storage device [¹]. The sender uses a number as divisor, then applies division on the message to get the remainder. Next, sender appends the remainder in the end of the message. To verify whether the message has any errors, the receiver applies division on the message. If the remainder is not zero, it means the message is erroneous. As it doesn’t modify the content of message (redundancy) and the division is just shifting the dividend then subtract (cyclic code), so the name, CRC, represents these behaviors.</p><p>A CRC algorithm is called an n-bit CRC when its divisor (formally check value) is n-bit long. Thus, the CRC32C, a variant of CRC32, has a 32-bit binary number as the dividend.</p><p>As a reminder, the CRC32C uses the following polynomials (I will represent as P for the rest of post):</p><ul><li>normal: 0x1EDC6F41 (usually denoted as 0x11EDC6F41)</li><li>bit-reflected: 0x82F63B78</li></ul><p>What’s more, we use the bit-reflected way for implementation. For the reasons of using bit-reflected method, you can refer to <em>Fastest CRC32 for x86, Intel and AMD, + comprehensive derivation and discussion of various approaches</em> [²].</p><h3>Road of Optimization</h3><p>Let’s start with the original implementation in sse2neon [³]:</p><pre>FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v)<br>{<br>    crc ^= v;<br>    for (int bit = 0; bit &lt; 8; bit++) {<br>        if (crc &amp; 1)<br>            crc = (crc &gt;&gt; 1) ^ UINT32_C(0x82f63b78);<br>        else<br>            crc = (crc &gt;&gt; 1);<br>    }<br>    return crc;<br>}</pre><h3>apply ternary operator</h3><p>Modern compiler can optimize the ternary operator into conditional move to prevent branching. As a consequence, we can re-write the if...else statement into ternary operator:</p><pre>for (int bit = 0; bit &lt; 8; bit++)<br>    crc = (crc &amp; 1) ? ((crc &gt;&gt; 1) ^ UINT32_C(0x82f63b78)) : (crc &gt;&gt; 1);</pre><p>However, as mentioned by the reviewer [⁴], we should come up with another way to utilize the power of NEON.</p><h3>tabular method</h3><p>Observing the following implementation of calculating CRC32C:</p><pre>for (int bit = 0; bit &lt; 8; bit++)<br>    crc = (crc &amp; 1) ? ((crc &gt;&gt; 1) ^ UINT32_C(0x82f63b78)) : (crc &gt;&gt; 1);</pre><p>You can realize that which bits of P will be shifted in of P then XOR’d are uniquely determined by the rightmost 8 bits of crc. Thus, we can rewrite the calculation procedure as follows:</p><pre>// I use A, B, C, D, ...<br>// as the substitution of either 0 or the polynominal.<br><br>crc = (crc &gt;&gt; 1) ^ A<br>crc = (crc &gt;&gt; 1) ^ B<br>crc = (crc &gt;&gt; 1) ^ C<br>crc = (crc &gt;&gt; 1) ^ D<br>crc = (crc &gt;&gt; 1) ^ E<br>crc = (crc &gt;&gt; 1) ^ F<br>crc = (crc &gt;&gt; 1) ^ G<br>crc = (crc &gt;&gt; 1) ^ H</pre><p>We then rewrite the above procedure to a single expression:</p><pre>(((((((((((((((crc &gt;&gt; 1) ^ A) &gt;&gt; 1) ^ B) &gt;&gt; 1) ^ C) &gt;&gt; 1) ^ D) &gt;&gt; 1) ^ E) &gt;&gt; 1) ^ F) &gt;&gt; 1) ^ G) &gt;&gt; 1) ^ H</pre><p>Re-distribute the shifts for simplifying the expression:</p><pre>(crc &gt;&gt; 8) ^ (A &gt;&gt; 7) ^ (B &gt;&gt; 6) ^ (C &gt;&gt; 5) ^ (D &gt;&gt; 4) ^ (E &gt;&gt; 3) ^ (F &gt;&gt; 2) ^ (G &gt;&gt; 1) ^ H</pre><p>Then, combine all the terms from A to H into a single value T:</p><pre>(crc &gt;&gt; 8) ^ T</pre><p>We can precompute the value of T because it is merely composed of 256 permutations (recall that we just do calculation on the rightmost 8 bits):</p><pre>// Adopted from qemu: https://github.com/qemu/qemu/blob/907209e3111dd62a553a19319b422ff8aba5b9c0/util/crc32c.c#L40<br><br>static const uint32_t _sse2neon_crc32_tbl[] = {<br>    0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4,<br>    0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB,<br>    0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B,<br>    0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24,<br>    0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B,<br>    0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384,<br>    0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, 0x89D76C54,<br>    0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B,<br>    0x20BD8EDE, 0xD2D60DDD, 0xC186FE29, 0x33ED7D2A,<br>    0xE72719C1, 0x154C9AC2, 0x061C6936, 0xF477EA35,<br>    0xAA64D611, 0x580F5512, 0x4B5FA6E6, 0xB93425E5,<br>    0x6DFE410E, 0x9F95C20D, 0x8CC531F9, 0x7EAEB2FA,<br>    0x30E349B1, 0xC288CAB2, 0xD1D83946, 0x23B3BA45,<br>    0xF779DEAE, 0x05125DAD, 0x1642AE59, 0xE4292D5A,<br>    0xBA3A117E, 0x4851927D, 0x5B016189, 0xA96AE28A,<br>    0x7DA08661, 0x8FCB0562, 0x9C9BF696, 0x6EF07595,<br>    0x417B1DBC, 0xB3109EBF, 0xA0406D4B, 0x522BEE48,<br>    0x86E18AA3, 0x748A09A0, 0x67DAFA54, 0x95B17957,<br>    0xCBA24573, 0x39C9C670, 0x2A993584, 0xD8F2B687,<br>    0x0C38D26C, 0xFE53516F, 0xED03A29B, 0x1F682198,<br>    0x5125DAD3, 0xA34E59D0, 0xB01EAA24, 0x42752927,<br>    0x96BF4DCC, 0x64D4CECF, 0x77843D3B, 0x85EFBE38,<br>    0xDBFC821C, 0x2997011F, 0x3AC7F2EB, 0xC8AC71E8,<br>    0x1C661503, 0xEE0D9600, 0xFD5D65F4, 0x0F36E6F7,<br>    0x61C69362, 0x93AD1061, 0x80FDE395, 0x72966096,<br>    0xA65C047D, 0x5437877E, 0x4767748A, 0xB50CF789,<br>    0xEB1FCBAD, 0x197448AE, 0x0A24BB5A, 0xF84F3859,<br>    0x2C855CB2, 0xDEEEDFB1, 0xCDBE2C45, 0x3FD5AF46,<br>    0x7198540D, 0x83F3D70E, 0x90A324FA, 0x62C8A7F9,<br>    0xB602C312, 0x44694011, 0x5739B3E5, 0xA55230E6,<br>    0xFB410CC2, 0x092A8FC1, 0x1A7A7C35, 0xE811FF36,<br>    0x3CDB9BDD, 0xCEB018DE, 0xDDE0EB2A, 0x2F8B6829,<br>    0x82F63B78, 0x709DB87B, 0x63CD4B8F, 0x91A6C88C,<br>    0x456CAC67, 0xB7072F64, 0xA457DC90, 0x563C5F93,<br>    0x082F63B7, 0xFA44E0B4, 0xE9141340, 0x1B7F9043,<br>    0xCFB5F4A8, 0x3DDE77AB, 0x2E8E845F, 0xDCE5075C,<br>    0x92A8FC17, 0x60C37F14, 0x73938CE0, 0x81F80FE3,<br>    0x55326B08, 0xA759E80B, 0xB4091BFF, 0x466298FC,<br>    0x1871A4D8, 0xEA1A27DB, 0xF94AD42F, 0x0B21572C,<br>    0xDFEB33C7, 0x2D80B0C4, 0x3ED04330, 0xCCBBC033,<br>    0xA24BB5A6, 0x502036A5, 0x4370C551, 0xB11B4652,<br>    0x65D122B9, 0x97BAA1BA, 0x84EA524E, 0x7681D14D,<br>    0x2892ED69, 0xDAF96E6A, 0xC9A99D9E, 0x3BC21E9D,<br>    0xEF087A76, 0x1D63F975, 0x0E330A81, 0xFC588982,<br>    0xB21572C9, 0x407EF1CA, 0x532E023E, 0xA145813D,<br>    0x758FE5D6, 0x87E466D5, 0x94B49521, 0x66DF1622,<br>    0x38CC2A06, 0xCAA7A905, 0xD9F75AF1, 0x2B9CD9F2,<br>    0xFF56BD19, 0x0D3D3E1A, 0x1E6DCDEE, 0xEC064EED,<br>    0xC38D26C4, 0x31E6A5C7, 0x22B65633, 0xD0DDD530,<br>    0x0417B1DB, 0xF67C32D8, 0xE52CC12C, 0x1747422F,<br>    0x49547E0B, 0xBB3FFD08, 0xA86F0EFC, 0x5A048DFF,<br>    0x8ECEE914, 0x7CA56A17, 0x6FF599E3, 0x9D9E1AE0,<br>    0xD3D3E1AB, 0x21B862A8, 0x32E8915C, 0xC083125F,<br>    0x144976B4, 0xE622F5B7, 0xF5720643, 0x07198540,<br>    0x590AB964, 0xAB613A67, 0xB831C993, 0x4A5A4A90,<br>    0x9E902E7B, 0x6CFBAD78, 0x7FAB5E8C, 0x8DC0DD8F,<br>    0xE330A81A, 0x115B2B19, 0x020BD8ED, 0xF0605BEE,<br>    0x24AA3F05, 0xD6C1BC06, 0xC5914FF2, 0x37FACCF1,<br>    0x69E9F0D5, 0x9B8273D6, 0x88D28022, 0x7AB90321,<br>    0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E,<br>    0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81,<br>    0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E,<br>    0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E,<br>    0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351, <br>};<br><br>FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v)<br>{<br>    crc ^= v;<br> crc = (crc &gt;&gt; 8) ^ _sse2neon_crc32_tbl[crc &amp; 0xFF];<br>    return crc;<br>}</pre><p>However, reviewer requested not to use this as it costs 1KiB space [⁵], which for my point-of-view, 1KiB space is costly on embedded system such as Raspberry Pi. Therefore, we have to emerge another tabular method solution with the balance between performance and space.</p><blockquote><em>Edit: thanks for the reply from [⁶], the table used in this implementation needs 16 times of cacheline for storing pre-computed values as the cacheline size of most CPU architectures is 64B. Hence, we ought to find a solution that can fit all the pre-computed values into the whole size of cacheline.</em></blockquote><h3>tabular method (half-byte)</h3><p>As mentioned in [⁷], we can break the whole 8-bit table look-up into two consecutive 4-bit table look-up:</p><pre>FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v)<br>{<br> crc ^= v;<br> static const uint32_t crc32_half_byte_tbl[] = {<br>     0x00000000, 0x105ec76f, 0x20bd8ede, 0x30e349b1, 0x417b1dbc, 0x5125dad3,<br>     0x61c69362, 0x7198540d, 0x82f63b78, 0x92a8fc17, 0xa24bb5a6, 0xb21572c9,<br>     0xc38d26c4, 0xd3d3e1ab, 0xe330a81a, 0xf36e6f75,<br> };<br> <br> crc = (crc &gt;&gt; 4) ^ crc32_half_byte_tbl[crc &amp; 0x0F];<br> crc = (crc &gt;&gt; 4) ^ crc32_half_byte_tbl[crc &amp; 0x0F];<br> return crc;<br>}</pre><p>The look-up table just needs to hold every 16th entry of the one-byte tabular method, thus 16 entries with only 64B space! Though this introduces an additional comparison thus cannot utilize the benefit of out-of-order execution in modern CPU, I think it will be a acceptable compromise as the entire pre-computed values can be fit into one cacheline.</p><h3>using Arm Cryptography Extension</h3><p>Though tabular method performs well, we always have to make a trade-off between performance and space: for better performance such as avoiding loop dependency, we ought to use more space to store the look-up table values; whilst reducing space for better memory usage we cannot avoid loop dependency as shown in <em>tabular method (half-byte)</em> section.</p><p>The Arm Cryptography Extension provides certain operations which we can utilize so that we don’t need to store a loop-up table. To begin with using Arm Cryptography Extension, I would like to introduce Barrett Reduction as it is the bedrock of further optimizing the CRC calculation.</p><h4>Barrett reduction [⁸]</h4><p>Recall that the fundamental of CRC is to do polynomial division on a message with a certain polynomial in order to get the remainder . As division is an expensive operation on computer, we can replace the division into multiplying the multiplicative inverse of the polynomial, and this is the core concept of Barrett reduction.</p><p>So to get CRC of message \(a\) with polynomial \(p\):</p><p>\[a \mod p = a — \lfloor sa \rfloor p\]</p><p>where \(s = 1/p\)</p><p>In practices, we can approximate \(1/p\) with a value \(m/2^k\) as division with \(2^k\) is merely right shift with \(k\) times.</p><p>I set \(k=64\) in my implementation as this is usually enough, and we can pre-calculate the \(s\). Thanks for the post in [⁹], we can use the uint256_t [¹⁰] project to get \(s\) with the following code snippet:</p><pre>#include &lt;cstdio&gt;<br>#include &quot;uint256_t.h&quot;<br><br>int find_mu(int i)<br>{<br>    uint256_t dividend = uint256_t{1} &lt;&lt; i;<br>    const uint256_t divisor = 0x11EDC6F41; // polynominal used by CRC32C<br>    const int bits_in_divisor = 33; <br><br>    uint256_t result = 0;<br>    int bit = 255;<br>    while (bit &gt;= 0) {<br>        if ((dividend &amp; (uint256_t{1} &lt;&lt; bit)) != 0) {<br>            int shift = bit - bits_in_divisor + 1;<br>            if (shift &gt;= 0) {<br>                dividend ^= divisor &lt;&lt; shift;<br>                result ^= uint256_t{1} &lt;&lt; shift;<br>            } else {<br>                dividend ^= divisor &gt;&gt; -shift;<br>            }<br>        }<br>        bit--;<br>    }   <br><br>    printf(&quot;%s\n&quot;, result.str(16).c_str());<br>    return 0;<br>}<br><br>int main()<br>{<br>    find_mu(64); // 2^64 / p<br>    return 0;<br>}</pre><h4>carry-less multiplication</h4><p>Recall that the main concept of CRC is to do polynomial division. As such, polynomial division has no need to do carries; yet, to allow each digit to become an arbitrary value is impractical. We can instead do the following: still don’t carry, but let the value in a sensible range. We should limit the range as \([0, 1]\) because we are using computer to perform the polynomial division. That is, preserve with MODULO 2.</p><p>There is an interesting property of polynomial operation MODULO 2: all of the polynomial operation is equivalent to binary arithmetic with no carries, or “carry-less” binary arithmetic. Consequently, we can substitute the multiplication in Barrett reduction into carry-less multiplication.</p><p>Though using Barrett reduction with carry-less multiplication does not need to store the look-up table, it needs the target to support hardware accelerated carry-less multiplication as the ordinary carry-less multiplication requires \(O(b²)\) time (\(b\) means the bits of number), which usually performs worse than look-up table method. Thankfully, Arm Cryptography Extension provides a hardware accelerated carry-less multiplication.</p><p>Summing up, we can come up with the following implementation:</p><pre>FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v)<br>{<br>    ...<br>    // Adapted from: https://mary.rs/lab/crc32/<br>    // If target supports Arm Cryptography Extension:<br><br>    // Barrent reduction<br>    uint64x2_t orig =<br>        vcombine_u64(vcreate_u64((uint64_t) (crc) &lt;&lt; 24), vcreate_u64(0x0));<br>    uint64x2_t tmp = orig;<br><br>    // Polynomial P(x) of CRC32C<br>    uint64_t p = 0x105EC76F1;<br>    // Barrett Reduction (in bit-reflected form) constant mu_{64} = \lfloor<br>    // 2^{64} / P(x) \rfloor = 0x11f91caf6<br>    uint64_t mu = 0x1dea713f1;<br><br>    // Note: the _sse2neon_vmull_p64 is a wrapper of carry-less multiplication<br>    // Multiply by mu_{64}<br>    tmp = _sse2neon_vmull_p64(vget_low_u64(tmp), vcreate_u64(mu));<br>    // Divide by 2^{64} (mask away the unnecessary bits)<br>    tmp =<br>        vandq_u64(tmp, vcombine_u64(vcreate_u64(0xFFFFFFFF), vcreate_u64(0x0)));<br>    // Multiply by P(x) (shifted left by 1 for alignment reasons)<br>    tmp = _sse2neon_vmull_p64(vget_low_u64(tmp), vcreate_u64(p));<br>    // Subtract original from result<br>    tmp = veorq_u64(tmp, orig);<br><br>    // Extract the &#39;lower&#39; (in bit-reflected sense) 32 bits<br>    crc = vgetq_lane_u32(vreinterpretq_u32_u64(tmp), 1);<br><br>    return crc;<br>}</pre><h3>Conclusion</h3><p>In this post, I have shown two methods of optimizing CRC32C calculation, and these implementations are merge to sse2neon. I also make brief depictions of CRC and carry-less multiplication, which are commonly seen topics in cryptography.</p><h3>Trivia</h3><p>While I was measuring the running time of each implementation, I found that the precedence of test function will affect the running time of each implementation in qemu.</p><h3>Reference</h3><p>[¹]: <a href="https://en.wikipedia.org/wiki/Cyclic_redundancy_check">https://en.wikipedia.org/wiki/Cyclic_redundancy_check</a></p><p>[²]: <a href="https://github.com/komrad36/CRC">https://github.com/komrad36/CRC</a></p><p>[³]: <a href="https://github.com/DLTcollab/sse2neon/blob/cfaa59fc04fecb117c0a0f3fe9c82dece6f359ad/sse2neon.h#L8502">https://github.com/DLTcollab/sse2neon/blob/cfaa59fc04fecb117c0a0f3fe9c82dece6f359ad/sse2neon.h#L8502</a></p><p>[⁴]: <a href="https://github.com/DLTcollab/sse2neon/pull/627#discussion_r1453360563">https://github.com/DLTcollab/sse2neon/pull/627#discussion_r1453360563</a></p><p>[⁵]: <a href="https://github.com/DLTcollab/sse2neon/pull/627#issuecomment-1895992394">https://github.com/DLTcollab/sse2neon/pull/627#issuecomment-1895992394</a></p><p>[⁶]: <a href="https://www.facebook.com/groups/system.software2024/posts/1556960111748548/?comment_id=1556971665080726">https://www.facebook.com/groups/system.software2024/posts/1556960111748548/?comment_id=1556971665080726</a> (the comments are written is Mandarin)</p><p>[⁷]: <a href="https://create.stephan-brumme.com/crc32/#half-byte">https://create.stephan-brumme.com/crc32/#half-byte</a></p><p>[⁸]: <a href="https://en.wikipedia.org/wiki/Barrett_reduction">https://en.wikipedia.org/wiki/Barrett_reduction</a></p><p>[⁹]: <a href="https://mary.rs/lab/crc32/">https://mary.rs/lab/crc32/</a></p><p>[¹⁰]: <a href="https://github.com/calccrypto/uint256_t">https://github.com/calccrypto/uint256_t</a></p><p><em>Originally published at </em><a href="https://cuda-chen.github.io/programming/open%20source%20contribution/2024/02/27/optimize-mm-crc32-u8-conversion-in-sse2neon.html"><em>https://cuda-chen.github.io</em></a><em> on February 27, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1094a0a7aed9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My sse2neon Contribution of _rdtsc]]></title>
            <link>https://clh0524.medium.com/my-sse2neon-contribution-of-rdtsc-87015c9fe8c5?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/87015c9fe8c5</guid>
            <category><![CDATA[open-source-contribution]]></category>
            <category><![CDATA[simd]]></category>
            <category><![CDATA[c-programming]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 00:00:42 GMT</pubDate>
            <atom:updated>2023-04-10T12:02:50.071Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I am going to illustrate the path of _rdtsc [¹] conversion contribution on sse2neon. At first, I will introduce the usage of_rdtsc, then talk about the implementation and test case . The full implementation can be seen in here: <a href="https://github.com/DLTcollab/sse2neon/pull/532">https://github.com/DLTcollab/sse2neon/pull/532</a></p><h3>What’s _rdtsc</h3><p>The _rdtsc is an SSE intrinsic which gets the current timestamp from processor. The way which makes it special is that it gets the timestamp directly from hardware, which is suitable for measuring precise execution time.</p><h3>Implementations</h3><p>As this post is talking about the conversion, let’s talk about how I implement the conversions on each target.</p><h3>ARMv8-A</h3><p>Pretty straightforward. You just read the value from CNTVCT_EL0 (counter-timer virtual count register).</p><pre>uint64_t val;<br>__asm__ __volatile__(&quot;mrs %0, cntvct_el0&quot; : &quot;=r&quot;(val));<br>return val;</pre><h3>ARMv7-A</h3><p>The ARMv7-A counterpart is trickier as it has no CNTVCT_EL0. Instead, you can get the value from PMCCNTR (performance monitors cycle count register).</p><p>Nevertheless, PMCCNTR can be accessed only in one of the following conditions:</p><ol><li>All modes executing at PL1 or higher.</li><li>User mode when PMCUSERENR.EN == 1 (PMCUSERENR stands for performance monitors user enable register).</li></ol><p>What’s more, PMCCNTR starts to count only if PMCNTENSET (performance monitors count enable set register) is set.</p><p>If none of the three above conditions is met, you will not be able to access PMCCNTR or get its value. In fact, you can get the current timestamp using Linux kernel API ( gettimeofday) as usually the API is running in kernel mode.</p><pre>uint32_t pmccntr, pmuseren, pmcntenset;<br>__asm__ __volatile__(&quot;mrc p15, 0, %0, c9, c14, 0&quot; : &quot;=r&quot;(pmuseren));<br>if (pmuseren &amp; 1) {<br>    __asm__ __volatile__(&quot;mrc p15, 0, %0, c9, c12, 1&quot; : &quot;=r&quot;(pmcntenset));<br>    if (pmcntenset &amp; 0x80000000UL) {<br>        __asm__ __volatile__(&quot;mrc p15, 0, %0, c9, c13, 0&quot; : &quot;=r&quot;(pmccntr));<br>        return (uint64_t) (pmccntr) &lt;&lt; 6;<br>    }<br>}<br><br>struct timeval tv;<br>gettimeofday(&amp;tv, NULL);<br>return (uint64_t) (tv.tv_sec) * 1000000 + tv.tv_usec;</pre><h3>Test Cases</h3><p>In order to prove the implementation works, I add a dedicated test case for unit testing.</p><pre>// test case implementation<br>result_t test_rdtsc(const SSE2NEONTestImpl &amp;impl, uint32_t iter)<br>{<br>    uint64_t start = _rdtsc();<br>    for (int i = 0; i &lt; 100000; i++)<br>        __asm__ __volatile__(&quot;&quot; ::: &quot;memory&quot;);<br>    uint64_t end = _rdtsc();<br>    return end &gt; start ? TEST_SUCCESS : TEST_FAIL;<br>}</pre><p>The test procedure as follows:</p><ol><li>get current timestamp</li><li>create a long-running time for loop</li><li>get current timestamp again</li><li>check whether the value of timestamp in 3. is larger than 1.</li></ol><h3>Why the for loop looks so strange?</h3><p>You may ask why not create the long-running for loop as follows:</p><pre>for(int i = 0; i &lt; 100000; i++)<br>    ; // no-op</pre><p>The reason is that modern compile sometimes eliminates the loops with no any operations. Therefore, we need a trick which creates a long-running for loop without being removed by compiler. Fortunately, we can use __asm__ __volatile__(&quot;&quot; ::: &quot;memory&quot;); to do the trick.</p><p>So you may ask another question: why __asm__ __volatile__(&quot;&quot; ::: &quot;memory&quot;); can fulfill the task?</p><p>According in this post [²], the __asm__ __volatile__(&quot;&quot; ::: &quot;memory&quot;); creates a compiler barrier. What&#39;s more, with the help of volatile keyword, compiler won&#39;t take any optimization of this assembly. Therefore, we create a statement which doing nothing. Thus, the long-running for loop serves its purpose.</p><h3>References</h3><p>[¹] <a href="https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=rdtsc">https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=rdtsc</a></p><p>[²] <a href="https://preshing.com/20120625/memory-ordering-at-compile-time/">https://preshing.com/20120625/memory-ordering-at-compile-time/</a></p><p><em>Originally published at </em><a href="https://cuda-chen.github.io/programming/open%20source%20contributions/2023/04/02/my-sse2neon-contribution-of-rdtsc.html"><em>https://cuda-chen.github.io</em></a><em> on April 2, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87015c9fe8c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Moderna COVID-19 First Booster Vaccination Report]]></title>
            <link>https://clh0524.medium.com/my-moderna-covid-19-first-booster-vaccination-report-d2089a87f79?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2089a87f79</guid>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Sun, 29 May 2022 00:00:00 GMT</pubDate>
            <atom:updated>2022-05-29T07:03:56.055Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PgO7cCWYBRpm95Ed" /><figcaption>Photo by <a href="https://unsplash.com/@mufidpwt?utm_source=medium&amp;utm_medium=referral">Mufid Majnun</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this post, I will record the situation after I got vaccination with <a href="https://modernacovid19global.com/">Moderna</a> COVID-19 vaccine.</p><h3>Day 1 (the day after got vaccinated)</h3><ul><li>Sore muscle on vaccinated arm.</li><li>Moderate fatigue.</li></ul><h3>Day 2</h3><ul><li>Strong fatigue.</li><li>Sore muscle on vaccinated arm.</li><li>Headache.</li><li>Fever.</li><li>Sweating a lot, I bet I haven’t sweated a lot before even for exercising.</li><li>Palpitation.</li></ul><h3>Day 3</h3><ul><li>A little fatigue.</li><li>A little sore muscle on vaccinated arm.</li><li>Coughing.</li><li>Stuffy nose.</li><li>Palpitation.</li></ul><h3>Day 4</h3><ul><li>A little fatigue.</li><li>Coughing sometimes.</li><li>Stuffy nose.</li><li>Palpitation.</li></ul><h3>Day 5</h3><ul><li>A little fatigue.</li><li>Coughing sometimes.</li><li>Stuffy nose.</li></ul><h3>Day 6</h3><ul><li>A little fatigue.</li><li>Coughing seldomly.</li></ul><h3>Day 7</h3><ul><li>Feel a little fatigue sometimes.</li><li>Coughing seldomly.</li><li><strong>Get PCR positive report today.</strong></li></ul><h3>Day 8</h3><ul><li>Awaken as hell.</li><li>Coughing seldomly.</li></ul><h3>Day 9</h3><ul><li>Awaken as hell.</li><li>Coughing seldomly.</li></ul><h3>Day 10</h3><ul><li>Awaken as hell.</li></ul><h3>Day 11</h3><ul><li>Awaken as hell.</li></ul><h3>Day 12</h3><ul><li>Awaken as hell.</li></ul><h3>Day 13</h3><ul><li>Awaken as hell.</li></ul><h3>Day 14</h3><ul><li>Awaken as hell.</li><li><strong>Get dis-quarantine notification today.</strong></li></ul><p><em>Originally published at </em><a href="https://cuda-chen.github.io/life/2022/05/29/moderna-booster-1st.html"><em>https://cuda-chen.github.io</em></a><em> on May 29, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2089a87f79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Switch Your Jekyll Blog to Google Analytics 4 Simplified]]></title>
            <link>https://clh0524.medium.com/switch-your-jekyll-blog-to-google-analytics-4-simplified-8704d23d9cf9?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8704d23d9cf9</guid>
            <category><![CDATA[google-analytics]]></category>
            <category><![CDATA[jekyll-themes]]></category>
            <category><![CDATA[google-analytics-tips]]></category>
            <category><![CDATA[jekyll]]></category>
            <category><![CDATA[google-analytics-4]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Sat, 30 Apr 2022 00:00:00 GMT</pubDate>
            <atom:updated>2022-04-30T12:55:07.646Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hIudQf3xvdVsD-7i" /><figcaption>Photo by <a href="https://unsplash.com/@hostreviews?utm_source=medium&amp;utm_medium=referral">Stephen Phillips - Hostreviews.co.uk</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>As a reminder from Google [¹]. Google Analytics will be replaced by Google Analytics 4 after July 1st, 2023. As a user of Google Analytics, I write down the switching procedures so that other user can have a post to know how to switch your Jekyll blog from Google Analytics to Google Analytics 4.</p><h3>Switching Procedures</h3><ol><li>Create a Google Analytics 4 Property. For more information you can visit <a href="https://support.google.com/analytics/answer/9304153?hl=en">the help center of Google</a>.</li><li>Record your measurement ID. This <a href="https://support.google.com/analytics/answer/9539598">answer</a> will let you find your measurement ID.</li><li>Put your measurement ID in _config.yml. Usually you put your measurement ID like this: <br>google_analytics: &lt;your-measurement-id&gt;</li><li>(Minima and GitHub Pages only) use remote theme. For <a href="https://github.com/jekyll/minima/issues/561">some reasons</a>, you have to use remote theme if your Jekyll blog uses minima theme and is hosted on GitHub Pages. Usually you set your blog to use remote theme like this:</li></ol><pre># _config.yml<br><br>- theme: minima<br>+ remote_theme: jekyll/minima<br><br>  plugins:<br>+ - jekyll-remote-theme</pre><h3>References</h3><p>[¹] <a href="https://support.google.com/analytics/answer/10089681?hl=en">https://support.google.com/analytics/answer/10089681?hl=en</a></p><p><em>Originally published at </em><a href="https://cuda-chen.github.io/blogging/2022/04/30/switch-your-jekyll-blog-to-google-analytics-4-simplified.html"><em>https://cuda-chen.github.io</em></a><em> on April 30, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8704d23d9cf9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Medigenvac COVID-19 Second Vaccination Report]]></title>
            <link>https://clh0524.medium.com/my-medigenvac-covid-19-second-vaccination-report-2e84004551e2?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e84004551e2</guid>
            <category><![CDATA[medigenvec]]></category>
            <category><![CDATA[covid-19-vaccination]]></category>
            <category><![CDATA[vaccine-hesitancy]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[vaccine-report]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Sat, 30 Oct 2021 14:29:22 GMT</pubDate>
            <atom:updated>2021-10-30T14:29:22.477Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4-cBVpMnCSK3iMDn" /><figcaption>Photo by <a href="https://unsplash.com/@matnapo?utm_source=medium&amp;utm_medium=referral">Mat Napo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this post, I will record the situation after I got vaccinated with <a href="https://www.medigenvac.com/public/en">Medigenvac</a> COVID-19 vaccine second shot.</p><h3>Day 1 (The day get vaccinated)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 2</h3><ul><li>Awaken as hell.</li></ul><h3>Day 3</h3><ul><li>Awaken as hell.</li><li>Sore shoulder on vaccined one.</li></ul><h3>Day 4</h3><ul><li>Awaken as hell.</li></ul><h3>Day 5</h3><ul><li>Awaken as hell.</li></ul><h3>Day 6</h3><ul><li>Awaken as hell.</li></ul><h3>Day 7</h3><ul><li>Awaken as hell.</li></ul><h3>Day 8</h3><ul><li>Awaken as hell.</li></ul><h3>Day 9</h3><ul><li>Awaken as hell.</li></ul><h3>Day 10</h3><ul><li>Awaken as hell.</li></ul><h3>Day 11</h3><ul><li>Awaken as hell.</li></ul><h3>Day 12</h3><ul><li>Awaken as hell.</li></ul><h3>Day 13</h3><ul><li>Awaken as hell.</li></ul><h3>Day 14</h3><ul><li>Awaken as hell.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e84004551e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How My LeNet Achieves 99% Accuracy]]></title>
            <link>https://medium.com/geekculture/how-my-lenet-achieves-99-accuracy-acb8a1c737f0?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/acb8a1c737f0</guid>
            <category><![CDATA[hyperparameter-tuning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[deep-learning-framework]]></category>
            <category><![CDATA[lenet-5]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Thu, 23 Sep 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-09-25T23:02:59.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hwXu3jpgoa9qDbCv" /><figcaption>Photo by <a href="https://unsplash.com/@ianstauffer?utm_source=medium&amp;utm_medium=referral">Ian Stauffer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>Fine-tuning plays a great role in model training, and realizing the meaning of each hyperparameter lets you succeed.</p><p>In this post, I am going to show you how I achieve 99% top-1 accuracy on MNIST hand-written number recognition by just fine-tuning three hyperparameters. I also try to implement a classic CNN model, LeNet-5, from scratch for making me familiarize the structure and the basic components of a CNN model. What’s more, I will build my LeNet-5 model in <a href="https://fluxml.ai/">Flux.jl</a> to show an example of Julia neural network framework.</p><h3>Base Model</h3><blockquote><em>You can get the code from </em><a href="https://github.com/Cuda-Chen/flux-lenet"><em>my repo</em></a><em>.</em></blockquote><p>The base model is the well-known 5-layer LeNet [¹], and the implementation is adopted from Flux.jl model zoo [²]. As such, there are some differences between the original LeNet and the implementation in Flux.jl model zoo [³]:</p><ol><li>The activation function of convolution layer in LeNet uses <strong>sigmoid</strong>, whilst in Flux.jl model zoo uses <strong>ReLU</strong>.</li><li>The pooling layer in LeNet uses <strong>average</strong> pooling, whereas in Flux.jl mode zoo uses <strong>max</strong> pooling.</li><li>The activation function of pooling layer in LeNet uses <strong>scaled hyperbolic tangent</strong>, while the one in Flux.jl model zoo uses <strong>identity</strong> (linear).</li><li>The multi-class classification used in original LeNet paper uses <strong>Euclidean radial basis (RBF) function</strong>. [3] However, <strong>softmax</strong> is used in Flux.jl’s implementation.</li></ol><p>For your ease, I list the structure of my implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bc1557aec364b9b88614f51db0ed0ed/href">https://medium.com/media/6bc1557aec364b9b88614f51db0ed0ed/href</a></iframe><h3>Let’s fine tuning!</h3><p>As such, hypermeter tuning plays a crucial role in machine learning model development. Though the LeNet implementation of Flux.jl can achieve 98% top-1 accuracy, I still want to try whether I can break the limits. What’s more, by experimenting fine tuning, I can attain the knowledge which parameters plays the major role in certain task.</p><h3>baseline and its performance</h3><blockquote><em>Baseline model can be found here: </em><a href="https://github.com/FluxML/model-zoo/blob/master/vision/conv_mnist/conv_mnist.jl"><em>https://github.com/FluxML/model-zoo/blob/master/vision/conv_mnist/conv_mnist.jl</em></a></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6ff6a76f6ca328efddf17ad8bede9d0/href">https://medium.com/media/b6ff6a76f6ca328efddf17ad8bede9d0/href</a></iframe><h3>batch size</h3><p>Batch size means how many training samples are used in one iteration. Furthermore, it represents you update, or formally, calculate the loss then back-propagate, the parameters of the model after ingest certain number of training samples. Therefore, assuming the following scenes:</p><ol><li>If you update the parameters after ingest <strong>the whole data</strong>. You may get a fast parameter updating time, but the model will perform poorly on actual case because the model falls into the trap of local minima. Besides, it needs a huge number of memory to load the data.</li><li>If you update the parameters after ingest <strong>each number of data</strong> (only one data in each iteration). You may get a model with fantastic outcome, but it takes an extraordinary time to train as it updates the parameters in each iteration.</li></ol><p>As such, choosing the right number of batch size can:</p><ul><li>reduce the training time and memory</li><li>coverage in better performance</li></ul><p>In this post, I tried different number of batch size, and the best batch size of my training platform is <strong>32</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c604e441fbdd7eac5ba137fa337f86ae/href">https://medium.com/media/c604e441fbdd7eac5ba137fa337f86ae/href</a></iframe><p>And the following paragraphs are the training log of different batch size:</p><h4>32</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a2346dd655612fabe216f6d64c228aa/href">https://medium.com/media/3a2346dd655612fabe216f6d64c228aa/href</a></iframe><h4>64</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f3d68e859997e3d93ffd1ba4c0e2992/href">https://medium.com/media/5f3d68e859997e3d93ffd1ba4c0e2992/href</a></iframe><h4>256</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94565fa164ae5aa2ff479512b618b18b/href">https://medium.com/media/94565fa164ae5aa2ff479512b618b18b/href</a></iframe><h4>512</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63bc4e30d27e966d01d9e4f217e39fbd/href">https://medium.com/media/63bc4e30d27e966d01d9e4f217e39fbd/href</a></iframe><h4>regularizer parameter</h4><p>The regularizer is to add penalty so that the model reduce the probability to become overfitting. Usually, we can use L1 and L2 regularizer, and I choose L2 regularizer for my LeNet-5 model.</p><p>In this experiment, the best L2 regularizer parameter is <strong>1e-6</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78f3445362d6fabadb9f9259910a9dd9/href">https://medium.com/media/78f3445362d6fabadb9f9259910a9dd9/href</a></iframe><p>As usual, I put the training logs with different regularizer parameters:</p><h4>1e-2</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd379dccee8a78dbb8b46b3e9e18ca0e/href">https://medium.com/media/dd379dccee8a78dbb8b46b3e9e18ca0e/href</a></iframe><h4>1e-4</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d06d1d3f547a0e5541f92d47a1e6232f/href">https://medium.com/media/d06d1d3f547a0e5541f92d47a1e6232f/href</a></iframe><h4>1e-6</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73549011ba1a6feab70024eb20bd2e54/href">https://medium.com/media/73549011ba1a6feab70024eb20bd2e54/href</a></iframe><h3>optimizer</h3><p>Optimizer in machine learning is to change the learning rate according to pre-assigned parameter so that the learning rate of model can be changed and the model is more likely to generalize well. In this post, I choose three optimizers: ADAMW, NADAM, and AdaBelief among commonly-seen ADAM. For the description of these optimizers, you can visit <a href="https://fluxml.ai/Flux.jl/stable/training/optimisers/#Optimisers">the documentation of optimizer of Flux.jl</a>.</p><p>In this post, the best optimizer is <strong>ADAMW</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5d56dc920878c4296b9cec4d9d53f95/href">https://medium.com/media/c5d56dc920878c4296b9cec4d9d53f95/href</a></iframe><p>And here are the training logs with different optimizer:</p><h4>ADAMW</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1c179a1cbb83da452d4a3934c0f5543/href">https://medium.com/media/c1c179a1cbb83da452d4a3934c0f5543/href</a></iframe><h4>NADAM</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ded1c846f3c8931dcc21dc81f0815a68/href">https://medium.com/media/ded1c846f3c8931dcc21dc81f0815a68/href</a></iframe><h4>AdaBelief</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3200fff326e8dffa66c6fc7ed1dd2961/href">https://medium.com/media/3200fff326e8dffa66c6fc7ed1dd2961/href</a></iframe><h3>Conclusion</h3><p>In this post, I build the classic LeNet-5 model not only practice my machine learning skills but also make myself familiar with emerging Flux.jl framework. I also show three possible criteria — batch size, regularizer, and optimizer — for the procedures of hyper-parameter tuning, or fine-tuning. At last, I bring you my LeNet-5 model can achieve 99% top-1 accuracy on MNIST dataset.</p><h3>List to Show the Training Environment</h3><ul><li>CPU: Intel(R) Core(TM) i7–9700 CPU @ 3.00GHz</li><li>RAM: 16 GiB</li><li>OS: Fedora 33 (Linux Kernel 5.13.12)</li><li>Julia version: 1.6.2</li><li>Flux.jl version: v0.12.4</li></ul><h3>References</h3><p>[¹] <a href="http://yann.lecun.com/exdb/publis/pdf/lecun-98.pdf">http://yann.lecun.com/exdb/publis/pdf/lecun-98.pdf</a></p><p>[²] <a href="https://github.com/FluxML/model-zoo/blob/33f5c472c321a50fc2105358a00eb7b3ec0ffa5e/vision/conv_mnist/conv_mnist.jl#L21">https://github.com/FluxML/model-zoo/blob/33f5c472c321a50fc2105358a00eb7b3ec0ffa5e/vision/conv_mnist/conv_mnist.jl#L21</a></p><p>[³] <a href="https://pabloinsente.github.io/the-convolutional-network">https://pabloinsente.github.io/the-convolutional-network</a></p><p><em>Originally published at </em><a href="https://cuda-chen.github.io/deep%20learning/2021/09/23/lenet-99.html"><em>https://cuda-chen.github.io</em></a><em> on September 23, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acb8a1c737f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-my-lenet-achieves-99-accuracy-acb8a1c737f0">How My LeNet Achieves 99% Accuracy</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Medigenvac COVID-19 First Vaccination Report]]></title>
            <link>https://clh0524.medium.com/my-medigenvac-covid-19-first-vaccination-report-b644448b778?source=rss-b979f7d2365d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b644448b778</guid>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[vaccine-hesitancy]]></category>
            <category><![CDATA[vaccine-report]]></category>
            <category><![CDATA[medigenvec]]></category>
            <category><![CDATA[covid-19-vaccination]]></category>
            <dc:creator><![CDATA[Lu-Hsuan Chen]]></dc:creator>
            <pubDate>Wed, 08 Sep 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-09-08T13:35:00.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*x-yZBhQt475CEfWJ" /><figcaption>Photo by <a href="https://unsplash.com/@schluditsch?utm_source=medium&amp;utm_medium=referral">Daniel Schludi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this post, I will record the situation after I got vaccinated with <a href="https://www.medigenvac.com/public/en">Medigenvac</a> COVID-19 vaccine.</p><h3>Day 1 (2021/08/24)</h3><ul><li>Fatigue.</li></ul><h3>Day 2 (2021/08/25)</h3><ul><li>Mild fatigue.</li><li>Mild sore on vaccined shoulder.</li></ul><h3>Day 3 (2021/08/26)</h3><ul><li>Moderate fatigue.</li></ul><h3>Day 4 (2021/08/27)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 5 (2021/08/28)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 6 (2021/08/29)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 7 (2021/08/30)</h3><ul><li>Awaken as hell in the morning, but after lunch with Subway, I felt fatigue and took a nap in the evening.</li></ul><h3>Day 8 (2021/08/31)</h3><ul><li>Awaken as hell in the morning.</li><li>Got headache after finishing lunch, maybe I am so tired these days.</li></ul><h3>Day 9 (2021/09/01)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 10 (2021/09/02)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 11 (2021/09/03)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 12 (2021/09/04)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 13 (2021/09/05)</h3><ul><li>Awaken as hell.</li></ul><h3>Day 14 (2021/09/06)</h3><ul><li>Awaken as hell.</li></ul><p><em>Originally published at </em><a href="https://cuda-chen.github.io/life/2021/09/08/medigenvac-report.html"><em>https://cuda-chen.github.io</em></a><em> on September 8, 2021.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fbutton.like.co%2Fin%2Fembed%2Fclh0524%2Fbutton&amp;display_name=LikeCoin&amp;url=https%3A%2F%2Fbutton.like.co%2Fclh0524&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Flikecoin-foundation.appspot.com%2Flikecoin_store_user_clh0524_main%3FGoogleAccessId%3Dfirebase-adminsdk-eyzut%2540likecoin-foundation.iam.gserviceaccount.com%26Expires%3D2430432000%26Signature%3Dizf%252BHb%252BzBu7vTc311JUNXJ%252BsmSgm72k%252FSu4D2IiIrxVcniv7CESi77yBzMxz7EpPgDw%252BpqAdiAQ71RCJyMZji6DHzpZ3rWja6ktouMQ0DxDOJ59NdqOjf%252F25tO7nE2sk7FMatnGl%252FaDkeQjMQfdf7TzzUOoPA%252Bq%252FJ5XNgyCehIIu6Evh4srWpu%252Fl4%252Bjb68RJR5fblguM0eCX%252BEbSiDoeWpjUPJ7cFvvm57wOSIjQZ1SZ%252BPKNFdkuA%252BRLZ4dQOlzR4YQyC4xkpMRSBQH1pFSqcNSJn%252BoNgxSKM6cFBUOW%252FamQlPyexg1uZ4uFImZ9u0%252BQsdzRrLxtSLbuAw%252BbERhnZw%253D%253D&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=like" width="485" height="212" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a09f21eb3ab75579c563e63cb65a1b8/href">https://medium.com/media/9a09f21eb3ab75579c563e63cb65a1b8/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b644448b778" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>