https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107459
Bug ID: 107459 Summary: microblaze moddi3 implementation is buggy Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgcc Assignee: unassigned at gcc dot gnu.org Reporter: alpsayin at alpsayin dot com Target Milestone: --- Created attachment 53791 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53791&action=edit Disassembly of the submitted code sample The issue has been mentioned and tried to be amended here: https://lists.yoctoproject.org/g/meta-xilinx/message/3409 gcc version: 12.1.0 (from zephyrproject-rtos/gcc fork) system: rhel8.5 compile flags: -isystem /home/asayin/zephyr_sdks/microblaze_devel/zephyr/lib/libc/minimal/include -isystem /home/asayin/zephyr_sdks/microblaze_devel/zephyr-sdk-0.93.0-47-g4470827/microblazeel-zephyr-elf/bin/../lib/gcc/microblazeel-zephyr-elf/12.1.0/include -isystem /home/asayin/zephyr_sdks/microblaze_devel/zephyr-sdk-0.93.0-47-g4470827/microblazeel-zephyr-elf/bin/../lib/gcc/microblazeel-zephyr-elf/12.1.0/include-fixed -fno-strict-aliasing -Og -imacros /home/asayin/workspace/zephyr/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=v9.00.a -mxl-barrel-shift -mno-xl-soft-mul -mxl-multiply-high -mno-xl-soft-div -msoft-float -fdollars-in-identifiers --sysroot=/home/asayin/zephyr_sdks/microblaze_devel/zephyr-sdk-0.93.0-47-g4470827/microblazeel-zephyr-elf/microblazeel-zephyr-elf -imacros /home/asayin/zephyr_sdks/microblaze_devel/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/asayin/workspace/zephyr/samples/hello_world=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/asayin/zephyr_sdks/microblaze_devel/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/asayin/zephyr_sdks/microblaze_devel=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles/app.dir/src/main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c /home/asayin/workspace/zephyr/samples/hello_world/src/main.c output: none preprocessed file: deemed unnecessary due to nature of the bug attachments: relevant sections of the disassembly Reproduction should be possible via the below code sample: void main(void) { volatile int64_t delta = 1514821494020000000; printf("delta = %016lld\n", delta); printf("NSEC_PER_SEC = %08d\n", NSEC_PER_SEC); uint32_t res1 = delta % NSEC_PER_SEC; printf("delta %% (moddi3) NSEC_PER_SEC = %"PRId32" (0x%"PRIx32")\n", res1, res1); uint64_t new_tv_sec = delta / NSEC_PER_SEC; uint32_t res2 = delta - (new_tv_sec * NSEC_PER_SEC); printf("delta - delta*(delta/NSEC_PER_SEC) = %"PRId32" (0x%"PRIx32")\n", res2, res2); }