{"action":"created","issue":{"url":"https://api.github.com/repos/z88dk/z88dk/issues/369","repository_url":"https://api.github.com/repos/z88dk/z88dk","labels_url":"https://api.github.com/repos/z88dk/z88dk/issues/369/labels{/name}","comments_url":"https://api.github.com/repos/z88dk/z88dk/issues/369/comments","events_url":"https://api.github.com/repos/z88dk/z88dk/issues/369/events","html_url":"https://github.com/z88dk/z88dk/issues/369","id":257315645,"number":369,"title":"tail jump optimisation issue - question","user":{"login":"feilipu","id":3955592,"avatar_url":"https://avatars0.githubusercontent.com/u/3955592?v=4","gravatar_id":"","url":"https://api.github.com/users/feilipu","html_url":"https://github.com/feilipu","followers_url":"https://api.github.com/users/feilipu/followers","following_url":"https://api.github.com/users/feilipu/following{/other_user}","gists_url":"https://api.github.com/users/feilipu/gists{/gist_id}","starred_url":"https://api.github.com/users/feilipu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feilipu/subscriptions","organizations_url":"https://api.github.com/users/feilipu/orgs","repos_url":"https://api.github.com/users/feilipu/repos","events_url":"https://api.github.com/users/feilipu/events{/privacy}","received_events_url":"https://api.github.com/users/feilipu/received_events","type":"User","site_admin":false},"labels":[{"id":342594055,"url":"https://api.github.com/repos/z88dk/z88dk/labels/bug","name":"bug","color":"fc2929","default":true},{"id":592551467,"url":"https://api.github.com/repos/z88dk/z88dk/labels/zsdcc","name":"zsdcc","color":"d4c5f9","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-09-13T09:31:51Z","updated_at":"2017-09-14T02:16:05Z","closed_at":"2017-09-13T17:41:14Z","author_association":"CONTRIBUTOR","body":"I'm trying to make a piece of code atomic, using the `cpu_push_di()` and `cpu_pop_ei()` functions referred to in #367.\r\n\r\nBut, the peephole optimiser is moving the call to `call _z180_pop_ei` to after the `pop xi` and converting it to a `jp _z180_pop_ei` which will mess up the stack, I believe.\r\n\r\nAlthough `_z180_pop_ei` takes no parameters, it disturbs the stack. Is there a way of signalling this to the C interface?\r\n\r\nThe C code:\r\n```c\r\nvoid\r\nset_system_time(time_t timestamp)\r\n{\r\n    cpu_push_di();\r\n    _system_time = timestamp;\r\n    cpu_pop_ei();\r\n}\r\n```\r\nand the resulting compiler output.\r\n```asm\r\n486   0000              \tSECTION code_compiler\r\n487   0000              ;./set_system_time.c:45: set_system_time(time_t timestamp)\r\n488   0000              ;\t---------------------------------\r\n489   0000              ; Function set_system_time\r\n490   0000              ; ---------------------------------\r\n491   0000              _set_system_time:\r\n492   0000  CD 00 00    \tcall\t___sdcc_enter_ix\r\n493   0003              ;./set_system_time.c:47: cpu_push_di();\r\n494   0003  CD 00 00    \tcall\t_z180_push_di\r\n495   0006              ;./set_system_time.c:48: _system_time = timestamp;\r\n496   0006  DD 6E 04    \tld\tl,(ix+4)\r\n497   0009  DD 66 05    \tld\th,(ix+5)\r\n498   000C  22 00 00    \tld\t(__system_time),hl\r\n499   000F  DD 6E 06    \tld\tl,(ix+6)\r\n500   0012  DD 66 07    \tld\th,(ix+7)\r\n501   0015  22 02 00    \tld\t(__system_time + 2),hl\r\n502   0018              ;./set_system_time.c:49: cpu_pop_ei();\r\n503   0018  DD E1       \tpop\tix\r\n504   001A  C3 00 00    \tjp\t_z180_pop_ei\r\n505   001D              \tSECTION IGNORE\r\n```"},"comment":{"url":"https://api.github.com/repos/z88dk/z88dk/issues/comments/329349341","html_url":"https://github.com/z88dk/z88dk/issues/369#issuecomment-329349341","issue_url":"https://api.github.com/repos/z88dk/z88dk/issues/369","id":329349341,"user":{"login":"feilipu","id":3955592,"avatar_url":"https://avatars0.githubusercontent.com/u/3955592?v=4","gravatar_id":"","url":"https://api.github.com/users/feilipu","html_url":"https://github.com/feilipu","followers_url":"https://api.github.com/users/feilipu/followers","following_url":"https://api.github.com/users/feilipu/following{/other_user}","gists_url":"https://api.github.com/users/feilipu/gists{/gist_id}","starred_url":"https://api.github.com/users/feilipu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feilipu/subscriptions","organizations_url":"https://api.github.com/users/feilipu/orgs","repos_url":"https://api.github.com/users/feilipu/repos","events_url":"https://api.github.com/users/feilipu/events{/privacy}","received_events_url":"https://api.github.com/users/feilipu/received_events","type":"User","site_admin":false},"created_at":"2017-09-14T02:16:05Z","updated_at":"2017-09-14T02:16:05Z","author_association":"CONTRIBUTOR","body":"Hmm. I think it may be better to leave the band-aid off.\r\n```c\r\nvoid\r\nset_system_time(time_t timestamp) __critical\r\n{\r\n    _system_time = timestamp;\r\n}\r\n```\r\nnow gives this...\r\n```asm\r\n390   0000              \tSECTION code_compiler\r\n391   0000              ;./set_system_time.c:43: set_system_time(time_t timestamp) __critical\r\n392   0000              ;\t---------------------------------\r\n393   0000              ; Function set_system_time\r\n394   0000              ; ---------------------------------\r\n395   0000              _set_system_time:\r\n396   0000  CD 00 00    \tcall\t____sdcc_cpu_push_di\r\n397   0003  CD 00 00    \tcall\t___sdcc_enter_ix\r\n398   0006              ;./set_system_time.c:45: _system_time = timestamp;\r\n399   0006  DD 6E 06    \tld\tl,(ix+6)\r\n400   0009  DD 66 07    \tld\th,(ix+7)\r\n401   000C  22 00 00    \tld\t(__system_time),hl\r\n402   000F  DD 6E 08    \tld\tl,(ix+8)\r\n403   0012  DD 66 09    \tld\th,(ix+9)\r\n404   0015  22 02 00    \tld\t(__system_time + 2),hl\r\n405   0018  CD 00 00    \tcall\t____sdcc_cpu_pop_ei\r\n406   001B  DD E1       \tpop\tix\r\n407   001D  C9          \tret\r\n408   001E              \tSECTION IGNORE\r\n```\r\nI guess it can't know that the different usage of `__critical` means that the optimisation is actually good (correct).\r\n\r\nPerhaps (until this can be fixed with sdcc), it is best remove the band-aid, and just note in the wiki references for usage that a `__critical` section can't be the last thing in a function?\r\n"}}
{"actor":{"display_login":"feilipu"}}