Remove the unnecessary PUFFS_LOW_BITS macro.

This commit is contained in:
Nigel Tao committed 2017-07-13 11:46:26 +10:00
1 parent 4302619eba
commit 73a4f2b263
5 files changed
+8 -13

No files matched your search

-2
View File
@@ -15,8 +15,6 @@
coro_susp_point = n; \
case n:
#define PUFFS_LOW_BITS(x, n) ((x) & ((1 << (n)) - 1))
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))
+1 -1
View File
@@ -12,5 +12,5 @@ const baseHeader = "" +
""
const baseImpl = "" +
"#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use a trivial macro instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case n:\n\n#define PUFFS_LOW_BITS(x, n) ((x) & ((1 << (n)) - 1))\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define PUFFS_LIKELY(expr) (expr)\n#define PUFFS_UNLIKELY(expr) (expr)\n#endif\n\n#endif // PUFFS_BASE_IMPL_H\n" +
"#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use a trivial macro instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case n:\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define PUFFS_LIKELY(expr) (expr)\n#define PUFFS_UNLIKELY(expr) (expr)\n#endif\n\n#endif // PUFFS_BASE_IMPL_H\n" +
""
+6 -5
View File
@@ -1057,15 +1057,16 @@ func (g *gen) writeExprOther(n *a.Expr, rp replacementPolicy, depth uint32) erro
// n is a function call.
// TODO: delete this hack that only matches "foo.low_bits(etc)".
if isLowBits(g.tm, n) {
g.printf("PUFFS_LOW_BITS(")
if err := g.writeExpr(n.LHS().Expr().LHS().Expr(), rp, parenthesesMandatory, depth); err != nil {
// "x.low_bits(n:etc)" in C is "((x) & ((1 << (n)) - 1))".
g.writes("((")
if err := g.writeExpr(n.LHS().Expr().LHS().Expr(), rp, parenthesesOptional, depth); err != nil {
return err
}
g.writes(",")
if err := g.writeExpr(n.Args()[0].Arg().Value(), rp, parenthesesMandatory, depth); err != nil {
g.writes(") & ((1 << (")
if err := g.writeExpr(n.Args()[0].Arg().Value(), rp, parenthesesOptional, depth); err != nil {
return err
}
g.writes(")")
g.writes(")) - 1))")
return nil
}
// TODO.
-2
View File
@@ -191,8 +191,6 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
coro_susp_point = n; \
case n:
#define PUFFS_LOW_BITS(x, n) ((x) & ((1 << (n)) - 1))
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))
+1 -3
View File
@@ -261,8 +261,6 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
coro_susp_point = n; \
case n:
#define PUFFS_LOW_BITS(x, n) ((x) & ((1 << (n)) - 1))
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))
@@ -1136,7 +1134,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
v_bits |= (((uint32_t)(t_0)) << v_n_bits);
v_n_bits += 8;
}
v_code = PUFFS_LOW_BITS(v_bits, v_width);
v_code = ((v_bits) & ((1 << (v_width)) - 1));
v_bits >>= v_width;
v_n_bits -= v_width;
if (v_code < v_clear_code) {