From 1f9960f92337a84f3f642ed27b66e97d75939ef7 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Mon, 10 Dec 2018 21:56:08 -0500 Subject: Add css changes --- src/css/styles.css | 8 ++- src/html/bread.html | 20 +++---- src/html/essay.html | 7 ++- src/html/essay/magic-division.html | 111 ++++++++++++++++++++----------------- src/html/index.html | 3 +- 5 files changed, 82 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/css/styles.css b/src/css/styles.css index 90d3f1a..b8bc0aa 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -25,7 +25,7 @@ img { .card { margin: 3em; - border: 1px solid #777777; + border: 1px solid #777777; } .card img { @@ -64,3 +64,9 @@ img { text-align: center; font-size: 20px; } + +.date { + font-style: italic; + margin-left: 2em; + margin-top: 1em; +} \ No newline at end of file diff --git a/src/html/bread.html b/src/html/bread.html index 774b0e6..7ad3b41 100644 --- a/src/html/bread.html +++ b/src/html/bread.html @@ -21,7 +21,7 @@ banneton, leaving a lot of residue.


-

Dec 4, 2018

+

Dec 4, 2018

@@ -31,7 +31,7 @@
-

Nov 21, 2018

+

Nov 21, 2018

@@ -40,7 +40,7 @@
-

Nov 16, 2018

+

Nov 16, 2018

@@ -49,7 +49,7 @@ and corn flours. A bit dense, but not bad.


-

Sep 30, 2018

+

Sep 30, 2018

@@ -57,7 +57,7 @@

A twist on normal beer bread, using hard cider.


-

Sep 30, 2018

+

Sep 30, 2018

@@ -67,7 +67,7 @@
-

Sep 27, 2018

+

Sep 27, 2018

@@ -77,7 +77,7 @@
-

Sep 19, 2018

+

Sep 19, 2018

@@ -87,7 +87,7 @@
-

Aug 30, 2018

+

Aug 30, 2018

@@ -96,7 +96,7 @@
-

Aug 16, 2018

+

Aug 16, 2018

@@ -105,7 +105,7 @@
-

Aug 9, 2018

+

Aug 9, 2018

diff --git a/src/html/essay.html b/src/html/essay.html index 3b419b6..7110df1 100644 --- a/src/html/essay.html +++ b/src/html/essay.html @@ -1,8 +1,8 @@ - + - Mark's Kitchen - Essay + Mark's Kitchen - Essays @@ -12,7 +12,7 @@

-

Essay

+

Essays

@@ -22,6 +22,7 @@

Read
+

Dec 8, 2018

diff --git a/src/html/essay/magic-division.html b/src/html/essay/magic-division.html index f40048d..10849b3 100644 --- a/src/html/essay/magic-division.html +++ b/src/html/essay/magic-division.html @@ -1,69 +1,74 @@ - - Magic Division - - - - - + + + Magic Division + + + + + +

Magic Division -- Or Division by Integer Multiplication

-

I noticed something strange in the assembly generated when compiling a program +

I noticed something strange in the assembly generated when compiling a program using gcc an optimization turned off. Here it is in Figure 1 (though using optimization level 3 just to simplify, but it still shows in level 0). - In this generated assembly, we see instead of using the div operator, - something strange is going on with the number 1717986919 and shifting. My first - attempts at searching for this phenomenon online were not helpful. The first result - for the number was on Amazon as a book identifier. This number also shows up on - stack overflow, however it is no more helpful. No one on the post is talking about - why this number is in the generated code (or perhaps they all know this arcane - secret and don’t wish share). Eventually, I found out what was going on. Even - with no optimization, the compiler prefers to generate multiplication operator + In this generated assembly, we see instead of using the div operator, + something strange is going on with the number 1717986919 and shifting. My first + attempts at searching for this phenomenon online were not helpful. The first result + for the number was on Amazon as a book identifier. This number also shows up on + stack overflow, however it is no more helpful. No one on the post is talking about + why this number is in the generated code (or perhaps they all know this arcane + secret and don’t wish share). Eventually, I found out what was going on. Even + with no optimization, the compiler prefers to generate multiplication operator over the division operator.

-

We will consider unsigned integer division first. Let - d - be some constant divisor, and n - our numerator (for now let’s make n - a multiple of d). We will assume - integers are 32 bits. In order to computer - n/d, - first we need to know the values l - and i where - d = l2i. - So to begin out division, we can shift n - by i bits. Now we must divide this result - be l. Since - l will be odd, there exists some - inverse of l, called +

We will consider unsigned integer division first. Let + d + be some constant divisor, and n + our numerator (for now let’s make n + a multiple of d). We will assume + integers are 32 bits. In order to computer + n/d, + first we need to know the values l + and i where + d = l2i. + So to begin out division, we can shift n + by i bits. Now we must divide this result + be l. Since + l will be odd, there exists some + inverse of l, called j where
- lj = 1(mod 232)
- So for any number x, - x/l = (xj)/(lj)=xj. - So now all that is left after the shift is to multiply by - j, and we will + lj = 1(mod 232)
+ So for any number x, + x/l = (xj)/(lj)=xj. + So now all that is left after the shift is to multiply by + j, and we will have computed n/d.

-

Dealing with remainder can go pretty in depth, and I recommend - reading the chapter in Hacker’s Delight about this topic +

Dealing with remainder can go pretty in depth, and I recommend + reading the chapter in Hacker’s Delight about this topic [1]. Another write up can be found in the MSDN blog archive [2].

-

Figure 1

- Source: -
-

+            
+                

Figure 1

+
+ Source: +
+

 int div20(int n){
     return a/20;
 }
-        
- Compiled excerpt: -
-

+        
+
+ Compiled excerpt: +
+

 .cfi_startproc
 movl    %edi, %eax
 movl    $1717986919, %edx
@@ -74,22 +79,24 @@ movl    %edx, %eax
 subl    %edi, %eax
 ret
 .cfi_endproc
-        
+
+

References

-

1 Hacker’s Delight Chapter 10. +

1 Hacker’s Delight Chapter 10. ( - http://www.hackersdelight.org/divcMore.pdf + http://www.hackersdelight.org/divcMore.pdf )

-

2 MSDN Blog Archive +

2 MSDN Blog Archive ( - https://blogs.msdn.microsoft.com/devdev/2005/12/12/integer-division-by-constants/ + https://blogs.msdn.microsoft.com/devdev/2005/12/12/integer-division-by-constants/ )

- + + \ No newline at end of file diff --git a/src/html/index.html b/src/html/index.html index ed90fe7..087cf5b 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -20,9 +20,10 @@

- Come check out my gallery of homemade bread, featuring mainly artisan sourdough. + Welcome to marks.kitchen. Check out my bread!

+

Dec 10, 2018

-- cgit v1.2.3