Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
  • This project
    • Loading...
  • Sign in / Register
S
swiftshader
  • Project
    • Overview
    • Details
    • Activity
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Chen Yisong
  • swiftshader
  • Repository

Switch branch/tag
  • swiftshader
  • third_party
  • subzero
  • src
  • IceInstX8664.h
Find file
BlameHistoryPermalink
  • Nicolas Capens's avatar
    Define constant static template members as constexpr · 3fc930f1
    Nicolas Capens authored Jul 05, 2021
    The static Opcode and Emitter members of the InstImpl<> template class
    have constant values, so we can make them constexpr and define them in
    the header.
    
    Note that we can't make them constexpr in the template class definition,
    since that requires in-class initialization, and GCC considers the
    definition of the static members of the concrete instantiations to be
    doing duplicate initialization (this might be a compiler bug, since
    Clang and MSVC allow it). Fortunately, constexpr is a specifier, which
    implies const, a qualifier, meaning a definition which is constexpr is
    compatible with a declaration which is only const. Declaring them as
    const in the class has the added benefit that if we instantiated the
    template without providing initialization of these members, we'd get a
    compilation error instead of using the in-class initializer of the
    primary template.
    
    Note also that defining these static members in the header doesn't lead
    to multiple definition errors because in C++17, static constexpr member
    variables are implicitly inline.
    
    Lastly, constexpr applied to a pointer affects the pointer value itself,
    not the pointee, so "constexpr const char *s" is a constexpr pointer to
    const characters. Thus while constexpr implies const, the second const
    isn't redundant because it applies to the pointee type.
    
    Bug: b/192890685
    Change-Id: Ia7c6a889d08007d42393979f3b08bcfc5fa8c614
    Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/55428
    Kokoro-Result: kokoro <noreply+kokoro@google.com>
    Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
    Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
    3fc930f1
IceInstX8664.h 1.21 KB
EditWeb IDE
×

Replace IceInstX8664.h

Attach a file by drag & drop or click to upload


Cancel
A new branch will be created in your fork and a new merge request will be started.