blob: 8edef1f14f565466245e3f8151d27f732913e33a [file] [log] [blame]
Dan Willemsenbc60c3c2021-12-15 01:09:00 -08001// run
2
3// Copyright 2021 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package main
8
9import "fmt"
10
11func f(x uint64) uint64 {
12 s := "\x04"
13 c := s[0]
14 return x - x<<c<<4
15}
16
17func g(x uint32) uint32 {
18 s := "\x04"
19 c := s[0]
20 return x - x<<c<<4
21}
22
23func main() {
24 if want, got := uint64(0xffffffffffffff01), f(1); want != got {
25 panic(fmt.Sprintf("want %x got %x", want, got))
26 }
27 if want, got := uint32(0xffffff01), g(1); want != got {
28 panic(fmt.Sprintf("want %x got %x", want, got))
29 }
30}