{"action":"created","comment":{"url":"https://api.github.com/repos/lowRISC/ibex/pulls/comments/338673772","pull_request_review_id":306708877,"id":338673772,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMzODY3Mzc3Mg==","diff_hunk":"@@ -464,19 +455,25 @@ module ibex_cs_registers #(\n         CSR_DSCRATCH1: dscratch1_d = csr_wdata_int;\n \n         CSR_MCOUNTINHIBIT: mcountinhibit_we   = 1'b1;\n-        CSR_MCYCLE:        mhpmcounter_we[0]  = 1'b1;\n-        CSR_MCYCLEH:       mhpmcounterh_we[0] = 1'b1;\n-        CSR_MINSTRET:      mhpmcounter_we[2]  = 1'b1;\n-        CSR_MINSTRETH:     mhpmcounterh_we[2] = 1'b1;\n-\n-        default: begin\n-          // performance counters and event selector\n-          if ((csr_addr & CSR_MASK_MCOUNTER) == CSR_OFF_MCOUNTER) begin\n-            mhpmcounter_we[mhpmcounter_idx] = 1'b1;\n-          end else if ((csr_addr & CSR_MASK_MCOUNTER) == CSR_OFF_MCOUNTERH) begin\n-            mhpmcounterh_we[mhpmcounter_idx] = 1'b1;\n-          end\n+\n+        CSR_Z_MCOUNTER: begin\n+          unique case (mhpmcounter_idx)\n+            CSR_MCYCLE[4:0]: mhpmcounter_we[0] = 1'b1;\n+            5'b00001: ;\n+            CSR_MINSTRET[4:0]: mhpmcounter_we[2] = 1'b1;\n+            default: mhpmcounter_we[mhpmcounter_idx] = 1'b1;","path":"rtl/ibex_cs_registers.sv","position":null,"original_position":108,"commit_id":"c94456a3128b33631228a2fb772b2bf2356882d7","original_commit_id":"7be7303466b9808f6c6a62b003e4a88850adf94d","user":{"login":"MarekPikula","id":1504981,"node_id":"MDQ6VXNlcjE1MDQ5ODE=","avatar_url":"https://avatars3.githubusercontent.com/u/1504981?v=4","gravatar_id":"","url":"https://api.github.com/users/MarekPikula","html_url":"https://github.com/MarekPikula","followers_url":"https://api.github.com/users/MarekPikula/followers","following_url":"https://api.github.com/users/MarekPikula/following{/other_user}","gists_url":"https://api.github.com/users/MarekPikula/gists{/gist_id}","starred_url":"https://api.github.com/users/MarekPikula/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarekPikula/subscriptions","organizations_url":"https://api.github.com/users/MarekPikula/orgs","repos_url":"https://api.github.com/users/MarekPikula/repos","events_url":"https://api.github.com/users/MarekPikula/events{/privacy}","received_events_url":"https://api.github.com/users/MarekPikula/received_events","type":"User","site_admin":false},"body":"Sorry for inconvenience. Check it out now.","created_at":"2019-10-24T16:30:01Z","updated_at":"2019-10-24T16:30:01Z","html_url":"https://github.com/lowRISC/ibex/pull/336#discussion_r338673772","pull_request_url":"https://api.github.com/repos/lowRISC/ibex/pulls/336","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/lowRISC/ibex/pulls/comments/338673772"},"html":{"href":"https://github.com/lowRISC/ibex/pull/336#discussion_r338673772"},"pull_request":{"href":"https://api.github.com/repos/lowRISC/ibex/pulls/336"}},"in_reply_to_id":338634187},"pull_request":{"url":"https://api.github.com/repos/lowRISC/ibex/pulls/336","id":319333136,"node_id":"MDExOlB1bGxSZXF1ZXN0MzE5MzMzMTM2","html_url":"https://github.com/lowRISC/ibex/pull/336","diff_url":"https://github.com/lowRISC/ibex/pull/336.diff","patch_url":"https://github.com/lowRISC/ibex/pull/336.patch","issue_url":"https://api.github.com/repos/lowRISC/ibex/issues/336","number":336,"state":"open","locked":false,"title":"[RTL] Quartus compatibility","user":{"login":"MarekPikula","id":1504981,"node_id":"MDQ6VXNlcjE1MDQ5ODE=","avatar_url":"https://avatars3.githubusercontent.com/u/1504981?v=4","gravatar_id":"","url":"https://api.github.com/users/MarekPikula","html_url":"https://github.com/MarekPikula","followers_url":"https://api.github.com/users/MarekPikula/followers","following_url":"https://api.github.com/users/MarekPikula/following{/other_user}","gists_url":"https://api.github.com/users/MarekPikula/gists{/gist_id}","starred_url":"https://api.github.com/users/MarekPikula/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarekPikula/subscriptions","organizations_url":"https://api.github.com/users/MarekPikula/orgs","repos_url":"https://api.github.com/users/MarekPikula/repos","events_url":"https://api.github.com/users/MarekPikula/events{/privacy}","received_events_url":"https://api.github.com/users/MarekPikula/received_events","type":"User","site_admin":false},"body":"I am working on porting PULPissimo project to support Altera/Intel Quartus and thus Intel FPGAs. Besides issues stated in #117 I had some weird problems with core not willing to enter debug mode. As it turns out Quartus isn't interpreting SystemVerilog in the same way as Vivado does (I'm currently documenting all the stuff I've stumbled upon [here](https://github.com/MarekPikula/quartus-sv-gotchas)) and makes some assumptions regarding `case` statement, which are not necessarily true.\r\n\r\nIn this commit I propose some changes, which result in correct RTL for Quartus (didn't test it in Vivado yet, but I guess it should work just fine) and IMHO make the code more readable in some places.\r\n\r\nIt's definitely not to be merged since I'd need to make some correct indentation and some cosmetic changes for a final version. I just wanted to make changes only in the places, which have indeed been changed, so that the diff is more readable. Purpose of this PR is to open discussion on some specific places in code, which don't synthesize correctly with Quartus.\r\n\r\nHere's the list of changes with explanations:\r\n\r\n## ibex_cs_registers.sv\r\n\r\nHere is the place where Quartus just cut entire `default` section (line 319 in upstream), leaving `illegal_csr` high for some reason. I presume that it's caused by some partial cases being handled before (like `CSR_MCOUNTINHIBIT`, `CSR_MCYCLE`, …).\r\n\r\n### CSR read logic \r\nSince we don't use `unique case inside` as pointed out in [style guides](https://github.com/lowRISC/style-guides) (this construct isn't supported in Quartus either way) I propose to use `casez` with wildcarded `CSR_OFF_MCOUNTER_SETUP`, `CSR_OFF_MCOUNTER` and `CSR_OFF_MCOUNTERH` with internal `unique case` for distinguishing between subaddresses in the same address range. This results in less code and IMHO more readable code, as a reader now clearly sees that these subaddresses are indded in this address range and that not all subaddresses are illegal as code suggests.\r\n\r\n### CSR write logic\r\n\r\nSimilar thing is done for write section and I'd have suggestion to change assignment for `illegal_csr_write` from global assign without much meaning to an assignment inside this case statement for particular cases and some additional ones, which are not handled by global assign.\r\n\r\nAnother thing, which reduces clutter is making `if (csr_we_int == 1'b1)` condition outside case statement. That's a minor change not particularly connected with topic of this PR, but I'd say it makes the code more readable.\r\n\r\n### Use of constant expression in case statement\r\n\r\nAs stated [here](https://github.com/MarekPikula/quartus-sv-gotchas/blob/master/Intel%20Quartus%20SystemVerilog%20gotchas.md#1252-constant-expression-in-case-statement) it simply doesn't synthesize correctly. For example for the code starting at line 499 in upstream the synthesizer basically replaced this case statement with `exception_pc = pc_if_i;` totally ignoring the second case. Correct me if I'm wrong, but I think that syntax in my patch is equivalent to constant expression case.\r\n\r\n## ibex_id_stage.sv and ibex_multdiv_fast.sv \r\n\r\nThe only problem was constant expression case.","created_at":"2019-09-19T15:20:05Z","updated_at":"2019-10-24T16:30:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ff359bafa393bf12932c5fc18536cc502a440cce","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/lowRISC/ibex/pulls/336/commits","review_comments_url":"https://api.github.com/repos/lowRISC/ibex/pulls/336/comments","review_comment_url":"https://api.github.com/repos/lowRISC/ibex/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lowRISC/ibex/issues/336/comments","statuses_url":"https://api.github.com/repos/lowRISC/ibex/statuses/c94456a3128b33631228a2fb772b2bf2356882d7","head":{"label":"MarekPikula:altera","ref":"altera","sha":"c94456a3128b33631228a2fb772b2bf2356882d7","user":{"login":"MarekPikula","id":1504981,"node_id":"MDQ6VXNlcjE1MDQ5ODE=","avatar_url":"https://avatars3.githubusercontent.com/u/1504981?v=4","gravatar_id":"","url":"https://api.github.com/users/MarekPikula","html_url":"https://github.com/MarekPikula","followers_url":"https://api.github.com/users/MarekPikula/followers","following_url":"https://api.github.com/users/MarekPikula/following{/other_user}","gists_url":"https://api.github.com/users/MarekPikula/gists{/gist_id}","starred_url":"https://api.github.com/users/MarekPikula/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarekPikula/subscriptions","organizations_url":"https://api.github.com/users/MarekPikula/orgs","repos_url":"https://api.github.com/users/MarekPikula/repos","events_url":"https://api.github.com/users/MarekPikula/events{/privacy}","received_events_url":"https://api.github.com/users/MarekPikula/received_events","type":"User","site_admin":false},"repo":{"id":209577725,"node_id":"MDEwOlJlcG9zaXRvcnkyMDk1Nzc3MjU=","name":"ibex","full_name":"MarekPikula/ibex","private":false,"owner":{"login":"MarekPikula","id":1504981,"node_id":"MDQ6VXNlcjE1MDQ5ODE=","avatar_url":"https://avatars3.githubusercontent.com/u/1504981?v=4","gravatar_id":"","url":"https://api.github.com/users/MarekPikula","html_url":"https://github.com/MarekPikula","followers_url":"https://api.github.com/users/MarekPikula/followers","following_url":"https://api.github.com/users/MarekPikula/following{/other_user}","gists_url":"https://api.github.com/users/MarekPikula/gists{/gist_id}","starred_url":"https://api.github.com/users/MarekPikula/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarekPikula/subscriptions","organizations_url":"https://api.github.com/users/MarekPikula/orgs","repos_url":"https://api.github.com/users/MarekPikula/repos","events_url":"https://api.github.com/users/MarekPikula/events{/privacy}","received_events_url":"https://api.github.com/users/MarekPikula/received_events","type":"User","site_admin":false},"html_url":"https://github.com/MarekPikula/ibex","description":"Ibex is a small 32 bit RISC-V CPU core (RV32IMC/EMC) with a two stage pipeline, previously known as zero-riscy.","fork":true,"url":"https://api.github.com/repos/MarekPikula/ibex","forks_url":"https://api.github.com/repos/MarekPikula/ibex/forks","keys_url":"https://api.github.com/repos/MarekPikula/ibex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MarekPikula/ibex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MarekPikula/ibex/teams","hooks_url":"https://api.github.com/repos/MarekPikula/ibex/hooks","issue_events_url":"https://api.github.com/repos/MarekPikula/ibex/issues/events{/number}","events_url":"https://api.github.com/repos/MarekPikula/ibex/events","assignees_url":"https://api.github.com/repos/MarekPikula/ibex/assignees{/user}","branches_url":"https://api.github.com/repos/MarekPikula/ibex/branches{/branch}","tags_url":"https://api.github.com/repos/MarekPikula/ibex/tags","blobs_url":"https://api.github.com/repos/MarekPikula/ibex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MarekPikula/ibex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MarekPikula/ibex/git/refs{/sha}","trees_url":"https://api.github.com/repos/MarekPikula/ibex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MarekPikula/ibex/statuses/{sha}","languages_url":"https://api.github.com/repos/MarekPikula/ibex/languages","stargazers_url":"https://api.github.com/repos/MarekPikula/ibex/stargazers","contributors_url":"https://api.github.com/repos/MarekPikula/ibex/contributors","subscribers_url":"https://api.github.com/repos/MarekPikula/ibex/subscribers","subscription_url":"https://api.github.com/repos/MarekPikula/ibex/subscription","commits_url":"https://api.github.com/repos/MarekPikula/ibex/commits{/sha}","git_commits_url":"https://api.github.com/repos/MarekPikula/ibex/git/commits{/sha}","comments_url":"https://api.github.com/repos/MarekPikula/ibex/comments{/number}","issue_comment_url":"https://api.github.com/repos/MarekPikula/ibex/issues/comments{/number}","contents_url":"https://api.github.com/repos/MarekPikula/ibex/contents/{+path}","compare_url":"https://api.github.com/repos/MarekPikula/ibex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MarekPikula/ibex/merges","archive_url":"https://api.github.com/repos/MarekPikula/ibex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MarekPikula/ibex/downloads","issues_url":"https://api.github.com/repos/MarekPikula/ibex/issues{/number}","pulls_url":"https://api.github.com/repos/MarekPikula/ibex/pulls{/number}","milestones_url":"https://api.github.com/repos/MarekPikula/ibex/milestones{/number}","notifications_url":"https://api.github.com/repos/MarekPikula/ibex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MarekPikula/ibex/labels{/name}","releases_url":"https://api.github.com/repos/MarekPikula/ibex/releases{/id}","deployments_url":"https://api.github.com/repos/MarekPikula/ibex/deployments","created_at":"2019-09-19T14:40:26Z","updated_at":"2019-10-24T13:34:31Z","pushed_at":"2019-10-24T16:29:38Z","git_url":"git://github.com/MarekPikula/ibex.git","ssh_url":"git@github.com:MarekPikula/ibex.git","clone_url":"https://github.com/MarekPikula/ibex.git","svn_url":"https://github.com/MarekPikula/ibex","homepage":"https://www.lowrisc.org","size":3678,"stargazers_count":0,"watchers_count":0,"language":"SystemVerilog","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"lowRISC:master","ref":"master","sha":"294849bb18e27c0487b7317f53ca878217712ffd","user":{"login":"lowRISC","id":7814611,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc4MTQ2MTE=","avatar_url":"https://avatars2.githubusercontent.com/u/7814611?v=4","gravatar_id":"","url":"https://api.github.com/users/lowRISC","html_url":"https://github.com/lowRISC","followers_url":"https://api.github.com/users/lowRISC/followers","following_url":"https://api.github.com/users/lowRISC/following{/other_user}","gists_url":"https://api.github.com/users/lowRISC/gists{/gist_id}","starred_url":"https://api.github.com/users/lowRISC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lowRISC/subscriptions","organizations_url":"https://api.github.com/users/lowRISC/orgs","repos_url":"https://api.github.com/users/lowRISC/repos","events_url":"https://api.github.com/users/lowRISC/events{/privacy}","received_events_url":"https://api.github.com/users/lowRISC/received_events","type":"Organization","site_admin":false},"repo":{"id":99689233,"node_id":"MDEwOlJlcG9zaXRvcnk5OTY4OTIzMw==","name":"ibex","full_name":"lowRISC/ibex","private":false,"owner":{"login":"lowRISC","id":7814611,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc4MTQ2MTE=","avatar_url":"https://avatars2.githubusercontent.com/u/7814611?v=4","gravatar_id":"","url":"https://api.github.com/users/lowRISC","html_url":"https://github.com/lowRISC","followers_url":"https://api.github.com/users/lowRISC/followers","following_url":"https://api.github.com/users/lowRISC/following{/other_user}","gists_url":"https://api.github.com/users/lowRISC/gists{/gist_id}","starred_url":"https://api.github.com/users/lowRISC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lowRISC/subscriptions","organizations_url":"https://api.github.com/users/lowRISC/orgs","repos_url":"https://api.github.com/users/lowRISC/repos","events_url":"https://api.github.com/users/lowRISC/events{/privacy}","received_events_url":"https://api.github.com/users/lowRISC/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/lowRISC/ibex","description":"Ibex is a small 32 bit RISC-V CPU core (RV32IMC/EMC) with a two stage pipeline, previously known as zero-riscy.","fork":false,"url":"https://api.github.com/repos/lowRISC/ibex","forks_url":"https://api.github.com/repos/lowRISC/ibex/forks","keys_url":"https://api.github.com/repos/lowRISC/ibex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lowRISC/ibex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lowRISC/ibex/teams","hooks_url":"https://api.github.com/repos/lowRISC/ibex/hooks","issue_events_url":"https://api.github.com/repos/lowRISC/ibex/issues/events{/number}","events_url":"https://api.github.com/repos/lowRISC/ibex/events","assignees_url":"https://api.github.com/repos/lowRISC/ibex/assignees{/user}","branches_url":"https://api.github.com/repos/lowRISC/ibex/branches{/branch}","tags_url":"https://api.github.com/repos/lowRISC/ibex/tags","blobs_url":"https://api.github.com/repos/lowRISC/ibex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lowRISC/ibex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lowRISC/ibex/git/refs{/sha}","trees_url":"https://api.github.com/repos/lowRISC/ibex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lowRISC/ibex/statuses/{sha}","languages_url":"https://api.github.com/repos/lowRISC/ibex/languages","stargazers_url":"https://api.github.com/repos/lowRISC/ibex/stargazers","contributors_url":"https://api.github.com/repos/lowRISC/ibex/contributors","subscribers_url":"https://api.github.com/repos/lowRISC/ibex/subscribers","subscription_url":"https://api.github.com/repos/lowRISC/ibex/subscription","commits_url":"https://api.github.com/repos/lowRISC/ibex/commits{/sha}","git_commits_url":"https://api.github.com/repos/lowRISC/ibex/git/commits{/sha}","comments_url":"https://api.github.com/repos/lowRISC/ibex/comments{/number}","issue_comment_url":"https://api.github.com/repos/lowRISC/ibex/issues/comments{/number}","contents_url":"https://api.github.com/repos/lowRISC/ibex/contents/{+path}","compare_url":"https://api.github.com/repos/lowRISC/ibex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lowRISC/ibex/merges","archive_url":"https://api.github.com/repos/lowRISC/ibex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lowRISC/ibex/downloads","issues_url":"https://api.github.com/repos/lowRISC/ibex/issues{/number}","pulls_url":"https://api.github.com/repos/lowRISC/ibex/pulls{/number}","milestones_url":"https://api.github.com/repos/lowRISC/ibex/milestones{/number}","notifications_url":"https://api.github.com/repos/lowRISC/ibex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lowRISC/ibex/labels{/name}","releases_url":"https://api.github.com/repos/lowRISC/ibex/releases{/id}","deployments_url":"https://api.github.com/repos/lowRISC/ibex/deployments","created_at":"2017-08-08T12:16:36Z","updated_at":"2019-10-24T14:30:49Z","pushed_at":"2019-10-24T16:29:40Z","git_url":"git://github.com/lowRISC/ibex.git","ssh_url":"git@github.com:lowRISC/ibex.git","clone_url":"https://github.com/lowRISC/ibex.git","svn_url":"https://github.com/lowRISC/ibex","homepage":"https://www.lowrisc.org","size":3665,"stargazers_count":136,"watchers_count":136,"language":"SystemVerilog","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":71,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":57,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":71,"open_issues":57,"watchers":136,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lowRISC/ibex/pulls/336"},"html":{"href":"https://github.com/lowRISC/ibex/pull/336"},"issue":{"href":"https://api.github.com/repos/lowRISC/ibex/issues/336"},"comments":{"href":"https://api.github.com/repos/lowRISC/ibex/issues/336/comments"},"review_comments":{"href":"https://api.github.com/repos/lowRISC/ibex/pulls/336/comments"},"review_comment":{"href":"https://api.github.com/repos/lowRISC/ibex/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lowRISC/ibex/pulls/336/commits"},"statuses":{"href":"https://api.github.com/repos/lowRISC/ibex/statuses/c94456a3128b33631228a2fb772b2bf2356882d7"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"MarekPikula"}}