{"id":2903,"date":"2009-04-06T10:47:00","date_gmt":"2009-04-06T10:47:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2009\/04\/06\/negative-delays-not-in-vb-lucian-wischik\/"},"modified":"2024-07-05T13:30:51","modified_gmt":"2024-07-05T20:30:51","slug":"negative-delays-not-in-vb-lucian-wischik","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/negative-delays-not-in-vb-lucian-wischik\/","title":{"rendered":"Negative delays: not in VB (Lucian Wischik)"},"content":{"rendered":"<p>Our <a href=\"http:\/\/blogs.msdn.com\/vbteam\/archive\/2009\/04\/01\/using-negative-sleeps-to-improve-responsiveness-in-vb-web-apps.aspx\">recent pos<\/a>t on &#8220;negative sleeps in VB&#8221; was an April Fool&#8217;s joke. VB doesn&#8217;t have negative sleeps, and isn&#8217;t going to. But the joke&#8217;s on me! Several readers wrote back to say that other languages <em>do<\/em> have negative sleeps. Tony Hoare, inventor of &#8220;Quicksort&#8221; amongst other things,&nbsp;wrote:<\/p>\n<blockquote>\n<p class=\"MsoNormal\"><span lang=\"EN-GB\"><font face=\"Calibri\"><em>Did you know that negative delays have long been used in practice in the design of systolic circuits?&nbsp; The negative delay is used to synchronise signals in the middle of the network, just like a positive delay.&nbsp; There are a series of commutation laws that allow delays to be moved before or after a circuit element.&nbsp; A negative delay can then be cancelled by an adjacent positive delay.&nbsp; <\/em><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-GB\"><font face=\"Calibri\"><em>&nbsp;<\/em><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-GB\"><font face=\"Calibri\"><em>Of course in hardware design, all these cancellations have to take place at \u2018compile time\u2019, before the circuit has to be printed on silicon.&nbsp; I expect that software compilation technology is sufficiently advanced to enable these negative waits to be similarly resolved at compile time.<\/em><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-GB\"><font face=\"Calibri\"><em>&nbsp;<\/em><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-GB\"><font face=\"Calibri\"><em>Another long-standing hardware application of the idea is more dynamic.&nbsp; In the instruction pipeline of a modern architecture, the highest latency is on memory reads.&nbsp; So whenever the instruction decoder meets a read instruction, it executes it after a negative delay, with an interval automatically adapted to deliver the answer \u2018just-in-time\u2019. <\/em><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-GB\"><font face=\"Calibri\"><em>&nbsp;<\/em><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN-GB\"><font face=\"Calibri\"><em>I do recommend the infinite negative sleep extension suggested by Albert.&nbsp; It is the first approach that I have seen to a wish fulfilment machine:&nbsp; anything we might ever want has already happened an infinite time ago!<\/em><\/font><\/span><span><\/span><\/p>\n<\/blockquote>\n<p>Actually,&nbsp;Tony started his email with a joke&nbsp;that he&#8217;d initially&nbsp;discovered a &#8220;VeryQuickSort&#8221; algorithm whose expected cost was O(-n) rather than QuickSort&#8217;s O(n.logn), unfortunately not reproduced by other researchers &#8212; so I didn&#8217;t know whether he was&nbsp;also joking about negative delay elements. It turns out that he wasn&#8217;t!<\/p>\n<p>Negative delay elements were used in <a href=\"http:\/\/web.comlab.ox.ac.uk\/people\/Geraint.Jones\/ruby\/\">Ruby<\/a>, a hardware description language developed in Oxford and Glasgow in the 1990s. The following diagrams are taken from its documentation [<a href=\"ftp:\/\/ftp.comlab.ox.ac.uk\/pub\/Documents\/techpapers\/Geraint.Jones\/RUBY-1-90.ps.Z\">Ruby-1-90.ps.Z<\/a>&nbsp;&#8211; extract using &#8220;<a href=\"http:\/\/unxutils.sourceforge.net\/\">gunzip<\/a>&#8221; or &#8220;uncompress&#8221;]. The task is to build a circuit where at each time-step it adds&nbsp;adds up&nbsp;a result from the previous time-step:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2009\/04\/delay1.png\" width=\"244\" height=\"71\"><\/p>\n<p>The documentation first gives this circuit diagram. The &#8220;curved D&#8221; blocks are delay elements, so that the result from the previous time-step arrives at the right time:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2009\/04\/delay2.png\" width=\"542\" height=\"202\"><\/p>\n<p>Then&nbsp;using negative delay elements (back-to-front D shapes) they redesign the circuit like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2009\/04\/delay3.png\" width=\"532\" height=\"202\"><\/p>\n<p>What does it mean&nbsp;in practice? Hardware designer Shay Ping Seng explains:<\/p>\n<blockquote>\n<p class=\"MsoNormal\"><span lang=\"EN-GB\"><font face=\"Calibri\"><em>Ruby has a concept of a negative delay element, which is really useful when you are algebraically factorizing a Ruby expression to retime\/pipeline a piece of hardware &#8212; but gets a little annoying when you are trying to map the expression into real hardware. What usually happens is that real delays are added to the inputs or outputs of I\/Os that have negative delays.<\/em><\/font><\/span><\/p>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p><strong>Concurrent programs wait faster<\/strong><\/p>\n<p>The honest answer&nbsp;for how to make&nbsp;your programs&nbsp;more responsive is that they have to be concurrent and asynchronous. This presentation of Tony Hoare&#8217;s is interesting:&nbsp;&#8220;Concurrent Programs Wait Faster&#8221; [<a href=\"http:\/\/research.microsoft.com\/en-us\/people\/thoare\/concurrentprogramswaitfaster.ppt\">download PPT<\/a>]. The burning question is how can we, as language designers, make it easier for programmers to write concurrent and asynchronous programs? We&#8217;re busy brainstorming on this now for future versions of VB and C#.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our recent post on &#8220;negative sleeps in VB&#8221; was an April Fool&#8217;s joke. VB doesn&#8217;t have negative sleeps, and isn&#8217;t going to. But the joke&#8217;s on me! Several readers wrote back to say that other languages do have negative sleeps. Tony Hoare, inventor of &#8220;Quicksort&#8221; amongst other things,&nbsp;wrote: Did you know that negative delays have [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[192,195],"tags":[99],"class_list":["post-2903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-featured","category-visual-basic","tag-lucian-wischik"],"acf":[],"blog_post_summary":"<p>Our recent post on &#8220;negative sleeps in VB&#8221; was an April Fool&#8217;s joke. VB doesn&#8217;t have negative sleeps, and isn&#8217;t going to. But the joke&#8217;s on me! Several readers wrote back to say that other languages do have negative sleeps. Tony Hoare, inventor of &#8220;Quicksort&#8221; amongst other things,&nbsp;wrote: Did you know that negative delays have [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/2903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=2903"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/2903\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=2903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=2903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=2903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}