Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop hiding the concept of sub-architecture #1526

Closed
andrewrk opened this issue Sep 14, 2018 · 3 comments
Closed

stop hiding the concept of sub-architecture #1526

andrewrk opened this issue Sep 14, 2018 · 3 comments
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@andrewrk
Copy link
Member

Right now, LLVM has the concept of architecture and sub-architecture, and the stag1 Zig compiler has this concept as well. However we hide the concept from Zig programmers, pretending there is only architecture:

$ zig targets
  armv8_3a
  armv8_2a
  armv8_1a
  armv8
  armv8r
  armv8m_baseline
  armv8m_mainline
  armv7
  armv7em
  armv7m
  armv7s
  armv7k
  armv7ve
  armv6
  armv6m
  armv6k
  armv6t2
  armv5
  armv5te
  armv4t
  armebv8_3a
  armebv8_2a
  armebv8_1a
  armebv8
  armebv8r
  armebv8m_baseline
  armebv8m_mainline
  armebv7
  armebv7em
  armebv7m
  armebv7s
  armebv7k
  armebv7ve
  armebv6
  armebv6m
  armebv6k
  armebv6t2
  armebv5
  armebv5te
  armebv4t
...

These should all be the arm architecture with a bunch of different sub-architectures.

Arguably even the thumb stuff should be sub-architecture of arm.

in @import("buitlin") this needs to change:

pub const Arch = enum {...};
...
pub const arch = Arch.x86_64;

we should make it a tagged union.

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Sep 14, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Sep 14, 2018
andrewrk added a commit that referenced this issue Oct 13, 2018
* add __multi3 compiler rt function. See #1290
* compiler rt includes ARM functions for thumb and aarch64 and
  other sub-arches left out. See #1526
* support C ABI for returning structs on ARM. see #1481
@jsonn
Copy link

jsonn commented Oct 31, 2018

What is the goal for exposing it? There are normally a couple of different dimensions when describing a platform, especially with as much variance as ARM/AArch64:
(1) Main ABI (e.g. O32 vs N32 vs N64 on MIPS)
(2) Floating ABI (on-stack passing vs CPU registers)
(3) Presence of optional architecture features for code generation
(4) For ARM: default code generation (arm mode vs thumb mode)
This is mostly reflected by the target flags in LLVM.

@andrewrk andrewrk added the accepted This proposal is planned. label Nov 21, 2018
@andrewrk
Copy link
Member Author

What is the goal for exposing it?

To avoid this:

const is_arm_64 = switch (builtin.arch) {
builtin.Arch.aarch64v8_3a,
builtin.Arch.aarch64v8_2a,
builtin.Arch.aarch64v8_1a,
builtin.Arch.aarch64v8,
builtin.Arch.aarch64v8r,
builtin.Arch.aarch64v8m_baseline,
builtin.Arch.aarch64v8m_mainline,
builtin.Arch.aarch64_bev8_3a,
builtin.Arch.aarch64_bev8_2a,
builtin.Arch.aarch64_bev8_1a,
builtin.Arch.aarch64_bev8,
builtin.Arch.aarch64_bev8r,
builtin.Arch.aarch64_bev8m_baseline,
builtin.Arch.aarch64_bev8m_mainline,
=> true,
else => false,
};
const is_arm_arch = switch (builtin.arch) {
builtin.Arch.armv8_3a,
builtin.Arch.armv8_2a,
builtin.Arch.armv8_1a,
builtin.Arch.armv8,
builtin.Arch.armv8r,
builtin.Arch.armv8m_baseline,
builtin.Arch.armv8m_mainline,
builtin.Arch.armv7,
builtin.Arch.armv7em,
builtin.Arch.armv7m,
builtin.Arch.armv7s,
builtin.Arch.armv7k,
builtin.Arch.armv7ve,
builtin.Arch.armv6,
builtin.Arch.armv6m,
builtin.Arch.armv6k,
builtin.Arch.armv6t2,
builtin.Arch.armv5,
builtin.Arch.armv5te,
builtin.Arch.armv4t,
builtin.Arch.armebv8_3a,
builtin.Arch.armebv8_2a,
builtin.Arch.armebv8_1a,
builtin.Arch.armebv8,
builtin.Arch.armebv8r,
builtin.Arch.armebv8m_baseline,
builtin.Arch.armebv8m_mainline,
builtin.Arch.armebv7,
builtin.Arch.armebv7em,
builtin.Arch.armebv7m,
builtin.Arch.armebv7s,
builtin.Arch.armebv7k,
builtin.Arch.armebv7ve,
builtin.Arch.armebv6,
builtin.Arch.armebv6m,
builtin.Arch.armebv6k,
builtin.Arch.armebv6t2,
builtin.Arch.armebv5,
builtin.Arch.armebv5te,
builtin.Arch.armebv4t,
builtin.Arch.aarch64v8_3a,
builtin.Arch.aarch64v8_2a,
builtin.Arch.aarch64v8_1a,
builtin.Arch.aarch64v8,
builtin.Arch.aarch64v8r,
builtin.Arch.aarch64v8m_baseline,
builtin.Arch.aarch64v8m_mainline,
builtin.Arch.aarch64_bev8_3a,
builtin.Arch.aarch64_bev8_2a,
builtin.Arch.aarch64_bev8_1a,
builtin.Arch.aarch64_bev8,
builtin.Arch.aarch64_bev8r,
builtin.Arch.aarch64_bev8m_baseline,
builtin.Arch.aarch64_bev8m_mainline,
builtin.Arch.thumb,
builtin.Arch.thumbeb,
=> true,
else => false,
};

and this:

/// TODO expose the arch and subarch separately
pub fn isArmOrThumb(self: Target) bool {
return switch (self.getArch()) {
builtin.Arch.armv8_3a,
builtin.Arch.armv8_2a,
builtin.Arch.armv8_1a,
builtin.Arch.armv8,
builtin.Arch.armv8r,
builtin.Arch.armv8m_baseline,
builtin.Arch.armv8m_mainline,
builtin.Arch.armv7,
builtin.Arch.armv7em,
builtin.Arch.armv7m,
builtin.Arch.armv7s,
builtin.Arch.armv7k,
builtin.Arch.armv7ve,
builtin.Arch.armv6,
builtin.Arch.armv6m,
builtin.Arch.armv6k,
builtin.Arch.armv6t2,
builtin.Arch.armv5,
builtin.Arch.armv5te,
builtin.Arch.armv4t,
builtin.Arch.armebv8_3a,
builtin.Arch.armebv8_2a,
builtin.Arch.armebv8_1a,
builtin.Arch.armebv8,
builtin.Arch.armebv8r,
builtin.Arch.armebv8m_baseline,
builtin.Arch.armebv8m_mainline,
builtin.Arch.armebv7,
builtin.Arch.armebv7em,
builtin.Arch.armebv7m,
builtin.Arch.armebv7s,
builtin.Arch.armebv7k,
builtin.Arch.armebv7ve,
builtin.Arch.armebv6,
builtin.Arch.armebv6m,
builtin.Arch.armebv6k,
builtin.Arch.armebv6t2,
builtin.Arch.armebv5,
builtin.Arch.armebv5te,
builtin.Arch.armebv4t,
builtin.Arch.thumb,
builtin.Arch.thumbeb,
=> true,
else => false,
};
}

@andrewrk
Copy link
Member Author

$ ./zig targets
Architectures:
  arm
    v8_4a
    v8_3a
    v8_2a
    v8_1a
    v8
    v8r
    v8m_baseline
    v8m_mainline
    v7
    v7em
    v7m
    v7s
    v7k
    v7ve
    v6
    v6m
    v6k
    v6t2
    v5
    v5te
    v4t
  armeb
    v8_4a
    v8_3a
    v8_2a
    v8_1a
    v8
    v8r
    v8m_baseline
    v8m_mainline
    v7
    v7em
    v7m
    v7s
    v7k
    v7ve
    v6
    v6m
    v6k
    v6t2
    v5
    v5te
    v4t
  aarch64
    v8_4a
    v8_3a
    v8_2a
    v8_1a
    v8
    v8r
    v8m_baseline
    v8m_mainline
  aarch64_be
    v8_4a
    v8_3a
    v8_2a
    v8_1a
    v8
    v8r
    v8m_baseline
    v8m_mainline
  avr
  bpfel
  bpfeb
  hexagon
  mips
  mipsel
  mips64
  mips64el
  msp430
  powerpc
  powerpc64
  powerpc64le
  r600
  amdgcn
  riscv32
  riscv64
  sparc
  sparcv9
  sparcel
  s390x
  thumb
    v8_4a
    v8_3a
    v8_2a
    v8_1a
    v8
    v8r
    v8m_baseline
    v8m_mainline
    v7
    v7em
    v7m
    v7s
    v7k
    v7ve
    v6
    v6m
    v6k
    v6t2
    v5
    v5te
    v4t
  thumbeb
    v8_4a
    v8_3a
    v8_2a
    v8_1a
    v8
    v8r
    v8m_baseline
    v8m_mainline
    v7
    v7em
    v7m
    v7s
    v7k
    v7ve
    v6
    v6m
    v6k
    v6t2
    v5
    v5te
    v4t
  i386
  x86_64 (native)
  xcore
  nvptx
  nvptx64
  lanai
  wasm32
  wasm64

Operating Systems:
  freestanding
  ananas
  cloudabi
  dragonfly
  freebsd
  fuchsia
  ios
  kfreebsd
  linux (native)
  lv2
  macosx
  netbsd
  openbsd
  solaris
  windows
  haiku
  minix
  rtems
  nacl
  cnk
  aix
  cuda
  nvcl
  amdhsa
  ps4
  elfiamcu
  tvos
  watchos
  mesa3d
  contiki
  amdpal
  zen
  uefi

C ABIs:
  none
  gnu (native)
  gnuabin32
  gnuabi64
  gnueabi
  gnueabihf
  gnux32
  code16
  eabi
  eabihf
  android
  musl
  musleabi
  musleabihf
  msvc
  itanium
  cygnus
  coreclr
  simulator
pub const Arch = union(enum) {
    arm: Arm32,
    armeb: Arm32,
    aarch64: Arm64,
    aarch64_be: Arm64,
    arc,
    avr,
    bpfel,
    bpfeb,
    hexagon,
    mips,
    mipsel,
    mips64,
    mips64el,
    msp430,
    nios2,
    powerpc,
    powerpc64,
    powerpc64le,
    r600,
    amdgcn,
    riscv32,
    riscv64,
    sparc,
    sparcv9,
    sparcel,
    s390x,
    tce,
    tcele,
    thumb: Arm32,
    thumbeb: Arm32,
    i386,
    x86_64,
    xcore,
    nvptx,
    nvptx64,
    le32,
    le64,
    amdil,
    amdil64,
    hsail,
    hsail64,
    spir,
    spir64,
    kalimba: Kalimba,
    shave,
    lanai,
    wasm32,
    wasm64,
    renderscript32,
    renderscript64,
    pub const Arm32 = enum {
        v8_4a,
        v8_3a,
        v8_2a,
        v8_1a,
        v8,
        v8r,
        v8m_baseline,
        v8m_mainline,
        v7,
        v7em,
        v7m,
        v7s,
        v7k,
        v7ve,
        v6,
        v6m,
        v6k,
        v6t2,
        v5,
        v5te,
        v4t,
    };
    pub const Arm64 = enum {
        v8_4a,
        v8_3a,
        v8_2a,
        v8_1a,
        v8,
        v8r,
        v8m_baseline,
        v8m_mainline,
    };
    pub const Kalimba = enum {
        v5,
        v4,
        v3,
    };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants