Skip to content

Commit

Permalink
#118: enc: asm: add memory and flags as clobbers
Browse files Browse the repository at this point in the history
Add the memory and flags ("cc") as clobbers to all assembly encoder
implementations. This informs the compiler that the assembly will access
an unspecified amount of memory and will modify the flags. The compiler
will not use any dangling references to memory or keep a cached copy of
the flags register.

In tests, the compilers seem to output the exact same code as before, so
this should have no functional impact beyond ensuring correctness.
  • Loading branch information
aklomp committed Jan 6, 2023
1 parent 7ea04d7 commit d7622aa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/arch/avx/enc_loop_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ enc_loop_avx (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen)
[msk3] "x" (_mm_set1_epi32(0x01000010)),
[n51] "x" (_mm_set1_epi8(51)),
[n25] "x" (_mm_set1_epi8(25))

// Clobbers.
: "cc", "memory"
);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/arch/avx2/enc_loop_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ enc_loop_avx2 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen)
[msk3] "x" (_mm256_set1_epi32(0x01000010)),
[n51] "x" (_mm256_set1_epi8(51)),
[n25] "x" (_mm256_set1_epi8(25))

// Clobbers.
: "cc", "memory"
);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/arch/neon32/enc_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ enc_loop_neon32_inner_asm (const uint8_t **s, uint8_t **o)
[n63] "w" (n63)

// Clobbers.
: "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31"
: "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
"cc", "memory"
);
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion lib/arch/neon64/enc_loop_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ enc_loop_neon64 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen)
// Clobbers.
: "v2", "v3", "v4", "v5",
"v8", "v9", "v10", "v11",
"v12", "v13", "v14", "v15"
"v12", "v13", "v14", "v15",
"cc", "memory"
);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/arch/ssse3/enc_loop_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ enc_loop_ssse3 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen)
[msk3] "x" (_mm_set1_epi32(0x01000010)),
[n51] "x" (_mm_set1_epi8(51)),
[n25] "x" (_mm_set1_epi8(25))

// Clobbers.
: "cc", "memory"
);
}

Expand Down

0 comments on commit d7622aa

Please sign in to comment.