Skip to content

Commit

Permalink
Tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
V0ldek committed Sep 27, 2023
1 parent 846a04d commit f020b5f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public static readonly RenderFragment Introduction = __builder =>
{
<Paragraph>
However, modern CPUs have special instructions for a more complex mode of execution,
Modern CPUs have special instructions for a more complex mode of execution,
together with separate registers for those instructions only. These are cheat codes
that compilers and library developers use to get massive performance gains without
fundamentally changing the algorithm being executed.
Expand Down Expand Up @@ -48,8 +48,8 @@
The magical world of new instructions and registers I mentioned at the start
is not actually needed to apply this concept. Consider the following toy problem.
</Paragraph>
<MudAlert Variant="Variant.Outlined" Class="mb-2">
<strong>The Discrepancy Problem.</strong> &mdash;
<MudAlert Variant="Variant.Outlined" Class="mb-4">
<strong>The Discrepancy Problem</strong> &mdash;
We are given two streams of $8$-bit measurements from two sensors over some time period.
We expect them to be the same, but since anomalies can occur we want to detect the first place
at which they differ, if it exists.
Expand Down Expand Up @@ -154,6 +154,7 @@ private int? Simd64(ReadOnlySpan<byte> sensor1, ReadOnlySpan<byte> sensor2)
{
throw new ArgumentException(""Unequal stream lengths"");
}

const int Size = 8;

// Take the cleanly divisible part and leave the remainders for later.
Expand Down Expand Up @@ -238,7 +239,8 @@ code, including memory latency, and without proper profiling we cannot identify
<Header2>Clever Bitwise Tricks</Header2>
<section>
<Paragraph>
There's a small wrinkle that doesn't really affect performance, but understanding
There's a small wrinkle that doesn't really affect performance in this case &ndash; it happens
at most once at the end &ndash; but understanding
how to fix it will go a long way. The sequential part of finding the exact place in a block
where there's a discrepancy is not elegant and can be done with a small trick.
</Paragraph>
Expand All @@ -262,14 +264,15 @@ code, including memory latency, and without proper profiling we cannot identify
vectors were identical. Thus, the check on the blocks now becomes:
</Paragraph>
<CodeBlock LineNumbers="true" LineNumbersStartAt="20" Code="@(@"
var xor = value1 ^ value2;
var xor = value1 ^ value2;

if (xor != 0)
{
// Recall that Size = 4 for 32-bit, 8 for 64-bit.
var offset = BitOperations.TrailingZeroCount(xor) / Size;
return i + offset;
}
if (xor != 0)
{
// This is a different 8 than the Size constant, it's for 8 bits in a byte
// that we need to count, e.g. 26 trailing zeroes is 26 / 8 = 3 full trailing bytes.
var offset = BitOperations.TrailingZeroCount(xor) / 8;
return i + offset;
}
")" />
<MudPaper Class="pa-2 mb-1" Elevation="4">
<MudGrid Justify="@Justify.Center">
Expand Down
2 changes: 1 addition & 1 deletion src/Sorcery/Pages/Sourcery/Sourcery.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@foreach (var post in BlogBook.Posts.Take(3))
{
<BlogPostCard Post="@post" class="my-1"/>
<BlogPostCard Post="@post" class="my-2"/>
}
</MudPaper>
</MudContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/Sorcery/Shared/Components/Header2.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<MudText Typo="Typo.h2" @attributes="@Attributes">@ChildContent</MudText>
<MudText Class="mt-3" Typo="Typo.h2" @attributes="@Attributes">@ChildContent</MudText>
<MudDivider Class="mt-2 mb-6" DividerType="DividerType.FullWidth" Vertical="false" />

@code {
Expand Down
2 changes: 1 addition & 1 deletion src/Sorcery/Shared/Components/Header3.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<MudText Typo="Typo.h3" @attributes="@Attributes">@ChildContent</MudText>
<MudText Class="mt-2" Typo="Typo.h3" @attributes="@Attributes">@ChildContent</MudText>
<MudDivider Class="mt-2 mb-4" DividerType="DividerType.FullWidth" Vertical="false" />

@code {
Expand Down
2 changes: 1 addition & 1 deletion src/Sorcery/Shared/Components/Header4.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<MudText Typo="Typo.h4" @attributes="@Attributes">@ChildContent</MudText>
<MudText Class="mt-1" Typo="Typo.h4" @attributes="@Attributes">@ChildContent</MudText>
<MudDivider Class="mt-2 mb-4" DividerType="DividerType.FullWidth" Vertical="false" />

@code {
Expand Down
26 changes: 13 additions & 13 deletions src/Sorcery/Shared/Components/LatexRenderer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
{
delimiters = new[]
{
new
{
left = "$$",
right = "$$",
display = true
},
new
{
left = "$",
right = "$",
display = false
}
},
new
{
left = "$$",
right = "$$",
display = true
},
new
{
left = "$",
right = "$",
display = false
}
},
throwOnError = true
};

Expand Down

0 comments on commit f020b5f

Please sign in to comment.