{"action":"created","comment":{"url":"https://api.github.com/repos/Fluci/benchmarkC/pulls/comments/48887774","id":48887774,"diff_hunk":"@@ -0,0 +1,691 @@\n+/* A test program to measure branch prediction by the CPU.\n+   compiled and tested on Intel i7 Haswell 2.5 GHz, OSX 10.11 using Clang 7.0.0\n+\n+   2015-11-24 / 2015-12-31 Pirmin Schmid\n+*/\n+\n+#include <inttypes.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <time.h>   \n+#include \"benchmark.h\"  \n+\n+// number of measurements -> results go into histogram\n+#define N 64\n+\n+// number of inner loops (= denominator in the benchmark library)\n+// allows bringing short instruction blocks to a better measurable time\n+// (see: already the naked timing machinery needs about 24 cycles)\n+\n+//#define N_inner_loop 32\n+\n+//#define N_inner_loop 4\n+\n+#define N_inner_loop 64   \n+\n+// two different sets of operations for different questions\n+// leave one set uncommented and the other commented\n+\n+// 1) uses one source variable for the assignments\n+// -> some sync associated but allows test whether counting actually works properly\n+\n+//*\n+#define UP_OP ++updown\n+#define DWN_OP --updown\n+#define SHOW_UPDOWN   \n+//*/\n+\n+// 2) two different source variable that may allow some instruction level parallelism (addition)\n+//    these were also included in the original example on the slice\n+//    currently no check possible whether sum at the end is correct\n+\n+/*\n+#define UP_OP ++cnt_gt\n+#define DWN_OP ++cnt_le\n+//*/\n+\n+//--- global helper variables -------------------------------------------------- \n+// deliberately not static to remove some optimization option for compiler\n+int64_t cnt_gt = 0;\n+int64_t cnt_le = 0;\n+int64_t updown = 0;\n+\n+int64_t global_result_updown = 0;\n+volatile int64_t volatile_result_updown = 0;\n+\n+\n+//--- test routines -------------------------------------------------------------\n+\n+// stores value in local variable on stack, no interdependence\n+uint64_t choose_cond(int x, int y) {\n+\tuint64_t result;\n+\tif(x < y) {\n+\t\tresult = UP_OP;\n+\t\t// note: this assignment is independent of earlier assignments to result\n+\t}\n+\telse {\n+\t\tresult = DWN_OP;\n+\t\t// note: this assignment is independent of earlier assignments to result\n+\t}\n+\treturn result;\n+}\n+\n+\n+// stores value in global non-volatile variable\n+uint64_t choose_cond_modified(int x, int y) {\n+\tif(x < y) {\n+\t\t// make sure that this is dependent on earlier result\n+\t\t//global_result = ++cnt_gt;\n+\t\tglobal_result_updown = UP_OP;\n+\t}\n+\telse {\n+\t\t// make sure that this is dependent on earlier result\n+\t\t//global_result = ++cnt_le;\n+\t\tglobal_result_updown = DWN_OP;\n+\t}\n+\treturn global_result_updown;\n+}\n+\n+\n+// stores value in global volatile variable\n+uint64_t choose_cond_blocking(int x, int y) {\n+\tif(x < y) {\n+\t\t// make sure that this is dependent on earlier result\n+\t\t//global_volatile_result = ++cnt_gt;\n+\t\tvolatile_result_updown = UP_OP;\n+\t}\n+\telse {\n+\t\t// make sure that this is dependent on earlier result\n+\t\t//global_volatile_result = ++cnt_le;\n+\t\tvolatile_result_updown = DWN_OP;\n+\t}\n+\treturn volatile_result_updown;\n+}\n+\n+\n+uint64_t nothing(int x, int y) {\n+\treturn 0;\n+}\n+\n+uint64_t no_branch(int x, int y) {\n+\tuint64_t result = UP_OP;\n+\treturn result;\n+}\n+\n+uint64_t no_branch_modified(int x, int y) {\n+\tglobal_result_updown = UP_OP;\n+\treturn global_result_updown;\n+}\n+\n+uint64_t no_branch_blocking(int x, int y) {\n+\tvolatile_result_updown = UP_OP;\n+\treturn volatile_result_updown;\n+}\n+\n+//--- data generation ----------------------------------------------------------\n+//    step by step\n+\n+enum options {\n+\tONE,\n+\tTWO,\n+\tTHREE,\n+\tFOUR,\n+\tALTERNATING,\n+\tRANDOM\n+};\n+\n+#define N_RANDOM 4\n+\n+static int old_plusminus = 1;\n+static int old_multi = 0;\n+static int random_count[N_RANDOM];\n+\n+void reset_data_generation() {\n+\told_plusminus = 1;\n+\told_multi = 0;\n+\tfor(int i=0; i < N_RANDOM; i++) {\n+\t\trandom_count[i] = 0;\n+\t}\n+}\n+\n+int next_plusminus(enum options which) {\n+\tint r = 0;\n+\tswitch(which) {\n+\t\tcase ONE:\n+\t\t\treturn 1;\n+\t\tcase TWO:\n+\t\t\treturn -1;\n+\t\tcase ALTERNATING:\n+\t\t\told_plusminus = -old_plusminus;\n+\t\t\treturn old_plusminus;\n+\t\tcase RANDOM:\n+\t\t\tr = rand() % 2;\n+\t\t\trandom_count[r]++;\n+\t\t\treturn r == 1 ? 1 : -1;\n+\t\tdefault:\n+\t\t\tprintf(\"invalid option in next_plusminus\\n\");","path":"example1/test_branch_prediction.c","position":166,"original_position":166,"commit_id":"2e3fd1ced92da449c5c6fa1b5e68f205e32da46c","original_commit_id":"2e3fd1ced92da449c5c6fa1b5e68f205e32da46c","user":{"login":"Fluci","id":9076628,"avatar_url":"https://avatars.githubusercontent.com/u/9076628?v=3","gravatar_id":"","url":"https://api.github.com/users/Fluci","html_url":"https://github.com/Fluci","followers_url":"https://api.github.com/users/Fluci/followers","following_url":"https://api.github.com/users/Fluci/following{/other_user}","gists_url":"https://api.github.com/users/Fluci/gists{/gist_id}","starred_url":"https://api.github.com/users/Fluci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fluci/subscriptions","organizations_url":"https://api.github.com/users/Fluci/orgs","repos_url":"https://api.github.com/users/Fluci/repos","events_url":"https://api.github.com/users/Fluci/events{/privacy}","received_events_url":"https://api.github.com/users/Fluci/received_events","type":"User","site_admin":false},"body":"to stderr?","created_at":"2016-01-05T19:48:06Z","updated_at":"2016-01-05T19:48:06Z","html_url":"https://github.com/Fluci/benchmarkC/pull/1#discussion_r48887774","pull_request_url":"https://api.github.com/repos/Fluci/benchmarkC/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/Fluci/benchmarkC/pulls/comments/48887774"},"html":{"href":"https://github.com/Fluci/benchmarkC/pull/1#discussion_r48887774"},"pull_request":{"href":"https://api.github.com/repos/Fluci/benchmarkC/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/Fluci/benchmarkC/pulls/1","id":55006213,"html_url":"https://github.com/Fluci/benchmarkC/pull/1","diff_url":"https://github.com/Fluci/benchmarkC/pull/1.diff","patch_url":"https://github.com/Fluci/benchmarkC/pull/1.patch","issue_url":"https://api.github.com/repos/Fluci/benchmarkC/issues/1","number":1,"state":"open","locked":false,"title":"review","user":{"login":"Fluci","id":9076628,"avatar_url":"https://avatars.githubusercontent.com/u/9076628?v=3","gravatar_id":"","url":"https://api.github.com/users/Fluci","html_url":"https://github.com/Fluci","followers_url":"https://api.github.com/users/Fluci/followers","following_url":"https://api.github.com/users/Fluci/following{/other_user}","gists_url":"https://api.github.com/users/Fluci/gists{/gist_id}","starred_url":"https://api.github.com/users/Fluci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fluci/subscriptions","organizations_url":"https://api.github.com/users/Fluci/orgs","repos_url":"https://api.github.com/users/Fluci/repos","events_url":"https://api.github.com/users/Fluci/events{/privacy}","received_events_url":"https://api.github.com/users/Fluci/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-04T18:30:59Z","updated_at":"2016-01-05T19:48:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"98d4d07cf850442b45eaa0d66d9abe81e5c79173","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Fluci/benchmarkC/pulls/1/commits","review_comments_url":"https://api.github.com/repos/Fluci/benchmarkC/pulls/1/comments","review_comment_url":"https://api.github.com/repos/Fluci/benchmarkC/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Fluci/benchmarkC/issues/1/comments","statuses_url":"https://api.github.com/repos/Fluci/benchmarkC/statuses/2e3fd1ced92da449c5c6fa1b5e68f205e32da46c","head":{"label":"Fluci:dev","ref":"dev","sha":"2e3fd1ced92da449c5c6fa1b5e68f205e32da46c","user":{"login":"Fluci","id":9076628,"avatar_url":"https://avatars.githubusercontent.com/u/9076628?v=3","gravatar_id":"","url":"https://api.github.com/users/Fluci","html_url":"https://github.com/Fluci","followers_url":"https://api.github.com/users/Fluci/followers","following_url":"https://api.github.com/users/Fluci/following{/other_user}","gists_url":"https://api.github.com/users/Fluci/gists{/gist_id}","starred_url":"https://api.github.com/users/Fluci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fluci/subscriptions","organizations_url":"https://api.github.com/users/Fluci/orgs","repos_url":"https://api.github.com/users/Fluci/repos","events_url":"https://api.github.com/users/Fluci/events{/privacy}","received_events_url":"https://api.github.com/users/Fluci/received_events","type":"User","site_admin":false},"repo":{"id":49015066,"name":"benchmarkC","full_name":"Fluci/benchmarkC","owner":{"login":"Fluci","id":9076628,"avatar_url":"https://avatars.githubusercontent.com/u/9076628?v=3","gravatar_id":"","url":"https://api.github.com/users/Fluci","html_url":"https://github.com/Fluci","followers_url":"https://api.github.com/users/Fluci/followers","following_url":"https://api.github.com/users/Fluci/following{/other_user}","gists_url":"https://api.github.com/users/Fluci/gists{/gist_id}","starred_url":"https://api.github.com/users/Fluci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fluci/subscriptions","organizations_url":"https://api.github.com/users/Fluci/orgs","repos_url":"https://api.github.com/users/Fluci/repos","events_url":"https://api.github.com/users/Fluci/events{/privacy}","received_events_url":"https://api.github.com/users/Fluci/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Fluci/benchmarkC","description":"A toolbox for (micro)benchmarking of C programs on x86_64.","fork":true,"url":"https://api.github.com/repos/Fluci/benchmarkC","forks_url":"https://api.github.com/repos/Fluci/benchmarkC/forks","keys_url":"https://api.github.com/repos/Fluci/benchmarkC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Fluci/benchmarkC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Fluci/benchmarkC/teams","hooks_url":"https://api.github.com/repos/Fluci/benchmarkC/hooks","issue_events_url":"https://api.github.com/repos/Fluci/benchmarkC/issues/events{/number}","events_url":"https://api.github.com/repos/Fluci/benchmarkC/events","assignees_url":"https://api.github.com/repos/Fluci/benchmarkC/assignees{/user}","branches_url":"https://api.github.com/repos/Fluci/benchmarkC/branches{/branch}","tags_url":"https://api.github.com/repos/Fluci/benchmarkC/tags","blobs_url":"https://api.github.com/repos/Fluci/benchmarkC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Fluci/benchmarkC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Fluci/benchmarkC/git/refs{/sha}","trees_url":"https://api.github.com/repos/Fluci/benchmarkC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Fluci/benchmarkC/statuses/{sha}","languages_url":"https://api.github.com/repos/Fluci/benchmarkC/languages","stargazers_url":"https://api.github.com/repos/Fluci/benchmarkC/stargazers","contributors_url":"https://api.github.com/repos/Fluci/benchmarkC/contributors","subscribers_url":"https://api.github.com/repos/Fluci/benchmarkC/subscribers","subscription_url":"https://api.github.com/repos/Fluci/benchmarkC/subscription","commits_url":"https://api.github.com/repos/Fluci/benchmarkC/commits{/sha}","git_commits_url":"https://api.github.com/repos/Fluci/benchmarkC/git/commits{/sha}","comments_url":"https://api.github.com/repos/Fluci/benchmarkC/comments{/number}","issue_comment_url":"https://api.github.com/repos/Fluci/benchmarkC/issues/comments{/number}","contents_url":"https://api.github.com/repos/Fluci/benchmarkC/contents/{+path}","compare_url":"https://api.github.com/repos/Fluci/benchmarkC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Fluci/benchmarkC/merges","archive_url":"https://api.github.com/repos/Fluci/benchmarkC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Fluci/benchmarkC/downloads","issues_url":"https://api.github.com/repos/Fluci/benchmarkC/issues{/number}","pulls_url":"https://api.github.com/repos/Fluci/benchmarkC/pulls{/number}","milestones_url":"https://api.github.com/repos/Fluci/benchmarkC/milestones{/number}","notifications_url":"https://api.github.com/repos/Fluci/benchmarkC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Fluci/benchmarkC/labels{/name}","releases_url":"https://api.github.com/repos/Fluci/benchmarkC/releases{/id}","created_at":"2016-01-04T18:27:14Z","updated_at":"2016-01-04T18:30:25Z","pushed_at":"2016-01-04T18:30:59Z","git_url":"git://github.com/Fluci/benchmarkC.git","ssh_url":"git@github.com:Fluci/benchmarkC.git","clone_url":"https://github.com/Fluci/benchmarkC.git","svn_url":"https://github.com/Fluci/benchmarkC","homepage":null,"size":1071,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"Fluci:master","ref":"master","sha":"030745a8235515f1148eebf26ce7916e525775fd","user":{"login":"Fluci","id":9076628,"avatar_url":"https://avatars.githubusercontent.com/u/9076628?v=3","gravatar_id":"","url":"https://api.github.com/users/Fluci","html_url":"https://github.com/Fluci","followers_url":"https://api.github.com/users/Fluci/followers","following_url":"https://api.github.com/users/Fluci/following{/other_user}","gists_url":"https://api.github.com/users/Fluci/gists{/gist_id}","starred_url":"https://api.github.com/users/Fluci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fluci/subscriptions","organizations_url":"https://api.github.com/users/Fluci/orgs","repos_url":"https://api.github.com/users/Fluci/repos","events_url":"https://api.github.com/users/Fluci/events{/privacy}","received_events_url":"https://api.github.com/users/Fluci/received_events","type":"User","site_admin":false},"repo":{"id":49015066,"name":"benchmarkC","full_name":"Fluci/benchmarkC","owner":{"login":"Fluci","id":9076628,"avatar_url":"https://avatars.githubusercontent.com/u/9076628?v=3","gravatar_id":"","url":"https://api.github.com/users/Fluci","html_url":"https://github.com/Fluci","followers_url":"https://api.github.com/users/Fluci/followers","following_url":"https://api.github.com/users/Fluci/following{/other_user}","gists_url":"https://api.github.com/users/Fluci/gists{/gist_id}","starred_url":"https://api.github.com/users/Fluci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fluci/subscriptions","organizations_url":"https://api.github.com/users/Fluci/orgs","repos_url":"https://api.github.com/users/Fluci/repos","events_url":"https://api.github.com/users/Fluci/events{/privacy}","received_events_url":"https://api.github.com/users/Fluci/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Fluci/benchmarkC","description":"A toolbox for (micro)benchmarking of C programs on x86_64.","fork":true,"url":"https://api.github.com/repos/Fluci/benchmarkC","forks_url":"https://api.github.com/repos/Fluci/benchmarkC/forks","keys_url":"https://api.github.com/repos/Fluci/benchmarkC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Fluci/benchmarkC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Fluci/benchmarkC/teams","hooks_url":"https://api.github.com/repos/Fluci/benchmarkC/hooks","issue_events_url":"https://api.github.com/repos/Fluci/benchmarkC/issues/events{/number}","events_url":"https://api.github.com/repos/Fluci/benchmarkC/events","assignees_url":"https://api.github.com/repos/Fluci/benchmarkC/assignees{/user}","branches_url":"https://api.github.com/repos/Fluci/benchmarkC/branches{/branch}","tags_url":"https://api.github.com/repos/Fluci/benchmarkC/tags","blobs_url":"https://api.github.com/repos/Fluci/benchmarkC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Fluci/benchmarkC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Fluci/benchmarkC/git/refs{/sha}","trees_url":"https://api.github.com/repos/Fluci/benchmarkC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Fluci/benchmarkC/statuses/{sha}","languages_url":"https://api.github.com/repos/Fluci/benchmarkC/languages","stargazers_url":"https://api.github.com/repos/Fluci/benchmarkC/stargazers","contributors_url":"https://api.github.com/repos/Fluci/benchmarkC/contributors","subscribers_url":"https://api.github.com/repos/Fluci/benchmarkC/subscribers","subscription_url":"https://api.github.com/repos/Fluci/benchmarkC/subscription","commits_url":"https://api.github.com/repos/Fluci/benchmarkC/commits{/sha}","git_commits_url":"https://api.github.com/repos/Fluci/benchmarkC/git/commits{/sha}","comments_url":"https://api.github.com/repos/Fluci/benchmarkC/comments{/number}","issue_comment_url":"https://api.github.com/repos/Fluci/benchmarkC/issues/comments{/number}","contents_url":"https://api.github.com/repos/Fluci/benchmarkC/contents/{+path}","compare_url":"https://api.github.com/repos/Fluci/benchmarkC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Fluci/benchmarkC/merges","archive_url":"https://api.github.com/repos/Fluci/benchmarkC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Fluci/benchmarkC/downloads","issues_url":"https://api.github.com/repos/Fluci/benchmarkC/issues{/number}","pulls_url":"https://api.github.com/repos/Fluci/benchmarkC/pulls{/number}","milestones_url":"https://api.github.com/repos/Fluci/benchmarkC/milestones{/number}","notifications_url":"https://api.github.com/repos/Fluci/benchmarkC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Fluci/benchmarkC/labels{/name}","releases_url":"https://api.github.com/repos/Fluci/benchmarkC/releases{/id}","created_at":"2016-01-04T18:27:14Z","updated_at":"2016-01-04T18:30:25Z","pushed_at":"2016-01-04T18:30:59Z","git_url":"git://github.com/Fluci/benchmarkC.git","ssh_url":"git@github.com:Fluci/benchmarkC.git","clone_url":"https://github.com/Fluci/benchmarkC.git","svn_url":"https://github.com/Fluci/benchmarkC","homepage":null,"size":1071,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Fluci/benchmarkC/pulls/1"},"html":{"href":"https://github.com/Fluci/benchmarkC/pull/1"},"issue":{"href":"https://api.github.com/repos/Fluci/benchmarkC/issues/1"},"comments":{"href":"https://api.github.com/repos/Fluci/benchmarkC/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/Fluci/benchmarkC/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/Fluci/benchmarkC/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Fluci/benchmarkC/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/Fluci/benchmarkC/statuses/2e3fd1ced92da449c5c6fa1b5e68f205e32da46c"}}}}