diff --git a/bun.lock b/bun.lock index d575dd2..e0737fc 100644 --- a/bun.lock +++ b/bun.lock @@ -5,14 +5,15 @@ "": { "name": "gapry.github.io", "dependencies": { + "@shikijs/rehype": "^4.6.0", "katex": "^0.16.44", "react": "^19.2.0", "react-dom": "^19.2.0", "react-markdown": "^10.1.0", - "react-syntax-highlighter": "^16.1.1", "rehype-katex": "^7.0.1", "remark-gfm": "^4.0.1", "remark-math": "^6.0.0", + "shiki": "^4.6.0", }, "devDependencies": { "@eslint/js": "^9.39.1", @@ -60,8 +61,6 @@ "@babel/plugin-transform-react-jsx-source": ["@babel/plugin-transform-react-jsx-source@7.27.1", "", { "dependencies": { "@babel/helper-plugin-utils": "^7.27.1" }, "peerDependencies": { "@babel/core": "^7.0.0-0" } }, "sha512-zbwoTsBruTeKB9hSq73ha66iFeJHuaFkUbwvqElnygoNbj/jHRsSeokowZFN3CZ64IvEqcmmkVe89OPXc7ldAw=="], - "@babel/runtime": ["@babel/runtime@7.28.6", "", {}, "sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA=="], - "@babel/template": ["@babel/template@7.28.6", "", { "dependencies": { "@babel/code-frame": "^7.28.6", "@babel/parser": "^7.28.6", "@babel/types": "^7.28.6" } }, "sha512-YA6Ma2KsCdGb+WC6UpBVFJGXL58MDA6oyONbjyF/+5sBgxY/dwkhLogbMT2GXXyU84/IhRw/2D1Os1B/giz+BQ=="], "@babel/traverse": ["@babel/traverse@7.29.0", "", { "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", "@babel/helper-globals": "^7.28.0", "@babel/parser": "^7.29.0", "@babel/template": "^7.28.6", "@babel/types": "^7.29.0", "debug": "^4.3.1" } }, "sha512-4HPiQr0X7+waHfyXPZpWPfWL/J7dcN1mx9gL6WdQVMbPnF3+ZhSMs8tCxN7oHddJE9fhNE7+lxdnlyemKfJRuA=="], @@ -208,6 +207,24 @@ "@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.59.0", "", { "os": "win32", "cpu": "x64" }, "sha512-2HRCml6OztYXyJXAvdDXPKcawukWY2GpR5/nxKp4iBgiO3wcoEGkAaqctIbZcNB6KlUQBIqt8VYkNSj2397EfA=="], + "@shikijs/core": ["@shikijs/core@4.6.0", "", { "dependencies": { "@shikijs/primitive": "4.6.0", "@shikijs/types": "4.6.0", "@shikijs/vscode-textmate": "^10.1.0", "@types/hast": "^3.0.5", "hast-util-to-html": "^9.0.6" } }, "sha512-bfd4OKgvoyXYiYmMRuleA656P4V7M/Du9lcTl38Ngm6KszMj7bq4J1IGZwSYR4c95Tv5UQALtYNWUwaI9UT3xw=="], + + "@shikijs/engine-javascript": ["@shikijs/engine-javascript@4.6.0", "", { "dependencies": { "@shikijs/types": "4.6.0", "@shikijs/vscode-textmate": "^10.1.0", "oniguruma-to-es": "^4.3.6" } }, "sha512-K0oqxFoL+kEMdz89mHLFO15Tsbv3kFZ6WR1cXZKMvLSc+oqaM00A6pyga1qSeXB22dP0tTiSApRcGBaKWsEccg=="], + + "@shikijs/engine-oniguruma": ["@shikijs/engine-oniguruma@4.6.0", "", { "dependencies": { "@shikijs/types": "4.6.0", "@shikijs/vscode-textmate": "^10.1.0" } }, "sha512-aggd6Q7SuJOXNnsUbfG2XesxBJKBMAw/PDTUo9PyRjMaaJJ2dNrI+q0C+25ARXAK9yLHAlwxc9oRT2u68YKZ7w=="], + + "@shikijs/langs": ["@shikijs/langs@4.6.0", "", { "dependencies": { "@shikijs/types": "4.6.0" } }, "sha512-1yMEX3oCVV54LUq/ovfpRkDQoYDkcvjSWFFa/YLUDMiSoRzMi2uxLJYbv41ahT8Lu9lFMaa7hecd3Q39trqUyg=="], + + "@shikijs/primitive": ["@shikijs/primitive@4.6.0", "", { "dependencies": { "@shikijs/types": "4.6.0", "@shikijs/vscode-textmate": "^10.1.0", "@types/hast": "^3.0.5" } }, "sha512-c54+TQEo9ToqgfL/AU8FpjnV09+GA9Oa7M5ROkkXteZfp5XzpAJGXjjvZQFQioJOwm/w/6Z3lIzQstAkl8coag=="], + + "@shikijs/rehype": ["@shikijs/rehype@4.6.0", "", { "dependencies": { "@shikijs/types": "4.6.0", "@types/hast": "^3.0.5", "hast-util-to-string": "^3.0.1", "shiki": "4.6.0", "unified": "^11.0.5", "unist-util-visit": "^5.2.0" } }, "sha512-qv3mGfYJuy+TW6UUyC2QrYSEmTxJNGXZ/NmCEsyH0NHfJIOYGvpWm0kNu6P2Ec14jmGwwTfVLMta/FZtY+MrJQ=="], + + "@shikijs/themes": ["@shikijs/themes@4.6.0", "", { "dependencies": { "@shikijs/types": "4.6.0" } }, "sha512-qHAVAs80RiGD+IRuH9G+JPDOEc9A/kHsng4EzCUCwB9bLzW6Z0y9WETh2YyCcADJBmfrIaJ1Jp7KBNP6FHkgtQ=="], + + "@shikijs/types": ["@shikijs/types@4.6.0", "", { "dependencies": { "@shikijs/vscode-textmate": "^10.1.0", "@types/hast": "^3.0.5" } }, "sha512-+ENG1adsKt/X7cRYw1Nl7BEpBmPOjmQ7bR/eGmHuMlT8gtOFf3KEi5l31DJYyAWhW6Y6bjP1plU7FmaxWGENFw=="], + + "@shikijs/vscode-textmate": ["@shikijs/vscode-textmate@10.1.0", "", {}, "sha512-cVBuhDQjBZaNMTwBquYfPydrUP+E3hE6oYGasx8h6ZrODIM7/r+gxLDXdd66oszbrggZHEntdE6j+5gYIVyMWQ=="], + "@types/babel__core": ["@types/babel__core@7.20.5", "", { "dependencies": { "@babel/parser": "^7.20.7", "@babel/types": "^7.20.7", "@types/babel__generator": "*", "@types/babel__template": "*", "@types/babel__traverse": "*" } }, "sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA=="], "@types/babel__generator": ["@types/babel__generator@7.27.0", "", { "dependencies": { "@babel/types": "^7.0.0" } }, "sha512-ufFd2Xi92OAVPYsy+P4n7/U7e68fex0+Ee8gSG9KX7eo084CWiQ4sdxktvdl0bOPupXtVJPY19zk6EwWqUQ8lg=="], @@ -222,7 +239,7 @@ "@types/estree-jsx": ["@types/estree-jsx@1.0.5", "", { "dependencies": { "@types/estree": "*" } }, "sha512-52CcUVNFyfb1A2ALocQw/Dd1BQFNmSdkuC3BkZ6iqhdMfQz7JWOFRuJFloOzjk+6WijU56m9oKXFAXc7o3Towg=="], - "@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + "@types/hast": ["@types/hast@3.0.5", "", { "dependencies": { "@types/unist": "*" } }, "sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g=="], "@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="], @@ -232,8 +249,6 @@ "@types/ms": ["@types/ms@2.1.0", "", {}, "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA=="], - "@types/prismjs": ["@types/prismjs@1.26.6", "", {}, "sha512-vqlvI7qlMvcCBbVe0AKAb4f97//Hy0EBTaiW8AalRnG/xAN5zOiWWyrNqNXeq8+KAuvRewjCVY1+IPxk4RdNYw=="], - "@types/react": ["@types/react@19.2.14", "", { "dependencies": { "csstype": "^3.2.2" } }, "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w=="], "@types/react-dom": ["@types/react-dom@19.2.3", "", { "peerDependencies": { "@types/react": "^19.2.0" } }, "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ=="], @@ -346,8 +361,6 @@ "fast-levenshtein": ["fast-levenshtein@2.0.6", "", {}, "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw=="], - "fault": ["fault@1.0.4", "", { "dependencies": { "format": "^0.2.0" } }, "sha512-CJ0HCB5tL5fYTEA7ToAq5+kTwd++Borf1/bifxd9iT70QcXr4MRrO3Llf8Ifs70q+SJcGHFtnIE/Nw6giCtECA=="], - "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], "file-entry-cache": ["file-entry-cache@8.0.0", "", { "dependencies": { "flat-cache": "^4.0.0" } }, "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ=="], @@ -358,8 +371,6 @@ "flatted": ["flatted@3.3.4", "", {}, "sha512-3+mMldrTAPdta5kjX2G2J7iX4zxtnwpdA8Tr2ZSjkyPSanvbZAcy6flmtnXbEybHrDcU9641lxrMfFuUxVz9vA=="], - "format": ["format@0.2.2", "", {}, "sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww=="], - "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], "gensync": ["gensync@1.0.0-beta.2", "", {}, "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg=="], @@ -382,8 +393,12 @@ "hast-util-parse-selector": ["hast-util-parse-selector@4.0.0", "", { "dependencies": { "@types/hast": "^3.0.0" } }, "sha512-wkQCkSYoOGCRKERFWcxMVMOcYE2K1AaNLU8DXS9arxnLOUEWbOXKXiJUNzEpqZ3JOKpnha3jkFrumEjVliDe7A=="], + "hast-util-to-html": ["hast-util-to-html@9.0.7", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", "ccount": "^2.0.0", "comma-separated-tokens": "^2.0.0", "hast-util-whitespace": "^3.0.0", "html-void-elements": "^3.0.0", "mdast-util-to-hast": "^13.0.0", "property-information": "^7.0.0", "space-separated-tokens": "^2.0.0", "stringify-entities": "^4.0.0", "zwitch": "^2.0.4" } }, "sha512-HYNDA3qdnzUPitY/LcQm1nWs8z0cWFNH1Nz09jdI/tXifAqF7h3+jrLl4S/b9Mi4VSjn0Dsn54ctuTV6zhBthA=="], + "hast-util-to-jsx-runtime": ["hast-util-to-jsx-runtime@2.3.6", "", { "dependencies": { "@types/estree": "^1.0.0", "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", "comma-separated-tokens": "^2.0.0", "devlop": "^1.0.0", "estree-util-is-identifier-name": "^3.0.0", "hast-util-whitespace": "^3.0.0", "mdast-util-mdx-expression": "^2.0.0", "mdast-util-mdx-jsx": "^3.0.0", "mdast-util-mdxjs-esm": "^2.0.0", "property-information": "^7.0.0", "space-separated-tokens": "^2.0.0", "style-to-js": "^1.0.0", "unist-util-position": "^5.0.0", "vfile-message": "^4.0.0" } }, "sha512-zl6s8LwNyo1P9uw+XJGvZtdFF1GdAkOg8ujOw+4Pyb76874fLps4ueHXDhXWdk6YHQ6OgUtinliG7RsYvCbbBg=="], + "hast-util-to-string": ["hast-util-to-string@3.0.1", "", { "dependencies": { "@types/hast": "^3.0.0" } }, "sha512-XelQVTDWvqcl3axRfI0xSeoVKzyIFPwsAGSLIsKdJKQMXDYJS4WYrBNF/8J7RdhIcFI2BOHgAifggsvsxp/3+A=="], + "hast-util-to-text": ["hast-util-to-text@4.0.2", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", "hast-util-is-element": "^3.0.0", "unist-util-find-after": "^5.0.0" } }, "sha512-KK6y/BN8lbaq654j7JgBydev7wuNMcID54lkRav1P0CaE1e47P72AWWPiGKXTJU271ooYzcvTAn/Zt0REnvc7A=="], "hast-util-whitespace": ["hast-util-whitespace@3.0.0", "", { "dependencies": { "@types/hast": "^3.0.0" } }, "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw=="], @@ -394,12 +409,10 @@ "hermes-parser": ["hermes-parser@0.25.1", "", { "dependencies": { "hermes-estree": "0.25.1" } }, "sha512-6pEjquH3rqaI6cYAXYPcz9MS4rY6R4ngRgrgfDshRptUZIc3lw0MCIJIGDj9++mfySOuPTHB4nrSW99BCvOPIA=="], - "highlight.js": ["highlight.js@10.7.3", "", {}, "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A=="], - - "highlightjs-vue": ["highlightjs-vue@1.0.0", "", {}, "sha512-PDEfEF102G23vHmPhLyPboFCD+BkMGu+GuJe2d9/eH4FsCwvgBpnc9n0pGE+ffKdph38s6foEZiEjdgHdzp+IA=="], - "html-url-attributes": ["html-url-attributes@3.0.1", "", {}, "sha512-ol6UPyBWqsrO6EJySPz2O7ZSr856WDrEzM5zMqp+FJJLGMW35cLYmmZnl0vztAZxRUoNZJFTCohfjuIJ8I4QBQ=="], + "html-void-elements": ["html-void-elements@3.0.0", "", {}, "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg=="], + "ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], "import-fresh": ["import-fresh@3.3.1", "", { "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" } }, "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ=="], @@ -450,8 +463,6 @@ "longest-streak": ["longest-streak@3.1.0", "", {}, "sha512-9Ri+o0JYgehTaVBBDoMqIl8GXtbWg711O3srftcHhZ0dqnETqLaoIK0x17fUw9rFSlK/0NlsKe0Ahhyl5pXE2g=="], - "lowlight": ["lowlight@1.20.0", "", { "dependencies": { "fault": "^1.0.0", "highlight.js": "~10.7.0" } }, "sha512-8Ktj+prEb1RoCPkEOrPMYUN/nCggB7qAWe3a7OpMjWQkh3l2RD5wKRQ+o8Q8YuI9RG/xs95waaI/E6ym/7NsTw=="], - "lru-cache": ["lru-cache@5.1.1", "", { "dependencies": { "yallist": "^3.0.2" } }, "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w=="], "markdown-table": ["markdown-table@3.0.4", "", {}, "sha512-wiYz4+JrLyb/DqW2hkFJxP7Vd7JuTDm77fvbM8VfEQdmSMqcImWeeRbHwZjBjIFki/VaMK2BhFi7oUUZeM5bqw=="], @@ -556,6 +567,10 @@ "node-releases": ["node-releases@2.0.36", "", {}, "sha512-TdC8FSgHz8Mwtw9g5L4gR/Sh9XhSP/0DEkQxfEFXOpiul5IiHgHan2VhYYb6agDSfp4KuvltmGApc8HMgUrIkA=="], + "oniguruma-parser": ["oniguruma-parser@0.12.2", "", {}, "sha512-6HVa5oIrgMC6aA6WF6XyyqbhRPJrKR02L20+2+zpDtO5QAzGHAUGw5TKQvwi5vctNnRHkJYmjAhRVQF2EKdTQw=="], + + "oniguruma-to-es": ["oniguruma-to-es@4.3.6", "", { "dependencies": { "oniguruma-parser": "^0.12.2", "regex": "^6.1.0", "regex-recursion": "^6.0.2" } }, "sha512-csuQ9x3Yr0cEIs/Zgx/OEt9iBw9vqIunAPQkx19R/fiMq2oGVTgcMqO/V3Ybqefr1TBvosI6jU539ksaBULJyA=="], + "optionator": ["optionator@0.9.4", "", { "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", "word-wrap": "^1.2.5" } }, "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g=="], "p-limit": ["p-limit@3.1.0", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="], @@ -580,8 +595,6 @@ "prelude-ls": ["prelude-ls@1.2.1", "", {}, "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="], - "prismjs": ["prismjs@1.30.0", "", {}, "sha512-DEvV2ZF2r2/63V+tK8hQvrR2ZGn10srHbXviTlcv7Kpzw8jWiNTqbVgjO3IY8RxrrOUF8VPMQQFysYYYv0YZxw=="], - "property-information": ["property-information@7.1.0", "", {}, "sha512-TwEZ+X+yCJmYfL7TPUOcvBZ4QfoT5YenQiJuX//0th53DE6w0xxLEtfK3iyryQFddXuvkIk51EEgrJQ0WJkOmQ=="], "punycode": ["punycode@2.3.1", "", {}, "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg=="], @@ -594,9 +607,11 @@ "react-refresh": ["react-refresh@0.18.0", "", {}, "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw=="], - "react-syntax-highlighter": ["react-syntax-highlighter@16.1.1", "", { "dependencies": { "@babel/runtime": "^7.28.4", "highlight.js": "^10.4.1", "highlightjs-vue": "^1.0.0", "lowlight": "^1.17.0", "prismjs": "^1.30.0", "refractor": "^5.0.0" }, "peerDependencies": { "react": ">= 0.14.0" } }, "sha512-PjVawBGy80C6YbC5DDZJeUjBmC7skaoEUdvfFQediQHgCL7aKyVHe57SaJGfQsloGDac+gCpTfRdtxzWWKmCXA=="], + "regex": ["regex@6.1.0", "", { "dependencies": { "regex-utilities": "^2.3.0" } }, "sha512-6VwtthbV4o/7+OaAF9I5L5V3llLEsoPyq9P1JVXkedTP33c7MfCG0/5NOPcSJn0TzXcG9YUrR0gQSWioew3LDg=="], + + "regex-recursion": ["regex-recursion@6.0.2", "", { "dependencies": { "regex-utilities": "^2.3.0" } }, "sha512-0YCaSCq2VRIebiaUviZNs0cBz1kg5kVS2UKUfNIx8YVs1cN3AV7NTctO5FOKBA+UT2BPJIWZauYHPqJODG50cg=="], - "refractor": ["refractor@5.0.0", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/prismjs": "^1.0.0", "hastscript": "^9.0.0", "parse-entities": "^4.0.0" } }, "sha512-QXOrHQF5jOpjjLfiNk5GFnWhRXvxjUVnlFxkeDmewR5sXkr3iM46Zo+CnRR8B+MDVqkULW4EcLVcRBNOPXHosw=="], + "regex-utilities": ["regex-utilities@2.3.0", "", {}, "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng=="], "rehype-katex": ["rehype-katex@7.0.1", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/katex": "^0.16.0", "hast-util-from-html-isomorphic": "^2.0.0", "hast-util-to-text": "^4.0.0", "katex": "^0.16.0", "unist-util-visit-parents": "^6.0.0", "vfile": "^6.0.0" } }, "sha512-OiM2wrZ/wuhKkigASodFoo8wimG3H12LWQaH8qSPVJn9apWKFSH3YOCtbKpBorTVw/eI7cuT21XBbvwEswbIOA=="], @@ -622,6 +637,8 @@ "shebang-regex": ["shebang-regex@3.0.0", "", {}, "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="], + "shiki": ["shiki@4.6.0", "", { "dependencies": { "@shikijs/core": "4.6.0", "@shikijs/engine-javascript": "4.6.0", "@shikijs/engine-oniguruma": "4.6.0", "@shikijs/langs": "4.6.0", "@shikijs/themes": "4.6.0", "@shikijs/types": "4.6.0", "@shikijs/vscode-textmate": "^10.1.0", "@types/hast": "^3.0.5" } }, "sha512-imjLsVHgPuWhvpU3P+zOekvMYqnel7QmKsFC4Sn0fCuAvaaalBsxwKEsrU8Ko5BdFnZA6Go/8a0RzahS634UgA=="], + "source-map-js": ["source-map-js@1.2.1", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="], "space-separated-tokens": ["space-separated-tokens@2.0.2", "", {}, "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q=="], @@ -656,7 +673,7 @@ "unist-util-stringify-position": ["unist-util-stringify-position@4.0.0", "", { "dependencies": { "@types/unist": "^3.0.0" } }, "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ=="], - "unist-util-visit": ["unist-util-visit@5.1.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0", "unist-util-visit-parents": "^6.0.0" } }, "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg=="], + "unist-util-visit": ["unist-util-visit@5.2.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0", "unist-util-visit-parents": "^6.1.0" } }, "sha512-fpsYs/VVoZxfGY9/j3FQpZmN8wdLJaV1Pt38AaJNZu9uKIHcFU3halCdBveEq1HGKO1OEfJY65w1zvoFV1b3qQ=="], "unist-util-visit-parents": ["unist-util-visit-parents@6.0.2", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0" } }, "sha512-goh1s1TBrqSqukSc8wrjwWhL0hiJxgA8m4kFxGlQ+8FYQ3C/m11FcTs4YYem7V664AhHVvgoQLk890Ssdsr2IQ=="], @@ -692,8 +709,54 @@ "@eslint/eslintrc/globals": ["globals@14.0.0", "", {}, "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ=="], + "hast-util-from-dom/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hast-util-from-html/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hast-util-from-html-isomorphic/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hast-util-from-parse5/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hast-util-is-element/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hast-util-parse-selector/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hast-util-to-jsx-runtime/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hast-util-to-text/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hast-util-whitespace/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "hastscript/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + "mdast-util-find-and-replace/escape-string-regexp": ["escape-string-regexp@5.0.0", "", {}, "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw=="], + "mdast-util-math/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "mdast-util-mdx-expression/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "mdast-util-mdx-jsx/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "mdast-util-mdxjs-esm/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "mdast-util-to-hast/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "mdast-util-to-hast/unist-util-visit": ["unist-util-visit@5.1.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0", "unist-util-visit-parents": "^6.0.0" } }, "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg=="], + + "mdast-util-to-markdown/unist-util-visit": ["unist-util-visit@5.1.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0", "unist-util-visit-parents": "^6.0.0" } }, "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg=="], + "parse-entities/@types/unist": ["@types/unist@2.0.11", "", {}, "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA=="], + + "react-markdown/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "react-markdown/unist-util-visit": ["unist-util-visit@5.1.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0", "unist-util-visit-parents": "^6.0.0" } }, "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg=="], + + "rehype-katex/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "remark-rehype/@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="], + + "unist-util-remove-position/unist-util-visit": ["unist-util-visit@5.1.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0", "unist-util-visit-parents": "^6.0.0" } }, "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg=="], + + "unist-util-visit/unist-util-visit-parents": ["unist-util-visit-parents@6.1.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0" } }, "sha512-vKXxz6O38sKDj1mtx/k2cWvkkFBuYGx6uGrlzBkVeWCRF/F8sdI0j3Wbkz/5rVNRRuVc8UrgRdbCxNhmYXgP3w=="], } } diff --git a/package.json b/package.json index 6d2cd95..2b0b008 100644 --- a/package.json +++ b/package.json @@ -12,14 +12,15 @@ "preview": "vite preview" }, "dependencies": { + "@shikijs/rehype": "^4.6.0", "katex": "^0.16.44", "react": "^19.2.0", "react-dom": "^19.2.0", "react-markdown": "^10.1.0", - "react-syntax-highlighter": "^16.1.1", "rehype-katex": "^7.0.1", "remark-gfm": "^4.0.1", - "remark-math": "^6.0.0" + "remark-math": "^6.0.0", + "shiki": "^4.6.0" }, "devDependencies": { "@eslint/js": "^9.39.1", diff --git a/public/posts/2026/2026-01-01-Advent-of-Compiler-Optimisations-Study-Notes-01.md b/public/posts/2026/2026-01-01-Advent-of-Compiler-Optimisations-Study-Notes-01.md index 5105153..71933a2 100644 --- a/public/posts/2026/2026-01-01-Advent-of-Compiler-Optimisations-Study-Notes-01.md +++ b/public/posts/2026/2026-01-01-Advent-of-Compiler-Optimisations-Study-Notes-01.md @@ -9,7 +9,7 @@ These notes are based on the post [**Why xor eax, eax?**](https://xania.org/2025 #### Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -49,7 +49,7 @@ Source Code (*.c) ---> | & | ---> | Optimizer | ---> | Generator For now, we use `main.c` as input (shown below), apply different optimization levels, and use `llvm-objdump` to analyze the corresponding assembly code. -```bash +```console $ nvim main.c ``` @@ -61,11 +61,11 @@ int main() { ###### Use `-O0` as optimization level -```bash +```console $ rm -f (path filter *.o); gcc -O0 -c main.c; llvm-objdump -d --x86-asm-syntax=att main.o ``` -```x86asm +```asm main.o: file format elf64-x86-64 Disassembly of section .text: @@ -79,7 +79,7 @@ Disassembly of section .text: e: c3 retq ``` -```bash +```console $ size main.o ``` @@ -91,11 +91,11 @@ text data bss dec hex filename As `-O0`, the compiler generates a stack frame, leading to unnecessary instruction overhead. ###### Use `-O1` as optimization level -```bash +```console $ rm -f (path filter *.o); gcc -O1 -c main.c; llvm-objdump -d --x86-asm-syntax=att main.o ``` -```x86asm +```asm main.o: file format elf64-x86-64 Disassembly of section .text: @@ -106,7 +106,7 @@ Disassembly of section .text: 9: c3 retq ``` -```bash +```console $ size main.o ``` @@ -118,11 +118,11 @@ text data bss dec hex filename It reduces the output from six instructions to three by removing the stack frame setup. ###### Use `-O2` as optimization level -```bash +```console $ rm -f (path filter *.o); gcc -O2 -c main.c; llvm-objdump -d --x86-asm-syntax=att main.o ``` -```x86asm +```asm main.o: file format elf64-x86-64 Disassembly of section .text: @@ -133,7 +133,7 @@ Disassembly of section .text: 6: c3 retq ``` -```bash +```console $ size main.o ``` @@ -149,15 +149,15 @@ making it smaller than the five bytes `movl $0x0, %eax`. Hence, you can see the total `.text` size reduces from 90 bytes to 87 bytes. #### How about we change `gcc` to `clang`? -```bash +```console $ rm -f (path filter *.o); clang -O1 -c main.c; llvm-objdump -d --x86-asm-syntax=att main.o ``` -```bash +```console $ rm -f (path filter *.o); clang -O1 -c main.c; llvm-objdump -d --x86-asm-syntax=att main.o ``` -```x86asm +```asm main.o: file format elf64-x86-64 Disassembly of section .text: @@ -172,7 +172,7 @@ Additionally, it consists of only two instructions because Clang does not genera #### Why `eax`, not `rax` ? -```bash +```console $ nvim get_val.c ``` @@ -182,11 +182,11 @@ long get_val() { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c get_val.c; llvm-objdump -d --x86-asm-syntax=att get_val.o ``` -```x86asm +```asm get_val.o: file format elf64-x86-64 Disassembly of section .text: @@ -203,7 +203,7 @@ into the upper 32 bits of the corresponding 64-bit register. Let's see an example for verifying Zero-Extension with LLDB -```bash +```console $ nvim main.c ``` @@ -213,7 +213,7 @@ int main() { } ``` -```bash +```console $ rm -f (path filter *.out); clang -g -O2 -o app.out main.c; lldb app.out ``` @@ -258,7 +258,7 @@ The LLDB output confirms that even though `xorl` only targets the lower 32 bits the hardware automatically cleared the entire 64-bit `%rax` register. #### Caller/Callee Arguments -```bash +```console $ nvim main.c ``` @@ -275,13 +275,13 @@ void f() { } ``` -```bash +```console $ rm -f (path filter *.o) $ clang -O2 -c main.c $ llvm-objdump -d --disassemble-symbols=f --x86-asm-syntax=att main.o ``` -```x86asm +```asm main.o: file format elf64-x86-64 Disassembly of section .text: diff --git a/public/posts/2026/2026-01-31-Advent-of-Compiler-Optimisations-Study-Notes-02.md b/public/posts/2026/2026-01-31-Advent-of-Compiler-Optimisations-Study-Notes-02.md index 963f963..dc01336 100644 --- a/public/posts/2026/2026-01-31-Advent-of-Compiler-Optimisations-Study-Notes-02.md +++ b/public/posts/2026/2026-01-31-Advent-of-Compiler-Optimisations-Study-Notes-02.md @@ -16,7 +16,7 @@ Selected technical insights from the YouTube comment section are reproduced at t Written by me and assisted by AI, proofread by me and assisted by AI. #### Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -37,7 +37,7 @@ $ echo $SHELL To understand how `clang` translates `C` addition into `x86-64` machine instructions, we use the following implementation -```bash +```console $ nvim add.c ``` @@ -49,11 +49,11 @@ int add(int x, int y) { ## Unoptimized Analysis -```bash +```console $ rm -f (path filter *.o); clang -O0 -c add.c; llvm-objdump -d --x86-asm-syntax=att add.o ``` -```x86asm +```asm add.o: file format elf64-x86-64 Disassembly of section .text: @@ -79,7 +79,7 @@ the compiler cannot translate `a = b + c` directly to a single `add` instruction value of `b` or `c` before the operation is executed, the compiler needs to use `mov` instruction to initialize the destination with one of the operands first: -```x86asm +```asm movl -0x4(%rbp), %eax addl -0x8(%rbp), %eax ``` @@ -87,11 +87,11 @@ addl -0x8(%rbp), %eax Hence, the compiler needs to use two instructions to execute the addition at the -O0 level. ## Optimized Analysis -```bash +```console $ rm -f (path filter *.o); clang -O2 -c add.c; llvm-objdump -d --x86-asm-syntax=att add.o ``` -```x86asm +```asm add.o: file format elf64-x86-64 Disassembly of section .text: @@ -112,11 +112,11 @@ The following assembly code demonstrates these two approaches: one utilizing the `mov` + `add` instruction sequence, and the other employing a single `lea` instruction. -```bash +```console $ nvim add.s ``` -```x86asm +```asm .section .note.GNU-stack, "", @progbits .section .rodata @@ -158,7 +158,7 @@ main: retq ``` -```bash +```console $ rm -f (path filter *.out); clang -o add.out add.s; ./add.out Result: 3 Result: 3 diff --git a/public/posts/2026/2026-01-31-Advent-of-Compiler-Optimisations-Study-Notes-03.md b/public/posts/2026/2026-01-31-Advent-of-Compiler-Optimisations-Study-Notes-03.md index fa3d98d..5d14862 100644 --- a/public/posts/2026/2026-01-31-Advent-of-Compiler-Optimisations-Study-Notes-03.md +++ b/public/posts/2026/2026-01-31-Advent-of-Compiler-Optimisations-Study-Notes-03.md @@ -12,7 +12,7 @@ My notes focus on reproducing and verifying [Matt Godbolt](https://xania.org/Mat Written by me and assisted by AI, proofread by me and assisted by AI. ## Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -42,7 +42,7 @@ $ echo $SHELL We can observe the compiler's optimization by implementing addition through recursion, as shown in the following code: -```bash +```console $ nvim add.c ``` @@ -66,18 +66,18 @@ int main(void) { The following analysis examines the unoptimized assembly code generated with the `-O0` flag. -```bash +```console $ rm -f (path filter *.out) $ clang -O0 -target aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu -static add.c -o app.out $ qemu-aarch64 ./app.out 11 = 11 ``` -```bash +```console $ llvm-objdump -d --disassemble-symbols=add app.out ``` -```armasm +```text app.out: file format elf64-littleaarch64 Disassembly of section .text: @@ -109,7 +109,7 @@ Disassembly of section .text: ``` #### Part 01: Function Prologue -```armasm +```text 4007f0: d10083ff sub sp, sp, #0x20 // Allocate 32 bytes on stack 4007f4: a9017bfd stp x29, x30, [sp, #0x10] // Save Frame Pointer (x29) and Link Register (x30) 4007f8: 910043fd add x29, sp, #0x10 // Set up new Frame Pointer @@ -135,7 +135,7 @@ facilitate the Stack Unwinding process during the Function Epilogue. ``` #### Part 02: Parameter Storage -```armasm +```text 4007fc: b81fc3a0 stur w0, [x29, #-0x4] // Store 'x' (w0) into stack 400800: b9000be1 str w1, [sp, #0x8] // Store 'y' (w1) into stack 400804: b9400be8 ldr w8, [sp, #0x8] // Load 'y' from stack into w8 @@ -146,7 +146,7 @@ Since it is at the `-O0` optimization level, an additional instruction is used to load `y` from stack memory back into a register (`w8`) for subsequent conditional evaluation. #### Part 03: Branching -```armasm +```text 400808: 71000108 subs w8, w8, #0x0 // Compare w8 (y) with 0 40080c: 540000a8 b.hi 0x400820 // If y > 0, jump to recursive case (400820) 400810: 14000001 b 0x400814 // Else, branch to base case logic @@ -159,7 +159,7 @@ if `y > 0`, the Program Counter (`PC`) jumps to the Recursive Case; otherwise, it jumps to the Base Case. #### Part 04: The Base Case: `y == 0` -```armasm +```text 400814: b85fc3a0 ldur w0, [x29, #-0x4] // [Base Case] Load 'x' into w0 400818: b90007e0 str w0, [sp, #0x4] // Store 'x' as the potential return value 40081c: 14000008 b 0x40083c // Jump to epilogue (return) (Part 06) @@ -170,7 +170,7 @@ The compiler then executes a `store` operation from register `W0` to stack memor return value. #### Part 05: The Recursive Step: `add(x + 1, y - 1)` -```armasm +```text 400820: b85fc3a8 ldur w8, [x29, #-0x4] // [Recursive Case] Load 'x' into w8 400824: 11000500 add w0, w8, #0x1 // w0 = x + 1 (Preparing 1st argument) 400828: b9400be8 ldr w8, [sp, #0x8] // Load 'y' into w8 @@ -185,7 +185,7 @@ The `bl` (Branch with Link) instruction then executes the recursive call, redire Once the recursive call returns, the resulting value in `w0` is stored into stack memory before jumping to the epilogue. #### Part 06: Function Epilogue -```armasm +```text 40083c: b94007e0 ldr w0, [sp, #0x4] // Load the result from stack into w0 400840: a9417bfd ldp x29, x30, [sp, #0x10] // Restore Frame Pointer and Link Register 400844: 910083ff add sp, sp, #0x20 // Deallocate stack space @@ -202,18 +202,18 @@ redirects the Control Flow back to the address stored in the link register. The following analysis examines the optimized assembly code generated with the `-O2` flag. -```bash +```console $ rm -f (path filter *.out) $ clang -O2 -target aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu -static add.c -o app.out $ qemu-aarch64 ./app.out 11 = 11 ``` -```bash +```console $ llvm-objdump -d --disassemble-symbols=add app.out ``` -```armasm +```text app.out: file format elf64-littleaarch64 Disassembly of section .text: diff --git a/public/posts/2026/2026-02-27-Advent-of-Compiler-Optimisations-Study-Notes-04.md b/public/posts/2026/2026-02-27-Advent-of-Compiler-Optimisations-Study-Notes-04.md index 1b9da0e..c13cd70 100644 --- a/public/posts/2026/2026-02-27-Advent-of-Compiler-Optimisations-Study-Notes-04.md +++ b/public/posts/2026/2026-02-27-Advent-of-Compiler-Optimisations-Study-Notes-04.md @@ -14,7 +14,7 @@ Selected technical insights from the YouTube comment section are reproduced at t Written by me and assisted by AI, proofread by me and assisted by AI. #### Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -41,7 +41,7 @@ These notes document specific patterns and filter out redundant results, highlig ## Case 01 : `x * 2` -```bash +```console $ nvim mul.c ``` @@ -51,11 +51,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -75,7 +75,7 @@ Here, it uses the leal instruction to perform `x + x` in a single cycle. ## Case 02: `x * 3` -```bash +```console $ nvim mul.c ``` @@ -85,11 +85,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -103,7 +103,7 @@ It utilizes x86 the `lea` with **Base + (Index * Scale)** addressing to calculat ## Case 03: `x * 4` -```bash +```console $ nvim mul.c ``` @@ -113,11 +113,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -132,7 +132,7 @@ eliminating the need for separate shift and multiply instructions. ## Case 04 : `x * 6` -```bash +```console $ nvim mul.c ``` @@ -142,11 +142,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -173,7 +173,7 @@ Consequently, the compiler must break the operation into multiple valid steps to ## Case 05 : `x * 7` -```bash +```console $ nvim mul.c ``` @@ -183,11 +183,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -202,7 +202,7 @@ The compiler uses **multiply and subtract** logic: It first scales `x` by 8 usin ## Case 06 : `x * 11` -```bash +```console $ nvim mul.c ``` @@ -212,11 +212,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -232,7 +232,7 @@ first `x + x * 4`, followed by `x + (5x * 2)`. ## Case 07 : `x * 12` -```bash +```console $ nvim mul.c ``` @@ -242,11 +242,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -262,7 +262,7 @@ first `x << 2`, followed by `4x + (4x * 2)`. ## Case 08: `x * 14` -```bash +```console $ nvim mul.c ``` @@ -272,11 +272,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -296,7 +296,7 @@ The compiler splits the multiplication `x * 14` into three distinct steps: ## Case 09: `x * 16` -```bash +```console $ nvim mul.c ``` @@ -306,11 +306,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: @@ -327,7 +327,7 @@ It need to generate an extra instruction to move the input value from `%edi` to ## Case 10: `x * 17` -```bash +```console $ nvim mul.c ``` @@ -337,11 +337,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c mul.c; llvm-objdump -d --x86-asm-syntax=att mul.o ``` -```x86asm +```asm mul.o: file format elf64-x86-64 Disassembly of section .text: diff --git a/public/posts/2026/2026-02-28-Advent-of-Compiler-Optimisations-Study-Notes-05.md b/public/posts/2026/2026-02-28-Advent-of-Compiler-Optimisations-Study-Notes-05.md index c33b18b..703e618 100644 --- a/public/posts/2026/2026-02-28-Advent-of-Compiler-Optimisations-Study-Notes-05.md +++ b/public/posts/2026/2026-02-28-Advent-of-Compiler-Optimisations-Study-Notes-05.md @@ -14,7 +14,7 @@ Selected technical insights from the YouTube comment section are reproduced at t Written by me and assisted by AI, proofread by me and assisted by AI. #### Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -43,7 +43,7 @@ I identified six distinct compiler optimization strategies that I would like to ## Case 01 : `x * 2` -```bash +```console $ nvim mul.c ``` @@ -53,11 +53,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -target aarch64-linux-gnu -c mul.c; llvm-objdump -d mul.o ``` -```armasm +```text mul.o: file format elf64-littleaarch64 Disassembly of section .text: @@ -75,7 +75,7 @@ Shifting a register left by 1 bit is equivalent to multiplying by 2. ## Case 02: `x * 3` -```bash +```console $ nvim mul.c ``` @@ -85,11 +85,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -target aarch64-linux-gnu -c mul.c; llvm-objdump -d mul.o ``` -```armasm +```text mul.o: file format elf64-littleaarch64 Disassembly of section .text: @@ -107,7 +107,7 @@ The operation represents the formula `w0 = w0 + (w0 << 1)`, which computes `x = ## Case 03 : `x * 6` -```bash +```console $ nvim mul.c ``` @@ -117,11 +117,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -target aarch64-linux-gnu -c mul.c; llvm-objdump -d mul.o ``` -```armasm +```text mul.o: file format elf64-littleaarch64 Disassembly of section .text: @@ -133,7 +133,7 @@ Disassembly of section .text: ``` ARM Instructions: -```armasm +```text add , , , lsl # lsl , , # ``` @@ -144,7 +144,7 @@ Second, it calculates `w0 = (w8 << 1) = 2 * w8 = 2 * (3 * w0) = 6 * w0` ## Case 04 : `x * 7` -```bash +```console $ nvim mul.c ``` @@ -154,11 +154,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -target aarch64-linux-gnu -c mul.c; llvm-objdump -d mul.o ``` -```armasm +```text mul.o: file format elf64-littleaarch64 Disassembly of section .text: @@ -170,7 +170,7 @@ Disassembly of section .text: ``` ARM Instructions: -```armasm +```text lsl , , # sub , , ``` @@ -181,7 +181,7 @@ It then performs `w0 = w8 - w0 = 8 * w0 - w0 = 7 * w0`. ## Case 05 : `x * 11` -```bash +```console $ nvim mul.c ``` @@ -191,11 +191,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -target aarch64-linux-gnu -c mul.c; llvm-objdump -d mul.o ``` -```armasm +```text mul.o: file format elf64-littleaarch64 Disassembly of section .text: @@ -207,7 +207,7 @@ Disassembly of section .text: ``` ARM Instructions: -```armasm +```text mov , mul , , ``` @@ -216,7 +216,7 @@ The compiler defaults to the `mul` instruction because decomposing the constant If the compiler were to adopt a manual shift-and-subtract strategy, the code generator would need to output three instructions: -```armasm +```text add w8, w0, w0, lsl #1 // w8 = x + 2x = 3x lsl w8, w8, #2 // w8 = w8 << 2 = 3x << 2 = 3x * 4 = 12x sub w0, w8, w0 // w0 = 12x - x = 11x @@ -226,7 +226,7 @@ the compiler achieves the same result in only 2 instructions. ## Case 06 : `x * 14` -```bash +```console $ nvim mul.c ``` @@ -236,11 +236,11 @@ int mul(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -target aarch64-linux-gnu -c mul.c; llvm-objdump -d mul.o ``` -```armasm +```text mul.o: file format elf64-littleaarch64 Disassembly of section .text: @@ -252,7 +252,7 @@ Disassembly of section .text: ``` ARM Instructions: -```armasm +```text lsl , , # sub , , , lsl # ``` diff --git a/public/posts/2026/2026-02-28-Advent-of-Compiler-Optimisations-Study-Notes-06.md b/public/posts/2026/2026-02-28-Advent-of-Compiler-Optimisations-Study-Notes-06.md index 31f9ebd..013523a 100644 --- a/public/posts/2026/2026-02-28-Advent-of-Compiler-Optimisations-Study-Notes-06.md +++ b/public/posts/2026/2026-02-28-Advent-of-Compiler-Optimisations-Study-Notes-06.md @@ -12,7 +12,7 @@ My notes focus on reproducing and verifying [Matt Godbolt](https://xania.org/Mat Written by me and assisted by AI, proofread by me and assisted by AI. #### Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -31,7 +31,7 @@ $ echo $SHELL ## x86 Signed Integer Division -```bash +```console $ nvim div.c ``` @@ -41,11 +41,11 @@ int div(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c div.c; llvm-objdump -d --x86-asm-syntax=att div.o ``` -```x86asm +```asm div.o: file format elf64-x86-64 Disassembly of section .text: @@ -59,7 +59,7 @@ Disassembly of section .text: ``` Instructions: -```x86asm +```asm leal (), ; = offset + base cmovnsl , ; cmov = conditional move ; ns = Not Signed @@ -77,7 +77,7 @@ int main(void) { } ``` -```bash +```console $ clang -o app.out main.c $ ./app.out $ 0 0 @@ -94,7 +94,7 @@ int main(void) { } ``` -```bash +```console $ clang -o app.out main.c $ ./app.out $ 0 -1 @@ -138,11 +138,11 @@ unsigned div(unsigned x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -c div.c; llvm-objdump -d --x86-asm-syntax=att div.o ``` -```x86asm +```asm div.o: file format elf64-x86-64 Disassembly of section .text: @@ -154,7 +154,7 @@ Disassembly of section .text: ``` Instruction: -```x86asm +```asm shrl , ; shr := Shift Right Logical, that is = >> ``` @@ -172,7 +172,7 @@ Here, I show an example to you. | -3 | 0b1101 | `sarl $2` | 0b1111 | ## Arm Signed Division (AArch64) -```bash +```console $ nvim div.c ``` @@ -182,11 +182,11 @@ int div(int x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -target aarch64-linux-gnu -c div.c; llvm-objdump -d div.o ``` -```armasm +```text div.o: file format elf64-littleaarch64 Disassembly of section .text: @@ -202,7 +202,7 @@ Disassembly of section .text: The reason is the same as in the previous x86 case, we need to know why we need to use `0x1FF`. Instructions: -```armasm +```text add , , #imm ; w8 = w0 + 0x1ff cmp , #imm ; Compares w0 with #0x0, and update the processor flags NZCV csel , , , ; Conditional Select. @@ -219,7 +219,7 @@ asr , , #imm ; Arithmetic Shift Right, w0 = w8 >> 9 | **V** | oVerflow | 28 | A signed overflow occurred (result exceeded signed range). | ## Arm Unsigned Division (AArch64) -```bash +```console $ nvim div.c ``` @@ -229,11 +229,11 @@ unsigned div(unsigned x) { } ``` -```bash +```console $ rm -f (path filter *.o); clang -O2 -target aarch64-linux-gnu -c div.c; llvm-objdump -d div.o ``` -```armasm +```text div.o: file format elf64-littleaarch64 Disassembly of section .text: @@ -244,7 +244,7 @@ Disassembly of section .text: ``` Instruction: -```armasm +```text lsr , , #imm ; Logical Shift Right, that is w0 = w0 >> 9. ``` diff --git a/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-07.md b/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-07.md index 2c8348a..30484b7 100644 --- a/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-07.md +++ b/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-07.md @@ -12,7 +12,7 @@ My notes focus on reproducing and verifying [Matt Godbolt](https://xania.org/Mat Written by me and assisted by AI, proofread by me and assisted by AI. #### Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -59,7 +59,7 @@ Let's analyze the following example to understand how it works. In this example, we analyze how the compiler handles unsigned division by 10. -```bash +```console $ nvim main.c ``` @@ -71,11 +71,11 @@ unsigned div10(unsigned x) { By disassembling the compiled object file, we can observe the magic number $M$ and the shift operation. -```bash +```console $ clang -O2 -c main.c; llvm-objdump -d --disassemble-symbols=div10 --x86-asm-syntax=att main.o ``` -```x86asm +```asm 0000000000000040 : 40: 89 f9 movl %edi, %ecx 42: b8 cd cc cc cc movl $0xcccccccd, %eax # Magic Number M = 0xCCCCCCCD diff --git a/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-08.md b/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-08.md index 59555b6..6e464f3 100644 --- a/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-08.md +++ b/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-08.md @@ -12,7 +12,7 @@ My notes focus on reproducing and verifying [Matt Godbolt](https://xania.org/Mat Written by me and assisted by AI, proofread by me and assisted by AI. #### Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -40,7 +40,7 @@ We will use `g++` and `clang++` to compile the same code, then utilize `llvm-obj We use `__asm__` markers **[1]** to define a specific code region for `llvm-mca`, allowing us to analyze the benchmark. -```bash +```console $ cat sum1.cpp ``` @@ -60,12 +60,12 @@ int sum1(const std::vector& xs) { #### Use g++ to compile -```bash +```console $ g++ -O2 -c sum1.cpp $ llvm-objdump -d --disassemble-symbols=$(nm sum1.o | awk '/sum1/ {print $3}') --x86-asm-syntax=att sum1.o ``` -```x86asm +```asm sum1.o: file format elf64-x86-64 Disassembly of section .text: @@ -93,7 +93,7 @@ Disassembly of section .text: 32: eb f8 jmp 0x2c <_Z4sum1RKSt6vectorIiSaIiEE+0x2c> ``` -```bash +```console $ g++ -O2 -S sum1.cpp -o sum1.s $ llvm-mca -march=x86-64 -mcpu=x86-64 -timeline sum1.s ``` @@ -114,12 +114,12 @@ Block RThroughput: 3.5 #### Use clang++ to compile -```bash +```console $ clang++ -O2 -c sum1.cpp $ llvm-objdump -d --disassemble-symbols=$(nm sum1.o | awk '/sum1/ {print $3}') --x86-asm-syntax=att sum1.o ``` -```x86asm +```asm sum1.o: file format elf64-x86-64 Disassembly of section .text: @@ -168,7 +168,7 @@ Disassembly of section .text: 84: eb f2 jmp 0x78 <_Z4sum1RKSt6vectorIiSaIiEE+0x78> ``` -```bash +```console $ clang++ -O2 -S sum1.cpp -o sum1.s $ llvm-mca -march=x86-64 -mcpu=x86-64 -timeline sum1.s ``` @@ -233,7 +233,7 @@ Although `clang++` demonstrates better IPC, Again, We use `__asm__` markers **[1]** to define a specific code region for `llvm-mca`, allowing us to analyze the benchmark. -```bash +```console $ cat sum2.cpp ``` @@ -253,12 +253,12 @@ int sum2(const std::vector& xs) { #### Use g++ to compile -```bash +```console $ g++ -O2 -c sum2.cpp $ llvm-objdump -d --disassemble-symbols=$(nm sum2.o | awk '/sum2/ {print $3}') --x86-asm-syntax=att sum2.o ``` -```x86asm +```asm sum2.o: file format elf64-x86-64 Disassembly of section .text: @@ -279,7 +279,7 @@ Disassembly of section .text: 25: c3 retq ``` -```bash +```console $ g++ -O2 -S sum2.cpp -o sum2.s $ llvm-mca -march=x86-64 -mcpu=x86-64 -timeline sum2.s ``` @@ -299,12 +299,12 @@ Block RThroughput: 2.5 ``` #### Use clang++ to compile -```bash +```console $ clang++ -O2 -c sum2.cpp $ llvm-objdump -d --disassemble-symbols=$(nm sum2.o | awk '/sum2/ {print $3}') --x86-asm-syntax=att sum2.o ``` -```x86asm +```asm sum2.o: file format elf64-x86-64 Disassembly of section .text: @@ -356,11 +356,11 @@ Disassembly of section .text: 9b: c3 retq ``` -```bash +```console $ clang++ -O2 -S sum2.cpp -o sum2.s ``` -```bash +```console $ llvm-mca -march=x86-64 -mcpu=x86-64 -timeline sum2.s ``` @@ -372,7 +372,7 @@ sum2.s:67:3: note: unable to find an active anonymous region # LLVM-MCA-END ``` -```bash +```console $ grep -n "LLVM-MCA" sum2.s 10: # LLVM-MCA-BEGIN 29: # LLVM-MCA-END diff --git a/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-09.md b/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-09.md index 1d61d5e..8fa5f2b 100644 --- a/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-09.md +++ b/public/posts/2026/2026-03-31-Advent-of-Compiler-Optimisations-Study-Notes-09.md @@ -12,7 +12,7 @@ My notes focus on reproducing and verifying [Matt Godbolt](https://xania.org/Mat Written by me and assisted by AI, proofread by me and assisted by AI. #### Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -46,7 +46,7 @@ $$ a_n = a_1 + (n - 1) d $$ -```bash +```console $ cat main.c ``` @@ -59,12 +59,12 @@ void sum(int* a, int n, int d) { } ``` -```bash +```console $ gcc -O2 -c main.c $ llvm-objdump -d --disassemble-symbols=sum --x86-asm-syntax=att main.o ``` -```x86asm +```asm 0000000000000000 : 0: f3 0f 1e fa endbr64 4: 8b 07 movl (%rdi), %eax ; Load a[0] into %eax outside the loop @@ -90,7 +90,7 @@ $$ a_{n + 1} = a_{n} + d $$ -```bash +```console $ cat main.c ``` @@ -104,12 +104,12 @@ void sum(int* a, int n, int d) { } ``` -```bash +```console $ gcc -O2 -c main.c $ llvm-objdump -d --disassemble-symbols=sum --x86-asm-syntax=att main.o ``` -```x86asm +```asm 0000000000000000 : 0: f3 0f 1e fa endbr64 4: 8b 07 movl (%rdi), %eax ; Load a[0] into %eax outside the loop diff --git a/public/posts/2026/2026-04-30-Advent-of-Compiler-Optimisations-Study-Notes-10.md b/public/posts/2026/2026-04-30-Advent-of-Compiler-Optimisations-Study-Notes-10.md index 0a523ef..1804df0 100644 --- a/public/posts/2026/2026-04-30-Advent-of-Compiler-Optimisations-Study-Notes-10.md +++ b/public/posts/2026/2026-04-30-Advent-of-Compiler-Optimisations-Study-Notes-10.md @@ -12,7 +12,7 @@ My notes focus on reproducing and verifying [Matt Godbolt](https://xania.org/Mat Written by me and assisted by AI, proofread by me and assisted by AI. ## Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -31,7 +31,7 @@ radare2 5.5.0 0 @ linux-x86-64 git.5.5.0 Let's do a quick introduction of `std::span` first. It provides a uniform interface for contiguous sequences of objects like vectors, arrays, or raw C-style arrays. -```bash +```console $ cat main.cpp ``` @@ -64,7 +64,7 @@ int main() { } ``` -```bash +```console $ rm -f *.out; clang++ -std=c++20 -o app.out main.cpp; ./app.out 15 16.8 @@ -81,7 +81,7 @@ To force on loop unrolling, we will disable the SIMD by `-fno-vectorize -mno-sse It is the standard for-loop and corresponding assembly. -```bash +```console $ cat sum.cpp ``` @@ -95,15 +95,15 @@ int sum(int data[8]) { } ``` -```bash +```console $ clang++ -std=c++20 -O2 -fno-unroll-loops -fno-vectorize -mno-sse -mno-avx -c sum.cpp ``` -```bash +```console $ llvm-objdump -d --disassemble-symbols=$(nm sum.o | awk '/sum/ {print $3}') --x86-asm-syntax=intel sum.o ``` -```x86asm +```asm sum.o: file format elf64-x86-64 Disassembly of section .text: @@ -123,7 +123,7 @@ Disassembly of section .text: We can manually unroll the loop using the following way. -```bash +```console $ cat sum.cpp ``` @@ -142,15 +142,15 @@ int sum(int data[8]) { } ``` -```bash +```console $ clang++ -std=c++20 -O2 -fno-unroll-loops -fno-vectorize -mno-sse -mno-avx -c sum.cpp ``` -```bash +```console $ llvm-objdump -d --disassemble-symbols=$(nm sum.o | awk '/sum/ {print $3}') --x86-asm-syntax=intel sum.o ``` -```x86asm +```asm sum.o: file format elf64-x86-64 Disassembly of section .text: @@ -173,7 +173,7 @@ In previous examples, we use `-fno-unroll-loops` to disable the compiler from do For now, we enable it and see the output assembly is as same as the part02, which manually unrolled in C code. -```bash +```console $ cat sum.cpp ``` @@ -187,15 +187,15 @@ int sum(int data[8]) { } ``` -```bash +```console $ clang++ -std=c++20 -O2 -fno-vectorize -mno-sse -mno-avx -c sum.cpp ``` -```bash +```console $ llvm-objdump -d --disassemble-symbols=$(nm sum.o | awk '/sum/ {print $3}') --x86-asm-syntax=intel sum.o ``` -```x86asm +```asm sum.o: file format elf64-x86-64 Disassembly of section .text: @@ -221,7 +221,7 @@ performs loop unrolling when the size is fixed at compile-time. In this case, the span size is unknown hence the compiler generated the standard loop assembly code. -```bash +```console $ cat sum.cpp ``` @@ -237,15 +237,15 @@ int sum(std::span dataset) { } ``` -```bash +```console $ clang++ -std=c++20 -O2 -fno-vectorize -mno-sse -mno-avx -c sum.cpp ``` -```bash +```console $ radare2 -q -e bin.cache=true -c "aa; pdf" sum.o ``` -```radare2 +```text ;-- section..text: ;-- .text: ;-- reloc..text: @@ -271,7 +271,7 @@ $ radare2 -q -e bin.cache=true -c "aa; pdf" sum.o In this case, the span size is defined hence the compiler can perform the loop unrolling. -```bash +```console $ cat sum.cpp ``` @@ -287,15 +287,15 @@ int sum(std::span dataset) { } ``` -```bash +```console $ clang++ -std=c++20 -O2 -fno-vectorize -mno-sse -mno-avx -c sum.cpp ``` -```bash +```console $ radare2 -q -e bin.cache=true -c "aa; pdf" sum.o ``` -```radare2 +```text ;-- section..text: ;-- .text: ;-- reloc..text: diff --git a/public/posts/2026/2026-05-31-Advent-of-Compiler-Optimisations-Study-Notes-11.md b/public/posts/2026/2026-05-31-Advent-of-Compiler-Optimisations-Study-Notes-11.md index 9e225f5..e108136 100644 --- a/public/posts/2026/2026-05-31-Advent-of-Compiler-Optimisations-Study-Notes-11.md +++ b/public/posts/2026/2026-05-31-Advent-of-Compiler-Optimisations-Study-Notes-11.md @@ -13,7 +13,7 @@ My notes focus on reproducing and verifying [Matt Godbolt](https://xania.org/Mat Written by me and assisted by AI, proofread by me and assisted by AI. ## Development Environment -```bash +```console $ lsb_release -d Description: Ubuntu 24.04.3 LTS @@ -31,7 +31,7 @@ Ubuntu LLVM version 18.1.8 I compile the code with `-O2` only. -```bash +```console $ vim main.c ``` @@ -56,12 +56,12 @@ int main(void) { } ``` -```bash +```console $ rm -f app.out && clang -O2 -o app.out main.c $ llvm-objdump -d --disassemble-symbols=count_set_bits --x86-asm-syntax=att app.out ``` -```x86asm +```asm 0000000000001140 : 1140: 31 c0 xorl %eax, %eax 1142: 85 ff testl %edi, %edi @@ -76,12 +76,12 @@ $ llvm-objdump -d --disassemble-symbols=count_set_bits --x86-asm-syntax=att app. 115c: 0f 1f 40 00 nopl (%rax) ``` -```bash +```console $ rm -f app.out && gcc -O2 -o app.out main.c $ llvm-objdump -d --disassemble-symbols=count_set_bits --x86-asm-syntax=att app.out ``` -```x86asm +```asm 0000000000001180 : 1180: f3 0f 1e fa endbr64 1184: 31 c0 xorl %eax, %eax @@ -104,7 +104,7 @@ a loop with a conditional branch to implement bit counting. I use `-O2` and `-mpopcnt` to optimize the code. -```bash +```console $ vim main.c ``` @@ -129,24 +129,24 @@ int main(void) { } ``` -```bash +```console $ rm -f app.out && clang -O2 -mpopcnt -o app.out main.c $ llvm-objdump -d --disassemble-symbols=count_set_bits --x86-asm-syntax=att app.out ``` -```x86asm +```asm 0000000000001140 : 1140: f3 0f b8 c7 popcntl %edi, %eax 1144: c3 retq 1145: 66 66 2e 0f 1f 84 00 00 00 00 00 nopw %cs:(%rax,%rax) ``` -```bash +```console $ rm -f app.out && gcc -O2 -mpopcnt -o app.out main.c $ llvm-objdump -d --disassemble-symbols=count_set_bits --x86-asm-syntax=att app.out ``` -```x86asm +```asm 0000000000001180 : 1180: f3 0f 1e fa endbr64 1184: 31 c0 xorl %eax, %eax diff --git a/src/components/MarkdownRenderer/MarkdownRenderer.css b/src/components/MarkdownRenderer/MarkdownRenderer.css index 4f49828..44d9723 100644 --- a/src/components/MarkdownRenderer/MarkdownRenderer.css +++ b/src/components/MarkdownRenderer/MarkdownRenderer.css @@ -91,42 +91,32 @@ overflow-x: auto; } +.markdown-body pre.shiki { + margin: 0.5em 0; + padding: 1em; + font-family: var(--font-code); + font-size: 13px; + line-height: 1.5; + tab-size: 4; +} + .markdown-body pre code { background-color: transparent; padding: 0; - color: var(--color-text); -} - -.markdown-body :is(pre, pre div, table) { - scrollbar-width: none; -} - -.markdown-body :is(pre, pre div, table)::-webkit-scrollbar { - display: none; -} - -.markdown-body .ansi-green { - color: var(--color-ansi-green); -} - -.markdown-body .ansi-red { - color: var(--color-ansi-red); + color: inherit; } -.markdown-body .ansi-yellow { - color: var(--color-ansi-yellow); +.markdown-body pre.shiki code { + font-family: inherit; + font-size: inherit; } -.markdown-body .ansi-blue { - color: var(--color-ansi-blue); -} - -.markdown-body .ansi-magenta { - color: var(--color-ansi-magenta); +.markdown-body :is(pre, table) { + scrollbar-width: none; } -.markdown-body .ansi-cyan { - color: var(--color-ansi-cyan); +.markdown-body :is(pre, table)::-webkit-scrollbar { + display: none; } .katex { diff --git a/src/components/MarkdownRenderer/MarkdownRenderer.jsx b/src/components/MarkdownRenderer/MarkdownRenderer.jsx index 5463d30..4d8ec31 100644 --- a/src/components/MarkdownRenderer/MarkdownRenderer.jsx +++ b/src/components/MarkdownRenderer/MarkdownRenderer.jsx @@ -1,53 +1,13 @@ -import ReactMarkdown from 'react-markdown'; +import { MarkdownHooks } from 'react-markdown'; import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; import rehypeKatex from 'rehype-katex'; import 'katex/dist/katex.min.css'; -import { Prism as PrismHighlighter, PrismLight } from 'react-syntax-highlighter'; -import { vscDarkPlus as PrismStyles } from 'react-syntax-highlighter/dist/esm/styles/prism'; -import x86asm from './prism/x86asm'; -import armasm from './prism/armasm'; -import radare2 from './prism/radare2'; -import './MarkdownRenderer.css' +import './MarkdownRenderer.css'; -PrismLight.registerLanguage(x86asm.displayName, x86asm); -PrismLight.registerLanguage(armasm.displayName, armasm); -PrismLight.registerLanguage(radare2.displayName, radare2); - -const LANGUAGE_OVERRIDES = { - armasm: armasm.displayName, -}; - -const PrismCodeBlock = ({ language, content, ...props }) => ( - - {content} - -); - -const CodeBlock = ({ inline, className, children, ...props }) => { - const match = /language-(\w+)/.exec(className || ''); - - if (!inline && match) { - const language = LANGUAGE_OVERRIDES[match[1]] || match[1]; - const content = String(children).replace(/\n$/, ''); - - return ; - } - - return ( - - {children} - - ); -}; - -const MarkdownComponents = { - code: CodeBlock, +const rehypeShiki = () => async (tree, file) => { + const { default: rehypeShikiPlugin } = await import('./shiki/highlight.js'); + return rehypeShikiPlugin()(tree, file); }; export default function MarkdownRenderer({ content }) { @@ -77,13 +37,12 @@ export default function MarkdownRenderer({ content }) { )} - {cleanContent} - + ); } diff --git a/src/components/MarkdownRenderer/prism/armasm.js b/src/components/MarkdownRenderer/prism/armasm.js deleted file mode 100644 index 6899ffe..0000000 --- a/src/components/MarkdownRenderer/prism/armasm.js +++ /dev/null @@ -1,23 +0,0 @@ -export default function armasm(Prism) { - Prism.languages[armasm.displayName] = { - 'asm-comment': /(?:\/\/|;).*/, - 'asm-string': /"(?:\\.|[^"\\\n])*"/, - 'asm-symbol': /<[^<>\n]+>/, - 'asm-immediate': { - pattern: /#-?(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)/i, - alias: 'ansi-red', - }, - 'asm-register': { - pattern: /\b(?:[wx](?:[12]?\d|30|zr)|w?sp|[vqdshb](?:[12]?\d|3[01])(?:\.\d*[bhsdq])?)\b(?!:)/, - alias: 'ansi-cyan', - }, - 'asm-address': { - pattern: /(^|[^\w+\-.#])0x[\da-f]+\b/i, - lookbehind: true, - alias: 'ansi-yellow', - }, - }; -} - -armasm.displayName = 'armasm-objdump'; -armasm.aliases = []; diff --git a/src/components/MarkdownRenderer/prism/radare2.js b/src/components/MarkdownRenderer/prism/radare2.js deleted file mode 100644 index 91e70c1..0000000 --- a/src/components/MarkdownRenderer/prism/radare2.js +++ /dev/null @@ -1,113 +0,0 @@ -import { REGISTER } from './x86asm.js'; - -const SIZE = /(?:byte|word|dword|qword|tbyte|xmmword|ymmword|zmmword)/.source; - -const mnemonic = (names, alias) => ({ - pattern: RegExp(`(^[ \\t]+)(?:${names})\\b(?:[ \\t]+${SIZE}\\b)?`, 'm'), - lookbehind: true, - alias, -}); - -const byte = (value, alias) => ({ - pattern: RegExp(`(^(?:..)*?)${value}`), - lookbehind: true, - alias, -}); - -export default function radare2(Prism) { - Prism.languages.radare2 = { - 'r2-flag': { - pattern: /;-- [^;\n]*/, - alias: 'ansi-cyan', - }, - 'r2-flow-back': { - pattern: /┌─*>|└─*<|╎/, - alias: 'ansi-blue', - }, - 'r2-flow': { - pattern: /[┌└│─├┤┬┴┼]+[<>]?/, - alias: 'ansi-cyan', - }, - 'r2-function': { - pattern: /^ \d+: \S+ \(.*\);$/m, - inside: { - 'r2-function-name': { - pattern: /(: )\S+/, - lookbehind: true, - alias: 'ansi-red', - }, - }, - }, - 'r2-reloc': /; RELOC [^;\n]*/, - 'r2-section': /; \[\d+\] .*/, - 'r2-variable': { - pattern: /; (?:arg|var) .*/, - inside: { - 'r2-variable-type': { - pattern: /((?:arg|var) )[^@\n]+/, - lookbehind: true, - alias: 'ansi-blue', - }, - 'r2-variable-address': { - pattern: /@ .+/, - alias: 'ansi-cyan', - }, - }, - }, - 'r2-comment-variable': { - pattern: /; (?:arg|var)\w+[^;\n]*/, - alias: 'ansi-blue', - }, - 'r2-comment': { - pattern: /;.*/, - alias: 'ansi-red', - }, - 'r2-offset': { - pattern: /0x[\da-f]{8,16}(?=[ \t]{2,}[\da-f]{2})/, - alias: 'ansi-green', - }, - 'r2-bytes': { - pattern: /(^[ \t]+)(?:[\da-f]{2})+\.?(?=[ \t])/m, - lookbehind: true, - inside: { - 'r2-byte-zero': byte('00', 'ansi-green'), - 'r2-byte-max': byte('ff', 'ansi-red'), - 'r2-byte-delete': byte('7f', 'ansi-cyan'), - 'r2-byte-text': byte('(?:[2-6][\\da-f]|7[\\da-e])', 'ansi-yellow'), - }, - }, - 'r2-jump': { - pattern: /(^[ \t]+)(?:j[a-z]{1,4}|call)\b[^;\n]*/m, - lookbehind: true, - alias: 'ansi-green', - }, - 'r2-return': mnemonic('ret', 'ansi-red'), - 'r2-nop': mnemonic('nop', 'ansi-blue'), - 'r2-stack': mnemonic('push|pop', 'ansi-magenta'), - 'r2-math': mnemonic('add|adc|sub|sbb|i?mul|i?div|inc|dec|neg|and|x?or|not|sh[lr]|sa[lr]|ro[lr]|rc[lr]|cmp|test|(?:add|sub|mul|div)[sp][sd]', 'ansi-yellow'), - 'r2-local': { - pattern: /\b(?:var|arg)_\w+\b/, - alias: 'ansi-blue', - }, - 'r2-flag-name': { - pattern: /\b(?:reloc|sym|obj|str|loc|fcn|section|method)\.[\w.:]+/, - alias: 'ansi-cyan', - }, - 'r2-register': { - pattern: REGISTER, - alias: 'ansi-cyan', - }, - 'r2-size': { - pattern: RegExp(`(,[ \\t]*)${SIZE}\\b`), - lookbehind: true, - alias: 'ansi-cyan', - }, - 'r2-number': { - pattern: /\b(?:0x[\da-f]+|\d+)\b/, - alias: 'ansi-yellow', - }, - }; -} - -radare2.displayName = 'radare2'; -radare2.aliases = []; diff --git a/src/components/MarkdownRenderer/prism/x86asm.js b/src/components/MarkdownRenderer/prism/x86asm.js deleted file mode 100644 index 31622d9..0000000 --- a/src/components/MarkdownRenderer/prism/x86asm.js +++ /dev/null @@ -1,75 +0,0 @@ -const NUMBER = /(?:0x[\da-f]+|\d+)/.source; -export const REGISTER = /\bst\(\d\)|\b(?:[re]?(?:[abcd]x|[sd]i|[sb]p|ip)|[abcd][lh]|(?:[sd]i|[sb]p)l|r(?:[89]|1[0-5])[dwb]?|[c-gs]s|[xyz]mm(?:[12]?\d|3[01])|mm[0-7]|st|k[0-7]|[cd]r\d{1,2})\b/; - -export default function x86asm(Prism) { - Prism.languages.x86asm = { - 'asm-comment': /[#;].*/, - 'asm-string': /"(?:\\.|[^"\\\n])*"/, - 'asm-register-stack': { - pattern: /%st\(\d\)/, - alias: ['asm-register', 'ansi-cyan'], - }, - 'asm-prefix': /^[ \t]*[\da-f]+:(?:[ \t]+[\da-f]{2}(?=\s|$))+|^[\da-f]{8,16}(?=[ \t]+<)/m, - 'asm-symbol': /<[^<>\n]+>/, - 'asm-memory': [ - { - pattern: RegExp(`(?:%\\w+:)?(?:-?${NUMBER}|[a-z_.][\\w.@+-]*)?\\([%,][^()\\n]*\\)`, 'i'), - alias: 'ansi-green', - inside: { - 'asm-register': { - pattern: /%\w+/, - alias: 'ansi-cyan', - }, - 'asm-immediate': { - pattern: /(,)\d+(?=\))/, - lookbehind: true, - alias: 'ansi-red', - }, - }, - }, - { - pattern: /\[[^[\]\n]*\]/, - alias: 'ansi-green', - inside: { - 'asm-register': { - pattern: REGISTER, - alias: 'ansi-cyan', - }, - 'asm-immediate': { - pattern: RegExp(`\\b${NUMBER}\\b(?!\\*)`, 'i'), - alias: 'ansi-red', - }, - }, - }, - ], - 'asm-address': { - pattern: RegExp(`(\\b(?:j[a-z]{1,4}|call[a-z]?|loop[a-z]{0,2})[ \\t]+)${NUMBER}\\b`, 'i'), - lookbehind: true, - alias: 'ansi-yellow', - }, - 'asm-immediate': [ - { - pattern: RegExp(`\\$-?${NUMBER}`, 'i'), - alias: 'ansi-red', - }, - { - pattern: RegExp(`(^|[\\s,])-?${NUMBER}\\b(?![:\\w])`, 'i'), - lookbehind: true, - alias: 'ansi-red', - }, - ], - 'asm-register': [ - { - pattern: /%\w+/, - alias: 'ansi-cyan', - }, - { - pattern: REGISTER, - alias: 'ansi-cyan', - }, - ], - }; -} - -x86asm.displayName = 'x86asm'; -x86asm.aliases = []; diff --git a/src/components/MarkdownRenderer/shiki/highlight.js b/src/components/MarkdownRenderer/shiki/highlight.js new file mode 100644 index 0000000..e623f07 --- /dev/null +++ b/src/components/MarkdownRenderer/shiki/highlight.js @@ -0,0 +1,30 @@ +import rehypeShikiFromHighlighter from '@shikijs/rehype/core'; +import { createHighlighterCore } from 'shiki/core'; +import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'; +import asm from 'shiki/langs/asm.mjs'; +import c from 'shiki/langs/c.mjs'; +import cpp from 'shiki/langs/cpp.mjs'; +import shellscript from 'shiki/langs/shellscript.mjs'; +import shellsession from 'shiki/langs/shellsession.mjs'; +import theme from './theme.js'; + +const highlighterPromise = createHighlighterCore({ + themes: [theme], + langs: [asm, c, cpp, shellscript, shellsession], + engine: createJavaScriptRegexEngine(), + langAlias: { + console: 'shellsession', + }, +}); + +export default function rehypeShiki() { + return async (tree, file) => { + const highlighter = await highlighterPromise; + const transformer = rehypeShikiFromHighlighter(highlighter, { + theme, + fallbackLanguage: 'text', + }); + + return transformer(tree, file); + }; +} diff --git a/src/components/MarkdownRenderer/shiki/theme.js b/src/components/MarkdownRenderer/shiki/theme.js new file mode 100644 index 0000000..5ff32b2 --- /dev/null +++ b/src/components/MarkdownRenderer/shiki/theme.js @@ -0,0 +1,11 @@ +import darkPlus from 'shiki/themes/dark-plus.mjs'; + +const theme = { + ...darkPlus, + colors: { + ...darkPlus.colors, + 'editor.background': 'var(--color-code-bg)', + }, +}; + +export default theme; diff --git a/src/styles/index.css b/src/styles/index.css index c1b46f4..7755132 100644 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -19,12 +19,7 @@ --color-accent: #ff7875; --color-accent-strong: #ff4d4f; - --color-ansi-red: #f14c4c; - --color-ansi-green: #23d18b; - --color-ansi-yellow: #f5f543; - --color-ansi-blue: #3b8eea; - --color-ansi-magenta: #d670d6; - --color-ansi-cyan: #29b8db; + --color-code-bg: #1e1e1e; --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;