{"action":"created","issue":{"url":"https://api.github.com/repos/japaric/rustc-builtins/issues/25","repository_url":"https://api.github.com/repos/japaric/rustc-builtins","labels_url":"https://api.github.com/repos/japaric/rustc-builtins/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/japaric/rustc-builtins/issues/25/comments","events_url":"https://api.github.com/repos/japaric/rustc-builtins/issues/25/events","html_url":"https://github.com/japaric/rustc-builtins/pull/25","id":170549427,"number":25,"title":"port udivmoddi4 and __aeabi_uldivmod","user":{"login":"japaric","id":5018213,"avatar_url":"https://avatars.githubusercontent.com/u/5018213?v=3","gravatar_id":"","url":"https://api.github.com/users/japaric","html_url":"https://github.com/japaric","followers_url":"https://api.github.com/users/japaric/followers","following_url":"https://api.github.com/users/japaric/following{/other_user}","gists_url":"https://api.github.com/users/japaric/gists{/gist_id}","starred_url":"https://api.github.com/users/japaric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/japaric/subscriptions","organizations_url":"https://api.github.com/users/japaric/orgs","repos_url":"https://api.github.com/users/japaric/repos","events_url":"https://api.github.com/users/japaric/events{/privacy}","received_events_url":"https://api.github.com/users/japaric/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-11T00:34:03Z","updated_at":"2016-08-11T04:45:31Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/japaric/rustc-builtins/pulls/25","html_url":"https://github.com/japaric/rustc-builtins/pull/25","diff_url":"https://github.com/japaric/rustc-builtins/pull/25.diff","patch_url":"https://github.com/japaric/rustc-builtins/pull/25.patch"},"body":"cc @thejpster\r\n\r\nThe `udivmoddi4` intrinsic is tested using quickcheck.\r\n\r\nI'm concerned about the `__aeabi_uldivmod` intrinsic. First, I get infinite recursion but that probably can be fixed with the hacks @Amanieu suggested in #16. The other issue is that the assembly of the `__aeabi*` intrinsic doesn't look like compiler-rt's assembly implementation.\r\n\r\nThis is the assembly generated by this crate (for the `arm-unknown-linux-gnueabi` target):\r\n\r\n``` asm\r\n00000000 <__aeabi_uldivmod>:\r\n   0:   e92d4010        push    {r4, lr}\r\n   4:   e24dd010        sub     sp, sp, #16\r\n   8:   e59dc018        ldr     ip, [sp, #24]\r\n   c:   e59de01c        ldr     lr, [sp, #28]\r\n  10:   e1a04000        mov     r4, r0\r\n  14:   e28d0008        add     r0, sp, #8\r\n  18:   e1a01003        mov     r1, r3\r\n  1c:   e58d0000        str     r0, [sp]\r\n  20:   e1a00002        mov     r0, r2\r\n  24:   e1a0200c        mov     r2, ip\r\n  28:   e1a0300e        mov     r3, lr\r\n  2c:   ebfffffe        bl      0 <__aeabi_uldivmod>\r\n  30:   e59d2008        ldr     r2, [sp, #8]\r\n  34:   e59d300c        ldr     r3, [sp, #12]\r\n  38:   e884000f        stm     r4, {r0, r1, r2, r3}\r\n  3c:   e28dd010        add     sp, sp, #16\r\n  40:   e8bd8010        pop     {r4, pc}\r\n```\r\n\r\nAnd this is compiler-rt's implementation:\r\n\r\n``` asm\r\n        push    {r11, lr}\r\n        sub     sp, sp, #16\r\n        add     r12, sp, #8\r\n        str     r12, [sp]\r\n        bl      SYMBOL_NAME(__divmoddi4)\r\n        ldr     r2, [sp, #8]\r\n        ldr     r3, [sp, #12]\r\n        add     sp, sp, #16\r\n        pop     {r11, pc}\r\n```\r\n\r\nEven though I implemented the intrinsic in Rust following the compiler-rt's \"C implementation\", which is written in the comments of the source file:\r\n\r\n``` c\r\nstruct { int64_t quot, int64_t rem}\r\n       __aeabi_ldivmod(int64_t numerator, int64_t denominator) {\r\n  int64_t rem, quot;\r\n  quot = __divmoddi4(numerator, denominator, &rem);\r\n  return {quot, rem};\r\n}\r\n```\r\n\r\nBut I used `u64` because `i64` doesn't really make sense (the `__divmoddi4` takes unsigned integers as arguments).\r\n\r\n@Amanieu Any idea of what's wrong with my `__aeabi_uldivmod` implementation? Should I implement it using assembly + naked functions instead?"},"comment":{"url":"https://api.github.com/repos/japaric/rustc-builtins/issues/comments/239073243","html_url":"https://github.com/japaric/rustc-builtins/pull/25#issuecomment-239073243","issue_url":"https://api.github.com/repos/japaric/rustc-builtins/issues/25","id":239073243,"user":{"login":"japaric","id":5018213,"avatar_url":"https://avatars.githubusercontent.com/u/5018213?v=3","gravatar_id":"","url":"https://api.github.com/users/japaric","html_url":"https://github.com/japaric","followers_url":"https://api.github.com/users/japaric/followers","following_url":"https://api.github.com/users/japaric/following{/other_user}","gists_url":"https://api.github.com/users/japaric/gists{/gist_id}","starred_url":"https://api.github.com/users/japaric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/japaric/subscriptions","organizations_url":"https://api.github.com/users/japaric/orgs","repos_url":"https://api.github.com/users/japaric/repos","events_url":"https://api.github.com/users/japaric/events{/privacy}","received_events_url":"https://api.github.com/users/japaric/received_events","type":"User","site_admin":false},"created_at":"2016-08-11T04:45:31Z","updated_at":"2016-08-11T04:45:31Z","body":"> It seems that __aeabi_uldivmod uses a custom calling convention, so you'll have to implement it as a naked function.\r\n\r\nAlright, thanks for the input and done.\r\n\r\n> Also note that your 64-bit division function makes use of 32-bit division, so you'll have to implement that as well.\r\n\r\nJust ported that.\r\n"}}
{"actor":{"display_login":"japaric"}}