)]}'
{
  "commit": "e91f79891fc657d48310f82da0da61eb4a0587ed",
  "tree": "64f33518053f43336b6103c0296d7e9872c28f1b",
  "parents": [
    "22d710cc5f40d79aab104ec5fb5fe97386d56d8a"
  ],
  "author": {
    "name": "Michiel Derhaeg",
    "email": "michiel@derhaeg.be",
    "time": "Sun Sep 13 13:30:17 2026 -0600"
  },
  "committer": {
    "name": "Jeff Law",
    "email": "jeffreyalaw@gmail.com",
    "time": "Sun Sep 13 13:30:17 2026 -0600"
  },
  "message": "[PATCH] RISC-V: Use clmulr for reversed crc32 on rv32\n\nFrom: Loeka Rogge \u003cloeka.rogge@globalfoundries.com\u003e\n\nThe clmul-based reversed crc expansion multiplies by the reflected\npolynomial shifted left by one.  For a 32-bit crc on rv32 that operand\nis 33 bits wide and does not fit in a register, so rv32 fell back to the\ntable based expansion.\n\nclmulr produces bits 2*xlen-2:xlen-1 of the carry-less product, which is\nwhat clmulh produces from an operand that is already shifted left by one:\n\n  clmulh (a, ref_poly \u003c\u003c 1) \u003d (a * ref_poly)[62:31] \u003d clmulr (a, ref_poly)\n\nso the shift can be dropped and the unshifted 32-bit reflected polynomial\nhanded to clmulr instead.\n\nThe Linux kernel uses the same identity in crc32_le_zbc(),\narch/riscv/lib/crc32.c (since moved to lib/crc/riscv/):\n\n\t/* We don\u0027t have a \"clmulrh\" insn, so use clmul + slli instead. */\n\tasm volatile (\".option push\\n\"\n\t\t      \".option arch,+zbc\\n\"\n\t\t      \"clmul\t%0, %1, %2\\n\"\n\t\t      \"slli\t%0, %0, 1\\n\"\n\t\t      \"xor\t%0, %0, %1\\n\"\n\t\t      \"clmulr\t%0, %0, %3\\n\"\n\t\t      \".option pop\\n\"\n\t\t      : \"\u003d\u0026r\" (crc)\n\t\t      : \"r\" (s), \"r\" (poly_qt), \"r\" (poly) 🙂;\n\n__builtin_rev_crc32_data32 (crc, data, 0x04C11DB7) on rv32_zbc now\ngenerates:\n\n\tli\ta5,305479680\n\taddi\tt0,a5,1791\n\tli\ta4,-150925312\n\txor\tt1,a0,t0\n\taddi\tt2,a4,1601\n\tclmul\ta1,t1,t2\n\tli\ta0,-306675712\n\taddi\ta2,a0,800\n\tclmulr\ta0,a1,a2\n\nRegtested for rv32gc and rv64gc.\n\ngcc/ChangeLog:\n\n\t* config/riscv/bitmanip.md (crc_rev\u003cANYI1:mode\u003e\u003cANYI:mode\u003e4):\n\tUse the clmul expansion for a word-sized crc on rv32 with Zbc.\n\t* config/riscv/riscv.cc (expand_reversed_crc_using_clmul): Use\n\tclmulr with the unshifted reflected polynomial when the crc is\n\tword-sized.\n\t(riscv_optab_supported_p): Allow crc_rev for a word-sized result\n\ton rv32 with Zbc when optimizing for size.\n\ngcc/testsuite/ChangeLog:\n\n\t* gcc.target/riscv/crc-builtin-zbc32.c: Add reversed crc32 tests.\n\nSigned-off-by: Michiel Derhaeg \u003cmichiel.derhaeg@globalfoundries.com\u003e\nSigned-off-by: Loeka Rogge \u003cloeka.rogge@globalfoundries.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "a9fc5af5a0e0839607397d61559679ab124fccf1",
      "old_mode": 33188,
      "old_path": "gcc/config/riscv/bitmanip.md",
      "new_id": "55bbf304bffd0c2c1269554d2def26b07aaa9e40",
      "new_mode": 33188,
      "new_path": "gcc/config/riscv/bitmanip.md"
    },
    {
      "type": "modify",
      "old_id": "39309b2b2058a17062db0586c8954ae40f9d357f",
      "old_mode": 33188,
      "old_path": "gcc/config/riscv/riscv.cc",
      "new_id": "49e7476b83224ca407d5c0e5c7eedc87d4aee328",
      "new_mode": 33188,
      "new_path": "gcc/config/riscv/riscv.cc"
    },
    {
      "type": "modify",
      "old_id": "8496555b93d1b37cd000adc298d3ea39f669bb07",
      "old_mode": 33188,
      "old_path": "gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c",
      "new_id": "ba0b855ee55196d6d3e75967fe93c692c195b9ea",
      "new_mode": 33188,
      "new_path": "gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c"
    }
  ]
}
