mirror of
https://github.com/google/liblc3.git
synced 2026-04-16 12:45:31 +00:00
wasm: Remove warnings, and separate builtin backend
This commit is contained in:
committed by
Antoine SOULIER
parent
bfea2c04c1
commit
16e082c929
11
Makefile
11
Makefile
@@ -35,11 +35,13 @@ CFLAGS += -std=c11 -Wall -Wextra -Wdouble-promotion -Wvla -pedantic
|
||||
|
||||
TARGET = $(lastword $(shell $(CC) -v 2>&1 | grep "Target: "))
|
||||
|
||||
LIB_SHARED := true
|
||||
LIB_SUFFIX := so
|
||||
|
||||
ifeq ($(TARGET),wasm32)
|
||||
LIB_SHARED := false
|
||||
LIB_SUFFIX := wasm
|
||||
CFLAGS += -mbulk-memory
|
||||
CFLAGS += -Iwasm -mbulk-memory
|
||||
LDFLAGS += -nostdlib -Wl,--no-entry -Wl,--export-dynamic
|
||||
endif
|
||||
|
||||
@@ -148,8 +150,11 @@ $(BUILD_DIR)/%.o: %.cc $(MAKEFILE_DEPS)
|
||||
$(addprefix -I,$(INCLUDE)) \
|
||||
$(addprefix -D,$(DEFINE)) -MMD -MF $(@:.o=.d) -o $@
|
||||
|
||||
$(LIB): CFLAGS += -fvisibility=hidden -flto -fPIC
|
||||
$(LIB): LDFLAGS += -flto -shared
|
||||
ifeq ($(LIB_SHARED),true)
|
||||
$(LIB): CFLAGS += -fvisibility=hidden -flto -fPIC
|
||||
$(LIB): LDFLAGS += -flto -shared
|
||||
endif
|
||||
|
||||
$(LIB): $(MAKEFILE_DEPS)
|
||||
@echo " LD $(notdir $@)"
|
||||
$(V)mkdir -p $(dir $@)
|
||||
|
||||
10
src/common.h
10
src/common.h
@@ -22,17 +22,9 @@
|
||||
#include <lc3.h>
|
||||
#include "fastmath.h"
|
||||
|
||||
#include <stdalign.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __wasm32__
|
||||
#define memmove __builtin_memmove
|
||||
#define memset __builtin_memset
|
||||
#define memcpy __builtin_memcpy
|
||||
#define NULL ((void*)0)
|
||||
#else
|
||||
#include <stdalign.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef __ARM_ARCH
|
||||
#include <arm_acle.h>
|
||||
|
||||
@@ -20,26 +20,7 @@
|
||||
#define __LC3_FASTMATH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __wasm32__
|
||||
#define log10f __builtin_log10f
|
||||
#define sqrtf __builtin_sqrtf
|
||||
#define fabsf __builtin_fabsf
|
||||
#define floorf __builtin_floorf
|
||||
#define fminf __builtin_fminf
|
||||
#define fmaxf __builtin_fmaxf
|
||||
#define truncf __builtin_truncf
|
||||
// This is not exactly roundf, as this return the even value for two equally near
|
||||
// values. e.g
|
||||
// - roundf(0.5) = 1, nearbyint(0.5) = 0,
|
||||
// - roundf(1.5) = 2, nearbyint(1.5) = 2,
|
||||
// - roundf(2.5) = 3, nearbyint(2.5) = 2
|
||||
// but this builtin maps to https://webassembly.github.io/spec/core/exec/numerics.html#op-fnearest
|
||||
#define roundf __builtin_nearbyint
|
||||
#define INFINITY __builtin_inff()
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
|
||||
37
wasm/math.h
Normal file
37
wasm/math.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __LC3_MATH_H
|
||||
#define __LC3_MATH_H
|
||||
|
||||
#define INFINITY __builtin_inff()
|
||||
|
||||
#define floorf __builtin_floorf
|
||||
#define truncf __builtin_truncf
|
||||
|
||||
static inline float roundf(float x)
|
||||
{ return x >= 0 ? truncf(x + 0.5f) : truncf(x - 0.5f); }
|
||||
|
||||
#define fabsf __builtin_fabsf
|
||||
#define fmaxf __builtin_fmaxf
|
||||
#define fminf __builtin_fminf
|
||||
|
||||
#define log10f __builtin_log10f
|
||||
#define sqrtf __builtin_sqrtf
|
||||
|
||||
#endif /* __LC3_MATH_H */
|
||||
28
wasm/string.h
Normal file
28
wasm/string.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __LC3_STRING_H
|
||||
#define __LC3_STRING_H
|
||||
|
||||
#define NULL ( (void *)0 )
|
||||
|
||||
#define memcpy __builtin_memcpy
|
||||
#define memmove __builtin_memmove
|
||||
#define memset __builtin_memset
|
||||
|
||||
#endif /* __LC3_STRING_H */
|
||||
Reference in New Issue
Block a user