From 48c69091601cedbaa75ff9f82bcae98bd89d4242 Mon Sep 17 00:00:00 2001 From: Anil Mahtani <929854+Anilm3@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:53:09 +0100 Subject: [PATCH] Use SSE4.1 ceilf when available and add badges to readme (#288) --- .github/workflows/fuzz.yml | 8 ++++++-- README.md | 5 +++++ src/glibc-compat/math.c | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index be48cf87b..bede5f6c4 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -1,11 +1,15 @@ name: Fuzz on: - # schedule: - # - cron: 30 0 * * * pull_request: branches: - "**" + push: + branches: [ master ] + tags: + - "*" + schedule: + - cron: 30 0 * * * workflow_dispatch: inputs: duration: diff --git a/README.md b/README.md index e5cc41598..b09717713 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ [![Build](https://github.com/DataDog/libddwaf/actions/workflows/build.yml/badge.svg)](https://github.com/DataDog/libddwaf/actions/workflows/build.yml) +[![Test](https://github.com/DataDog/libddwaf/actions/workflows/test.yml/badge.svg)](https://github.com/DataDog/libddwaf/actions/workflows/test.yml) +[![fuzz](https://github.com/DataDog/libddwaf/actions/workflows/fuzz.yml/badge.svg)](https://github.com/DataDog/libddwaf/actions/workflows/fuzz.yml) +[![Coverage status](https://codecov.io/github/DataDog/libddwaf/coverage.svg?branch=master)](https://codecov.io/github/DataDog/libddwaf?branch=master) +[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](LICENSE) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) # Datadog's WAF & RASP Engine diff --git a/src/glibc-compat/math.c b/src/glibc-compat/math.c index a330b004b..f5431e196 100644 --- a/src/glibc-compat/math.c +++ b/src/glibc-compat/math.c @@ -21,6 +21,18 @@ static float ceilf_local(float x) return x; } #else +#if defined(__x86_64__) +static float ceilf_local_sse41(float x) +{ + float result; + __asm__( + "roundss $0x0A, %[x], %[result]" + : [result] "=x" (result) + : [x] "x" (x) + ); + return result; +} +#endif /* fp_force_eval ensures that the input value is computed when that's otherwise unused. To prevent the constant folding of the input expression, an additional fp_barrier may be needed or a compilation @@ -79,7 +91,16 @@ float ceilf(float x) if (unlikely(ceilf_global_ == NULL)) { void *ceilf_sym = dlsym(RTLD_DEFAULT, "ceilf"); if (ceilf_sym == NULL || ceilf_sym == &ceilf) { +#if defined(__x86_64__) + __builtin_cpu_init(); + if (__builtin_cpu_supports("sse4.1")) { + ceilf_global_ = &ceilf_local_sse41; + } else { + ceilf_global_ = &ceilf_local; + } +# else ceilf_global_ = &ceilf_local; +#endif } else { ceilf_global_ = (ceilf_t)ceilf_sym; }