{"id":309,"date":"2017-12-06T22:15:04","date_gmt":"2017-12-06T22:15:04","guid":{"rendered":"http:\/\/www.burningimage.net\/cattrack\/?p=309"},"modified":"2023-07-22T07:56:57","modified_gmt":"2023-07-22T06:56:57","slug":"ccs-c-vs-microchip-xc8-compiler-comparison","status":"publish","type":"post","link":"https:\/\/www.burningimage.net\/cattrack\/ccs-c-vs-microchip-xc8-compiler-comparison\/","title":{"rendered":"Comparing compilers: CCS C and Microchip XC8"},"content":{"rendered":"<p>Now that I&#8217;ve got CatTrack working, I&#8217;ve been having a look at refining the code. \u00a0As I <a href=\"https:\/\/www.burningimage.net\/cattrack\/writing-the-code\/\">previously mentioned<\/a>, I am using the <a href=\"http:\/\/www.ccsinfo.com\">CCS<\/a> C compiler, basically because the &#8216;paid for&#8217; version of their compiler is significantly cheaper than <a href=\"http:\/\/www.microchip.com\/mplab\/compilers\">Microchip&#8217;s XC8<\/a> &#8216;paid-for&#8217; version. \u00a0I did begin to wonder though, just how much bigger would my code be, and how much slower would it run if I used the <em>free<\/em> version of Microchip&#8217;s XC8 compiler?<\/p>\n<p>This is what the Memory usage currently looks like in the PIC16LF18345, compiled with CCS C:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-312\" src=\"https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/16lf18345-ccs-usage.png\" alt=\"\" width=\"315\" height=\"161\" \/><\/p>\n<p><!--more--><\/p>\n<p>It took a few hours of work to plough through the code and make all the necessary changes required to convert from CCS to XC8. \u00a0So now the moment of truth, let&#8217;s see the Memory usage when using the free version of the XC8 compiler:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-314\" src=\"https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/xc8-free-mode-1.png\" alt=\"\" width=\"390\" height=\"167\" srcset=\"https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/xc8-free-mode-1.png 904w, https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/xc8-free-mode-1-300x129.png 300w, https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/xc8-free-mode-1-768x330.png 768w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/p>\n<p>Oh. \u00a0It appears that the free version of the XC8 compiler is creating more efficient code than the paid-for CCS compiler! \u00a0Ignore the references to the PRO licence above &#8211; it was compiled in Free mode.<\/p>\n<p>I then thought that although the CCS code takes up more space, perhaps it&#8217;s compiled for speed rather than space? \u00a0To cut a long story short &#8211; no, it isn&#8217;t. \u00a0The free XC8 compiled code took <strong>26329<\/strong> clock cycles to configure CatTrack and run an encryption routine, whereas the CCS compiled code took <strong>31849.<\/strong><\/p>\n<p>So the headline so far is that CCS is <strong>21% slower<\/strong>, takes up <strong>4% more ROM<\/strong> and<strong> 38% more RAM<\/strong> than the free XC8 compiler!<\/p>\n<p>Out of curiosity, I wondered how small the PRO version of the XC8 compiler could make the code. \u00a0This is the answer:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-316\" src=\"https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/xc8-pro-version.png\" alt=\"\" width=\"390\" height=\"167\" srcset=\"https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/xc8-pro-version.png 894w, https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/xc8-pro-version-300x128.png 300w, https:\/\/www.burningimage.net\/cattrack\/wp-content\/uploads\/2017\/12\/xc8-pro-version-768x328.png 768w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/p>\n<p>Fairly remarkable! \u00a0The PRO (paid-for) version of the XC8 compiler is creating code that consumes 63% less ROM and 15% less RAM than the paid-for version of CCS.<\/p>\n<p>This prompted me to come up with a project specifically to compare the two compilers, so that&#8217;s what I&#8217;ve done. \u00a0I&#8217;ve stuck it in git, here:<\/p>\n<p><a href=\"https:\/\/bitbucket.org\/andyec\/compare_xc8_ccs\">https:\/\/bitbucket.org\/andyec\/compare_xc8_ccs<\/a><\/p>\n<p>It&#8217;s designed to be opened in MPLAB X and is full of #defines, so it&#8217;ll compile fine using either CCS or XC8. \u00a0The code sets up some IO, encrypts 128 bits using XXTEA then prints the encrypted result out of the UART.<\/p>\n<p>Results are as follows:<\/p>\n\n<table id=\"tablepress-2\" class=\"tablepress tablepress-id-2\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Compiler<\/th><th class=\"column-2\">ROM Used (words)<\/th><th class=\"column-3\">RAM Used (bytes)<\/th><th class=\"column-4\">Cycles to run<\/th><th class=\"column-5\">Price<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">XC8 v1.44 Free<\/td><td class=\"column-2\">1317<\/td><td class=\"column-3\">108<\/td><td class=\"column-4\">26371<\/td><td class=\"column-5\">\u00a30<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">XC8 v1.44 PRO<br \/>\n(for space)<\/td><td class=\"column-2\">720<\/td><td class=\"column-3\">104<\/td><td class=\"column-4\">26637<\/td><td class=\"column-5\">\u00a3750<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">XC8 v1.44 PRO<br \/>\n(for speed)<\/td><td class=\"column-2\">1168<\/td><td class=\"column-3\">104<\/td><td class=\"column-4\">24097<\/td><td class=\"column-5\">\u00a3750<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">CCS v5.074<\/td><td class=\"column-2\">1798<\/td><td class=\"column-3\">196<\/td><td class=\"column-4\">38656<\/td><td class=\"column-5\">\u00a3112 (16F, command line only)<br \/>\n\u00a3450 (All PICs)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-2 from cache -->\n<p>I think the results probably speak for themselves.<\/p>\n<p>I wondered if this was limited to the 16F range of PIC devices, but it&#8217;s not. \u00a0I converted one of my other projects which uses an 18F PIC. \u00a0Migrating from CCS to the free XC8 compiler resulted in the ROM usage reducing from 22420 words to 20457 words.<\/p>\n<p>So there you have it! \u00a0I dismissed the free version of the XC8 compiler, but you really shouldn&#8217;t.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that I&#8217;ve got CatTrack working, I&#8217;ve been having a look at refining the code. \u00a0As I previously mentioned, I am using the CCS C compiler, basically because the &#8216;paid for&#8217; version of their compiler is significantly cheaper than Microchip&#8217;s XC8 &#8216;paid-for&#8217; version. \u00a0I did begin to wonder though, just how much bigger would my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":326,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[36,83,81,84,82,79,38,25,11,85],"class_list":["post-309","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-posts","tag-16lf18345","tag-c","tag-ccs","tag-comparison","tag-compiler","tag-encryption","tag-microchip","tag-pic","tag-uart","tag-xc8"],"_links":{"self":[{"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/posts\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/comments?post=309"}],"version-history":[{"count":10,"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/posts\/309\/revisions"}],"predecessor-version":[{"id":332,"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/posts\/309\/revisions\/332"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/media\/326"}],"wp:attachment":[{"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/media?parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/categories?post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.burningimage.net\/cattrack\/wp-json\/wp\/v2\/tags?post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}