{"action":"created","comment":{"url":"https://api.github.com/repos/littlekernel/lk/pulls/comments/118815631","pull_request_review_id":40647905,"id":118815631,"diff_hunk":"@@ -0,0 +1,172 @@\n+/*\n+ * Copyright (c) 2017 Intel Corporation\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining\n+ * a copy of this software and associated documentation files\n+ * (the \"Software\"), to deal in the Software without restriction,\n+ * including without limitation the rights to use, copy, modify, merge,\n+ * publish, distribute, sublicense, and/or sell copies of the Software,\n+ * and to permit persons to whom the Software is furnished to do so,\n+ * subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be\n+ * included in all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n+ */\n+#include <string.h>\n+#include <sys/types.h>\n+\n+#define LONG_SIZE sizeof(long)\n+#define LONG_MASK (LONG_SIZE - 1)\n+#define BYTE_SIZE 1\n+\n+#ifndef TRUE\n+#define TRUE 1\n+#endif\n+\n+#ifndef FALSE\n+#define FALSE 0\n+#endif\n+\n+static inline void memcpy_inc(char *dest, const char *src, size_t len)\n+{\n+    __asm__ __volatile__ (\n+            \"cld        \\n\\t\"\n+            \"rep movsb  \\n\\t\"\n+            :: \"D\" (dest), \"S\" (src), \"c\" (len)\n+            );\n+}\n+\n+static inline void memcpy64_inc(char *dest, const char *src, size_t len)\n+{\n+    __asm__ __volatile__ (\n+            \"cld        \\n\\t\"\n+            \"rep movsq  \\n\\t\"\n+            :: \"D\" (dest), \"S\" (src), \"c\" (len >> 3)\n+            );\n+}\n+\n+static inline void memcpy_dec(char *dest, const char *src, size_t len)\n+{\n+    __asm__ __volatile__ (\n+            \"std        \\n\\t\"\n+            \"rep movsb  \\n\\t\"\n+            \"cld        \\n\\t\"\n+            :: \"D\" (dest + len - BYTE_SIZE),\n+            \"S\" (src + len - BYTE_SIZE),\n+            \"c\" (len)\n+            );\n+}\n+\n+static inline void memcpy64_dec(char *dest, const char *src, size_t len)\n+{\n+    __asm__ __volatile__ (\n+            \"std        \\n\\t\"\n+            \"rep movsq  \\n\\t\"\n+            \"cld        \\n\\t\"\n+            :: \"D\" (dest + len - LONG_SIZE),\n+            \"S\" (src + len - LONG_SIZE),\n+            \"c\" (len >> 3)\n+            );\n+}\n+\n+static inline int para_available(char *d, const char *s, size_t c)\n+{\n+    if ((NULL == d) || (NULL == s) || (0 == c) || (d == s))\n+        return FALSE;\n+\n+    return TRUE;\n+}\n+\n+static inline int para_with_different_offset(char *d, const char *s)\n+{\n+    if (((long)d ^ (long)s) & LONG_MASK)\n+        return TRUE;\n+\n+    return FALSE;\n+}\n+\n+static inline int para_count_too_small(size_t count)\n+{\n+    if (count < LONG_SIZE)\n+        return TRUE;\n+\n+    return FALSE;\n+}\n+\n+/*\n+ * Two types of copy methods provided by Intel x86 architecutre:\n+ * increment and decrement copy, DF flag controls copy direction.\n+ * If source is larger than destination, increment copy selected,\n+ * otherwise, decrement copy selected (since if increment copy used\n+ * in this scenario, destination and source memory might overlapped\n+ * for some region: src < dest < src + count, copy to destination may\n+ * overwrite original source data, decrement copy sloves this issue).\n+ *\n+ * When decrement copy selected, processor copys data first, and then\n+ * decreases RDI/RSI/RCX. In this case, we need to adjust RDI/RSI before\n+ * copy to right address.\n+ *\n+ * More details about MOVS/MOVSB/MOVSW/MOVSD/MOVSQ please refer to\n+ * <Intel 64 and IA-32 Architectures Software Developer's Manaual>\n+ * Volume 2: Instruction Set Reference\n+ */\n+void *memcpy(void *dest, const void *src, size_t count)","path":"lib/libc/string/arch/x86/64/memcpy.c","position":121,"original_position":121,"commit_id":"090491e9611f9a2c49635a1dc2f3d52f69740153","original_commit_id":"090491e9611f9a2c49635a1dc2f3d52f69740153","user":{"login":"James-Zzz","id":12709693,"avatar_url":"https://avatars1.githubusercontent.com/u/12709693?v=3","gravatar_id":"","url":"https://api.github.com/users/James-Zzz","html_url":"https://github.com/James-Zzz","followers_url":"https://api.github.com/users/James-Zzz/followers","following_url":"https://api.github.com/users/James-Zzz/following{/other_user}","gists_url":"https://api.github.com/users/James-Zzz/gists{/gist_id}","starred_url":"https://api.github.com/users/James-Zzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/James-Zzz/subscriptions","organizations_url":"https://api.github.com/users/James-Zzz/orgs","repos_url":"https://api.github.com/users/James-Zzz/repos","events_url":"https://api.github.com/users/James-Zzz/events{/privacy}","received_events_url":"https://api.github.com/users/James-Zzz/received_events","type":"User","site_admin":false},"body":"Yes, you are right, we have noticed that magenta has implemented x86 implementation, it uses movsb only. And using SSE is most efficient way to implement it.\r\nSo, do you have plan to update x86 implementation on lib/libc/string ? If yes, may be we can help implement it.\r\nThanks. :)","created_at":"2017-05-27T07:29:30Z","updated_at":"2017-05-27T07:29:30Z","html_url":"https://github.com/littlekernel/lk/pull/189#discussion_r118815631","pull_request_url":"https://api.github.com/repos/littlekernel/lk/pulls/189","_links":{"self":{"href":"https://api.github.com/repos/littlekernel/lk/pulls/comments/118815631"},"html":{"href":"https://github.com/littlekernel/lk/pull/189#discussion_r118815631"},"pull_request":{"href":"https://api.github.com/repos/littlekernel/lk/pulls/189"}}},"pull_request":{"url":"https://api.github.com/repos/littlekernel/lk/pulls/189","id":122576691,"html_url":"https://github.com/littlekernel/lk/pull/189","diff_url":"https://github.com/littlekernel/lk/pull/189.diff","patch_url":"https://github.com/littlekernel/lk/pull/189.patch","issue_url":"https://api.github.com/repos/littlekernel/lk/issues/189","number":189,"state":"open","locked":false,"title":"[arch][x86] SMEP/SMAP detection bug fix and memcpy/memset x86 architecture implementation","user":{"login":"James-Zzz","id":12709693,"avatar_url":"https://avatars1.githubusercontent.com/u/12709693?v=3","gravatar_id":"","url":"https://api.github.com/users/James-Zzz","html_url":"https://github.com/James-Zzz","followers_url":"https://api.github.com/users/James-Zzz/followers","following_url":"https://api.github.com/users/James-Zzz/following{/other_user}","gists_url":"https://api.github.com/users/James-Zzz/gists{/gist_id}","starred_url":"https://api.github.com/users/James-Zzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/James-Zzz/subscriptions","organizations_url":"https://api.github.com/users/James-Zzz/orgs","repos_url":"https://api.github.com/users/James-Zzz/repos","events_url":"https://api.github.com/users/James-Zzz/events{/privacy}","received_events_url":"https://api.github.com/users/James-Zzz/received_events","type":"User","site_admin":false},"body":"Hi Travisg,\r\nThis pull request contains 3 changes now:\r\n1. Bug fix on Intel architecture SMEP/SMAP detection: there is an bug while calculating SMEP/SMAP bit in return value of CPUID instruction;\r\n2. Float test: float test for each thread has different result, but message shows they should be similar. To address this issue, introduced an array to contain value for each thread, and present to uses as a reference.\r\n3. Intel x86-64 architecture memcpy/memset implementation. Current libc function memcpy has defect while copy memory in this scenario: src < dst < src + count, content of source memory would be overwritten. To address this issue, we introduce x86-64 implementation of memcpy. Also we provided memset implementation on x86-64. Also memcpy_s introduced for secure concern.","created_at":"2017-05-26T05:52:14Z","updated_at":"2017-05-27T07:29:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e6e98471a5e45eba581916111cab104fca2d1825","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/littlekernel/lk/pulls/189/commits","review_comments_url":"https://api.github.com/repos/littlekernel/lk/pulls/189/comments","review_comment_url":"https://api.github.com/repos/littlekernel/lk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/littlekernel/lk/issues/189/comments","statuses_url":"https://api.github.com/repos/littlekernel/lk/statuses/090491e9611f9a2c49635a1dc2f3d52f69740153","head":{"label":"James-Zzz:master","ref":"master","sha":"090491e9611f9a2c49635a1dc2f3d52f69740153","user":{"login":"James-Zzz","id":12709693,"avatar_url":"https://avatars1.githubusercontent.com/u/12709693?v=3","gravatar_id":"","url":"https://api.github.com/users/James-Zzz","html_url":"https://github.com/James-Zzz","followers_url":"https://api.github.com/users/James-Zzz/followers","following_url":"https://api.github.com/users/James-Zzz/following{/other_user}","gists_url":"https://api.github.com/users/James-Zzz/gists{/gist_id}","starred_url":"https://api.github.com/users/James-Zzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/James-Zzz/subscriptions","organizations_url":"https://api.github.com/users/James-Zzz/orgs","repos_url":"https://api.github.com/users/James-Zzz/repos","events_url":"https://api.github.com/users/James-Zzz/events{/privacy}","received_events_url":"https://api.github.com/users/James-Zzz/received_events","type":"User","site_admin":false},"repo":{"id":88944575,"name":"lk","full_name":"James-Zzz/lk","owner":{"login":"James-Zzz","id":12709693,"avatar_url":"https://avatars1.githubusercontent.com/u/12709693?v=3","gravatar_id":"","url":"https://api.github.com/users/James-Zzz","html_url":"https://github.com/James-Zzz","followers_url":"https://api.github.com/users/James-Zzz/followers","following_url":"https://api.github.com/users/James-Zzz/following{/other_user}","gists_url":"https://api.github.com/users/James-Zzz/gists{/gist_id}","starred_url":"https://api.github.com/users/James-Zzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/James-Zzz/subscriptions","organizations_url":"https://api.github.com/users/James-Zzz/orgs","repos_url":"https://api.github.com/users/James-Zzz/repos","events_url":"https://api.github.com/users/James-Zzz/events{/privacy}","received_events_url":"https://api.github.com/users/James-Zzz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/James-Zzz/lk","description":"LK embedded kernel","fork":true,"url":"https://api.github.com/repos/James-Zzz/lk","forks_url":"https://api.github.com/repos/James-Zzz/lk/forks","keys_url":"https://api.github.com/repos/James-Zzz/lk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/James-Zzz/lk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/James-Zzz/lk/teams","hooks_url":"https://api.github.com/repos/James-Zzz/lk/hooks","issue_events_url":"https://api.github.com/repos/James-Zzz/lk/issues/events{/number}","events_url":"https://api.github.com/repos/James-Zzz/lk/events","assignees_url":"https://api.github.com/repos/James-Zzz/lk/assignees{/user}","branches_url":"https://api.github.com/repos/James-Zzz/lk/branches{/branch}","tags_url":"https://api.github.com/repos/James-Zzz/lk/tags","blobs_url":"https://api.github.com/repos/James-Zzz/lk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/James-Zzz/lk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/James-Zzz/lk/git/refs{/sha}","trees_url":"https://api.github.com/repos/James-Zzz/lk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/James-Zzz/lk/statuses/{sha}","languages_url":"https://api.github.com/repos/James-Zzz/lk/languages","stargazers_url":"https://api.github.com/repos/James-Zzz/lk/stargazers","contributors_url":"https://api.github.com/repos/James-Zzz/lk/contributors","subscribers_url":"https://api.github.com/repos/James-Zzz/lk/subscribers","subscription_url":"https://api.github.com/repos/James-Zzz/lk/subscription","commits_url":"https://api.github.com/repos/James-Zzz/lk/commits{/sha}","git_commits_url":"https://api.github.com/repos/James-Zzz/lk/git/commits{/sha}","comments_url":"https://api.github.com/repos/James-Zzz/lk/comments{/number}","issue_comment_url":"https://api.github.com/repos/James-Zzz/lk/issues/comments{/number}","contents_url":"https://api.github.com/repos/James-Zzz/lk/contents/{+path}","compare_url":"https://api.github.com/repos/James-Zzz/lk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/James-Zzz/lk/merges","archive_url":"https://api.github.com/repos/James-Zzz/lk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/James-Zzz/lk/downloads","issues_url":"https://api.github.com/repos/James-Zzz/lk/issues{/number}","pulls_url":"https://api.github.com/repos/James-Zzz/lk/pulls{/number}","milestones_url":"https://api.github.com/repos/James-Zzz/lk/milestones{/number}","notifications_url":"https://api.github.com/repos/James-Zzz/lk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/James-Zzz/lk/labels{/name}","releases_url":"https://api.github.com/repos/James-Zzz/lk/releases{/id}","deployments_url":"https://api.github.com/repos/James-Zzz/lk/deployments","created_at":"2017-04-21T05:31:16Z","updated_at":"2017-04-21T05:31:20Z","pushed_at":"2017-05-26T05:35:02Z","git_url":"git://github.com/James-Zzz/lk.git","ssh_url":"git@github.com:James-Zzz/lk.git","clone_url":"https://github.com/James-Zzz/lk.git","svn_url":"https://github.com/James-Zzz/lk","homepage":"","size":19892,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"littlekernel:master","ref":"master","sha":"089dce3a7d4a169bafb01d41b137fad751267a5c","user":{"login":"littlekernel","id":15386632,"avatar_url":"https://avatars2.githubusercontent.com/u/15386632?v=3","gravatar_id":"","url":"https://api.github.com/users/littlekernel","html_url":"https://github.com/littlekernel","followers_url":"https://api.github.com/users/littlekernel/followers","following_url":"https://api.github.com/users/littlekernel/following{/other_user}","gists_url":"https://api.github.com/users/littlekernel/gists{/gist_id}","starred_url":"https://api.github.com/users/littlekernel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/littlekernel/subscriptions","organizations_url":"https://api.github.com/users/littlekernel/orgs","repos_url":"https://api.github.com/users/littlekernel/repos","events_url":"https://api.github.com/users/littlekernel/events{/privacy}","received_events_url":"https://api.github.com/users/littlekernel/received_events","type":"Organization","site_admin":false},"repo":{"id":3058456,"name":"lk","full_name":"littlekernel/lk","owner":{"login":"littlekernel","id":15386632,"avatar_url":"https://avatars2.githubusercontent.com/u/15386632?v=3","gravatar_id":"","url":"https://api.github.com/users/littlekernel","html_url":"https://github.com/littlekernel","followers_url":"https://api.github.com/users/littlekernel/followers","following_url":"https://api.github.com/users/littlekernel/following{/other_user}","gists_url":"https://api.github.com/users/littlekernel/gists{/gist_id}","starred_url":"https://api.github.com/users/littlekernel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/littlekernel/subscriptions","organizations_url":"https://api.github.com/users/littlekernel/orgs","repos_url":"https://api.github.com/users/littlekernel/repos","events_url":"https://api.github.com/users/littlekernel/events{/privacy}","received_events_url":"https://api.github.com/users/littlekernel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/littlekernel/lk","description":"LK embedded kernel","fork":false,"url":"https://api.github.com/repos/littlekernel/lk","forks_url":"https://api.github.com/repos/littlekernel/lk/forks","keys_url":"https://api.github.com/repos/littlekernel/lk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/littlekernel/lk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/littlekernel/lk/teams","hooks_url":"https://api.github.com/repos/littlekernel/lk/hooks","issue_events_url":"https://api.github.com/repos/littlekernel/lk/issues/events{/number}","events_url":"https://api.github.com/repos/littlekernel/lk/events","assignees_url":"https://api.github.com/repos/littlekernel/lk/assignees{/user}","branches_url":"https://api.github.com/repos/littlekernel/lk/branches{/branch}","tags_url":"https://api.github.com/repos/littlekernel/lk/tags","blobs_url":"https://api.github.com/repos/littlekernel/lk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/littlekernel/lk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/littlekernel/lk/git/refs{/sha}","trees_url":"https://api.github.com/repos/littlekernel/lk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/littlekernel/lk/statuses/{sha}","languages_url":"https://api.github.com/repos/littlekernel/lk/languages","stargazers_url":"https://api.github.com/repos/littlekernel/lk/stargazers","contributors_url":"https://api.github.com/repos/littlekernel/lk/contributors","subscribers_url":"https://api.github.com/repos/littlekernel/lk/subscribers","subscription_url":"https://api.github.com/repos/littlekernel/lk/subscription","commits_url":"https://api.github.com/repos/littlekernel/lk/commits{/sha}","git_commits_url":"https://api.github.com/repos/littlekernel/lk/git/commits{/sha}","comments_url":"https://api.github.com/repos/littlekernel/lk/comments{/number}","issue_comment_url":"https://api.github.com/repos/littlekernel/lk/issues/comments{/number}","contents_url":"https://api.github.com/repos/littlekernel/lk/contents/{+path}","compare_url":"https://api.github.com/repos/littlekernel/lk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/littlekernel/lk/merges","archive_url":"https://api.github.com/repos/littlekernel/lk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/littlekernel/lk/downloads","issues_url":"https://api.github.com/repos/littlekernel/lk/issues{/number}","pulls_url":"https://api.github.com/repos/littlekernel/lk/pulls{/number}","milestones_url":"https://api.github.com/repos/littlekernel/lk/milestones{/number}","notifications_url":"https://api.github.com/repos/littlekernel/lk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/littlekernel/lk/labels{/name}","releases_url":"https://api.github.com/repos/littlekernel/lk/releases{/id}","deployments_url":"https://api.github.com/repos/littlekernel/lk/deployments","created_at":"2011-12-27T19:19:36Z","updated_at":"2017-05-27T06:00:22Z","pushed_at":"2017-05-26T05:52:15Z","git_url":"git://github.com/littlekernel/lk.git","ssh_url":"git@github.com:littlekernel/lk.git","clone_url":"https://github.com/littlekernel/lk.git","svn_url":"https://github.com/littlekernel/lk","homepage":"","size":19896,"stargazers_count":930,"watchers_count":930,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":213,"mirror_url":null,"open_issues_count":25,"forks":213,"open_issues":25,"watchers":930,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/littlekernel/lk/pulls/189"},"html":{"href":"https://github.com/littlekernel/lk/pull/189"},"issue":{"href":"https://api.github.com/repos/littlekernel/lk/issues/189"},"comments":{"href":"https://api.github.com/repos/littlekernel/lk/issues/189/comments"},"review_comments":{"href":"https://api.github.com/repos/littlekernel/lk/pulls/189/comments"},"review_comment":{"href":"https://api.github.com/repos/littlekernel/lk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/littlekernel/lk/pulls/189/commits"},"statuses":{"href":"https://api.github.com/repos/littlekernel/lk/statuses/090491e9611f9a2c49635a1dc2f3d52f69740153"}}}}
{"actor":{"display_login":"James-Zzz"}}