From b19218f88b6e1ea3b3f645ace87c32e70e3c05c2 Mon Sep 17 00:00:00 2001 From: "S. Gilles" Date: Sun, 13 May 2018 06:52:32 -0400 Subject: [PATCH] support log and log1p --- checker/checker.myr | 4 +++- impl-libc/impl-libc.c | 24 ++++++++++++++++-------- impl-mpfr/impl-mpfr.c | 18 ++++++++++++------ impl-myrddin/impl-myrddin.myr | 2 ++ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/checker/checker.myr b/checker/checker.myr index 7bd2ff1..c959d43 100644 --- a/checker/checker.myr +++ b/checker/checker.myr @@ -52,6 +52,8 @@ const main = {args : byte[:][:] [.name = "expm1", .inputs = [`Flt][:], .outputs = [`Flt][:]], [.name = "floor", .inputs = [`Flt][:], .outputs = [`Flt][:]], [.name = "fma", .inputs = [`Flt, `Flt, `Flt][:], .outputs = [`Flt][:]], + [.name = "log", .inputs = [`Flt][:], .outputs = [`Flt][:]], + [.name = "log1p", .inputs = [`Flt][:], .outputs = [`Flt][:]], [.name = "sin", .inputs = [`Flt][:], .outputs = [`Flt][:]], [.name = "sqrt", .inputs = [`Flt][:], .outputs = [`Flt][:]], [.name = "trunc", .inputs = [`Flt][:], .outputs = [`Flt][:]], @@ -113,7 +115,7 @@ const args_width = {ts : fp_type[:], p : flt_prec const read_args = {args : byte[:][:] var exactness : exactness = `Exact var precision : flt_prec = `Single - var fn_name : byte[:] = "id" + var fn_name : byte[:] = "UNSPECIFIED" var fn : fn_desc = available_fns[0] var next_bits_fn : (b : byte[:], n : std.size -> bool) = next_rand diff --git a/impl-libc/impl-libc.c b/impl-libc/impl-libc.c index 4ddc91d..345ddfa 100644 --- a/impl-libc/impl-libc.c +++ b/impl-libc/impl-libc.c @@ -80,6 +80,10 @@ void determine_function(const char *f, action *a) a->a = A__FLT__FLT; a->f32.f32__f32 = floorf; a->f64.f64__f64 = floor; + } else if (!strcmp(f, "fma")) { + a->a = A__FLT_FLT_FLT__FLT; + a->f32.f32_f32_f32__f32 = fmaf; + a->f64.f64_f64_f64__f64 = fma; } else if (!strcmp(f, "exp")) { a->a = A__FLT__FLT; a->f32.f32__f32 = expf; @@ -88,22 +92,26 @@ void determine_function(const char *f, action *a) a->a = A__FLT__FLT; a->f32.f32__f32 = expm1f; a->f64.f64__f64 = expm1; + } else if (!strcmp(f, "log")) { + a->a = A__FLT__FLT; + a->f32.f32__f32 = logf; + a->f64.f64__f64 = log; + } else if (!strcmp(f, "log1p")) { + a->a = A__FLT__FLT; + a->f32.f32__f32 = log1pf; + a->f64.f64__f64 = log1p; } else if (!strcmp(f, "sin")) { a->a = A__FLT__FLT; a->f32.f32__f32 = sinf; a->f64.f64__f64 = sin; - } else if (!strcmp(f, "trunc")) { - a->a = A__FLT__FLT; - a->f32.f32__f32 = truncf; - a->f64.f64__f64 = trunc; - } else if (!strcmp(f, "fma")) { - a->a = A__FLT_FLT_FLT__FLT; - a->f32.f32_f32_f32__f32 = fmaf; - a->f64.f64_f64_f64__f64 = fma; } else if (!strcmp(f, "sqrt")) { a->a = A__FLT__FLT; a->f32.f32__f32 = sqrtf; a->f64.f64__f64 = sqrt; + } else if (!strcmp(f, "trunc")) { + a->a = A__FLT__FLT; + a->f32.f32__f32 = truncf; + a->f64.f64__f64 = trunc; } else { fprintf(stderr, "impl-libc: unknown function \"%s\"\n", f); _exit(1); diff --git a/impl-mpfr/impl-mpfr.c b/impl-mpfr/impl-mpfr.c index 4c95cf2..4a60bb2 100644 --- a/impl-mpfr/impl-mpfr.c +++ b/impl-mpfr/impl-mpfr.c @@ -69,18 +69,24 @@ void determine_function(const char *f, action *a) } else if (!strcmp(f, "expm1")) { a->a = A__FLT_RND__FLT; a->f.flt_rnd__flt = mpfr_expm1; - } else if (!strcmp(f, "sin")) { - a->a = A__FLT_RND__FLT; - a->f.flt_rnd__flt = mpfr_sin; - } else if (!strcmp(f, "trunc")) { - a->a = A__FLT__FLT; - a->f.flt__flt = mpfr_trunc; } else if (!strcmp(f, "fma")) { a->a = A__FLT_FLT_FLT_RND__FLT; a->f.flt_flt_flt_rnd__flt = mpfr_fma; + } else if (!strcmp(f, "log")) { + a->a = A__FLT_RND__FLT; + a->f.flt_rnd__flt = mpfr_log; + } else if (!strcmp(f, "log1p")) { + a->a = A__FLT_RND__FLT; + a->f.flt_rnd__flt = mpfr_log1p; + } else if (!strcmp(f, "sin")) { + a->a = A__FLT_RND__FLT; + a->f.flt_rnd__flt = mpfr_sin; } else if (!strcmp(f, "sqrt")) { a->a = A__FLT_RND__FLT; a->f.flt_rnd__flt = mpfr_sqrt; + } else if (!strcmp(f, "trunc")) { + a->a = A__FLT__FLT; + a->f.flt__flt = mpfr_trunc; } else { fprintf(stderr, "impl-mpfr: unknown function \"%s\"\n", f); _exit(1); diff --git a/impl-myrddin/impl-myrddin.myr b/impl-myrddin/impl-myrddin.myr index 9ce877e..76aefef 100644 --- a/impl-myrddin/impl-myrddin.myr +++ b/impl-myrddin/impl-myrddin.myr @@ -37,6 +37,8 @@ const main = {args : byte[:][:] [.name = "expm1", .f = `Flt__flt [ .f32 = math.expm1, .f64 = math.expm1]], [.name = "floor", .f = `Flt__flt [ .f32 = math.floor, .f64 = math.floor]], [.name = "fma", .f = `Flt_flt_flt__flt [ .f32 = math.fma, .f64 = math.fma]], + [.name = "log", .f = `Flt__flt [ .f32 = math.log, .f64 = math.log]], + [.name = "log1p", .f = `Flt__flt [ .f32 = math.log1p, .f64 = math.log1p]], [.name = "sqrt", .f = `Flt__flt [ .f32 = math.sqrt, .f64 = math.sqrt]], [.name = "trunc", .f = `Flt__flt [ .f32 = math.trunc, .f64 = math.trunc]], ][:] -- 2.11.4.GIT