# SPDX-License-Identifier: GPL-2.0-only OR License-Ref-kk-custom
#
# Copyright (C) 2023 Kernkonzept GmbH.
# Author(s): Georg Kotheimer <georg.kotheimer@kernkonzept.com>

define x86_ARCH_SOURCES
  i386/fp_mode.c
endef

define x86_80_BIT_SOURCES
  divxc3.c
  fixxfdi.c
  fixxfti.c
  fixunsxfdi.c
  fixunsxfsi.c
  fixunsxfti.c
  floatdixf.c
  floattixf.c
  floatundixf.c
  floatuntixf.c
  mulxc3.c
  powixf2.c
endef

# Clang < 18
ifeq ($(call libclang_rt_if_min_version,18),)
  x86_ARCH_SOURCES += cpu_model.c
# Clang >= 18
else
  x86_ARCH_SOURCES += cpu_model/x86.c
  x86_80_BIT_SOURCES += extendxftf2.c trunctfxf2.c
endif

# Clang >= 20
ifneq ($(call libclang_rt_if_min_version,20),)
  x86_80_BIT_SOURCES += extendhfxf2.c truncxfhf2.c
endif

ifeq ($(BUILD_ARCH),x86)

  define BUILTINS_SRC
    $(x86_ARCH_SOURCES)
    i386/ashldi3.S
    i386/ashrdi3.S
    i386/divdi3.S
    i386/floatdidf.S
    i386/floatdisf.S
    i386/floatundidf.S
    i386/floatundisf.S
    i386/lshrdi3.S
    i386/moddi3.S
    i386/muldi3.S
    i386/udivdi3.S
    i386/umoddi3.S

    $(x86_80_BIT_SOURCES)
    i386/floatdixf.S
    i386/floatundixf.S
  endef

  else

  GENERIC_BUILTINS_SRC += $(GENERIC_SOURCES_TF)

  define BUILTINS_SRC
    $(x86_ARCH_SOURCES)
    x86_64/floatdidf.c
    x86_64/floatdisf.c
    x86_64/floatundidf.S
    x86_64/floatundisf.S

    $(x86_80_BIT_SOURCES)
    x86_64/floatdixf.c
    x86_64/floatundixf.S
  endef

endif
