aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-25 04:48:58 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-08-25 04:48:58 -0400
commit815950996dcc92ac6ac285f2005dbac51b9cb6f8 (patch)
tree1f77690a5fb7ccbef75bcab9c8c1e008ef3c5068
parent8aacfc846523aad142537b2bff49162d5feb6a91 (diff)
parentbf1f91595d4d3b5911632c671ef16e44d70dc9a6 (diff)
downloadzig-815950996dcc92ac6ac285f2005dbac51b9cb6f8.tar.gz
zig-815950996dcc92ac6ac285f2005dbac51b9cb6f8.zip
Merge remote-tracking branch 'origin/master' into macos-stack-traces
-rw-r--r--doc/langref.html.in12
-rw-r--r--src/all_types.hpp4
-rw-r--r--src/analyze.cpp2
-rw-r--r--src/codegen.cpp6
-rw-r--r--src/ir.cpp12
-rw-r--r--std/event/fs.zig5
-rw-r--r--std/fmt/errol/index.zig4
-rw-r--r--std/math/ceil.zig2
-rw-r--r--std/math/complex/exp.zig2
-rw-r--r--std/math/cos.zig2
-rw-r--r--std/math/exp.zig4
-rw-r--r--std/math/exp2.zig4
-rw-r--r--std/math/expm1.zig4
-rw-r--r--std/math/floor.zig2
-rw-r--r--std/math/ln.zig4
-rw-r--r--std/math/pow.zig2
-rw-r--r--std/math/round.zig12
-rw-r--r--std/math/sin.zig2
-rw-r--r--std/math/sinh.zig2
-rw-r--r--std/math/tan.zig2
-rw-r--r--std/mem.zig42
21 files changed, 62 insertions, 69 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index e34ab677f6..6f9a2bf3ea 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -744,19 +744,19 @@ const yet_another_hex_float = 0x103.70P-5;
{#code_end#}
{#header_close#}
{#header_open|Floating Point Operations#}
- <p>By default floating point operations use <code>Optimized</code> mode,
- but you can switch to <code>Strict</code> mode on a per-block basis:</p>
+ <p>By default floating point operations use <code>Strict</code> mode,
+ but you can switch to <code>Optimized</code> mode on a per-block basis:</p>
{#code_begin|obj|foo#}
{#code_release_fast#}
const builtin = @import("builtin");
const big = f64(1 << 40);
export fn foo_strict(x: f64) f64 {
- @setFloatMode(this, builtin.FloatMode.Strict);
return x + big - big;
}
export fn foo_optimized(x: f64) f64 {
+ @setFloatMode(this, builtin.FloatMode.Optimized);
return x + big - big;
}
{#code_end#}
@@ -5948,7 +5948,7 @@ pub const FloatMode = enum {
{#code_end#}
<ul>
<li>
- <code>Optimized</code> (default) - Floating point operations may do all of the following:
+ <code>Optimized</code> - Floating point operations may do all of the following:
<ul>
<li>Assume the arguments and result are not NaN. Optimizations are required to retain defined behavior over NaNs, but the value of the result is undefined.</li>
<li>Assume the arguments and result are not +/-Inf. Optimizations are required to retain defined behavior over +/-Inf, but the value of the result is undefined.</li>
@@ -5960,7 +5960,7 @@ pub const FloatMode = enum {
This is equivalent to <code>-ffast-math</code> in GCC.
</li>
<li>
- <code>Strict</code> - Floating point operations follow strict IEEE compliance.
+ <code>Strict</code> (default) - Floating point operations follow strict IEEE compliance.
</li>
</ul>
{#see_also|Floating Point Operations#}
@@ -6166,7 +6166,7 @@ pub const TypeInfo = union(TypeId) {
size: Size,
is_const: bool,
is_volatile: bool,
- alignment: u32,
+ alignment: u29,
child: type,
pub const Size = enum {
diff --git a/src/all_types.hpp b/src/all_types.hpp
index b1e8a3746d..a8dd9dde83 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -1852,7 +1852,7 @@ struct ScopeDecls {
HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> decl_table;
bool safety_off;
AstNode *safety_set_node;
- bool fast_math_off;
+ bool fast_math_on;
AstNode *fast_math_set_node;
ImportTableEntry *import;
// If this is a scope from a container, this is the type entry, otherwise null
@@ -1872,7 +1872,7 @@ struct ScopeBlock {
bool safety_off;
AstNode *safety_set_node;
- bool fast_math_off;
+ bool fast_math_on;
AstNode *fast_math_set_node;
};
diff --git a/src/analyze.cpp b/src/analyze.cpp
index eb43575d62..a8b3ea7132 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -3073,7 +3073,7 @@ static bool scope_is_root_decls(Scope *scope) {
static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) {
add_node_error(g, proto_node,
- buf_sprintf("expected 'fn([]const u8, ?&builtin.StackTrace) unreachable', found '%s'",
+ buf_sprintf("expected 'fn([]const u8, ?*builtin.StackTrace) noreturn', found '%s'",
buf_ptr(&fn_type->name)));
}
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 56d15a43dc..7ea322c1c3 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -829,15 +829,15 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {
if (scope->id == ScopeIdBlock) {
ScopeBlock *block_scope = (ScopeBlock *)scope;
if (block_scope->fast_math_set_node)
- return !block_scope->fast_math_off;
+ return block_scope->fast_math_on;
} else if (scope->id == ScopeIdDecls) {
ScopeDecls *decls_scope = (ScopeDecls *)scope;
if (decls_scope->fast_math_set_node)
- return !decls_scope->fast_math_off;
+ return decls_scope->fast_math_on;
}
scope = scope->parent;
}
- return true;
+ return false;
}
static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
diff --git a/src/ir.cpp b/src/ir.cpp
index 363d49feed..5bf39ee691 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -15203,17 +15203,17 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_void;
}
- bool *fast_math_off_ptr;
+ bool *fast_math_on_ptr;
AstNode **fast_math_set_node_ptr;
if (target_type->id == TypeTableEntryIdBlock) {
ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;
- fast_math_off_ptr = &block_scope->fast_math_off;
+ fast_math_on_ptr = &block_scope->fast_math_on;
fast_math_set_node_ptr = &block_scope->fast_math_set_node;
} else if (target_type->id == TypeTableEntryIdFn) {
assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction);
FnTableEntry *target_fn = target_val->data.x_ptr.data.fn.fn_entry;
assert(target_fn->def_scope);
- fast_math_off_ptr = &target_fn->def_scope->fast_math_off;
+ fast_math_on_ptr = &target_fn->def_scope->fast_math_on;
fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;
} else if (target_type->id == TypeTableEntryIdMetaType) {
ScopeDecls *decls_scope;
@@ -15229,7 +15229,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));
return ira->codegen->builtin_types.entry_invalid;
}
- fast_math_off_ptr = &decls_scope->fast_math_off;
+ fast_math_on_ptr = &decls_scope->fast_math_on;
fast_math_set_node_ptr = &decls_scope->fast_math_set_node;
} else {
ir_add_error_node(ira, target_instruction->source_node,
@@ -15251,7 +15251,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_invalid;
}
*fast_math_set_node_ptr = source_node;
- *fast_math_off_ptr = (float_mode_scalar == FloatModeStrict);
+ *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);
ir_build_const_from(ira, &instruction->base);
return ira->codegen->builtin_types.entry_void;
@@ -17093,7 +17093,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry
// alignment: u32
ensure_field_index(result->type, "alignment", 3);
fields[3].special = ConstValSpecialStatic;
- fields[3].type = ira->codegen->builtin_types.entry_u32;
+ fields[3].type = get_int_type(ira->codegen, false, 29);
bigint_init_unsigned(&fields[3].data.x_bigint, attrs_type->data.pointer.alignment);
// child: type
ensure_field_index(result->type, "child", 4);
diff --git a/std/event/fs.zig b/std/event/fs.zig
index ac99f13c9b..5e7e24ff43 100644
--- a/std/event/fs.zig
+++ b/std/event/fs.zig
@@ -638,10 +638,7 @@ pub async fn readFile(loop: *Loop, file_path: []const u8, max_size: usize) ![]u8
var close_op = try CloseOperation.start(loop);
defer close_op.finish();
- const path_with_null = try std.cstr.addNullByte(loop.allocator, file_path);
- defer loop.allocator.free(path_with_null);
-
- const fd = try await (async openRead(loop, path_with_null[0..file_path.len]) catch unreachable);
+ const fd = try await (async openRead(loop, file_path) catch unreachable);
close_op.setHandle(fd);
var list = std.ArrayList(u8).init(loop.allocator);
diff --git a/std/fmt/errol/index.zig b/std/fmt/errol/index.zig
index 3222913107..8b1ffa3622 100644
--- a/std/fmt/errol/index.zig
+++ b/std/fmt/errol/index.zig
@@ -253,11 +253,7 @@ fn gethi(in: f64) f64 {
/// Normalize the number by factoring in the error.
/// @hp: The float pair.
fn hpNormalize(hp: *HP) void {
- // Required to avoid segfaults causing buffer overrun during errol3 digit output termination.
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const val = hp.val;
-
hp.val += hp.off;
hp.off += val - hp.val;
}
diff --git a/std/math/ceil.zig b/std/math/ceil.zig
index 1c429504e8..8a5221d862 100644
--- a/std/math/ceil.zig
+++ b/std/math/ceil.zig
@@ -61,10 +61,8 @@ fn ceil64(x: f64) f64 {
}
if (u >> 63 != 0) {
- @setFloatMode(this, builtin.FloatMode.Strict);
y = x - math.f64_toint + math.f64_toint - x;
} else {
- @setFloatMode(this, builtin.FloatMode.Strict);
y = x + math.f64_toint - math.f64_toint - x;
}
diff --git a/std/math/complex/exp.zig b/std/math/complex/exp.zig
index 48fb132d97..e696ee42b4 100644
--- a/std/math/complex/exp.zig
+++ b/std/math/complex/exp.zig
@@ -17,8 +17,6 @@ pub fn exp(z: var) @typeOf(z) {
}
fn exp32(z: Complex(f32)) Complex(f32) {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const exp_overflow = 0x42b17218; // max_exp * ln2 ~= 88.72283955
const cexp_overflow = 0x43400074; // (max_exp - min_denom_exp) * ln2
diff --git a/std/math/cos.zig b/std/math/cos.zig
index 71d5e4a8f6..b6a2fbffe6 100644
--- a/std/math/cos.zig
+++ b/std/math/cos.zig
@@ -37,8 +37,6 @@ const C5 = 4.16666666666665929218E-2;
//
// This may have slight differences on some edge cases and may need to replaced if so.
fn cos32(x_: f32) f32 {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const pi4a = 7.85398125648498535156e-1;
const pi4b = 3.77489470793079817668E-8;
const pi4c = 2.69515142907905952645E-15;
diff --git a/std/math/exp.zig b/std/math/exp.zig
index d6185d4f0b..cf8fd62d80 100644
--- a/std/math/exp.zig
+++ b/std/math/exp.zig
@@ -18,8 +18,6 @@ pub fn exp(x: var) @typeOf(x) {
}
fn exp32(x_: f32) f32 {
- @setFloatMode(this, builtin.FloatMode.Strict);
-
const half = []f32{ 0.5, -0.5 };
const ln2hi = 6.9314575195e-1;
const ln2lo = 1.4286067653e-6;
@@ -95,8 +93,6 @@ fn exp32(x_: f32) f32 {
}
fn exp64(x_: f64) f64 {
- @setFloatMode(this, builtin.FloatMode.Strict);
-
const half = []const f64{ 0.5, -0.5 };
const ln2hi: f64 = 6.93147180369123816490e-01;
const ln2lo: f64 = 1.90821492927058770002e-10;
diff --git a/std/math/exp2.zig b/std/math/exp2.zig
index d590b0b60b..3d8e5d692e 100644
--- a/std/math/exp2.zig
+++ b/std/math/exp2.zig
@@ -36,8 +36,6 @@ const exp2ft = []const f64{
};
fn exp2_32(x: f32) f32 {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const tblsiz = @intCast(u32, exp2ft.len);
const redux: f32 = 0x1.8p23 / @intToFloat(f32, tblsiz);
const P1: f32 = 0x1.62e430p-1;
@@ -353,8 +351,6 @@ const exp2dt = []f64{
};
fn exp2_64(x: f64) f64 {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const tblsiz = @intCast(u32, exp2dt.len / 2);
const redux: f64 = 0x1.8p52 / @intToFloat(f64, tblsiz);
const P1: f64 = 0x1.62e42fefa39efp-1;
diff --git a/std/math/expm1.zig b/std/math/expm1.zig
index 6fa0194b32..6729417f60 100644
--- a/std/math/expm1.zig
+++ b/std/math/expm1.zig
@@ -19,8 +19,6 @@ pub fn expm1(x: var) @typeOf(x) {
}
fn expm1_32(x_: f32) f32 {
- @setFloatMode(this, builtin.FloatMode.Strict);
-
if (math.isNan(x_))
return math.nan(f32);
@@ -149,8 +147,6 @@ fn expm1_32(x_: f32) f32 {
}
fn expm1_64(x_: f64) f64 {
- @setFloatMode(this, builtin.FloatMode.Strict);
-
if (math.isNan(x_))
return math.nan(f64);
diff --git a/std/math/floor.zig b/std/math/floor.zig
index 0858598eea..6ce462b10f 100644
--- a/std/math/floor.zig
+++ b/std/math/floor.zig
@@ -97,10 +97,8 @@ fn floor64(x: f64) f64 {
}
if (u >> 63 != 0) {
- @setFloatMode(this, builtin.FloatMode.Strict);
y = x - math.f64_toint + math.f64_toint - x;
} else {
- @setFloatMode(this, builtin.FloatMode.Strict);
y = x + math.f64_toint - math.f64_toint - x;
}
diff --git a/std/math/ln.zig b/std/math/ln.zig
index e78cc379e0..a560fee8ec 100644
--- a/std/math/ln.zig
+++ b/std/math/ln.zig
@@ -35,8 +35,6 @@ pub fn ln(x: var) @typeOf(x) {
}
pub fn ln_32(x_: f32) f32 {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const ln2_hi: f32 = 6.9313812256e-01;
const ln2_lo: f32 = 9.0580006145e-06;
const Lg1: f32 = 0xaaaaaa.0p-24;
@@ -89,8 +87,6 @@ pub fn ln_32(x_: f32) f32 {
}
pub fn ln_64(x_: f64) f64 {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const ln2_hi: f64 = 6.93147180369123816490e-01;
const ln2_lo: f64 = 1.90821492927058770002e-10;
const Lg1: f64 = 6.666666666666735130e-01;
diff --git a/std/math/pow.zig b/std/math/pow.zig
index 7fc334c06b..c764b58182 100644
--- a/std/math/pow.zig
+++ b/std/math/pow.zig
@@ -28,8 +28,6 @@ const assert = std.debug.assert;
// This implementation is taken from the go stlib, musl is a bit more complex.
pub fn pow(comptime T: type, x: T, y: T) T {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
if (T != f32 and T != f64) {
@compileError("pow not implemented for " ++ @typeName(T));
}
diff --git a/std/math/round.zig b/std/math/round.zig
index c8d9eb4fd4..4fe35365c8 100644
--- a/std/math/round.zig
+++ b/std/math/round.zig
@@ -35,11 +35,7 @@ fn round32(x_: f32) f32 {
return 0 * @bitCast(f32, u);
}
- {
- @setFloatMode(this, builtin.FloatMode.Strict);
- y = x + math.f32_toint - math.f32_toint - x;
- }
-
+ y = x + math.f32_toint - math.f32_toint - x;
if (y > 0.5) {
y = y + x - 1;
} else if (y <= -0.5) {
@@ -72,11 +68,7 @@ fn round64(x_: f64) f64 {
return 0 * @bitCast(f64, u);
}
- {
- @setFloatMode(this, builtin.FloatMode.Strict);
- y = x + math.f64_toint - math.f64_toint - x;
- }
-
+ y = x + math.f64_toint - math.f64_toint - x;
if (y > 0.5) {
y = y + x - 1;
} else if (y <= -0.5) {
diff --git a/std/math/sin.zig b/std/math/sin.zig
index 3796d74812..15b2f9f17a 100644
--- a/std/math/sin.zig
+++ b/std/math/sin.zig
@@ -38,8 +38,6 @@ const C5 = 4.16666666666665929218E-2;
//
// This may have slight differences on some edge cases and may need to replaced if so.
fn sin32(x_: f32) f32 {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const pi4a = 7.85398125648498535156e-1;
const pi4b = 3.77489470793079817668E-8;
const pi4c = 2.69515142907905952645E-15;
diff --git a/std/math/sinh.zig b/std/math/sinh.zig
index bb3af280ab..3105b9a26e 100644
--- a/std/math/sinh.zig
+++ b/std/math/sinh.zig
@@ -54,8 +54,6 @@ fn sinh32(x: f32) f32 {
}
fn sinh64(x: f64) f64 {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const u = @bitCast(u64, x);
const w = @intCast(u32, u >> 32);
const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
diff --git a/std/math/tan.zig b/std/math/tan.zig
index ff3ed06186..a71a17e625 100644
--- a/std/math/tan.zig
+++ b/std/math/tan.zig
@@ -31,8 +31,6 @@ const Tq4 = -5.38695755929454629881E7;
//
// This may have slight differences on some edge cases and may need to replaced if so.
fn tan32(x_: f32) f32 {
- @setFloatMode(this, @import("builtin").FloatMode.Strict);
-
const pi4a = 7.85398125648498535156e-1;
const pi4b = 3.77489470793079817668E-8;
const pi4c = 2.69515142907905952645E-15;
diff --git a/std/mem.zig b/std/mem.zig
index 1ba5b3b73e..4390f8ad5b 100644
--- a/std/mem.zig
+++ b/std/mem.zig
@@ -679,10 +679,38 @@ test "testWriteInt" {
comptime testWriteIntImpl();
}
fn testWriteIntImpl() void {
- var bytes: [4]u8 = undefined;
+ var bytes: [8]u8 = undefined;
+
+ writeInt(bytes[0..], u64(0x12345678CAFEBABE), builtin.Endian.Big);
+ assert(eql(u8, bytes, []u8{
+ 0x12,
+ 0x34,
+ 0x56,
+ 0x78,
+ 0xCA,
+ 0xFE,
+ 0xBA,
+ 0xBE,
+ }));
+
+ writeInt(bytes[0..], u64(0xBEBAFECA78563412), builtin.Endian.Little);
+ assert(eql(u8, bytes, []u8{
+ 0x12,
+ 0x34,
+ 0x56,
+ 0x78,
+ 0xCA,
+ 0xFE,
+ 0xBA,
+ 0xBE,
+ }));
writeInt(bytes[0..], u32(0x12345678), builtin.Endian.Big);
assert(eql(u8, bytes, []u8{
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
0x12,
0x34,
0x56,
@@ -695,12 +723,20 @@ fn testWriteIntImpl() void {
0x34,
0x56,
0x78,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
}));
writeInt(bytes[0..], u16(0x1234), builtin.Endian.Big);
assert(eql(u8, bytes, []u8{
0x00,
0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
0x12,
0x34,
}));
@@ -711,6 +747,10 @@ fn testWriteIntImpl() void {
0x12,
0x00,
0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
}));
}