1"use strict";(self.webpackChunkmilkv_website=self.webpackChunkmilkv_website||[]).push([[1157],{12791:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>h,frontMatter:()=>r,metadata:()=>d,toc:()=>a});var t=i(85893),s=i(11151);const r={sidebar_label:"LLVM Toolchain",sidebar_position:30},o="SG2042 Thead LLVM documentation",d={id:"pioneer/resources/llvm",title:"SG2042 Thead LLVM documentation",description:"This document is about the installation and use thead llvm in SG2042.",source:"@site/docs/pioneer/resources/llvm.md",sourceDirName:"pioneer/resources",slug:"/pioneer/resources/llvm",permalink:"/docs/pioneer/resources/llvm",draft:!1,unlisted:!1,editUrl:"https://github.com/milk-v/milkv.io/edit/main/docs/pioneer/resources/llvm.md",tags:[],version:"current",sidebarPosition:30,frontMatter:{sidebar_label:"LLVM Toolchain",sidebar_position:30},sidebar:"pioneer",previous:{title:"InferLLM",permalink:"/docs/pioneer/resources/inferllm"},next:{title:"ZCC Toolchain",permalink:"/docs/pioneer/resources/zcc"}},l={},a=[{value:"1. Current status",id:"1-current-status",level:2},{value:"2. How to build",id:"2-how-to-build",level:2},{value:"2.1 Install prerequisites",id:"21-install-prerequisites",level:3},{value:"2.2 Build steps",id:"22-build-steps",level:3},{value:"3. How to use",id:"3-how-to-use",level:2}];function c(e){const n={a:"a",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",...(0,s.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.h1,{id:"sg2042-thead-llvm-documentation",children:"SG2042 Thead LLVM documentation"}),"\n",(0,t.jsx)(n.p,{children:"This document is about the installation and use thead llvm in SG2042."}),"\n",(0,t.jsx)(n.h2,{id:"1-current-status",children:"1. Current status"}),"\n",(0,t.jsxs)(n.p,{children:["Thead vendor extensions are extensions which are not standardized by RISC-V International, and are instead defined by a thead hardware. Check spec ",(0,t.jsx)(n.a,{href:"https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.2.2/xthead-2023-01-30-2.2.2.pdf",children:"Here"})]}),"\n",(0,t.jsxs)(n.p,{children:["Instructions are prefixed with ",(0,t.jsx)(n.code,{children:"th."})," as described in the specification. There are 13 vendor extensions in spec, but llvm supports 11 vendor extensions\uff0cthey are:"]}),"\n",(0,t.jsxs)(n.ol,{children:["\n",(0,t.jsx)(n.li,{children:"XTHeadBa, address-generation."}),"\n",(0,t.jsx)(n.li,{children:"XTHeadBb, basic bit-manipulation."}),"\n",(0,t.jsx)(n.li,{children:"XTHeadBs, single-bit operations"}),"\n",(0,t.jsx)(n.li,{children:"XTHeadCondMov, conditional move"}),"\n",(0,t.jsx)(n.li,{children:"XTHeadCmo, cache management operations"}),"\n",(0,t.jsx)(n.li,{children:"XTHeadFMemIdx, indexed memory operations for floating point"}),"\n",(0,t.jsx)(n.li,{children:"XTheadMac, multiply-accumulate instructions"}),"\n",(0,t.jsx)(n.li,{children:"XTHeadMemIdx, indexed memory operations"}),"\n",(0,t.jsx)(n.li,{children:"XTHeadMemPair\uff0ctwo-GPR memory operations"}),"\n",(0,t.jsx)(n.li,{children:"XTHeadSync\uff0cmulti-core synchronization instructions"}),"\n",(0,t.jsx)(n.li,{children:"XTHeadVdot, version 1.0.0 of the THeadV-family custom instructions"}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"2-how-to-build",children:"2. How to build"}),"\n",(0,t.jsx)(n.h3,{id:"21-install-prerequisites",children:"2.1 Install prerequisites"}),"\n",(0,t.jsx)(n.p,{children:"Several standard packages are needed to build the toolchain, so we need to prepare the build environment before build. Using ubuntu as an example\uff1a"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{children:"$ apt-get -y install flex bison git-core build-essential ninja-build libssh-dev libc6-dev python3-pip clang cmake\n"})}),"\n",(0,t.jsx)(n.h3,{id:"22-build-steps",children:"2.2 Build steps"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{children:'$ git clone [email protected]:llvm/llvm-project.git\n$ cd llvm-project\n$ mkdir build && cd build\n$ cmake -DLLVM_TARGETS_TO_BUILD="RISCV" -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE="RELEASE" -G Ninja ../llvm\n$ ninja\n'})}),"\n",(0,t.jsx)(n.h2,{id:"3-how-to-use",children:"3. How to use"}),"\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.code,{children:"$.example, test.c"})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{children:"unsigned int clz_32(unsigned int a) {\n return __builtin_riscv_clz_32(a);\n}\n"})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{children:"$llvm-project/build/bin/clang -march=rv64gc_zfh_xtheadba_xtheadbb_xtheadbs_xtheadcmo_xtheadcondmov_xtheadfmemidx_xtheadmac_xtheadmemidx_xtheadmempair_xtheadsync test.c \n"})}),"\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.em,{children:"Notes: If we add the -S option\uff0cwe can see the thead instruction."})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{children:" not a0, a0\n slli a0, a0, 32\n th.ff0 a0, a0 ----- the thead instruction.\n ret\n"})})]})}function h(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(c,{...e})}):c(e)}},11151:(e,n,i)=>{i.d(n,{Z:()=>d,a:()=>o});var t=i(67294);const s={},r=t.createContext(s);function o(e){const n=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),t.createElement(r.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.